flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
msg_buf.h
Go to the documentation of this file.
1#ifndef FLEXPTP_MSG_BUF
2#define FLEXPTP_MSG_BUF
3
4#include <stdbool.h>
5#include <stdint.h>
6
7#include "ptp_types.h"
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#define MSGBUF_TTL_DONT_AGE (0xFFFFFFFF)
14
15#define MSGBUF_TAG_OVERWRITE (0x80000000)
16
20typedef struct {
21 bool allocated;
22 bool committed;
23 bool sent;
24 uint32_t tag;
25 uint32_t uid;
26 uint32_t ttl;
29
33typedef enum {
39
43typedef struct {
44 uint32_t n;
45 uint32_t used;
46 uint32_t lastUId;
47 uint32_t error;
49} PtpMsgBuf;
50
58void msgb_init(PtpMsgBuf *buf, PtpMsgBufBlock *pool, uint32_t n);
59
70RawPtpMessage *msgb_alloc(PtpMsgBuf *buf, uint32_t tag, uint32_t ttl);
71
79void msgb_commit(PtpMsgBuf *buf, RawPtpMessage *msg);
80
87void msgb_free(PtpMsgBuf *buf, RawPtpMessage *msg);
88
97
106RawPtpMessage *msgb_get_by_uid(PtpMsgBuf *buf, uint32_t uid);
107
114void msgb_set_sent(PtpMsgBuf *buf, RawPtpMessage *msg);
115
124uint32_t msgb_get_uid(const PtpMsgBuf *buf, const RawPtpMessage *msg);
125
134RawPtpMessage *msgb_get_sent_by_tag(PtpMsgBuf *buf, uint32_t tag);
135
141void msgb_tick(PtpMsgBuf *buf);
142
148void msgb_report(PtpMsgBuf *buf);
149
156uint32_t msgb_get_error(PtpMsgBuf * buf);
157
158#ifdef __cplusplus
159}
160#endif
161
162#endif /* FLEXPTP_MSG_BUF */
void msgb_set_sent(PtpMsgBuf *buf, RawPtpMessage *msg)
Definition: msg_buf.c:216
RawPtpMessage * msgb_get_oldest(PtpMsgBuf *buf)
Definition: msg_buf.c:143
RawPtpMessage * msgb_get_by_uid(PtpMsgBuf *buf, uint32_t uid)
Definition: msg_buf.c:170
void msgb_report(PtpMsgBuf *buf)
Definition: msg_buf.c:240
void msgb_init(PtpMsgBuf *buf, PtpMsgBufBlock *pool, uint32_t n)
Definition: msg_buf.c:12
PtpMsgBufError
Error enumeration for the message buffer.
Definition: msg_buf.h:33
@ MSGB_ERR_FULL
The buffer is full, cannot allocate a slot.
Definition: msg_buf.h:35
@ MSGB_ERR_MISC
Miscellaneous allocation error.
Definition: msg_buf.h:37
@ MSGB_ERR_EXISTS
An allocated message has already been stored under the same tag.
Definition: msg_buf.h:36
@ MSGB_ERR_NONE
No error.
Definition: msg_buf.h:34
void msgb_commit(PtpMsgBuf *buf, RawPtpMessage *msg)
Definition: msg_buf.c:98
RawPtpMessage * msgb_get_sent_by_tag(PtpMsgBuf *buf, uint32_t tag)
Definition: msg_buf.c:197
uint32_t msgb_get_uid(const PtpMsgBuf *buf, const RawPtpMessage *msg)
Definition: msg_buf.c:221
RawPtpMessage * msgb_alloc(PtpMsgBuf *buf, uint32_t tag, uint32_t ttl)
Definition: msg_buf.c:39
void msgb_free(PtpMsgBuf *buf, RawPtpMessage *msg)
Definition: msg_buf.c:115
void msgb_tick(PtpMsgBuf *buf)
Definition: msg_buf.c:226
uint32_t msgb_get_error(PtpMsgBuf *buf)
Definition: msg_buf.c:253
This module defines the fundamental PTP message and state machine type, flags, bitfields and the PTP ...
PTP message buffer entry.
Definition: msg_buf.h:20
bool allocated
This block has been allocated.
Definition: msg_buf.h:21
uint32_t tag
Block tag.
Definition: msg_buf.h:24
bool committed
This block has been committed.
Definition: msg_buf.h:22
RawPtpMessage msg
The contained PTP message.
Definition: msg_buf.h:27
bool sent
This block has been sent.
Definition: msg_buf.h:23
uint32_t ttl
Time-to-Live in ticks.
Definition: msg_buf.h:26
uint32_t uid
Unique ID, a sequence number.
Definition: msg_buf.h:25
PTP message buffer.
Definition: msg_buf.h:43
PtpMsgBufBlock * blocks
Block pool.
Definition: msg_buf.h:48
uint32_t n
Number of blocks.
Definition: msg_buf.h:44
uint32_t used
Number of used blocks.
Definition: msg_buf.h:45
uint32_t lastUId
Last UID.
Definition: msg_buf.h:46
uint32_t error
Last error.
Definition: msg_buf.h:47