flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
task_ptp.c File Reference
#include "task_ptp.h"
#include <string.h>
#include "config.h"
#include "event.h"
#include "flexptp/port/osless/fifo.h"
#include "msg_buf.h"
#include "network_stack_driver.h"
#include "profiles.h"
#include "ptp_core.h"
#include "ptp_defs.h"
#include "ptp_types.h"
#include "settings_interface.h"
#include <flexptp_options.h>
#include <time.h>
#include "minmax.h"

Go to the source code of this file.

Data Structures

struct  TxTs
 Structure for communicating transmit timestamp writeback. More...
 

Macros

#define RX_PACKET_FIFO_LENGTH   (16)
 Receive packet FIFO length.
 
#define TX_PACKET_FIFO_LENGTH   (16)
 Transmit packet FIFO length.
 
#define EVENT_FIFO_LENGTH   (16)
 Event FIFO length.
 
#define NOTIFICATION_FIFO_LENGTH   (16)
 Notification FIFO length.
 
#define TX_CALLBACK_FIFO_LENGTH   (10)
 Transmit callback FIFO length.
 
#define TX_TTL_MS   (2000)
 TTL for outbound packets.
 
#define RX_TTL_MS   (2000)
 TTL for inbound packets.
 

Enumerations

enum  ProcThreadNotification {
  PTN_NONE = 0x00 , PTN_RECEIVE = 0x01 , PTN_TRANSMIT = 0x02 , PTN_TRANSMIT_DONE = 0x04 ,
  PTN_EVENT = 0x08
}
 Notifications for the processing thread. More...
 

Functions

static void task_ptp (void *pParam)
 
static void ptp_heartbeat_tmr_cb (TimerHandle_t timer)
 
static bool ptp_create_heartbeat_tmr ()
 
static void ptp_remove_heartbeat_tmr ()
 
void ptp_start_heartbeat_tmr ()
 
void ptp_stop_heartbeat_tmr ()
 
static bool ptp_create_message_queues ()
 
static void ptp_destroy_message_queues ()
 
bool reg_task_ptp ()
 
void unreg_task_ptp ()
 
bool ptp_event_enqueue (const PtpCoreEvent *event)
 
void ptp_receive_enqueue (const void *pPayload, uint32_t len, uint32_t ts_sec, uint32_t ts_ns, int tp)
 
bool ptp_transmit_enqueue (const RawPtpMessage *pMsg)
 
void ptp_transmit_timestamp_cb (uint32_t uid, uint32_t seconds, uint32_t nanoseconds)
 
bool ptp_read_and_clear_transmit_timestamp (uint32_t tag, TimestampI *pTs)
 
bool is_flexPTP_operating ()
 

Variables

static TaskHandle_t sTH
 
static bool sPTP_operating = false
 

Macro Definition Documentation

◆ EVENT_FIFO_LENGTH

#define EVENT_FIFO_LENGTH   (16)

Event FIFO length.

Definition at line 54 of file task_ptp.c.

◆ NOTIFICATION_FIFO_LENGTH

#define NOTIFICATION_FIFO_LENGTH   (16)

Notification FIFO length.

Definition at line 55 of file task_ptp.c.

◆ RX_PACKET_FIFO_LENGTH

#define RX_PACKET_FIFO_LENGTH   (16)

Receive packet FIFO length.

Definition at line 49 of file task_ptp.c.

◆ RX_TTL_MS

#define RX_TTL_MS   (2000)

TTL for inbound packets.

Definition at line 60 of file task_ptp.c.

◆ TX_CALLBACK_FIFO_LENGTH

#define TX_CALLBACK_FIFO_LENGTH   (10)

Transmit callback FIFO length.

Definition at line 56 of file task_ptp.c.

◆ TX_PACKET_FIFO_LENGTH

#define TX_PACKET_FIFO_LENGTH   (16)

Transmit packet FIFO length.

Definition at line 50 of file task_ptp.c.

◆ TX_TTL_MS

#define TX_TTL_MS   (2000)

TTL for outbound packets.

Definition at line 59 of file task_ptp.c.

Enumeration Type Documentation

◆ ProcThreadNotification

Notifications for the processing thread.

Enumerator
PTN_NONE 

Empty notification.

PTN_RECEIVE 

A message has been received.

PTN_TRANSMIT 

A message awaits transmission.

PTN_TRANSMIT_DONE 

A transmit timestamp awaits delegation.

PTN_EVENT 

