syncMaster for problem 3
Embed:
(wiki syntax)
Show/hide line numbers
timesync.h
00001 #ifndef TIMESYNC_H 00002 #define TIMESYNC_H 00003 #include "mbed.h" 00004 00005 typedef unsigned int uint32_t; 00006 typedef int int32_t; 00007 typedef unsigned short uint16_t; 00008 typedef short int16_t; 00009 typedef unsigned char uint8_t; 00010 //typedef char int8_t; 00011 00012 typedef struct timeval { 00013 int32_t tv_sec; 00014 uint32_t tv_usec; 00015 } timeval_t; 00016 00017 typedef struct hdtimeval { 00018 int32_t tv_sec; 00019 uint32_t ticks; 00020 } hdtimeval_t; 00021 00022 typedef union sync_pkt24 { 00023 struct { 00024 uint32_t rx_time; 00025 uint16_t tx_time; 00026 }; 00027 struct { 00028 char no_use; 00029 char raw[5]; 00030 }; 00031 } sync_pkt24_t; 00032 00033 typedef union sync_pkt32 { 00034 struct { 00035 uint32_t rx_time; 00036 uint16_t tx_time; 00037 }; 00038 char raw[6]; 00039 } sync_pkt32_t; 00040 00041 typedef union sync_pkt64 { 00042 struct { 00043 hdtimeval_t rx_time; 00044 uint16_t tx_time; 00045 }; 00046 char raw[10]; 00047 } sync_pkt64_t; 00048 00049 typedef enum { 00050 SYNCTYPE_NONE = 0, 00051 SYNCTYPE_64 = 0xA0, 00052 SYNCTYPE_32 = 0xA3, 00053 SYNCTYPE_24 = 0xA5 00054 } synctype_t; 00055 00056 void timesync_init(); 00057 void getTime(struct timeval * tv); 00058 int runAtTime(void (*schedFunc)(void), struct timeval *tv); 00059 void runAtTrigger(void (*trigFunc)(struct timeval *tv)); 00060 00061 #define TMR LPC_TIM2 00062 #define MAX_TICK (SystemCoreClock) 00063 00064 #define PCLK_DEVIDER 1 // PCLK = CCLK 00065 #define CLK_TIMER 12 // TIMER2 as the timer 00066 #define CLK_UART 16 // UART2 as uart 00067 #define PCTIM0 1 // Power Control Timer0 00068 #define PCTIM1 2 // Power Control Timer1 00069 #define PCTIM2 22 // Power Control Timer1 00070 #define PCUART2 24 // Power Control UART2 00071 00072 #define QUEUE_SIZE 16 00073 00074 #endif //TIMESYNC_H
Generated on Fri Jul 29 2022 08:06:44 by
1.7.2