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