An event has occurred.

Definition at line 67 of file task_ptp.c.

Function Documentation

◆ is_flexPTP_operating()

bool is_flexPTP_operating ( )

Is the PTP task operating?

Definition at line 786 of file task_ptp.c.

◆ ptp_create_heartbeat_tmr()

static bool ptp_create_heartbeat_tmr ( )
static

Construct the heartbeat timer.

Definition at line 164 of file task_ptp.c.

◆ ptp_create_message_queues()

static bool ptp_create_message_queues ( )
static

Definition at line 240 of file task_ptp.c.

◆ ptp_destroy_message_queues()

static void ptp_destroy_message_queues ( )
static

Definition at line 300 of file task_ptp.c.

◆ ptp_event_enqueue()

bool ptp_event_enqueue ( const PtpCoreEvent event)

Post an event.

Parameters
eventpointer to a filled event object
Returns
successful posting

Definition at line 430 of file task_ptp.c.

◆ ptp_heartbeat_tmr_cb()

static void ptp_heartbeat_tmr_cb ( TimerHandle_t  timer)
static

Provide the flexPTP with periodic ticks of PTP_HEARTBEAT_TICKRATE_MS intervals. This function is only exposed if operating in FLEXPTP_OSLESS mode!

Call this function at PTP_HEARTBEAT_TICKRATE_MS intervals if operating in FLEXPTP_OSLESS mode, otherwise flexPTP manages it.

Definition at line 148 of file task_ptp.c.

◆ ptp_read_and_clear_transmit_timestamp()

bool ptp_read_and_clear_transmit_timestamp ( uint32_t  tag,
TimestampI pTs 
)

Read transmit timestamp and release message buffer area.

Parameters
tagunique message tag
pTspointer to a TimestampI object
Returns
successful timestamp fetch

Definition at line 564 of file task_ptp.c.

◆ ptp_receive_enqueue()

void ptp_receive_enqueue ( const void *  pPayload,
uint32_t  len,
uint32_t  ts_sec,
uint32_t  ts_ns,
int  tp 
)

Enqueue PTP message.

Parameters
pPayloadmessage payload
lenmessage length
ts_secreception timestamp seconds part
ts_nsreception timestamp nanoseconds part
tptransport protocol (L2/L4)

Definition at line 457 of file task_ptp.c.

◆ ptp_remove_heartbeat_tmr()

static void ptp_remove_heartbeat_tmr ( )
static

Remove the heartbeat timer.

Definition at line 196 of file task_ptp.c.

◆ ptp_start_heartbeat_tmr()

void ptp_start_heartbeat_tmr ( )

Start the heartbeat timer.

Definition at line 210 of file task_ptp.c.

◆ ptp_stop_heartbeat_tmr()

void ptp_stop_heartbeat_tmr ( )

Stop the heartbeat timer.

Definition at line 225 of file task_ptp.c.

◆ ptp_transmit_enqueue()

bool ptp_transmit_enqueue ( const RawPtpMessage pMsg)

Put a PTP message into the transmit queue.

Parameters
pMsgpointer to raw PTP message. Can be discarded after the function has returned.
Returns
successful insertion

Definition at line 502 of file task_ptp.c.

◆ ptp_transmit_timestamp_cb()

void ptp_transmit_timestamp_cb ( uint32_t  uid,
uint32_t  seconds,
uint32_t  nanoseconds 
)

Transmit timestamp callback handler.

Parameters
tagunique message tag
secondstransmit timestamp seconds part
nanosecondstransmit timestamp nanoseconds part

Definition at line 537 of file task_ptp.c.

◆ reg_task_ptp()

bool reg_task_ptp ( )

Register PTP task.

Returns
initialization successful

Definition at line 326 of file task_ptp.c.

◆ task_ptp()

static void task_ptp ( void *  pParam)
static

flexPTP's main loop. This function is only exposed if operating in FLEXPTP_OSLESS mode!

Call this function periodically to advance internal processing if operating in FLEXPTP_OSLESS mode, otherwise the library internally manages it.

Definition at line 588 of file task_ptp.c.

◆ unreg_task_ptp()

void unreg_task_ptp ( )

Unreg PTP task.

Definition at line 404 of file task_ptp.c.

Variable Documentation

◆ sPTP_operating

bool sPTP_operating = false
static

Definition at line 39 of file task_ptp.c.

◆ sTH

TaskHandle_t sTH
static

Definition at line 25 of file task_ptp.c.