Commit fcc4ec48 authored by Aurelio Colosimo's avatar Aurelio Colosimo

implementation of posix-timer

parent 39ed260c
...@@ -7,43 +7,76 @@ ...@@ -7,43 +7,76 @@
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h>
#include <pproto/pproto.h> #include <pproto/pproto.h>
#include <pproto/diag.h> #include <pproto/diag.h>
#include "posix.h" #include "posix.h"
extern int posix_timer_init(struct pp_timer *tm) /* FIXME
* In ptpd-2.1.0/src/dep/timer.c the mechanism was different.
* A SIGALARM timer was called once a second, increasing the counter of elapsed
* time.
* I find it easier to check for the timestamp when needed. The granularity of
* this timer is the same as the ptpd solution: 1 second.
* Should be checked if this is enough, but I guess yes.
* Maybe a certain SIGALARM timer solution must be re-introduced, because the
* select in the main loop must exit when a timer elapses. To be checked
*/
extern int posix_timer_init(struct pp_instance *ppi)
{ {
/* TODO */ struct pp_timer *t;
int i;
for (i = 0; i < PP_TIMER_ARRAY_SIZE; i++) {
t = calloc(1,sizeof(*t));
if (!t)
return 0;
ppi->timers[i] = t;
}
return 0; return 0;
} }
extern int posix_timer_start(struct pp_timer *tm)
extern int posix_timer_start(uint32_t interval, struct pp_timer *tm)
{ {
/* TODO */ pp_get_stamp(&tm->start);
tm->interval = interval;
return 0; return 0;
} }
extern int posix_timer_stop(struct pp_timer *tm) extern int posix_timer_stop(struct pp_timer *tm)
{ {
/* TODO */ tm->interval = 0;
return 0; tm->start = 0;
}
extern int posix_timer_update(struct pp_timer *tm)
{
/* TODO */
return 0; return 0;
} }
extern int posix_timer_expired(struct pp_timer *tm) extern int posix_timer_expired(struct pp_timer *tm)
{ {
/* TODO */ uint32_t now;
if (tm->start == 0) {
/* FIXME: print a warning message */
return 0;
}
pp_get_stamp(&now);
if (tm->start + tm->interval < now)
return 1;
return 0; return 0;
} }
int pp_timer_init(struct pp_timer *tm) int pp_timer_init(struct pp_instance *ppi)
__attribute__((alias("posix_timer_init"))); __attribute__((alias("posix_timer_init")));
int pp_timer_start(struct pp_timer *tm) int pp_timer_start(struct pp_timer *tm)
...@@ -52,8 +85,5 @@ int pp_timer_start(struct pp_timer *tm) ...@@ -52,8 +85,5 @@ int pp_timer_start(struct pp_timer *tm)
int pp_timer_stop(struct pp_timer *tm) int pp_timer_stop(struct pp_timer *tm)
__attribute__((alias("posix_timer_stop"))); __attribute__((alias("posix_timer_stop")));
int pp_timer_update(struct pp_timer *tm)
__attribute__((alias("posix_timer_update")));
int pp_timer_expired(struct pp_timer *tm) int pp_timer_expired(struct pp_timer *tm)
__attribute__((alias("posix_timer_expired"))); __attribute__((alias("posix_timer_expired")));
...@@ -32,12 +32,12 @@ ...@@ -32,12 +32,12 @@
#define PP_DEFAULT_MAX_FOREIGN_RECORDS 5 #define PP_DEFAULT_MAX_FOREIGN_RECORDS 5
#define PP_DEFAULT_PARENTS_STATS 0 #define PP_DEFAULT_PARENTS_STATS 0
/* FIXME: check if the following defines are really useful */
#define PP_TIMER_PDELAYREQ_INTERVAL 0 #define PP_TIMER_PDELAYREQ_INTERVAL 0
#define PP_TIMER_DELAYREQ_INTERVAL 1 #define PP_TIMER_DELAYREQ_INTERVAL 1
#define PP_TIMER_SYNC_INTERVAL 2 #define PP_TIMER_SYNC_INTERVAL 2
#define PP_TIMER_ANNOUNCE_RECEIPT 3 #define PP_TIMER_ANNOUNCE_RECEIPT 3
#define PP_TIMER_ANNOUNCE_INTERVAL 4 #define PP_TIMER_ANNOUNCE_INTERVAL 4
#define PP_TIMER_ARRAY_SIZE 5
#define PP_TWO_STEP_FLAG 2 #define PP_TWO_STEP_FLAG 2
#define PP_VERSION_PTP 2 #define PP_VERSION_PTP 2
......
...@@ -65,6 +65,17 @@ struct pp_channel { ...@@ -65,6 +65,17 @@ struct pp_channel {
unsigned char peer[6]; /* Our peer's MAC address */ unsigned char peer[6]; /* Our peer's MAC address */
}; };
/*
* Timer
*/
struct pp_timer
{
uint32_t start;
uint32_t interval;
};
/* /*
* Structure for the standard protocol * Structure for the standard protocol
*/ */
...@@ -82,6 +93,7 @@ struct pp_instance { ...@@ -82,6 +93,7 @@ struct pp_instance {
DSParent *parentDS; DSParent *parentDS;
DSPort *portDS; DSPort *portDS;
DSTimeProperties *timePropertiesDS; DSTimeProperties *timePropertiesDS;
struct pp_timer *timers[PP_TIMER_ARRAY_SIZE];
}; };
...@@ -100,17 +112,12 @@ extern int pp_net_shutdown(struct pp_instance *ppi); ...@@ -100,17 +112,12 @@ extern int pp_net_shutdown(struct pp_instance *ppi);
extern int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len); extern int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len);
extern int pp_send_packet(struct pp_instance *ppi, void *pkt, int len); extern int pp_send_packet(struct pp_instance *ppi, void *pkt, int len);
/* Timer stuff */
struct pp_timer
{
int dummy; /* FIXME */
};
extern int pp_timer_init(struct pp_timer *tm); extern int pp_timer_init(struct pp_instance *ppi); /* initializes timer common
structure */
extern int pp_timer_start(struct pp_timer *tm); extern int pp_timer_start(struct pp_timer *tm);
extern int pp_timer_stop(struct pp_timer *tm); extern int pp_timer_stop(struct pp_timer *tm);
extern int pp_timer_update(struct pp_timer *tm); extern int pp_timer_expired(struct pp_timer *tm); /* returns 1 when expired */
extern int pp_timer_expired(struct pp_timer *tm);
/* Get a timestamp */ /* Get a timestamp */
......
...@@ -47,7 +47,7 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -47,7 +47,7 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
ppi->portDS->logMinPdelayReqInterval = PP_DEFAULT_PDELAYREQ_INTERVAL; ppi->portDS->logMinPdelayReqInterval = PP_DEFAULT_PDELAYREQ_INTERVAL;
ppi->portDS->versionNumber = PP_VERSION_PTP; ppi->portDS->versionNumber = PP_VERSION_PTP;
if (pp_timer_init(0)) /* FIXME */ if (pp_timer_init(ppi))
goto failure; goto failure;
/* TODO Check the following code coming from ptpd. /* TODO Check the following code coming from ptpd.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment