syncSlave for problem 3

Committer:
the729
Date:
Fri Dec 03 20:53:52 2010 +0000
Revision:
0:362932d519c6

        

Who changed what in which revision?

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