residual code errors fixed

This commit is contained in:
Wiesner András 2023-04-16 22:53:03 +02:00
parent ac63947fe1
commit cc86923abd
8 changed files with 40 additions and 7 deletions

View File

@ -32,3 +32,29 @@ void ptp_create_clock_identity()
ptp_print_clock_identity(S.hwoptions.clockIdentity); ptp_print_clock_identity(S.hwoptions.clockIdentity);
MSG("\n"); MSG("\n");
} }
// convert string clock id to 64-bit number
uint64_t hextoclkid(const char *str)
{
size_t len = strlen(str);
uint64_t clkid = 0;
for (size_t i = 0; i < len; i++) {
char digit = tolower(str[i]);
if (digit >= '0' && digit <= '9') {
digit = digit - '0';
} else if (digit >= 'a' && digit <= 'f') {
digit = digit - 'a' + 10;
} else {
break;
}
clkid += (uint64_t) digit *((uint64_t) 1 << (4 * i));
}
uint8_t *p = NULL;
for (size_t i = 0; i < 8; i++) {
p = ((uint8_t *) & clkid) + i;
*p = ((*p & 0x0F) << 4) | ((*p & 0xF0) >> 4);
}
return clkid;
}

View File

@ -4,6 +4,7 @@
#include <stdint.h> #include <stdint.h>
void ptp_print_clock_identity(uint64_t clockID); // print clock identity void ptp_print_clock_identity(uint64_t clockID); // print clock identity
uint64_t hextoclkid(const char *str); // convert hexadecimal string to 64-bit clock id
void ptp_create_clock_identity(); // create clock identity based on MAC address void ptp_create_clock_identity(); // create clock identity based on MAC address

View File

@ -85,10 +85,10 @@ void ptp_delete_timers()
// initialize Delay_Req header // initialize Delay_Req header
void ptp_init_delay_req_header() void ptp_init_delay_req_header()
{ {
sDelayReqHeader.messageType = S.profile.delayMechanism == PTP_DM_E2E ? PTP_MT_Delay_Req : PTP_MT_PDelay_Req; sDelayReqHeader.messageType = PTP_MT_Delay_Req;
sDelayReqHeader.transportSpecific = (uint8_t) S.profile.transportSpecific; sDelayReqHeader.transportSpecific = (uint8_t) S.profile.transportSpecific;
sDelayReqHeader.versionPTP = 2; // PTPv2 sDelayReqHeader.versionPTP = 2; // PTPv2
sDelayReqHeader.messageLength = PTP_HEADER_LENGTH + PTP_TIMESTAMP_LENGTH + (S.profile.delayMechanism == PTP_DM_P2P ? PTP_TIMESTAMP_LENGTH : 0); sDelayReqHeader.messageLength = PTP_HEADER_LENGTH + PTP_TIMESTAMP_LENGTH;
sDelayReqHeader.domainNumber = S.profile.domainNumber; sDelayReqHeader.domainNumber = S.profile.domainNumber;
ptp_clear_flags(&(sDelayReqHeader.flags)); // no flags ptp_clear_flags(&(sDelayReqHeader.flags)); // no flags
sDelayReqHeader.correction_ns = 0; sDelayReqHeader.correction_ns = 0;
@ -98,7 +98,7 @@ void ptp_init_delay_req_header()
sDelayReqHeader.sourcePortID = 1; // TODO? No more ports... sDelayReqHeader.sourcePortID = 1; // TODO? No more ports...
sDelayReqHeader.sequenceID = 0; // will change in every sync cycle sDelayReqHeader.sequenceID = 0; // will change in every sync cycle
sDelayReqHeader.control = S.profile.delayMechanism == PTP_DM_E2E ? PTP_CON_Delay_Req : PTP_CON_Other; sDelayReqHeader.control = PTP_CON_Delay_Req;
sDelayReqHeader.logMessagePeriod = 0; sDelayReqHeader.logMessagePeriod = 0;
} }

View File

@ -18,9 +18,9 @@ static struct {
static const uint16_t sPortLut[2] = { PTP_PORT_EVENT, PTP_PORT_GENERAL }; static const uint16_t sPortLut[2] = { PTP_PORT_EVENT, PTP_PORT_GENERAL };
static ip4_addr_t sIpLut[2] = { 0 }; static ip4_addr_t sIpLut[2] = { 0 };
static const uint8_t *sEthLut[2] = { PTP_ETHERNET_PRIMARY, PTP_ETHERNET_PEER_DELAY }; static const uint8_t *sEthLut[2] = { PTP_ETHERNET_PRIMARY };
void ptp_transmit_init(struct udp_pcb *pPriE, struct udp_pcb *pPriG,) void ptp_transmit_init(struct udp_pcb *pPriE, struct udp_pcb *pPriG)
{ {
sPcbLut.pPri_Ev = pPriE; sPcbLut.pPri_Ev = pPriE;
sPcbLut.pPri_Gen = pPriG; sPcbLut.pPri_Gen = pPriG;

View File

@ -3,7 +3,7 @@
#include "ptp_types.h" #include "ptp_types.h"
void ptp_transmit_init(struct udp_pcb *pPriE, struct udp_pcb *pPriG,); // initialize PTP transmitter void ptp_transmit_init(struct udp_pcb *pPriE, struct udp_pcb *pPriG); // initialize PTP transmitter
void ptp_transmit_msg(RawPtpMessage * pMsg); // transmit PTP message void ptp_transmit_msg(RawPtpMessage * pMsg); // transmit PTP message
bool ptp_transmit_enqueue(const RawPtpMessage * pMsg); // enqueue message TODO: refactor... bool ptp_transmit_enqueue(const RawPtpMessage * pMsg); // enqueue message TODO: refactor...

View File

@ -58,6 +58,11 @@ uint32_t ptp_get_addend()
return S.hwclock.addend; return S.hwclock.addend;
} }
PtpTransportType ptp_get_transport_type()
{
return S.profile.transportType;
}
void ptp_time(TimestampU * pT) void ptp_time(TimestampU * pT)
{ {
PTP_HW_GET_TIME(pT); PTP_HW_GET_TIME(pT);

View File

@ -15,6 +15,7 @@ void ptp_set_domain(uint8_t domain); // set PTP domain
uint8_t ptp_get_domain(); // get PTP domain uint8_t ptp_get_domain(); // get PTP domain
void ptp_set_addend(uint32_t addend); // set hardware clock addend (frequency tuning!) void ptp_set_addend(uint32_t addend); // set hardware clock addend (frequency tuning!)
uint32_t ptp_get_addend(); // get hardware clock addend uint32_t ptp_get_addend(); // get hardware clock addend
PtpTransportType ptp_get_transport_type(); // get PTP transport type
void ptp_time(TimestampU * pT); // get time void ptp_time(TimestampU * pT); // get time

View File

@ -126,7 +126,7 @@ void reg_task_ptp()
join_ptp_igmp_groups(); // enter PTP IGMP groups join_ptp_igmp_groups(); // enter PTP IGMP groups
create_ptp_listeners(); // create listeners create_ptp_listeners(); // create listeners
#ifndef SIMULATION #ifndef SIMULATION
ptp_transmit_init(spPTP_PRIMARY_EVENT_pcb, spPTP_PRIMARY_GENERAL_pcb,); // initialize transmit function*/ ptp_transmit_init(spPTP_PRIMARY_EVENT_pcb, spPTP_PRIMARY_GENERAL_pcb); // initialize transmit function*/
#endif #endif
// create task // create task