建設(shè)一個(gè)網(wǎng)站需要哪些費(fèi)用靜態(tài)網(wǎng)站開(kāi)發(fā)網(wǎng)站
鶴壁市浩天電氣有限公司
2026/01/22 03:00:13
建設(shè)一個(gè)網(wǎng)站需要哪些費(fèi)用,靜態(tài)網(wǎng)站開(kāi)發(fā)網(wǎng)站,北京到安陽(yáng)火車時(shí)刻表,做網(wǎng)站怎么放視頻本小節(jié)介紹RT-Thread中定時(shí)器相關(guān)API的使用。
注意#xff0c;與API使用相關(guān)的部分細(xì)節(jié)#xff0c;會(huì)在后面的課時(shí)中說(shuō)明。
定時(shí)器的基本結(jié)構(gòu)
RT-Thread使用軟件方法來(lái)創(chuàng)建軟定時(shí)器#xff0c;從而提供不受硬件定時(shí)器數(shù)量限制的定時(shí)器。每個(gè)軟定時(shí)器使用定時(shí)器控制塊rt_t…本小節(jié)介紹RT-Thread中定時(shí)器相關(guān)API的使用。注意與API使用相關(guān)的部分細(xì)節(jié)會(huì)在后面的課時(shí)中說(shuō)明。定時(shí)器的基本結(jié)構(gòu)RT-Thread使用軟件方法來(lái)創(chuàng)建軟定時(shí)器從而提供不受硬件定時(shí)器數(shù)量限制的定時(shí)器。每個(gè)軟定時(shí)器使用定時(shí)器控制塊rt_timer_t來(lái)進(jìn)行管理。在定時(shí)控制塊中存儲(chǔ)定時(shí)器的一些信息例如初始節(jié)拍數(shù)超時(shí)時(shí)的節(jié)拍數(shù)也包含定時(shí)器與定時(shí)器之間連接用的鏈表結(jié)構(gòu)超時(shí)回調(diào)函數(shù)等。在這些信息中核心的信息有定時(shí)時(shí)長(zhǎng)多少個(gè) tick 之后觸發(fā)是否周期一次性或者周期性執(zhí)行回調(diào)函數(shù)定時(shí)觸發(fā)時(shí)調(diào)用的函數(shù)運(yùn)行上下文在什么環(huán)境定時(shí)中斷、軟定時(shí)器任務(wù)中執(zhí)行示例一創(chuàng)建周期性和一次性定時(shí)器下面的例子中演示了使用相關(guān)的接口創(chuàng)建了兩種類型的定時(shí)器周期性定時(shí)器led_timer每隔500ms閃爍一次LED一次性定時(shí)器在啟動(dòng)定時(shí)器3秒后點(diǎn)亮LED#include rtthread.h #include base.h #include rtconfig.h #include rtdef.h // 回調(diào)函數(shù) static void led_timer_cb(void *parameter) { RT_UNUSED(parameter); led_toggle(LED0); // 切換LED 狀態(tài) } struct rt_timer oneshort_timer; static void oneshort_timer_cb (void * parameter) { RT_UNUSED(parameter); led_set(LED1, 1); } int main (void) { hardware_init(); // 創(chuàng)建一個(gè)周期性定時(shí)器1000ms rt_timer_t led_timer rt_timer_create(led_t, led_timer_cb, RT_NULL, rt_tick_from_millisecond(500), // RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC); if (led_timer ! RT_NULL) { rt_timer_start(led_timer); // 啟動(dòng)定時(shí)器 } rt_timer_init(oneshort_timer, oneshort, oneshort_timer_cb, RT_NULL, 3*RT_TICK_PER_SECOND, // 3秒 RT_TIMER_FLAG_ONE_SHOT); rt_timer_start(oneshort_timer); return 0; }示例二重啟或結(jié)束定時(shí)器在定時(shí)器回調(diào)函數(shù)被調(diào)用時(shí)可以手動(dòng)重啟或者停止定時(shí)器。示例代碼如下#include rtthread.h #include base.h #include rtconfig.h #include rtdef.h rt_timer_t led_timer; // 回調(diào)函數(shù) static void led_timer_cb(void *parameter) { RT_UNUSED(parameter); led_toggle(LED0); // 切換LED 狀態(tài) static int count; if (count 20) { // 可以關(guān)閉 rt_timer_stop(led_timer); } } struct rt_timer oneshort_timer; static void oneshort_timer_cb (void * parameter) { RT_UNUSED(parameter); led_toggle(LED1); // 可以重啟 rt_timer_start(oneshort_timer); } int main (void) { hardware_init(); // 創(chuàng)建一個(gè)周期性定時(shí)器1000ms led_timer rt_timer_create(led_t, led_timer_cb, (void *)20, rt_tick_from_millisecond(500), // RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC); if (led_timer ! RT_NULL) { rt_timer_start(led_timer); // 啟動(dòng)定時(shí)器 } rt_timer_init(oneshort_timer, oneshort, oneshort_timer_cb, RT_NULL, 3*RT_TICK_PER_SECOND, // 3秒 RT_TIMER_FLAG_ONE_SHOT); rt_timer_start(oneshort_timer); return 0; }課程推薦全新升級(jí)的手寫RTOS課程從原理到實(shí)戰(zhàn)一次掌握操作系統(tǒng)的核心用10000行代碼手寫一個(gè)TCP/IP協(xié)議棧硬核項(xiàng)目從0手搓一個(gè)RISC-V模擬器作者介紹 李述銅嵌入式系統(tǒng)與底層架構(gòu)領(lǐng)域講師專注于操作系統(tǒng)、CPU 架構(gòu)、RTOS 內(nèi)核與系統(tǒng)軟件實(shí)現(xiàn)原理的教學(xué)與研究。 出版作品《從0手寫x86計(jì)算機(jī)操作系統(tǒng)》主講課程包括《從0手寫嵌入式操作系統(tǒng)》《從0手寫TCP/IP協(xié)議?!贰稄?手寫FAT32文件系統(tǒng)》等。