syncSlave for problem 2

Committer:
the729
Date:
Fri Dec 03 20:52:44 2010 +0000
Revision:
0:988132ee7271

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
the729 0:988132ee7271 1 #ifndef TIMESYNC_H
the729 0:988132ee7271 2 #define TIMESYNC_H
the729 0:988132ee7271 3
the729 0:988132ee7271 4 #include "mbed.h"
the729 0:988132ee7271 5
the729 0:988132ee7271 6 typedef unsigned int uint32_t;
the729 0:988132ee7271 7 typedef int int32_t;
the729 0:988132ee7271 8 typedef unsigned short uint16_t;
the729 0:988132ee7271 9 typedef short int16_t;
the729 0:988132ee7271 10 typedef unsigned char uint8_t;
the729 0:988132ee7271 11 //typedef char int8_t;
the729 0:988132ee7271 12
the729 0:988132ee7271 13 typedef struct timeval {
the729 0:988132ee7271 14 int32_t tv_sec;
the729 0:988132ee7271 15 uint32_t tv_usec;
the729 0:988132ee7271 16 } timeval_t;
the729 0:988132ee7271 17
the729 0:988132ee7271 18 typedef struct hdtimeval {
the729 0:988132ee7271 19 int32_t tv_sec;
the729 0:988132ee7271 20 uint32_t ticks;
the729 0:988132ee7271 21 } hdtimeval_t;
the729 0:988132ee7271 22
the729 0:988132ee7271 23 typedef union sync_pkt24 {
the729 0:988132ee7271 24 struct {
the729 0:988132ee7271 25 uint32_t rx_time;
the729 0:988132ee7271 26 uint16_t tx_time;
the729 0:988132ee7271 27 };
the729 0:988132ee7271 28 struct {
the729 0:988132ee7271 29 char no_use;
the729 0:988132ee7271 30 char raw[5];
the729 0:988132ee7271 31 };
the729 0:988132ee7271 32 } sync_pkt24_t;
the729 0:988132ee7271 33
the729 0:988132ee7271 34 typedef union sync_pkt32 {
the729 0:988132ee7271 35 struct {
the729 0:988132ee7271 36 uint32_t rx_time;
the729 0:988132ee7271 37 uint16_t tx_time;
the729 0:988132ee7271 38 };
the729 0:988132ee7271 39 char raw[6];
the729 0:988132ee7271 40 } sync_pkt32_t;
the729 0:988132ee7271 41
the729 0:988132ee7271 42 typedef union sync_pkt64 {
the729 0:988132ee7271 43 struct {
the729 0:988132ee7271 44 hdtimeval_t rx_time;
the729 0:988132ee7271 45 uint16_t tx_time;
the729 0:988132ee7271 46 };
the729 0:988132ee7271 47 char raw[10];
the729 0:988132ee7271 48 } sync_pkt64_t;
the729 0:988132ee7271 49
the729 0:988132ee7271 50 typedef enum {
the729 0:988132ee7271 51 SYNCTYPE_NONE = 0,
the729 0:988132ee7271 52 SYNCTYPE_64 = 0xA0,
the729 0:988132ee7271 53 SYNCTYPE_32 = 0xA3,
the729 0:988132ee7271 54 SYNCTYPE_24 = 0xA5
the729 0:988132ee7271 55 } synctype_t;
the729 0:988132ee7271 56
the729 0:988132ee7271 57 void timesync_init();
the729 0:988132ee7271 58
the729 0:988132ee7271 59 void getTime(struct timeval * tv);
the729 0:988132ee7271 60 int runAtTime(void (*schedFunc)(void), struct timeval *tv);
the729 0:988132ee7271 61 void runAtTrigger(void (*trigFunc)(struct timeval *tv));
the729 0:988132ee7271 62
the729 0:988132ee7271 63 #define TMR LPC_TIM2
the729 0:988132ee7271 64 #define MAX_TICK (SystemCoreClock)
the729 0:988132ee7271 65
the729 0:988132ee7271 66 #define PCLK_DEVIDER 1 // PCLK = CCLK
the729 0:988132ee7271 67 #define CLK_TIMER 12 // TIMER2 as the timer
the729 0:988132ee7271 68 #define CLK_UART 16 // UART2 as uart
the729 0:988132ee7271 69 #define PCTIM0 1 // Power Control Timer0
the729 0:988132ee7271 70 #define PCTIM1 2 // Power Control Timer1
the729 0:988132ee7271 71 #define PCTIM2 22 // Power Control Timer1
the729 0:988132ee7271 72 #define PCUART2 24 // Power Control UART2
the729 0:988132ee7271 73
the729 0:988132ee7271 74 #define QUEUE_SIZE 16
the729 0:988132ee7271 75
the729 0:988132ee7271 76 #endif //TIMESYNC_H