flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
ptp_raw_msg_circbuf.h File Reference

This module implements a circular buffer that is used for accepting and omitting received and to be transmissed packets in a controlled way. The implementation does not rely on any OS features, will not block. More...

#include <stdbool.h>
#include "ptp_types.h"

Go to the source code of this file.

Data Structures

struct  PtpCircBuf
 "Ring" buffer for PTP-messages. More...
 

Functions

void ptp_circ_buf_init (PtpCircBuf *pCircBuf, RawPtpMessage *pMsgPool, uint8_t n)
 
RawPtpMessageptp_circ_buf_alloc (PtpCircBuf *pCircBuf)
 
int ptp_circ_buf_commit (PtpCircBuf *pCircBuf)
 
void ptp_circ_buf_free (PtpCircBuf *pCircBuf)
 
RawPtpMessageptp_circ_buf_get (PtpCircBuf *pCircBuf, uint8_t idx)
 

Detailed Description

This module implements a circular buffer that is used for accepting and omitting received and to be transmissed packets in a controlled way. The implementation does not rely on any OS features, will not block.

Definition in file ptp_raw_msg_circbuf.h.

Function Documentation

◆ ptp_circ_buf_alloc()

RawPtpMessage * ptp_circ_buf_alloc ( PtpCircBuf pCircBuf)

Allocate an available buffer area from the circular buffer.

Parameters
pCircBufpointer to an existing PtpCircBuf object
Returns
pointer to the allocated area or NULL on failure

Definition at line 12 of file ptp_raw_msg_circbuf.c.

◆ ptp_circ_buf_commit()

int ptp_circ_buf_commit ( PtpCircBuf pCircBuf)

Commit last allocation, claim the first available area. The first available area can be obtained through ptp_circ_buf_alloc().

Parameters
pCircBufpointer to an existing PtpCircBuf object

Definition at line 22 of file ptp_raw_msg_circbuf.c.

◆ ptp_circ_buf_free()

void ptp_circ_buf_free ( PtpCircBuf pCircBuf)

Release the oldest allocation.

Parameters
pCircBufpointer to an existing PtpCircBuf object

Definition at line 33 of file ptp_raw_msg_circbuf.c.

◆ ptp_circ_buf_get()

RawPtpMessage * ptp_circ_buf_get ( PtpCircBuf pCircBuf,
uint8_t  idx 
)

Peek an allocated area by index. Read the circular buffer like it was an array.

Parameters
pCircBufpointer to an existing PtpCircBuf object
idxindex of the allocation
Returns
pointer to the area or NULL if is idx is out of bounds

Definition at line 39 of file ptp_raw_msg_circbuf.c.

◆ ptp_circ_buf_init()

void ptp_circ_buf_init ( PtpCircBuf pCircBuf,
RawPtpMessage pMsgPool,
uint8_t  n 
)

Initialize circular buffer.

Parameters
pCircBufpointer to an empty (non-initialized) PtpCircBuf object
pMsgPoolpointer to an allocated pool that supports holding at least n full PTP messages
nnumber of supported elements

Definition at line 3 of file ptp_raw_msg_circbuf.c.