From 08af426f01cf0321719c937d29a1d9315a0feab8 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 7 Mar 2021 08:34:04 +0800 Subject: [example] æ ¼å¼�化整ç�† MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/kernel/tc_comm.h | 2 +- examples/kernel/timer_control.c | 2 +- examples/kernel/timer_timeout.c | 68 ++++++++++++++++++++--------------------- 3 files changed, 36 insertions(+), 36 deletions(-) (limited to 'examples/kernel') diff --git a/examples/kernel/tc_comm.h b/examples/kernel/tc_comm.h index aee1fec2d2..c72c91ad53 100644 --- a/examples/kernel/tc_comm.h +++ b/examples/kernel/tc_comm.h @@ -1,7 +1,7 @@ #ifndef __TC_COMM_H__ #define __TC_COMM_H__ -/* +/* * RT-Thread TestCase * */ diff --git a/examples/kernel/timer_control.c b/examples/kernel/timer_control.c index 9fcb0d4c4d..d1f782fcce 100644 --- a/examples/kernel/timer_control.c +++ b/examples/kernel/timer_control.c @@ -14,7 +14,7 @@ static rt_uint8_t count; static void timeout1(void* parameter) { rt_tick_t timeout = 50; - + rt_kprintf("periodic timer is timeout\n"); count ++; diff --git a/examples/kernel/timer_timeout.c b/examples/kernel/timer_timeout.c index d1a7099e2e..4d9a4fcc1d 100644 --- a/examples/kernel/timer_timeout.c +++ b/examples/kernel/timer_timeout.c @@ -1,21 +1,21 @@ /* - * ³ÌÐòÇåµ¥£ºÏûÏ¢¶ÓÁÐÀý³Ì + * 程åº�清å�•:消æ�¯é˜Ÿåˆ—例程 * - * Õâ¸ö³ÌÐò»á´´½¨3¸ö¶¯Ì¬Ị̈߳¬Ò»¸öÏ̻߳á´ÓÏûÏ¢¶ÓÁÐÖÐÊÕÈ¡ÏûÏ¢£»Ò»¸öÏ̻߳ᶨʱ¸øÏû - * Ï¢¶ÓÁз¢ËÍÏûÏ¢£»Ò»¸öÏ̻߳ᶨʱ¸øÏûÏ¢¶ÓÁз¢Ëͽô¼±ÏûÏ¢¡£ + * 这个程åº�会创建3个动æ€�线程,一个线程会从消æ�¯é˜Ÿåˆ—中收å�–消æ�¯ï¼›ä¸€ä¸ªçº¿ç¨‹ä¼šå®šæ—¶ç»™æ¶ˆ + * æ�¯é˜Ÿåˆ—å�‘é€�消æ�¯ï¼›ä¸€ä¸ªçº¿ç¨‹ä¼šå®šæ—¶ç»™æ¶ˆæ�¯é˜Ÿåˆ—å�‘é€�紧急消æ�¯ã€‚ */ #include #include "tc_comm.h" -/* Ö¸ÏòÏ߳̿ØÖÆ¿éµÄÖ¸Õë */ +/* 指å�‘线程控制å�—的指针 */ static rt_thread_t tid = RT_NULL; -/* ÏûÏ¢¶ÓÁпØÖÆ¿é */ +/* 消æ�¯é˜Ÿåˆ—控制å�— */ static struct rt_messagequeue mq; -/* ÏûÏ¢¶ÓÁÐÖÐÓõ½µÄ·ÅÖÃÏûÏ¢µÄÄÚ´æ³Ø */ +/* 消æ�¯é˜Ÿåˆ—中用到的放置消æ�¯çš„内存池 */ static char msg_pool[2048]; -/* ¶¨Ê±Æ÷µÄ¿ØÖÆ¿é */ +/* 定时器的控制å�— */ static struct rt_timer timer; static rt_uint16_t no = 0; static void timer_timeout(void* parameter) @@ -27,24 +27,24 @@ static void timer_timeout(void* parameter) rt_mq_send(&mq, &buf[0], length); } -/* Ïß³ÌÈë¿Úº¯Êý */ +/* 线程入å�£å‡½æ•° */ static void thread_entry(void* parameter) { char buf[64]; rt_err_t result; - /* ³õʼ»¯¶¨Ê±Æ÷ */ - rt_timer_init(&timer, "timer", /* ¶¨Ê±Æ÷Ãû×ÖÊÇ timer1 */ - timer_timeout, /* ³¬Ê±Ê±»Øµ÷µÄ´¦Àíº¯Êý */ - RT_NULL, /* ³¬Ê±º¯ÊýµÄÈë¿Ú²ÎÊý */ - 1, /* ¶¨Ê±³¤¶È£¬ÒÔOS TickΪµ¥Î»£¬¼´1¸öOS Tick */ - RT_TIMER_FLAG_PERIODIC); /* ÖÜÆÚÐÔ¶¨Ê±Æ÷ */ + /* åˆ�始化定时器 */ + rt_timer_init(&timer, "timer", /* 定时器å��字是 timer1 */ + timer_timeout, /* 超时时回调的处ç�†å‡½æ•° */ + RT_NULL, /* 超时函数的入å�£å�‚æ•° */ + 1, /* 定时长度,以OS Tick为å�•ä½�,å�³1个OS Tick */ + RT_TIMER_FLAG_PERIODIC); /* 周期性定时器 */ while (1) { rt_memset(&buf[0], 0, sizeof(buf)); - /* ´ÓÏûÏ¢¶ÓÁÐÖнÓÊÕÏûÏ¢ */ + /* 从消æ�¯é˜Ÿåˆ—中接收消æ�¯ */ result = rt_mq_recv(&mq, &buf[0], sizeof(buf), 1); if (result == RT_EOK) { @@ -59,16 +59,16 @@ static void thread_entry(void* parameter) int timer_timeout_init() { - /* ³õʼ»¯ÏûÏ¢¶ÓÁÐ */ - rt_mq_init(&mq, "mqt", - &msg_pool[0], /* ÄÚ´æ³ØÖ¸Ïòmsg_pool */ - 128 - sizeof(void*), /* ÿ¸öÏûÏ¢µÄ´óСÊÇ 128 - void* */ - sizeof(msg_pool), /* ÄÚ´æ³ØµÄ´óСÊÇmsg_poolµÄ´óС */ - RT_IPC_FLAG_FIFO); /* Èç¹ûÓжà¸öÏ̵߳ȴý£¬°´ÕÕÏÈÀ´Ïȵõ½µÄ·½·¨·ÖÅäÏûÏ¢ */ - - /* ´´½¨Ïß³Ì */ + /* åˆ�始化消æ�¯é˜Ÿåˆ— */ + rt_mq_init(&mq, "mqt", + &msg_pool[0], /* 内存池指å�‘msg_pool */ + 128 - sizeof(void*), /* æ¯�个消æ�¯çš„大å°�是 128 - void* */ + sizeof(msg_pool), /* 内存池的大å°�是msg_pool的大å°� */ + RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先æ�¥å…ˆå¾—到的方法分é…�消æ�¯ */ + + /* 创建线程 */ tid = rt_thread_create("t", - thread_entry, RT_NULL, /* Ïß³ÌÈë¿ÚÊÇthread_entry, Èë¿Ú²ÎÊýÊÇRT_NULL */ + thread_entry, RT_NULL, /* 线程入å�£æ˜¯thread_entry, å…¥å�£å�‚数是RT_NULL */ THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); if (tid != RT_NULL) rt_thread_startup(tid); @@ -81,38 +81,38 @@ int timer_timeout_init() #ifdef RT_USING_TC static void _tc_cleanup() { - /* µ÷¶ÈÆ÷ÉÏËø£¬ÉÏËøºó£¬½«²»ÔÙÇл»µ½ÆäËûỊ̈߳¬½öÏìÓ¦ÖÐ¶Ï */ + /* 调度器上é”�,上é”�å�Žï¼Œå°†ä¸�å†�切æ�¢åˆ°å…¶ä»–线程,仅å“�应中断 */ rt_enter_critical(); - /* ɾ³ýÏß³Ì */ + /* 删除线程 */ if (tid != RT_NULL && tid->stat != RT_THREAD_CLOSE) rt_thread_delete(tid); - /* Ö´ÐÐÏûÏ¢¶ÓÁжÔÏóÍÑÀë */ + /* 执行消æ�¯é˜Ÿåˆ—对象脱离 */ rt_mq_detach(&mq); - /* Ö´Ðж¨Ê±Æ÷ÍÑÀë */ + /* 执行定时器脱离 */ rt_timer_detach(&timer); - /* µ÷¶ÈÆ÷½âËø */ + /* 调度器解é”� */ rt_exit_critical(); - /* ÉèÖÃTestCase״̬ */ + /* 设置TestCase状æ€� */ tc_done(TC_STAT_PASSED); } int _tc_timer_timeout() { - /* ÉèÖÃTestCaseÇåÀí»Øµ÷º¯Êý */ + /* 设置TestCase清ç�†å›žè°ƒå‡½æ•° */ tc_cleanup(_tc_cleanup); timer_timeout_init(); - /* ·µ»ØTestCaseÔËÐеÄ×ʱ¼ä */ + /* 返回TestCaseè¿�行的最长时间 */ return 100; } -/* Êä³öº¯ÊýÃüÁîµ½finsh shellÖÐ */ +/* 输出函数命令到finsh shell中 */ FINSH_FUNCTION_EXPORT(_tc_timer_timeout, a thread timer testcase); #else -/* Óû§Ó¦ÓÃÈë¿Ú */ +/* 用户应用入å�£ */ int rt_application_init() { timer_timeout_init(); -- cgit v1.3.1