19#include <flexptp_options.h>
26#define MIN(a, b) (((a) < (b)) ? (a) : (b))
30static TaskHandle_t sTH;
31static uint8_t sPrio = FLEXPTP_TASK_PRIORITY;
32static uint16_t sStkSize = 2048;
36static bool sPTP_operating =
false;
43#define RX_PACKET_FIFO_LENGTH (32)
44#define TX_PACKET_FIFO_LENGTH (16)
45#define EVENT_FIFO_LENGTH (32)
49static QueueHandle_t sRxPacketFIFO, sEventFIFO;
50QueueHandle_t gTxPacketFIFO;
51static QueueSetHandle_t sRxTxEvFIFOSet;
66 xQueueAddToSet(sRxPacketFIFO, sRxTxEvFIFOSet);
67 xQueueAddToSet(gTxPacketFIFO, sRxTxEvFIFOSet);
68 xQueueAddToSet(sEventFIFO, sRxTxEvFIFOSet);
78 xQueueRemoveFromSet(sRxPacketFIFO, sRxTxEvFIFOSet);
79 xQueueRemoveFromSet(gTxPacketFIFO, sRxTxEvFIFOSet);
80 xQueueRemoveFromSet(sEventFIFO, sRxTxEvFIFOSet);
81 vQueueDelete(sRxPacketFIFO);
82 vQueueDelete(gTxPacketFIFO);
83 vQueueDelete(sEventFIFO);
84 vQueueDelete(sRxTxEvFIFOSet);
94#ifdef PTP_USER_EVENT_CALLBACK
104 MSG(
"Loading PTP-config!\n");
117 BaseType_t result = xTaskCreate(
task_ptp,
"ptp", sStkSize / 4, NULL, sPrio, &sTH);
118 if (result != pdPASS) {
119 MSG(
"Failed to create PTP task! (errcode: %d)\n", result);
124 sPTP_operating =
true;
133 sPTP_operating =
false;
137 return xQueueSend(sEventFIFO, event, portMAX_DELAY) == pdPASS;
152 memcpy(pMsg->
data, pPayload, copyLen);
153 pMsg->
size = copyLen;
154 pMsg->
ts.
sec = ts_sec;
161 xQueueSend(sRxPacketFIFO, &idx, portMAX_DELAY);
163 MSG(
"PTP-packet buffer full, a packet has been dropped!\n");
173 extern QueueHandle_t gTxPacketFIFO;
178 BaseType_t hptWoken =
false;
179 if (xPortIsInsideInterrupt()) {
180 xQueueSendFromISR(gTxPacketFIFO, &idx, (BaseType_t *)&hptWoken);
182 xQueueSend(gTxPacketFIFO, &idx, portMAX_DELAY);
186 MSG(
"PTP TX Enqueue failed!\n");
196 QueueHandle_t activeQueue = xQueueSelectFromSet(sRxTxEvFIFOSet, pdMS_TO_TICKS(200));
199 if (activeQueue == sRxPacketFIFO) {
202 xQueueReceive(sRxPacketFIFO, &bufIdx, portMAX_DELAY);
206 pRawMsg->
pTs = &pRawMsg->
ts;
213 }
else if (activeQueue == gTxPacketFIFO) {
216 xQueueReceive(gTxPacketFIFO, &bufIdx, portMAX_DELAY);
221 }
else if (activeQueue == sEventFIFO) {
224 xQueueReceive(sEventFIFO, &event, portMAX_DELAY);
238 return sPTP_operating;
void ptp_load_config_from_dump(const void *pDump)
This module defines functions for storing and loading flexPTP configurations.
In this module are the core and user events defined.
@ PTP_UEV_QUEUE_ERROR
This event signals that the flexPTP's internal transmission output queue is full and blocked.
This file is a header for the employed Network Stack Driver (NSD). A NSD must define ALL four functio...
void ptp_nsd_transmit_msg(RawPtpMessage *pMsg)
void ptp_nsd_init(PtpTransportType tp, PtpDelayMechanism dm)
PtpCircBuf gRawTxMsgBuf
Output circular buffers.
void ptp_nsd_get_interface_address(uint8_t *hwa)
PtpCircBuf gRawRxMsgBuf
Input circular buffer.
This module implements defines a single method that prints a verbose summary of the operating PTP pro...
void ptp_process_event(const PtpCoreEvent *event)
void ptp_init(const uint8_t *hwa)
void ptp_process_packet(RawPtpMessage *pRawMsg)
void ptp_set_user_event_callback(PtpUserEventCallback userEventCb)
Core of the PTP implementation. Defines functions for message processing, clock tuning,...
RawPtpMessage * ptp_circ_buf_alloc(PtpCircBuf *pCircBuf)
void ptp_circ_buf_free(PtpCircBuf *pCircBuf)
int ptp_circ_buf_commit(PtpCircBuf *pCircBuf)
RawPtpMessage * ptp_circ_buf_get(PtpCircBuf *pCircBuf, uint8_t idx)
void ptp_circ_buf_init(PtpCircBuf *pCircBuf, RawPtpMessage *pMsgPool, uint8_t n)
This module implements a circular buffer that is used for accepting and omitting received and to be t...
#define MAX_PTP_MSG_SIZE
Maximum PTP message size.
PtpDelayMechanism ptp_get_delay_mechanism()
PtpTransportType ptp_get_transport_type()
This module features functions to tweak around the PTP engine's almost every property.
"Ring" buffer for PTP-messages.
Raw PTP message structure.
void(* pTxCb)(const struct RawPtpMessage_ *pMsg)
transmit callback function
uint32_t size
Packet size.
TimestampI * pTs
pointer to timestamp
uint8_t data[(128)]
raw packet data
int32_t nanosec
nanoseconds
void ptp_receive_enqueue(const void *pPayload, uint32_t len, uint32_t ts_sec, uint32_t ts_ns, int tp)
static void task_ptp(void *pParam)
bool ptp_transmit_enqueue(const RawPtpMessage *pMsg)
static void ptp_create_message_queues()
static void ptp_destroy_message_queues()
#define EVENT_FIFO_LENGTH
Event FIFO length.
bool ptp_event_enqueue(const PtpCoreEvent *event)
bool task_ptp_is_operating()
#define RX_PACKET_FIFO_LENGTH
Receive packet FIFO length.
#define TX_PACKET_FIFO_LENGTH
Transmit packet FIFO length.
The entry point of the whole PTP-implementation. Calling reg_task_ptp() initializes the PTP-engine,...