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