flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
msg_buf.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include "ptp_types.h"

Go to the source code of this file.

Data Structures

struct  PtpMsgBufBlock
 PTP message buffer entry. More...
 
struct  PtpMsgBuf
 PTP message buffer. More...
 

Macros

#define MSGBUF_TTL_DONT_AGE   (0xFFFFFFFF)
 Do not age messages.
 
#define MSGBUF_TAG_OVERWRITE   (0x80000000)
 Overwrite if a message exists with the same tag.
 

Enumerations

enum  PtpMsgBufError { MSGB_ERR_NONE = 0 , MSGB_ERR_FULL , MSGB_ERR_EXISTS , MSGB_ERR_MISC }
 Error enumeration for the message buffer. More...
 

Functions

void msgb_init (PtpMsgBuf *buf, PtpMsgBufBlock *pool, uint32_t n)
 
RawPtpMessagemsgb_alloc (PtpMsgBuf *buf, uint32_t tag, uint32_t ttl)
 
void msgb_commit (PtpMsgBuf *buf, RawPtpMessage *msg)
 
void msgb_free (PtpMsgBuf *buf, RawPtpMessage *msg)
 
RawPtpMessagemsgb_get_oldest (PtpMsgBuf *buf)
 
RawPtpMessagemsgb_get_by_uid (PtpMsgBuf *buf, uint32_t uid)
 
void msgb_set_sent (PtpMsgBuf *buf, RawPtpMessage *msg)
 
uint32_t msgb_get_uid (const PtpMsgBuf *buf, const RawPtpMessage *msg)
 
RawPtpMessagemsgb_get_sent_by_tag (PtpMsgBuf *buf, uint32_t tag)
 
void msgb_tick (PtpMsgBuf *buf)
 
void msgb_report (PtpMsgBuf *buf)
 
uint32_t msgb_get_error (PtpMsgBuf *buf)
 

Macro Definition Documentation

◆ MSGBUF_TAG_OVERWRITE

#define MSGBUF_TAG_OVERWRITE   (0x80000000)

Overwrite if a message exists with the same tag.

Definition at line 15 of file msg_buf.h.

◆ MSGBUF_TTL_DONT_AGE

#define MSGBUF_TTL_DONT_AGE   (0xFFFFFFFF)

Do not age messages.

Definition at line 13 of file msg_buf.h.

Enumeration Type Documentation

◆ PtpMsgBufError

Error enumeration for the message buffer.

Enumerator
MSGB_ERR_NONE 

No error.

MSGB_ERR_FULL 

The buffer is full, cannot allocate a slot.

MSGB_ERR_EXISTS 

An allocated message has already been stored under the same tag.

MSGB_ERR_MISC 

Miscellaneous allocation error.

Definition at line 33 of file msg_buf.h.

Function Documentation

◆ msgb_alloc()

RawPtpMessage * msgb_alloc ( PtpMsgBuf buf,
uint32_t  tag,
uint32_t  ttl 
)

Allocate a block.

Parameters
bufpointer to the PtpMsgBuf object
tagunique tag
ttlTime-to-Live in ticks
Returns
pointer to a RawPtpMessage object or NULL if there's a block already allocated with the current tag or the buffer is full

Definition at line 39 of file msg_buf.c.

◆ msgb_commit()

void msgb_commit ( PtpMsgBuf buf,
RawPtpMessage msg 
)

Commit a previous allocation, make the message available for later pulling.

Parameters
bufpointer to the PtpMsgBuf object
msgpointer to the allocated message

Definition at line 98 of file msg_buf.c.

◆ msgb_free()

void msgb_free ( PtpMsgBuf buf,
RawPtpMessage msg 
)

Release an allocated message block.

Parameters
bufpointer to the PtpMsgBuf object
msgpointer to the allocated message

Definition at line 115 of file msg_buf.c.

◆ msgb_get_by_uid()

RawPtpMessage * msgb_get_by_uid ( PtpMsgBuf buf,
uint32_t  uid 
)

Get message by its UID.

Parameters
bufpointer to the PtpMsgBuf object
uiduid of the message sought
Returns
message with the UID or NULL if not found

Definition at line 170 of file msg_buf.c.

◆ msgb_get_error()

uint32_t msgb_get_error ( PtpMsgBuf buf)

Read and clear last error.

Parameters
bufpointer to the PtpMsgBuf object
Returns
error code

Definition at line 253 of file msg_buf.c.

◆ msgb_get_oldest()

RawPtpMessage * msgb_get_oldest ( PtpMsgBuf buf)

Get oldest message from the buffer. (i.e. sequential reading)

Parameters
bufpointer to the PtpMsgBuf object
Returns
pointer to the oldest message or NULL if the buffer is empty

Definition at line 143 of file msg_buf.c.

◆ msgb_get_sent_by_tag()

RawPtpMessage * msgb_get_sent_by_tag ( PtpMsgBuf buf,
uint32_t  tag 
)

Get sent message by tag.

Parameters
bufpointer to the PtpMsgBuf object
tagtag of the message sought
Returns
message with the tag or NULL if not found

Definition at line 197 of file msg_buf.c.

◆ msgb_get_uid()

uint32_t msgb_get_uid ( const PtpMsgBuf buf,
const RawPtpMessage msg 
)

Get the UID of an allocated message.

Parameters
bufpointer to PtpMsgBuf object
msgpointer to an allocated message
Returns
message UID

Definition at line 221 of file msg_buf.c.

◆ msgb_init()

void msgb_init ( PtpMsgBuf buf,
PtpMsgBufBlock pool,
uint32_t  n 
)

Initialize PTP message buffer.

Parameters
bufpointer to an empty (non-initialized) PtpMsgBuf object
poolpointer to an allocated pool for n pieces of PtpMsgBufEntry
nnumber of supported elements

Definition at line 12 of file msg_buf.c.

◆ msgb_report()

void msgb_report ( PtpMsgBuf buf)

Report the message buffer state.

Parameters
bufpointer to the PtpMsgBuf object

Definition at line 240 of file msg_buf.c.

◆ msgb_set_sent()

void msgb_set_sent ( PtpMsgBuf buf,
RawPtpMessage msg 
)

Set sent flag for a message.

Parameters
bufpointer to PtpMsgBuf object
msgpointer to an allocated message

Definition at line 216 of file msg_buf.c.

◆ msgb_tick()

void msgb_tick ( PtpMsgBuf buf)

Tick the storage.

Parameters
bufpointer to the PtpMsgBuf object

Definition at line 226 of file msg_buf.c.