flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
msg_buf.c File Reference
#include "msg_buf.h"
#include <stdlib.h>
#include "minmax.h"
#include "ptp_core.h"

Go to the source code of this file.

Macros

#define MSGB_DEBUG   0
 Message buffer debugging.
 
#define RAW_MSG_TO_BLOCK(rmsg)   ((PtpMsgBufBlock *)(((uint8_t *)(rmsg)) - (sizeof(PtpMsgBufBlock) - sizeof(RawPtpMessage))))
 Get block address by message address.
 

Functions

void msgb_init (PtpMsgBuf *buf, PtpMsgBufBlock *pool, uint32_t n)
 
static PtpMsgBufBlockmsgb_get_entry_by_tag (PtpMsgBuf *buf, uint32_t tag)
 
static void msgb_free_block (PtpMsgBuf *buf, PtpMsgBufBlock *block)
 
RawPtpMessagemsgb_alloc (PtpMsgBuf *buf, uint32_t tag, uint32_t ttl)
 
void msgb_commit (PtpMsgBuf *buf, RawPtpMessage *msg)
 
void msgb_free (PtpMsgBuf *buf, RawPtpMessage *msg)
 
static PtpMsgBufBlockmsgb_get_oldest_block (PtpMsgBuf *buf)
 
RawPtpMessagemsgb_get_oldest (PtpMsgBuf *buf)
 
static PtpMsgBufBlockmsgb_get_block_by_uid (PtpMsgBuf *buf, uint32_t uid)
 
RawPtpMessagemsgb_get_by_uid (PtpMsgBuf *buf, uint32_t uid)
 
static PtpMsgBufBlockmsgb_get_sent_block_by_tag (PtpMsgBuf *buf, uint32_t tag)
 
RawPtpMessagemsgb_get_sent_by_tag (PtpMsgBuf *buf, uint32_t tag)
 
static void msgb_set_block_sent (PtpMsgBuf *buf, PtpMsgBufBlock *block)
 
void msgb_set_sent (PtpMsgBuf *buf, RawPtpMessage *msg)
 
uint32_t msgb_get_uid (const PtpMsgBuf *buf, const RawPtpMessage *msg)
 
void msgb_tick (PtpMsgBuf *buf)
 
void msgb_report (PtpMsgBuf *buf)
 
uint32_t msgb_get_error (PtpMsgBuf *buf)
 

Macro Definition Documentation

◆ MSGB_DEBUG

#define MSGB_DEBUG   0

Message buffer debugging.

Definition at line 9 of file msg_buf.c.

◆ RAW_MSG_TO_BLOCK

#define RAW_MSG_TO_BLOCK (   rmsg)    ((PtpMsgBufBlock *)(((uint8_t *)(rmsg)) - (sizeof(PtpMsgBufBlock) - sizeof(RawPtpMessage))))

Get block address by message address.

Definition at line 96 of file msg_buf.c.

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_free_block()

static void msgb_free_block ( PtpMsgBuf buf,
PtpMsgBufBlock block 
)
static

Release an allocated block.

Parameters
bufpointer to the PtpMsgBuf object
blockpointer to a previously allocated block

Definition at line 109 of file msg_buf.c.

◆ msgb_get_block_by_uid()

static PtpMsgBufBlock * msgb_get_block_by_uid ( PtpMsgBuf buf,
uint32_t  uid 
)
static

Get block by its UID.

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

Definition at line 160 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_entry_by_tag()

static PtpMsgBufBlock * msgb_get_entry_by_tag ( PtpMsgBuf buf,
uint32_t  tag 
)
static

Retrieve entry by tag.

Parameters
bufpointer to PtpMsgBuf object
tagblock tag
Returns
corresponding allocated entry if found OR NULL

Definition at line 27 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_oldest_block()

static PtpMsgBufBlock * msgb_get_oldest_block ( PtpMsgBuf buf)
static

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

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

Definition at line 127 of file msg_buf.c.

◆ msgb_get_sent_block_by_tag()

static PtpMsgBufBlock * msgb_get_sent_block_by_tag ( PtpMsgBuf buf,
uint32_t  tag 
)
static

Get sent block by tag.

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

Definition at line 187 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_block_sent()

static void msgb_set_block_sent ( PtpMsgBuf buf,
PtpMsgBufBlock block 
)
static

Set sent flag in a block.

Parameters
bufpointer to PtpMsgBuf object
blockpointer to a block

Definition at line 212 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.