syncMaster for problem 2

Committer:
the729
Date:
Fri Dec 03 20:52:00 2010 +0000
Revision:
0:6a0716eb2e73
working

Who changed what in which revision?

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