├── common_libs ├── app_error │ ├── app_error.c │ └── app_error.h ├── calendar │ ├── calendar.c │ ├── calendar.h │ └── readme.md ├── common.c ├── common.h ├── common_string │ ├── common_string.c │ └── common_string.h ├── crc16 │ ├── crc16.c │ └── crc16.h ├── datetime │ ├── datetime.c │ └── datetime.h ├── list │ ├── list.c │ └── list.h ├── poll_buffer │ ├── poll_buffer.c │ └── poll_buffer.h ├── port.h ├── port_A.h ├── readme.md ├── softwdt │ ├── readme.md │ ├── softwdt.c │ └── softwdt.h └── wait_event │ ├── event.c │ ├── event.h │ └── readme.md └── readme.md /common_libs/app_error/app_error.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/app_error/app_error.c -------------------------------------------------------------------------------- /common_libs/app_error/app_error.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/app_error/app_error.h -------------------------------------------------------------------------------- /common_libs/calendar/calendar.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/calendar/calendar.c -------------------------------------------------------------------------------- /common_libs/calendar/calendar.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/calendar/calendar.h -------------------------------------------------------------------------------- /common_libs/calendar/readme.md: -------------------------------------------------------------------------------- 1 | # 软件万年历实现 2 | 3 | 应用系统实现诸如linux date万年历的功能,一般情况下,嵌入式系统,硬件上做法一般有如下几种: 4 | 5 | 第一种,搭载一颗永久不断电的时钟芯片(系统断电可由纽扣电池供电); 6 | 7 | 第二种,片上有一直在运行的硬件万年历的外设(系统断电可由纽扣电池供电); 8 | 9 | 第三种,片上有一个一直在运行的硬件定时器的外设(系统断电可由纽扣电池供电); 10 | 11 | 12 | 13 | ### 第一种具体做法 14 | 15 | 1)系统开机时刻,从时钟芯片上读取当前硬件万年历时间,一般能取到year-month-day hour:minute:second,有时还有时区。 16 | 17 | 2)计算开机时刻的时间戳SecondCountRTC(从2000-01-01 00:00:00到该硬件万年历时间走过的秒数)。详见接口`set_system_clock()`。 18 | 19 | 3)之后,运行一个周期性1秒的软件定时器,在定时器中断里,将SecondCountRTC加1。 20 | 21 | 4)应用程序,每次要获取当前时刻的软件万年历时间,只需调用一个负责将当前时刻的时间戳(从2000-01-01 00:00:00到此刻的走过的秒数)转为软件万年历时间的接口`get_wall_clock_time()`即可。 22 | 23 | 24 | 详见`calendar.c`实现。 25 | 26 | 27 | #### note 28 | 1)应用程序,如果要获取当前时刻的标准时间戳(从1970-01-01 00:00:00到此刻的走过的秒数),则调用`get_curr_timestamp_int()`和`linux_mktime()` 29 | 30 | 详见`datetime.c`实现。 31 | 32 | ### 第二种具体做法 33 | 直接操作硬件寄存器即可 34 | 35 | ### 第三种具体做法 36 | 1)重新实现接口`set_system_clock()` 37 | 38 | 2)重新实现接口`get_wall_clock_time()` 39 | 40 | 详见`calendar_enhance.c`实现。 41 | 42 | 3) 外部需要定义以上两个接口实现所需要的其他接口。`clock_gettime()`和`clock_settime()` 43 | 44 | 以下是具体的代码举例: 45 | 46 | 在这里讲述的硬件定时器,需要具备如下能力:芯片在外部断电期间,能够通过该外挂纽扣电池继续给该硬件定时器和备份域供电。 47 | 48 | 以EFM32GG系列为例,该硬件定时器为burtc。 49 | 50 | 51 | 重点关注硬件定时器几个参数: 52 | 53 | 1)每秒走过的计数值`COUNTS_PER_SEC` 54 | 55 | 2)计数最大值`RTC_COUNTER_MASK` 56 | 57 | 通过以上参数,能够获取1个溢出周期内走过的秒数: 58 | 59 | /* Set overflow interval based on counter width and frequency */ 60 | overflow_interval = ((uint64_t)UINT32_MAX+1) / COUNTS_PER_SEC; /* in seconds */ 61 | overflow_interval_r = ((uint64_t)UINT32_MAX+1) % COUNTS_PER_SEC; /* division remainder */ 62 | 63 | 在整个实现过程,需要保存 万年历起始时间,和 计数溢出次数,到备份域。 64 | 65 | 66 | 67 | //wallClockTimeBase:万年历起始时间戳 68 | //wallClockOverflowCnt:硬件定时器计数溢出次数 69 | extern volatile uint32_t wallClockTimeBase; 70 | extern volatile uint32_t wallClockOverflowCnt; 71 | 72 | //对外函数接口 73 | /***************************************************************************//** 74 | * @brief wallclock_set_timebase 75 | ******************************************************************************/ 76 | __STATIC_INLINE void wallclock_set_timebase(uint32_t timebase) 77 | { 78 | wallClockTimeBase = timebase; 79 | } 80 | 81 | /***************************************************************************//** 82 | * @brief wallclock_get_timebase 83 | ******************************************************************************/ 84 | __STATIC_INLINE uint32_t wallclock_get_timebase(void) 85 | { 86 | return wallClockTimeBase; 87 | } 88 | 89 | /***************************************************************************//** 90 | * @brief wallclock_set_overflowcnt 91 | ******************************************************************************/ 92 | __STATIC_INLINE void wallclock_set_overflowcnt(uint32_t overflowcnt) 93 | { 94 | wallClockOverflowCnt = overflowcnt; 95 | } 96 | 97 | /***************************************************************************//** 98 | * @brief wallclock_get_overflowcnt 99 | ******************************************************************************/ 100 | __STATIC_INLINE uint32_t wallclock_get_overflowcnt(void) 101 | { 102 | return wallClockOverflowCnt; 103 | } 104 | 105 | 106 | 107 | 以EFM32GG系列为例,片上有一个一直在运行的硬件定时器的外设burtc 108 | 109 | //RTC_DIVIDER:外设时钟分频比 110 | //RTC_CLOCK:外设时钟频率 111 | #define BURTC_PRESCALING (RTC_DIVIDER) 112 | #define COUNTS_PER_SEC (RTC_CLOCK/BURTC_PRESCALING) 113 | 114 | static uint32_t overflow_interval; 115 | static uint32_t overflow_interval_r; 116 | 117 | /***************************************************************************** 118 | * @brief Backup CALENDAR to retention registers 119 | * RET[0].REG : number of BURTC overflows 120 | * RET[1].REG : epoch offset 121 | ******************************************************************************/ 122 | static void clock_backup(void) 123 | { 124 | uint32_t burtcOverflowCounter = wallclock_get_overflowcnt(); 125 | uint32_t burtcStartTime = wallclock_get_timebase(); 126 | 127 | /* Write overflow counter to retention memory */ 128 | BURTC_RetRegSet(0, burtcOverflowCounter); 129 | 130 | /* Write local epoch offset to retention memory */ 131 | BURTC_RetRegSet(1, burtcStartTime); 132 | } 133 | 134 | /****************************************************************************** 135 | * @brief Returns the current system time 136 | * 137 | * @param timer 138 | * If not a null pointer, time is copied to this 139 | * 140 | * @return 141 | * Current system time. Should, but does not, return -1 if system time is not available 142 | * 143 | *****************************************************************************/ 144 | uint32_t clock_gettime(void) 145 | { 146 | uint32_t burtcOverflowCounter = wallclock_get_overflowcnt(); 147 | 148 | /* Add the time offset */ 149 | uint32_t t = wallclock_get_timebase(); 150 | 151 | /* Add time based on number of counter overflows*/ 152 | t += burtcOverflowCounter * overflow_interval; 153 | 154 | /* Correct if overflow interval is not an integer*/ 155 | if ( overflow_interval_r != 0 ) 156 | { 157 | t += burtcOverflowCounter * overflow_interval_r / COUNTS_PER_SEC; 158 | } 159 | 160 | /* Add the number of seconds for BURTC */ 161 | t += (BURTC_CounterGet() / COUNTS_PER_SEC); 162 | 163 | return t; 164 | } 165 | 166 | /***************************************************************************** 167 | * @brief Set the epoch offset 168 | ******************************************************************************/ 169 | void clock_settime(const uint32_t set_timestamp) 170 | { 171 | uint32_t burtcOverflowCounter = wallclock_get_overflowcnt(); 172 | 173 | //这里,不能改变burtc的cnt值 174 | uint32_t burtcStartTime = set_timestamp; 175 | burtcStartTime -= (BURTC_CounterGet() / COUNTS_PER_SEC); 176 | burtcStartTime -= burtcOverflowCounter * overflow_interval; 177 | if ( overflow_interval_r != 0 ) 178 | { 179 | burtcStartTime -= burtcOverflowCounter * overflow_interval_r / COUNTS_PER_SEC; 180 | } 181 | 182 | //更新开始时间戳,并保存到备份域 183 | wallclock_set_timebase(burtcStartTime); 184 | LOG(LEVEL_DEBUG, "settime TimeBase=%d", wallclock_get_timebase()); 185 | clock_backup(); 186 | } 187 | 188 | /***************************************************************************** 189 | * @brief hal_burtc_over_flow_irq_process 190 | * @该接口需要在burtc定时器溢出中断中被执行 191 | ******************************************************************************/ 192 | void hal_burtc_over_flow_irq_process(void) 193 | { 194 | uint32_t overflowcnt = wallclock_get_overflowcnt(); 195 | 196 | //更新溢出值 197 | wallclock_set_overflowcnt(overflowcnt++); 198 | 199 | //保存到备份域 200 | clock_backup(); 201 | } 202 | 203 | -------------------------------------------------------------------------------- /common_libs/common.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "common.h" 5 | 6 | 7 | -------------------------------------------------------------------------------- /common_libs/common.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/common.h -------------------------------------------------------------------------------- /common_libs/common_string/common_string.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/common_string/common_string.c -------------------------------------------------------------------------------- /common_libs/common_string/common_string.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/common_string/common_string.h -------------------------------------------------------------------------------- /common_libs/crc16/crc16.c: -------------------------------------------------------------------------------- 1 | #include "crc16.h" 2 | 3 | /** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */ 4 | uint16_t const crc16_table[256] = 5 | { 6 | 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 7 | 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, 8 | 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 9 | 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, 10 | 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 11 | 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, 12 | 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 13 | 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, 14 | 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 15 | 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, 16 | 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 17 | 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, 18 | 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 19 | 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, 20 | 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 21 | 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, 22 | 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 23 | 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, 24 | 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 25 | 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, 26 | 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 27 | 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, 28 | 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 29 | 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, 30 | 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 31 | 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, 32 | 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 33 | 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, 34 | 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 35 | 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, 36 | 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 37 | 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 38 | }; 39 | 40 | /****************************************************************************** 41 | * @brief crc16_byte 42 | *****************************************************************************/ 43 | static inline uint16_t crc16_byte(uint16_t crc, const uint8_t data) 44 | { 45 | return (crc >> 8) ^ crc16_table[(crc ^ data) & 0xff]; 46 | } 47 | 48 | /** 49 | * crc16 - compute the CRC-16 for the data buffer 50 | * @crc: previous CRC value 51 | * @buffer: data pointer 52 | * @len: number of bytes in the buffer 53 | * 54 | * Returns the updated CRC value. 55 | */ 56 | uint16_t bd_crc16(uint16_t crc, uint8_t const *buffer, uint32_t len) 57 | { 58 | while (len--) 59 | crc = crc16_byte(crc, *buffer++); 60 | return crc; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /common_libs/crc16/crc16.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/crc16/crc16.h -------------------------------------------------------------------------------- /common_libs/datetime/datetime.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/datetime/datetime.c -------------------------------------------------------------------------------- /common_libs/datetime/datetime.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/datetime/datetime.h -------------------------------------------------------------------------------- /common_libs/list/list.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/list/list.c -------------------------------------------------------------------------------- /common_libs/list/list.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/list/list.h -------------------------------------------------------------------------------- /common_libs/poll_buffer/poll_buffer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "poll_buffer.h" 5 | #include "common.h" 6 | 7 | #include "port.h" 8 | 9 | static __INLINE uint32_t poll_length(poll_t * p_poll) 10 | { 11 | uint32_t tmp = p_poll->read_pos; 12 | return p_poll->write_pos - tmp; 13 | } 14 | 15 | /**< Macro for calculating the FIFO length. */ 16 | #define POLL_LENGTH poll_length(p_fifo) 17 | 18 | 19 | /**@brief Put one byte to the FIFO. */ 20 | static __INLINE void poll_put(poll_t * p_poll, uint8_t byte) 21 | { 22 | p_poll->p_buf[p_poll->write_pos & p_poll->buf_size_mask] = byte; 23 | p_poll->write_pos++; 24 | } 25 | 26 | 27 | /**@brief Look at one byte in the FIFO. */ 28 | static __INLINE void poll_peek(poll_t * p_poll, uint16_t index, uint8_t * p_byte) 29 | { 30 | *p_byte = p_poll->p_buf[(p_poll->read_pos + index) & p_poll->buf_size_mask]; 31 | } 32 | 33 | 34 | /****************************************************************************** 35 | * @brief poll_init 36 | *****************************************************************************/ 37 | int poll_init(poll_t * poll, int poll_size) 38 | { 39 | if (poll == NULL) 40 | return -1; 41 | 42 | if (poll_size == 0) 43 | return -2; 44 | 45 | if (!IS_POWER_OF_TWO(poll_size)) 46 | return -3; 47 | 48 | uint8_t * poll_buf = MEM_MALLOC(poll_size); 49 | if (poll_buf == NULL) 50 | return -3; 51 | 52 | poll->p_buf = poll_buf; 53 | poll->buf_size_mask = poll_size - 1; 54 | poll->read_pos = 0; 55 | poll->write_pos = 0; 56 | return 0; 57 | } 58 | 59 | /****************************************************************************** 60 | * @brief poll_init_static 61 | * @cannot release data_buf before poll_uninit_static 62 | *****************************************************************************/ 63 | int poll_init_static(poll_t * p_poll, uint8_t * data_buf, int poll_size) 64 | { 65 | if (p_poll == NULL) 66 | return -1; 67 | 68 | if (poll_size == 0) 69 | return -2; 70 | 71 | if (!IS_POWER_OF_TWO(poll_size)) 72 | return -3; 73 | 74 | uint8_t * poll_buf = data_buf; 75 | 76 | p_poll->p_buf = poll_buf; 77 | p_poll->buf_size_mask = poll_size - 1; 78 | p_poll->read_pos = 0; 79 | p_poll->write_pos = 0; 80 | return 0; 81 | } 82 | 83 | /****************************************************************************** 84 | * @brief poll_uninit 85 | *****************************************************************************/ 86 | void poll_uninit(poll_t * p_poll) 87 | { 88 | if (p_poll == NULL) 89 | return; 90 | 91 | if (p_poll->p_buf) 92 | MEM_FREE(p_poll->p_buf); 93 | 94 | p_poll->p_buf = NULL; 95 | p_poll->buf_size_mask = 0; 96 | p_poll->read_pos = 0; 97 | p_poll->write_pos = 0; 98 | } 99 | 100 | /****************************************************************************** 101 | * @brief poll_uninit_static 102 | *****************************************************************************/ 103 | void poll_uninit_static(poll_t * poll) 104 | { 105 | if (poll == NULL) 106 | return; 107 | 108 | poll->p_buf = NULL; 109 | poll->buf_size_mask = 0; 110 | poll->read_pos = 0; 111 | poll->write_pos = 0; 112 | } 113 | 114 | /****************************************************************************** 115 | * @brief poll_get_data_size 116 | *****************************************************************************/ 117 | int poll_get_data_size(poll_t * p_poll) 118 | { 119 | return poll_length(p_poll); 120 | } 121 | 122 | /****************************************************************************** 123 | * @brief poll_fetch 124 | *****************************************************************************/ 125 | int poll_fetch(poll_t * p_poll, uint8_t * p_buf, int except_size) 126 | { 127 | if (p_poll == NULL || p_buf == NULL) 128 | return -1; 129 | 130 | const uint32_t byte_count = poll_length(p_poll); 131 | const uint32_t requested_len = except_size; 132 | uint32_t index = 0; 133 | uint32_t read_size = MIN(requested_len, byte_count); 134 | 135 | // Fetch bytes from the FIFO. 136 | while (index < read_size) 137 | { 138 | poll_peek(p_poll, index, &p_buf[index]); 139 | index++; 140 | } 141 | 142 | return read_size; 143 | } 144 | 145 | /****************************************************************************** 146 | * @brief poll_flush 147 | * @thread safe 148 | *****************************************************************************/ 149 | int poll_flush(poll_t * p_poll) 150 | { 151 | ENTER_REGION_SECTION(); 152 | p_poll->write_pos = 0; 153 | p_poll->read_pos = 0; 154 | EXIT_REGION_SECTION(); 155 | 156 | return 0; 157 | } 158 | 159 | /****************************************************************************** 160 | * @brief poll_read 161 | * @thread safe 162 | *****************************************************************************/ 163 | int poll_read(poll_t * p_poll, uint8_t * p_buf, int except_size) 164 | { 165 | if (p_poll == NULL || p_buf == NULL) 166 | return -1; 167 | 168 | uint32_t read_size = poll_fetch(p_poll, p_buf, except_size); 169 | 170 | ENTER_REGION_SECTION(); 171 | p_poll->read_pos += read_size; 172 | EXIT_REGION_SECTION(); 173 | 174 | return read_size; 175 | } 176 | 177 | /****************************************************************************** 178 | * @brief poll_write 179 | * @thread safe 180 | *****************************************************************************/ 181 | int poll_write(poll_t * p_poll, uint8_t * p_buf, int except_size) 182 | { 183 | if (p_poll == NULL || p_buf == NULL) 184 | return -1; 185 | 186 | const uint32_t available_count = p_poll->buf_size_mask - poll_length(p_poll) + 1; 187 | const uint32_t requested_len = except_size; 188 | uint32_t index = 0; 189 | uint32_t write_size = MIN(requested_len, available_count); 190 | 191 | if( (requested_len != available_count) 192 | && (available_count == write_size) ) 193 | { 194 | LOG(LEVEL_DEBUG, "\033[1;34;40mpoll write full!\033[0m"); 195 | } 196 | 197 | ENTER_REGION_SECTION(); 198 | while (index < write_size) 199 | { 200 | poll_put(p_poll, p_buf[index++]); 201 | } 202 | EXIT_REGION_SECTION(); 203 | 204 | return write_size; 205 | } 206 | 207 | -------------------------------------------------------------------------------- /common_libs/poll_buffer/poll_buffer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/poll_buffer/poll_buffer.h -------------------------------------------------------------------------------- /common_libs/port.h: -------------------------------------------------------------------------------- 1 | #ifndef __PORT_H 2 | #define __PORT_H 3 | 4 | #include "common_string.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define COMMON_LIBS_VERSION VERSION(1, 0, 0, 0) 11 | 12 | #if defined(BSP_A) 13 | #include "port_A.h" 14 | #endif 15 | 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /common_libs/port_A.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/port_A.h -------------------------------------------------------------------------------- /common_libs/readme.md: -------------------------------------------------------------------------------- 1 | #### How to use 2 | 3 | 4 | port.h: 与硬件平台、编译器相关,使用时需要重定义。 5 | 6 | #### note 7 | `#define LOG(level, format, ...)`被外部的`log.h`所定义 -------------------------------------------------------------------------------- /common_libs/softwdt/readme.md: -------------------------------------------------------------------------------- 1 | # 多路软件看门狗实现线程存活状态监控 2 | 3 | 4 | 5 | 多线程下的应用程序,可能或多或少会出现线程僵死的情况,需要提供一种组件,实现类似硬件看门狗一样对所有线程存活状态进行全局监控的软件看门狗。 6 | 7 | 8 | 9 | - **实现功能** 10 | 11 | - **实例代码** 12 | 13 | 14 | 15 | ------------------- 16 | 17 | 18 | 19 | ## 实现功能 20 | 每个存活线程,创建时注册一个带最大超时时间`wdt_timeout`的软狗,并根据`wdt_timeout`时间定期手动喂软狗。 21 | 22 | 监控线程,每隔1秒的周期,定期检查所有软狗是否超时。如果超时,则当异常处理。 23 | 24 | ## 实例代码 25 | 26 | 27 | 详见:`softwdt.c`实现。 -------------------------------------------------------------------------------- /common_libs/softwdt/softwdt.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/softwdt/softwdt.c -------------------------------------------------------------------------------- /common_libs/softwdt/softwdt.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/softwdt/softwdt.h -------------------------------------------------------------------------------- /common_libs/wait_event/event.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/wait_event/event.c -------------------------------------------------------------------------------- /common_libs/wait_event/event.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RunningChild/embeded_c_components/3594d4b4649b529a742cb00c748a83b3d1332c2f/common_libs/wait_event/event.h -------------------------------------------------------------------------------- /common_libs/wait_event/readme.md: -------------------------------------------------------------------------------- 1 | #一种自定义事件的异步回调处理框架 2 | 3 | 4 | 5 | 应用程序,有时会需要等待某种事件,当事件发生时需要对该事件执行具体动作。 6 | 7 | 8 | 9 | - **实现功能** 10 | 11 | - **实例代码** 12 | 13 | 14 | 15 | ------------------- 16 | 17 | 18 | 19 | ## 实现功能 20 | 应用程序可以在初始化时,创建一个自定义的等待事件wait_event。 21 | 22 | 当需要等待该事件触发时,应用程序可以注册一个带超时时间ms、事件发生时执行的具体动作回调cb、回调可带参数cb_data。 23 | 24 | 当事件发生时,执行该回调函数。如果超时时间达到内,该事件还没发生,则超时会自动注销该等待事件。 25 | 26 | 27 | ## 实例代码 28 | 29 | 30 | 详见:`event.c`实现。 -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | #### How to use 2 | 3 | port.h:调用与用户平台相关的接口的头文件,比如port_A.h 4 | 5 | port_A.h:定义用户平台相关的接口,这些接口由外部模块实现。 6 | 7 | 8 | 9 | #### 功能介绍 10 | 1) softwdt 11 | 12 | 参考 common_libs/softwdt/readme.md 13 | 14 | 2) wait_event 15 | 16 | 参考 common_libs/wait_event/readme.md 17 | 18 | 3) poll_buffer, list, crc16 19 | 20 | 4) common_string 21 | 22 | 5) app_error 23 | 24 | 6) calendar, datetime 25 | 26 | 参考 common_libs/calendar/readme.md --------------------------------------------------------------------------------