国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

軟件定時器(一)

2019-11-10 23:04:23
字體:
來源:轉載
供稿:網友

之前偶爾了解到軟件定時器,也在網上找了許多網友寫的各種版本,知道讀到嵌入式TCP/ip協議棧中的軟件定時器的寫法時,嘆為觀止,故將其修改移植到裸機stm32上使用,并向大家做一分享。

首先得感謝那些兢兢業業從事著自己的工作,并毫不吝嗇的向別人公布自己源代碼的前輩們,正因為他們慷慨無私,我們才能閱讀到各種精巧的代碼,并從中汲取養分,從而培養了許多熱愛技術,真誠無私的人。

/**@brief:1、該文件參考LWIP協議中的times.c編寫 * 2、該超時定時器按鏈表的形式進行組織,按時間長短進行排序,時間最短的永遠排在最前面 * 3、移植時應該注意的幾點: * a.周期性的調用函數。b.需要外部定時器實現時基。c.注意動態內存分配mallco的使用。 *@author: LT *@date: 2016/12/3 */#ifndef __SOFT_TIME_H#define __SOFT_TIME_H#include "typedef.h"#include <string.h>#include <stdlib.h>/* 定時器超時處理函數指針 */typedef void (* soft_timeout_handler)(void *arg);/* 超時定時器 */struct soft_timeo { struct soft_timeo *next; u32 time; soft_timeout_handler h; void *arg;};#define MEMP_soft_TIMEOUT (sizeof(struct soft_timeo))void soft_timeouts_init(u32 msecs, soft_timeout_handler handler, void *arg);void soft_timeout(u32 msecs, soft_timeout_handler handler, void *arg);void soft_untimeout(soft_timeout_handler handler, void *arg);void soft_check_timeouts(void);void soft_restart_timeouts(void);void soft_run_timeout(soft_timeout_handler handler, void *arg);u32 time_to_sec(char *RTC_set);u32 RTC_set(char* RTC_set);#endif#include "soft_time.h"#include "bsp.h"#include "malloc.h"extern volatile u32 g_soft_timer_count;static u32 timeouts_last_time; static struct soft_timeo *next_timeout;/*從字符串的左邊截取n個字符*/char * str_left(char *dst,const char *src, int n){ const char *p = src; char *q = dst; int len = strlen(src); if(n>len) n = len; while(n--) *(q++) = *(p++); *(q++)='/0'; /*有必要嗎?很有必要*/ return dst;}u32 soft_time_now(void){ return RTC_GetCounter();}/** @brief 計算預定時間距現在的時間(單位:s) * @param 預定時間轉成的字符串(例如:2016 12 03 18 30 00 錯誤) * ( 2016 12 3 18 30 0 正確) * @retval * @tips 注意strtol函數的使用 */u32 time_to_sec(char *RTC_set){ u32 set_sec;// u32 now_sec; u8 n; char *pEnd; n = accumulationdayfrom1970((int*)&set_sec, RTC_set); set_sec = set_sec * 3600 * 24 + (int)strtol(RTC_set + n,&pEnd,0) * 3600 ; set_sec = set_sec + (int)strtol(pEnd, &pEnd, 0) * 60; set_sec = set_sec + (int)strtol(pEnd, NULL, 0);/* RTC_Get_str(RTC_now); n = accumulationdayfrom1970((int*)&now_sec, RTC_now); now_sec = now_sec * 3600 * 24 + (int)strtol(RTC_now + n,&pEnd_,0) * 3600 ; now_sec = now_sec + (int)strtol(pEnd_, &pEnd_, 0) * 60; now_sec = now_sec + (int)strtol(pEnd_, NULL, 0);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 綦江县| 水富县| 汉源县| 宾阳县| 安丘市| 高安市| 穆棱市| 山阳县| 黄浦区| 莆田市| 龙川县| 蒙城县| 龙山县| 南涧| 泗水县| 都昌县| 香格里拉县| 常德市| 昌都县| 开化县| 柳林县| 临海市| 若尔盖县| 那坡县| 台中市| 邳州市| 广元市| 隆回县| 永嘉县| 南宁市| 沙坪坝区| 沛县| 利津县| 南昌县| 明光市| 南汇区| 荣昌县| 绥中县| 常宁市| 涿州市| 襄城县|