ѧϰ´ïµ½Ð§¹û£º
1£©Á˽âUCOS¹¤×÷ÔËÐеÄÔÀí£»
2£©Á˽âUCOSµÄÎļþ½á¹¹£¬Äܹ»×ÔÐÐÔĶÁÏà¹ØÎļþ£»
3£©ÕÆÎÕUCOSµÄAPIº¯Êý¡£¶àд£¬¶àÁ·¡£
//£ºCÓïÑÔ¡¢CÓïÑÔѧϰ¡¢CÓïÑÔÅàѵ¡¢MCUѧϰ¡¢PCB½Ì³Ì¡¢PCBѧϰ¡¢Ç¶Èëʽѧϰ¡¢Ç¶ÈëʽÅàѵ¡¢Ç¶Èëʽ½Ì³Ì¡¢Ç¶Èëʽǰ¾°¡¢Ç¶ÈëʽLinux¡¢Linux¿ª·¢¡¢Linuxϵͳ¡¢python¡¢python½Ì³Ì¡¢pythonѧϰ¡¢Python±à³Ì¡¢Python´ýÓö¡¢ÎïÁªÍø¿ª·¢¡¢ÎïÁªÍøÅàѵ¡¢ÎïÁªÍøÖÇÄÜ¿ØÖÆ¡¢ÎïÁªÍøѧϰ¡¢ÐÅÓ¯´ïÅàѵ¡¢ÐÅÓ¯´ïǶÈëʽ £º//
ѧϰµÄÖ÷ÒªÎĵµ£º
1£©UCOSIIÔ´Â룻
2£©¦ÌCOS-II_2.92 APIº¯ÊýÏê½â v2.0
3£©Ç¶Èëʽʵʱ²Ù×÷ϵͳ¦ÌCOS-IIÔÀí¼°Ó¦ÓÃ-ÈÎÕÜ(¸ßÇå°æ±¾)
µÚ1Õ ²Ù×÷ϵͳµÄ¸ÅÄî
1.1 ²Ù×÷ϵͳµÄ»ù±¾¸ÅÄî
²Ù×÷ϵͳµÄ¶¨Ò壺²Ù×÷ϵͳ£¨Operating System£¬OS£©½éÓÚÓ²¼þºÍÈí¼þÖ®¼ä£¬Îª¿ª·¢ÕßÌṩAPI£¨Application Programming Interface£©º¯Êý½Ó¿Ú£¬ÆÁ±ÎÓ²¼þϸ½Ú£¬Ìá¸ß¿ª·¢Ð§ÂÊ¡£
²Ù×÷ϵͳµÄ·ÖÀࣺʵʱ²Ù×÷ϵͳ£¨FreeRTOS£¬UCOS£¬RTX£¬RT-Thread¡££©ºÍ·Öʱ²Ù×÷ϵͳ£¨¸ß°æ±¾µÄLinux£¬windows£©¡£
RTOS£ºReal Time Operating System ¡£Ò»°ãÓÃÓڵͶ˳¡ºÏ£¬Ð¾Æ¬µÄÖ÷Ƶ½ÏµÍ¡£ÊµÊ±ÐÔ£º¶ÔÓÚÖØÒªµÄʼþÄܹ»¼°Ê±ÏìÓ¦£¬¿ÉÄÜͬʱ·¢ÉúºÜ¶àÊÂÇ飬ËäÈ»MCU²»¿ÉÄÜͬʱȫ²¿´¦Àí£¬µ«ÊÇËûÒ»¶¨Äܹ»´¦Àí×îÖØÒªµÄÒ»¼þÊ¡£ÔÚ¹¤Òµ²úÆ·ÖÐÓкܶàÓ¦Óá£
UCOS£ºUCOSµÄѧϰ×ÊÁϷḻ¡£´úÂëÌåϵÍêÉÆ¡£
Ç°ºǫ́ϵͳ£º
Âã»ú´úÂ룺ǰºǫ́ϵͳ£¬Ò»°ã½«while(1)Ñ»·ÀïÃæµÄ³ÌÐò³Æ֮Ϊºǫ́´úÂ룬½«ÖжϷþÎñº¯Êý³Æ֮Ϊǰ̨´úÂë¡£³ÌÐò¹¦ÄÜÊÇͨ¹ýÔÚÖ÷º¯Êýµ±Öе÷ÓÃÒ»¸ö¸öµÄ×Óº¯Êý£¬²¢Í¨¹ý¿ØÖÆÓï¾ä¿ØÖƳÌÐòÁ÷Ïò¡£
ÎÒÃÇÒ»°ãÔÚÖжϷþÎñº¯ÊýÐ޸ıê־룬ÔÚÖ÷º¯ÊýÅжϱê־λ´¦ÀíÈÎÎñ£¬µ«ÊÇÕâÖмä»áÓÐʱ¼äÑÓʱ£¬³Æ֮ΪÈÎÎñÑÓʱ£¬µ±ÎÒÃǵÄÖ÷º¯Êý¹¦ÄÜÔ½À´Ô½¶à£¬ÅжÏÌõ¼þÔ½À´Ô½¶à£¬»áµ¼Ö²Ù×÷ʱ¼äÔ½À´Ô½³¤£¬¹¦ÄÜά»¤Ô½À´Ô½À§ÄÑ¡£
²Ù×÷ϵͳ£ºÍ¨¹ýÈÎÎñµ÷¶ÈÆ÷¶ÔÄÚºË×ÊÔ´µÄ¹ÜÀí£¨¹ÜÀíCPUµÄʹÓÃȨ£©£¬Äܹ»ÊµÏÖ¶Ô¶à¸öÈÎÎñµÄ¼°Ê±¡¢²¢·¢ÐÔ£¨Ã¿´Î»¹ÊÇÖ»ÓÐÒ»¸öÈÎÎñÔËÐУ¬ÈÎÎñÇл»ºÜ¿ì£©µÄ´¦Àí¡£
UCOSµÄºËÐÄÊÇÈÎÎñ£¬³ÌÐò¹¦ÄÜÊÇͨ¹ýÒ»¸ö¸öÈÎÎñȥʵÏֵġ£Ã¿¸öÈÎÎñ¶¼ÓÐÒ»¸öwhile(1)ËÀÑ»·£¬Ã»ÓÐÍ˳öÌõ¼þ£¬Ã»Óзµ»ØÖµ£¬ ÎÒÃÇÊÇͨ¹ýÔÚÈÎÎñÖе÷ÓÃϵͳÌṩµÄAPIʵÏÖÈÎÎñºÍÈÎÎñÖ®¼äµÄת»»¡£
1.2 UCOS²Ù×÷ϵͳ
1.2.1 UCOSµÄÔ´ÂëÌåϵ½á¹¹
Óë´¦ÀíÆ÷ÎÞ¹Ø | os_core.c | ϵͳºËÐÄÎļþ |
|
os_flag.c | ÈÎÎñͨÐÅ£ºÊ¼þ±êÖ¾×éµ×²ãÎļþ | ||
os_mbox.c | ÈÎÎñͨÐÅ£ºÏûÏ¢ÓÊÏä | ||
os_mem.c | ÄÚ´æ¹ÜÀí£ºÊµÏÖÄڴ涯̬·ÖÅ䣬ÒÔ¼°ÊͷŹ¦ÄÜÀàËƱê×¼C malloc free | ||
os_mutex.c | ÈÎÎñͨÐÅ£º»¥³âËøÖ§³Ö | ||
os_q.c | ÈÎÎñͨÐÅ£ºÏûÏ¢¶ÓÁÐÖ§³Ö | ||
os_task.c | ÈÎÎñ¹ÜÀí | ||
os_time.c | ʱ¼ä¹ÜÀíÏà¹Øº¯Êý | ||
os_tmr.c | Èí¼þ¶¨Ê±Æ÷Ïà¹Øº¯Êý | ||
Óë´¦ÀíÆ÷ÓÐ¹Ø | os_cpu_c.c£¬os_cpu_a.s | ÒÆֲʱºòÐèÒªÐ޸ĵÄÎļþ |
|
os_cpu.h | cpuÏà¹ØµÄÍ·Îļþ | ||
| ucos_ii.h | ¦ÌC/OSÖÐËùÓпÉÓÃAPIº¯ÊýÉùÃ÷Îļþ |
|
1.2.2 UCOSϵͳµÄÌصã
΢ÐÍ»¯£º ´úÂëÁ¿ºÜÉÙ£¬×îС¿ÉÒÔÊÇ8K×óÓÒ¡£
רÓÃÐÔÇ¿£ºUCOSϵͳÄܹ»Ó¦ÓÃÔںܶàµÍ¶ËоƬÉÏ£¬±ÈÈçSTM32¡£
¿É²Ã¼ô£º ÎÒÃÇÔÚÒÆֲʱ£¬Ö»ÐèÒªÔÚOS_CFG_HÎļþÖн«ÏàÓ¦µÄºê¿ª¹Ø¹Ø±Õ£¬¾ÍÄܲüôµôÎÒÃDz»ÐèÒªµÄ´úÂë³ÌÐò£¬´ïµ½ÏµÍ³²Ã¼ôµÄÄ¿µÄ¡£
ʵʱÐԸߣºÒòΪUCOS²Ù×÷ϵͳÊÇÇÀÕ¼ÈÎÎñʽ²Ù×÷ϵͳ£¬ÏµÍ³ÕýÔÚÖ´ÐеÄÈÎÎñÒ»¶¨ÊǾÍÐ÷µÄÈÎÎñµ±ÖУ¬ÈÎÎñÓÅÏȼ¶×î¸ßµÄ¡£
µÚ2ÕÂ UCOSÈÎÎñ
2.0.1 ÈÎÎñµÄ¸ÅÄî
ʲô½ÐÈÎÎñ£¿ÔÚϵͳÖУ¬¿ÉÒÔÏȼòµ¥µÄÈÏΪÿ¸öUCOSÈÎÎñ¾ÍÊÇÒ»¸öwhile(1)Ñ»·¡£
ÔÚUCOSϵͳÖУ¬³ÌÐòµÄÁ÷Ïò²»ÊÇÓÉÖ÷º¯Êý¾ö¶¨µÄ¡£¶øÊÇÓÉϵͳ·ÖÅäCPUʹÓÃȨµÄ¡£
Âã»ú´úÂ룬ûÓÐÅܲÙ×÷ϵͳ£¬³ÌÐò»ù±¾¶¼ÊÇÔÚwhile(1)Ñ»·ÀïʵÏÖ£¬Í¬Ò»Ê±¿Ì£¬Ö»»áÖ´ÐÐÒ»¸öwhile(1)Ñ»·£¬while(1)Ñ»·µÄÇл»Ò»°ãÓÃbreakʵÏÖ¡£ | ÅÜϵͳ£¬Ã¿¸öÈÎÎñ¾ÍÊÇÒ»¸öwhile(1)Ñ»·£¬¿ÉÒÔ¶à¸öwhile(1)Ñ»·²¢ÐÐÖ´ÐУ¨Á½¸öÑ»·µÄÇл»·Ç³£¿ì£¬ÑÓʱºÜС¡££© |
int main(void) { //¸÷Ä£¿é³õʼ»¯ while(1) { //ͨ¹ý¸÷¸ö¿ØÖÆÓï¾ä¿ØÖƳÌÐòÁ÷Ïò } } | int main(void) { //Æô¶¯UCOSϵͳ }
void task1(void) { //Õⲿ·Ö´úÂëÒ²»áÖ´ÐУ¬µ«ÊÇÖ»»áÔÚÈÎÎñµÚÒ»´ÎÖ´ÐÐʱִÐÐ while(1) { //Ö»ÒªÈÎÎñ»¹ÔÚÔËÐУ¬¾Í»á¼ÌÐøÖ´ÐÐ } }
void task2(void) { //Õⲿ·Ö´úÂëÒ²»áÖ´ÐУ¬µ«ÊÇÖ»»áÔÚÈÎÎñµÚÒ»´ÎÖ´ÐÐʱִÐÐ while(1) { //Ö»ÒªÈÎÎñ»¹ÔÚÔËÐУ¬¾Í»á¼ÌÐøÖ´ÐÐ } }
|
2.0.2 ÈÎÎñ״̬
2.0.3 ÈÎÎñ¼ä¹Øϵ
2.1 ÈÎÎñÓÅÏȼ¶
2.1.1 ÈÎÎñÓÅÏȼ¶
2.8.6°æ±¾Ö®ºóµÄUCOSÓÐ256¸ö²»Í¬µÄÓÅÏȼ¶ÉèÖã¬ÓÅÏȼ¶ÓÃÊý×Ö±íʾ0~255£¬Êý×ÖԽСÓÅÏȼ¶Ô½¸ß¡£ÏµÍ³ÒѾĬÈϽ«×îµÍÓÅÏȼ¶255·ÖÅä¸ø¿ÕÏÐÈÎÎñ£»Èç¹ûʹÓÃÁËͳ¼ÆÈÎÎñ£¬ÏµÍ³»¹»á½«ÓÅÏȼ¶254·ÖÅä¸øͳ¼ÆÈÎÎñ¡£Ò»°ã½«Èí¼þ¶¨Ê±Æ÷µÄÓÅÏȼ¶É趨Ϊ×î¸ß0¡££¨ÎÒÃÇÒÆÖ²µÄucosϵͳ£¬Ö»ÔÊÐíÉèÖÃ64²ãÓÅÏȼ¶£¬¿ÉÒÔÔÚÅäÖÃÎļþÐ޸ġ££©
Ò»°ã²»½¨Ò齫ÈÎÎñÉèÖÃΪ×î¸ßµÄ¼¸¸öÓÅÏȼ¶£¬½¨Òé·ÖÅäÖмäÄDz¿·ÖµÄÓÅÏȼ¶¡£Áô³ö½Ï¸ßºÍ½ÏµÍ·½±ãÍØÕ¹¡£
×¢Ò⣺ÿ¸öÈÎÎñ¶ÔÓ¦Ò»¸öÓÅÏȼ¶£¬Ò»¸öÓÅÏȼ¶Ò»¶¨ÊÇÖ»ÄܶÔÓ¦Ò»¸öÈÎÎñ¡£
2.1.2 ¿ÕÏÐÈÎÎñ
ÓÉÓÚÈÎÎñ×ÜÊÇÔÚ5ÖÖ״̬֮¼äÇл»£¬ËùÒÔϵͳ¼«ÓпÉÄÜÔÚijһʱ¿ÌûÓÐÈÎÎñ¿ÉÖ´ÐУ¬µ«ÊÇÍ£Ö¹CPU¹¤×÷»áµ¼ÖÂһЩĪÃû´íÎó£¬ËùÒÔϵͳ´´½¨ÁËÒ»¸ö¿ÕÏÐÈÎÎñ£¬µ±ÏµÍ³ÖеÄÆäËûÈÎÎñ¶¼²»Ö´ÐÐʱ£¬ÏµÍ³¾Í»áÔËÐпÕÏÐÈÎÎñ¡£
2.1.3 ͳ¼ÆÈÎÎñ
ͳ¼ÆÈÎÎñͳ¼ÆCPUÔÚ1ÃëÖÓÄÚ±»ÆäËûÈÎÎñÕ¼ÓõÄʱ¼ä£¬²¢½«½á¹û±£´æÔÚÈ«¾Ö±äÁ¿ OSCPUsageµ±ÖÐ
2.2 ÈÎÎñµ÷¶È
UCOSÈÎÎñÇл»ÊÇͨ¹ýÈÎÎñµ÷¶ÈÆ÷ʵÏֵģ¬ÈÎÎñµ÷¶ÈÆ÷µÄÈÎÎñµ÷¶È£¬Ö»ÓÐÔÚÕýÔÚÔËÐеÄÈÎÎñ·ÅÆúCPUʹÓÃȨ£¬»òÕß·¢ÉúÈÎÎñÇÀռʱ²Å¹¤×÷£¬ÖжÏÍ˳ö¡£
2.3 ÈÎÎñ¿ØÖÆ¿é
UCOSµÄÈÎÎñ¿ØÖÆ¿éÊÇÓÃÀ´¼Ç¼ÈÎÎñµÄ¶ÑÕ»Ö¸Õ룬µ±Ç°×´Ì¬£¬ÓÅÏȼ¶µÈµÈÓëÈÎÎñÏà¹ØµÄÐÅÏ¢£¬Ã¿¸öÈÎÎñ±»´´½¨Ê±£¬UCOS¶¼»á·ÖÅä¸øËýÒ»¸ö¿Õ°×µÄÈÎÎñ¿ØÖÆ¿éÓÃÒÔ´æ´¢¸ÃÈÎÎñµÄÏà¹ØÐÅÏ¢¡£µ±Ò»¸öÈÎÎñ±»É¾³ýÖ®ºó£¬ËûµÄÈÎÎñ¿ØÖÆ¿éÓÖ¿ÉÒÔÖØÐÂʹÓá£
ÈÎÎñ¿ØÖƿ飺TCB£¬task control block¡£
¸Ã¿ØÖÆ¿éµÄ¶¨ÒåÔÚucosii.hÎļþµÄ 530ÐС£
µÚ3ՠн¨UCOS¹¤³Ì
3.1 ÐèÒªµÄ×ÊÁÏ
1) Ò»¸öÒѾÍêÕûµÄÂã»ú´úÂë
2) ÏàÓ¦µÄUCOSÔ´Îļþ£¬¹ÙÍøÏÂÔØmicrum
3) os_cpu.h£¬os_cpu_a.asm£¬os_cpu_c.c£¬os_cfg.h£¬includes.h
3.2 µÚÒ»²½
½«Ïà¹ØÎļþÌí¼Óµ½¹¤³Ì£¬¸ù¾Ý±àÒëÌáʾ£¬È¥³ýÏàÓ¦Îļþ£¬²¢ÇÒµ½os_cfg.hÎļþÐ޸ĺ꿪¹ØÁ¿¡£
3.3 µÚ¶þ²½
ʹÓõδð¶¨Ê±Æ÷ΪϵͳÉú³ÉʱÖÓ½ÚÅÄ£¬µ÷ÓÃÏà¹Øº¯ÊýÍê³É½ÚÅÄͳ¼Æ¡£
3.4 µÚÈý²½
³õʼ»¯ÏµÍ³£¬½¨Á¢ÈÎÎñ£¬Æô¶¯UCOS
µÚ4Õ UCOSϵͳ³õʼ»¯
4.1 ϵͳ½ÚÅĽéÉÜ
UCOSϵͳÈÎÎñÇл»ÊÇÒÔʱ¼äƬΪµ¥Î»µÄ£¬Ê±¼äƬ¼´ÊÇUCOSϵͳµÄÐÄÌø¡¢ÏµÍ³½ÚÅÄ¡£¿ÉÒÔÓõδð¶¨Ê±Æ÷ʵÏÖ£¬»òÕßÆäËû¶¨Ê±Æ÷£¬ÔÚÏà¹ØµÄ¶¨Ê±ÖжÏÖе÷ÓÃϵͳ¹ØÓÚ½ÚÅÄͳ¼ÆµÄÏà¹Øº¯Êý¡£
ʱÖÓ½ÚÅÄÊý£ºÖ¸µÄÊÇϵͳһÃëÖÓ½øÈëµÄ¶¨Ê±Æ÷ÖжϵĴÎÊý¡£
¼ÙÉèϵͳ½ÚÅÄÊÇ200£¬ÄÇôÇëÎʵδð¶¨Ê±Æ÷¶à¾Ã²úÉúÒ»´ÎµÎ´ðÖжϡ£
´ð£ºÃ¿¸ö½ÚÅÄʱ¼äÊÇ5ms¡£
ÔÚOS_CFG_HÎļþÖУ¬¶¨ÒåÁËʱÖÓ½ÚÅÄÊý£¬½¨Òé³õʼ»¯½ÚÅÄʱµ÷ÓøÃÁ¿¡£
¼ÙÉ躯ÊýSysTick_Init_ms(u16 ms);ҪʵÏÖÒ»ÃëÖÓ200¸ö½ÚÅÄ¡£
SysTick_Init_ms(1000/OS_TICKS_PER_SEC);
Ò»¸ö½ÚÅĵÄʱ¼äԽС£º½ÚÅÄÊýÔ½¶à£¬CPUԽ棬ϵͳµÄʵʱÐÔ¸ü¸ß¡£
Ò»¸ö½ÚÅĵÄʱ¼äÔ½´ó£º½ÚÅÄÊýÔ½ÉÙ£¬CPUÔ½ÏУ¬ÏµÍ³µÄʵʱÐԽϲ
Ò»°ã½¨ÒéÒ»¸ö½ÚÅÄ5~10ms¡£½ÚÅÄÊý£º200~100£»
µÎ´ðÖжϵÄÓÅÏȼ¶£ºÓ¦¸ÃÅäÖÃΪ×îµÍÓÅÏȼ¶¡£
4.2 ϵͳ½ÚÅijõʼ»¯´úÂë
void SysTick_Init_xms(u32 ms) { SysTick->CTRL &=~(1<<0); //¹Ø±ÕµÎ´ð¶¨Ê±Æ÷ SysTick->CTRL &=~(1<<2); //Ñ¡ÔñʱÖÓԴΪ 21 MHz SysTick->CTRL &=~(1<<1); //¹Ø±ÕµÎ´ðÖÐ¶Ï SysTick->LOAD = 21000*ms; //Ïò×Ô¶¯ÖØÔؼĴæÆ÷дÈë¼ÆÊýÖµ SysTick->VAL =0; //³õʼ»¯µ±Ç°Öµ¼Ä´æÆ÷ SysTick->CTRL |=1<<1; //´ò¿ªµÎ´ðÖÐ¶Ï NVIC_SetPriorityGrouping(5); //·Ö×éÉèÖà NVIC_SetPriority(SysTick_IRQn,NVIC_EncodePriority(5,3,3) ); //ÓÅÏȼ¶ÉèÖÃΪ×îµÍ NVIC_EnableIRQ(SysTick_IRQn); //ÖжÏͨµÀʹÄÜ SysTick->CTRL |=1<<0; //´ò¿ªµÎ´ð¶¨Ê±Æ÷ } |
void SysTick_Handler(void) { OSIntEnter();//֪ͨÄÚºËÖжϺ¯ÊýÕýÔÚÖ´ÐС£ if( SysTick->CTRL & (1<<16)) { OSTimeTick();//½ÚÅÄͳ¼Æ } OSIntExit(); //֪ͨÄÚºËÒ»¸öÖжϷþÎñÒÑÖ´ÐÐÍê±Ï¡£ } |
4.3 ϵͳ³õʼ»¯
OSInit(); // ³õʼ»¯ uC/OS-II // ×îÉÙ´´½¨Ò»¸öÈÎÎñ OSStart(); //Æô¶¯¶àÈÎÎñÄںˡ£ |
µÚ5Õ ʱ¼ä¹ÜÀíº¯Êý
5.1 ʱÖÓ½ÚÅijõʼ»¯
ÔÚos_cfg.h ÖÐÓж¨Ò壺#define OS_TICKS_PER_SEC 1000£¬Òâ˼ÊÇ°Ñ 1 Ãë·Ö³É 1000 ·Ý£¬Ôòÿ·ÝÊÇ 1ms , ÔòÒ»¸öʱÖÓ½ÚÅľÍÊÇ 1MS £¬Ò»ÃëÓÐ1000¸öʱÖÓ½ÚÅÄ¡£
ÔÚʹÓõδð¶¨Ê±Æ÷³õʼ»¯Ê±£¬Ôò
SysTick_Init(1000/OS_TICKS_PER_SEC);//Ò»ÃëµÄ½ÚÅÄÊýÊÇ200 |
ÐÞ¸ÄʱÖÓ½ÚÅÄÊý£¬Ö»ÐèÒªÐÞ¸ÄOS_TICKS_PER_SECµÄÖµ¡£
5.2 ÈÎÎñÑÓʱº¯ÊýOSTimeDly()
×÷Ó㺠ÈÎÎñÑÓʱº¯Êý(ʱÖÓ½ÚÅÄÊý)¡£ ʵ¼ÊÊÇÉÏ·ÅÆú CPUʹÓÃȨ£¬ÐÝÃßÈ¥ÁË¡£ º¯ÊýÔÐÍ£º void OSTimeDly(INT32U ticks); ²ÎÊý£º ticks£º ΪҪÑÓʱµÄʱÖÓ½ÚÅÄÊý¡£ OSTimeDly(100); //ÑÓʱ100¸ö½ÚÅÄ£¬500ms ×¢Ò⣺ËùÓеÄÈÎÎñµ±Öж¼Ó¦¸ÃÓзÅÆúCPUʹÓÃȨµÄ²Ù×÷»òÕßÃüÁ·ñÔòÓÅÏȼ¶µÍÓÚ´ËÈÎÎñµÄÆäËûÈÎÎñ¾ÍÓÀԶûÓа취ִÐС£ |
5.3 ÈÎÎñÑÓʱº¯ÊýOSTimeDlyHMSM()
×÷Ó㺠ÈÎÎñÑÓʱº¯Êý(ʱÖÓ½ÚÅÄÊý)¡£ º¯ÊýÔÐÍ£º INT8U OSTimeDlyHMSM (INT8U hours, INT8U minutes, INT8U seconds, INT16U ms); ²ÎÊý£º hours£º ΪÑÓʱСʱÊý£¬·¶Î§´Ó 0-255¡£ minutes£º ΪÑÓʱ·ÖÖÓÊý£¬·¶Î§´Ó 0-59¡£ seconds£º ΪÑÓʱÃëÊý£¬·¶Î§´Ó 0-59¡£ ms£º ΪÑÓʱºÁÃëÊý£¬·¶Î§´Ó 0-999¡£ÐèҪ˵Ã÷µÄÊÇ£¬ÑÓʱ²Ù×÷º¯Êý¶¼ÊÇÒÔʱÖÓ½ÚÅÄΪΪµ¥Î»µÄ¡£Êµ ¼ÊµÄÑÓʱʱ¼äÊÇʱÖÓ½ÚÅĵÄÕûÊý±¶¡£ ÀýÈ磺ϵͳÿ´ÎʱÖÓ½ÚÅļä¸ôÊÇ 10ms£¬Èç¹ûÉ趨ÑÓʱΪ 5ms£¬½«²»²úÉúÈκÎÑÓʱ²Ù×÷£¬¶øÉ趨ÑÓʱ 15ms£¬Êµ¼ÊµÄÑÓʱÊÇÁ½¸öʱÖÓ½ÚÅÄ£¬Ò²¾ÍÊÇ 20ms¡£ |
µÚ6Õ ÈÎÎñ¹ÜÀí
6.1 ÈÎÎñ´´½¨º¯Êý
×÷Ó㺴´½¨Ò»¸öÐÂÈÎÎñ¡£ º¯ÊýÔÐÍ£º INT8U OSTaskCreate(void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio); OSTaskCreate£¨£©½¨Á¢Ò»¸öÐÂÈÎÎñ¡£ÈÎÎñµÄ½¨Á¢¿ÉÒÔÔÚ¶àÈÎÎñ»·¾³Æô¶¯Ö®Ç°£¬Ò²¿ÉÒÔÔÚÕýÔÚÔËÐеÄÈÎÎñÖн¨Á¢¡£Öжϴ¦Àí³ÌÐòÖв»Äܽ¨Á¢ÈÎÎñ¡£ Ò»¸öÈÎÎñ±ØÐëΪÎÞÏÞÑ»·½á¹¹£¬ÇÒ²»ÄÜÓзµ»Øµã¡£ ²ÎÊý£º task£º ÊÇÖ¸ÏòÈÎÎñ´úÂëµÄÖ¸Õë¡£ pdata£ºÖ¸ÏòÒ»¸öÊý¾Ý½á¹¹£¬¸Ã½á¹¹ÓÃÀ´ÔÚ½¨Á¢ÈÎÎñʱÏòÈÎÎñ´«µÝ²ÎÊý¡£ ptos£º ΪָÏòÈÎÎñ¶ÑÕ»Õ»¶¥µÄÖ¸Õë¡£ prio£º ΪÈÎÎñµÄÓÅÏȼ¶¡£Ã¿¸öÈÎÎñ±ØÐëÓÐÒ»¸öΨһµÄÓÅÏȼ¶×÷Ϊ±êʶ¡£Êý×ÖԽС£¬ÓÅÏȼ¶Ô½¸ß¡£ Õ»¶¥Õ»µ×£º Êý×ébuff[64],×î¸ßµØÖ·&buff[63] Êý¾ÝµØÖ·ÓɸߵØÖ·ÏòµÍµØÖ·Ôö³¤£¬ buff[63](Õ»¶¥)-> buff[0](Õ»µ×) |
6.2 ÈÎÎñɾ³ýº¯Êý
6.2.1 Ö±½Óɾ³ý
×÷Ó㺠ɾ³ýÈÎÎñ£¬²»ÈÃÔÙÓлú»áµ÷¶È£¬³ý·ÇÖØд´½¨¡£ º¯ÊýÔÐÍ£º INT8U OSTaskDel(INT8U prio); ²ÎÊý£º prio£º Ϊָ¶¨ÒªÉ¾³ýÈÎÎñµÄÓÅÏȼ¶£¬Ò²¿ÉÒÔÓòÎÊý OS_PRIO_SELF ´úÌ棬´Ëʱ£¬ÏÂÒ»¸öÓÅÏȼ¶×î¸ßµÄ¾ÍÐ÷ ÈÎÎñ½«¿ªÊ¼ÔËÐС£ |
6.2.2 ÇëÇóɾ³ýÈÎÎñº¯Êý
×÷Ó㺠ÇëÇóÒ»¸öÈÎÎñɾ³ýÆäËüÈÎÎñ»ò×ÔÉí¡£ º¯ÊýÔÐÍ£º INT8U OSTaskDelReq(INT8U prio); ²ÎÊý£º prio£º ΪҪÇóɾ³ýÈÎÎñµÄÓÅÏȼ¶¡£Èç¹û²ÎÊýΪ OS_PRIO_SELF£¬Ôò±íʾµ÷Óú¯ÊýµÄÈÎÎñÕýÔÚ²éѯÊÇ·ñÓÐÀ´×Ô ÆäËûÈÎÎñµÄɾ³ýÇëÇó¡£ ·µ»ØÖµ£º OSTaskDelReq£¨£©·µ»ØÏÂÁдíÎó´úÂëÖ®Ò»£º OS_ERR_NONE£º ɾ³ýÇëÇóÒÑÈÎÎñ¼Ç¼¡£ OS_ERR_TASK_NOT_EXIST£ºÖ¸¶¨µÄÈÎÎñ²»´æÔÚ¡£·¢ËÍɾ³ýÇëÇóµÄÈÎÎñ¿ÉÒԵȴý´Ë·µ»ØÖµ¿´ÊÇ·ñ³É¹¦¡£ OS_ERR_TASK_IDLE£º ³¢ÊÔɾ³ý¿ÕÏÐÈÎÎñ£¬²»ÔÊÐí¡£ OS_ERR_PRIO_INVALID£º Ö¸¶¨ÈÎÎñµÄÓÅÏȼ¶±È OS_LOWEST_PRIO ¸ßÓÚ»ò²»Ö¸¶¨ OS_PRIO_SELF¡£ OS_ERR_TASK_DEL£º ÈÎÎñ±»·ÖÅäµ½Ò»»¥³â¡£ OS_ERR_TASK_DEL_REQ£º µ±Ç°ÈÎÎñÊÕµ½À´×ÔÆäËûÈÎÎñµÄɾ³ýÇëÇó¡£ |
µÚ7Õ ÈÎÎñ¼äͨÐÅ
7.1 ÈÎÎñ¼äͨÐÅ
ÔÚÂã»ú´úÂëµ±ÖУ¬¹¦ÄÜÊÇͨ¹ý¸÷¸öº¯ÊýʵÏֵġ£
¸÷¸öº¯ÊýÖ®¼äÈçºÎͬ²½¡¢Í¨ÐÅ£º²ÎÊý´«µÝ£¬µØÖ·´«µÝ£¬·µ»ØÖµ£¬È«¾Ö±äÁ¿¡£
ÔÚ²Ù×÷ϵͳµ±ÖУ¬¹¦ÄÜÊÇͨ¹ý¸÷¸öÈÎÎñʵÏֵģ¬ÈÎÎñûÓÐÍ˳öÌõ¼þ¡£
ÈÎÎñ¼äͨÐÅ£ºÈÎÎñûÓе÷ÓùØϵ£º²ÎÊý´«µÝ£¬µØÖ·´«µÝ£¨²»·½±ã£©£¬Ö»ÔÚÈÎÎñ´´½¨Ê±¿ÉÓã»È«¾Ö±äÁ¿¡£
i=10£»i++£» ¼ÙÈçÖжϵ±ÖжԱäÁ¿iÖ´ÐвÙ×÷i--¡£×îºói=£¿
1£©¼ÙÈçÒѾ»ñµÃÁËiµÄÖµ£¬È»ºóÖжϷ¢Éú£¬ÖжÏÍ˳öʱ²»ÔÙÈ¥ÌáÈ¡iµÄÖµ¡£
2£©Öжϵ±ÖУ¬i--£¬»ñÈ¡iµÄµ±Ç°Öµ¡£i=10£»i--£»i=9;
3£©Ö®Ç°½«iµÄÖµ10£¬ÒѾ±»±£´æµ½Õ»Çø£¬Ö±½ÓʹÓã¬×îºói=11;
ΪÁËʵÏÖÈÎÎñ¼äµÄʵʱÐÔ£¬¿É¿¿µÄͨÐÅ¡£ÎÒÃÇÒýÈëʼþµÄ¸ÅÄî¡£
ʼþ£ºÊµÏÖÈÎÎñ¼äµÄͨÐÅ¡¢Í¬²½¡£
ʼþµÄÀàÐÍ£ºÐźÅÁ¿¡¢ÏûÏ¢ÓÊÏä¡¢ÏûÏ¢¶ÓÁС¢»¥³âÐÍÐźÅÁ¿¡¢Ê¼þ±êÖ¾×é¡£
7.1.1 ʲôÊÇʼþ
ÈÎÎñ¼äͨÐÅÐèÒªÓõ½Ê¼þ¡£
ʼþÀàÐÍ£ºÐźÅÁ¿£¬ÏûÏ¢ÓÊÏ䣬ÏûÏ¢¶ÓÁУ¬»¥³âÐÍÐźÅÁ¿£¬Ê¼þ±êÖ¾×é¡£
ʼþ¿ØÖƿ飺µ±ÎÒÃÇ´´½¨Ò»¸öʼþµÄʱºò£¬UCOS¾Í»á´´½¨Ò»¸öÏàÓ¦µÄʼþ¿ØÖƿ飬ʼþ¿ØÖÆ¿éÓÃÀ´´æ´¢Ê¼þµÄÏà¹ØÐÅÏ¢£¬±¾ÖÊÊÇÒ»¸ö½á¹¹Ìå¡£
typedef struct os_event { INT8U OSEventType; void *OSEventPtr; INT16U OSEventCnt; OS_PRIO OSEventGrp; OS_PRIO OSEventTbl[OS_EVENT_TBL_SIZE]; #if OS_EVENT_NAME_EN > 0u INT8U *OSEventName; #endif } OS_EVENT; |
7.2 ÐźÅÁ¿´´½¨ºÍʹÓÃ
ÐźÅÁ¿£ºÐźÅÁ¿ÓÃÓÚ¶Ô¹²Ïí×ÊÔ´µÄ·ÃÎÊ¡£ÐźÅÁ¿±êʶÁ˹²Ïí×ÊÔ´µÄÓÐЧ¿É±»·ÃÎÊÊýÁ¿£¬Òª»ñµÃ¹²Ïí×ÊÔ´µÄ·ÃÎÊȨ£¬Ê×ÏȱØÐëµÃµ½ÐźÅÁ¿Õâ°ÑÔ¿³×¡£ÐźÅÁ¿±¾ÖÊÊÇÒ»¸öu16µÄÕûÐͱäÁ¿£¬ÎÒÃǶÔÐźÅÁ¿µÄ²Ù×÷£¬Æäʵ¶¼ÊÇÔÚ¶ÔÕâ¸ö±äÁ¿½øÐÐ++»òÕß--µÄ²Ù×÷£¬»òÕ߸³Öµ²Ù×÷¡£
ÎÒÃÇʹÓÃÐźÅÁ¿£¬Ö»ÐèÒª½«Ëüµ±×÷Ò»¸ö±äÁ¿Ê¹Óᣣ¨¶¨Òå¡¢++¡¢--£¬¸³Öµ£©
×÷ÓãºËùÓеÄÄãÔÚÂã»ú´úÂëµ±ÖÐÈ«¾Ö±äÁ¿£¨u16£©ÄÜÍê³ÉµÄÊÂÇ飬¶¼ÄÜÍê³É¡£
7.2.1 ´´½¨ÐźÅÁ¿
×÷Ó㺠½¨Á¢²¢³õʼ»¯Ò»¸öÐźÅÁ¿¡£ º¯ÊýÔÐÍ£º OS_EVENT *OSSemCreate(INT16U value); ²ÎÊý£º value ²ÎÊýÊǽ¨Á¢µÄÐźÅÁ¿µÄ³õʼֵ£¬¿ÉÒÔÈ¡ 0 µ½ 65535 Ö®¼äµÄÈκÎÖµ¡£ ·µ»ØÖµ£º OSSemCreate£¨£©º¯Êý·µ»ØÖ¸Ïò·ÖÅä¸øËù½¨Á¢µÄÏûÏ¢ÓÊÏäµÄʼþ¿ØÖÆ¿éµÄÖ¸Õë¡£Èç¹ûûÓпÉÓõÄʼþ¿ØÖƿ飬 OSSemCreate£¨£©º¯Êý·µ»Ø¿ÕÖ¸Õë¡£ |
7.2.2 ·¢ËÍÐźÅÁ¿
×÷Ó㺠·¢³öÒ»¸öÐźÅÁ¿£¬°ÑÐźÅÖµ¼Ó 1¡£ º¯ÊýÔÐÍ£º INT8U OSSemPost(OS_EVENT *pevent); OSSemPost()º¯ÊýÖÃÆð(°ÑÐźÅÖµ¼Ó 1)Ö¸¶¨µÄÐźÅÁ¿¡£Èç¹ûÖ¸¶¨µÄÐźÅÁ¿ÊÇÁã»ò´óÓÚÁ㣬 OSSemPost()º¯ÊýµÝ Ôö¸ÃÐźÅÁ¿²¢·µ»Ø¡£Èç¹ûÓÐÈκÎÈÎÎñÔڵȴýÐźÅÁ¿£¬×î¸ßÓÅÏȼ¶µÄÈÎÎñ½«µÃµ½ÐźÅÁ¿²¢½øÈë¾ÍÐ÷״̬,ÈÎÎñµ÷¶È º¯Êý½«½øÐÐÈÎÎñµ÷¶È¡£ ²ÎÊý£º pevent£º Ö¸ÏòÐźÅÁ¿µÄÖ¸Õë¡£ |
7.2.3 Î޵ȴý²é¿´ÐÅÏ¢
×÷Ó㺠Î޵ȴý²é¿´ÏûÏ¢ÓÊÏäÊÇ·ñÊÕµ½ÏûÏ¢¡£ º¯ÊýÔÐÍ£º INT16U OSSemAccept(OS_EVENT *pevent); OSSemAccept()º¯Êý²é¿´É豸ÊÇ·ñ¾ÍÐ÷»òʼþÊÇ·ñ·¢Éú¡£²»Í¬ÓÚ OSSemPend()º¯Êý£¬Èç¹ûÉ豸ûÓоÍÐ÷£¬ OSSemAccept()º¯Êý²¢²»¹ÒÆðÈÎÎñ¡£Öжϵ÷Óøú¯ÊýÀ´²éѯÐźÅÁ¿¡£ ²ÎÊý£º pevent£º ÊÇÖ¸ÏòÐèÒª²éѯµÄÉ豸µÄÐźÅÁ¿¡£µ±½¨Á¢ÐźÅÁ¿Ê±£¬¸ÃÖ¸Õë·µ»Øµ½Óû§³ÌÐò¡££¨²Î¿¼ OSSemCreate £¨£©º¯Êý£©¡£ ·µ»ØÖµ£º µ±µ÷Óà OSSemAccept()º¯Êýʱ£¬É豸ÐźÅÁ¿µÄÖµ´óÓÚÁ㣬˵Ã÷É豸¾ÍÐ÷£¬Õâ¸öÖµ±»·µ»Øµ÷ÓÃÕߣ¬É豸ÐźÅÁ¿µÄÖµ¼õÒ»¡£Èç¹ûµ÷Óà OSSemAccept()º¯Êýʱ£¬É豸ÐźÅÁ¿µÄÖµµÈÓÚÁ㣬˵Ã÷É豸ûÓоÍÐ÷£¬·µ»ØÁã¡£ |
7.2.4 ¹ÒÆðÈÎÎñµÈ´ýÐźÅÁ¿
×÷Ó㺠ÉêÇëÒ»¸öÐźÅÁ¿£¨¹ÒÆðÈÎÎñµÈ´ýÐźÅÁ¿£©¡£ º¯ÊýÔÐÍ£º void OSSemPend (OS_EVENT *pevent, INT32U timeout, INT8U *perr); OSSemPend()º¯ÊýÓÃÓÚÈÎÎñÊÔͼȡµÃÉ豸µÄʹÓÃȨ£¬ÈÎÎñÐèÒªºÍÆäËûÈÎÎñ»òÖжÏͬ²½£¬ÈÎÎñÐèÒªµÈ´ýÌض¨Ê ¼þµÄ·¢ÉúµÄ³¡ºÏ¡£ Èç¹ûÈÎÎñµ÷Óà OSSemPend()º¯Êýʱ£¬ÐźÅÁ¿µÄÖµ´óÓÚÁ㣬 OSSemPend()º¯ÊýµÝ¼õ¸ÃÖµ¡£ Èç¹ûµ÷ÓÃʱÐźÅÁ¿µÈÓÚÁ㣬 OSSemPend()º¯Êýº¯Êý½«ÈÎÎñ¼ÓÈë¸ÃÐźÅÁ¿µÄµÈ´ý¶ÓÁС£ ²ÎÊý£º pevent: Ö¸ÏòÏûÏ¢ÓÊÏäµÄÖ¸Õë¡£ timeout£º ÈÎÎñµÈ´ý³¬Ê±ÖÜÆÚ£¬ Ϊ 0 ʱ±íʾÎÞÏ޵ȴý£» ÆäËü£¬ µÝ¼õµ½ 0 ʱÈÎÎñ»Ö¸´Ö´ÐС£ perr: ×öΪÊä³ö²ÎÊýʹÓ㬠ָÏò´íÎó´úÂë±äÁ¿µÄÖ¸Õë¡£ |
7.2.5 ÉèÖÃÐźÅÁ¿µÄÖµOSSemSet()
×÷Ó㺠¸Ä±äµ±Ç°ÐźÅÁ¿µÄ¼ÆÊýÖµ¡£ µ±ÐźÅÁ¿±»ÓÃÓÚ±íʾijʼþ·¢ÉúÁ˶àÉٴεÄÇé¿öÏ»áʹÓᣠ²ÎÊý£º |
7.3
ÏûÏ¢ÓÊÏä
7.4 ÏûÏ¢ÓÊÏä
7.4.1 ½¨Á¢ÏûÏ¢ÓÊÏä
×÷Ó㺠½¨Á¢²¢³õʼ»¯Ò»¸öÏûÏ¢ÓÊÏä¡£ º¯ÊýÔÐÍ£º OS_EVENT *OSMboxCreate (void *pmsg); ²ÎÊý£º msg£º ²ÎÊýÓÃÀ´³õʼ»¯½¨Á¢µÄÏûÏ¢ÓÊÏä¡£Èç¹û¸ÃÖ¸Õ벻Ϊ¿Õ£¬ Ôò½¨Á¢µÄÏûÏ¢ÓÊÏ佫º¬ÓÐÏûÏ¢¡£ ·µ»ØÖµ£º Ö¸Ïò·ÖÅä¸øËù½¨Á¢µÄÏûÏ¢ÓÊÏäµÄʼþ¿ØÖÆ¿éµÄÖ¸Õë¡£Èç¹ûûÓпÉÓõÄʼþ¿ØÖƿ飬·µ»Ø¿ÕÖ¸Õë¡£ |
7.4.2 ·¢ËÍÏûÏ¢
×÷Ó㺠ÏòÓÊÏä·¢ËÍÒ»ÔòÏûÏ¢¡£ º¯ÊýÔÐÍ£º INT8U OSMboxPost (OS_EVENT *pevent,void *pmsg); OSMboxPost()º¯Êýͨ¹ýÏûÏ¢ÓÊÏäÏòÈÎÎñ·¢ËÍÏûÏ¢¡£ÏûÏ¢ÊÇÒ»¸öÖ¸Õ볤¶ÈµÄ±äÁ¿£¬ÔÚ²»Í¬µÄ³ÌÐòÖÐÏûÏ¢µÄʹÓà Ҳ¿ÉÄܲ»Í¬¡£Èç¹ûÏûÏ¢ÓÊÏäÖÐÒѾ´æÔÚÏûÏ¢£¬·µ»Ø´íÎóÂë˵Ã÷ÏûÏ¢ÓÊÏäÒÑÂú£¬OSMboxPost()º¯ÊýÁ¢¼´·µ»Øµ÷ÓÃÕߣ¬ ÏûϢҲûÓÐÄܹ»·¢µ½ÏûÏ¢ÓÊÏä¡£ Èç¹ûÓÐÈκÎÈÎÎñÔڵȴýÏûÏ¢ÓÊÏäµÄÏûÏ¢£¬×î¸ßÓÅÏȼ¶µÄÈÎÎñ½«µÃµ½Õâ¸öÏûÏ¢¡£ Èç ¹ûµÈ´ýÏûÏ¢µÄÈÎÎñÓÅÏȼ¶±È·¢ËÍÏûÏ¢µÄÈÎÎñÓÅÏȼ¶¸ß£¬ÄÇô¸ßÓÅÏȼ¶µÄÈÎÎñ½«µÃµ½ÏûÏ¢¶ø»Ö¸´Ö´ÐУ¬Ò²¾ÍÊÇ˵£¬ ·¢ÉúÁËÒ»´ÎÈÎÎñÇл»¡£ ²ÎÊý£º pevent£º Ö¸ÏòÏûÏ¢ÓÊÏäµÄÖ¸Õë¡£ pmsg£º ÊǼ´½«·¢Ë͸øÈÎÎñµÄÏûÏ¢¡£ÏûÏ¢ÊÇÒ»¸öÖ¸Õ볤¶ÈµÄ±äÁ¿£¬ÔÚ²»Í¬µÄ³ÌÐòÖÐÏûÏ¢µÄʹÓÃÒ²¿ÉÄܲ»Í¬¡£²»ÔÊÐí´«µÝÒ»¸ö¿ÕÖ¸Õë¡£ |
7.4.3 »ñÈ¡ÏûÏ¢
×÷Ó㺠Î޵ȴý²é¿´ÏûÏ¢ÓÊÏäÊÇ·ñÊÕµ½ÏûÏ¢¡£ º¯ÊýÔÐÍ£º void *OSMboxAccept(OS_EVENT *pevent); OSMboxAccept£¨£©º¯Êý²é¿´Ö¸¶¨µÄÏûÏ¢ÓÊÏäÊÇ·ñÓÐÐèÒªµÄÏûÏ¢¡£²»Í¬ÓÚ OSMboxPend£¨£©º¯Êý£¬Èç¹ûûÓÐÐèÒªµÄÏûÏ¢£¬OSMboxAccept£¨£©º¯Êý²¢²»¹ÒÆðÈÎÎñ¡£Èç¹ûÏûÏ¢ÒѾµ½´ï£¬¸ÃÏûÏ¢±»´«µÝµ½Óû§ÈÎÎñ²¢ÇÒ´ÓÏûÏ¢ÓÊÏäÖÐÇå³ý¡£Í¨³£Öжϵ÷Óøú¯Êý£¬ÒòΪÖжϲ»ÔÊÐí¹ÒÆðµÈ´ýÏûÏ¢¡£ ²ÎÊý£º pevent£º ÊÇÖ¸ÏòÐèÒª²é¿´µÄÏûÏ¢ÓÊÏäµÄÖ¸Õë¡£µ±½¨Á¢ÏûÏ¢ÓÊÏäʱ£¬¸ÃÖ¸Õë·µ»Øµ½Óû§³ÌÐò¡££¨²Î¿¼ OSMboxCreate£¨£©º¯Êý£©¡£ ·µ»ØÖµ£º Èç¹ûÏûÏ¢ÒѾµ½´ï£¬·µ»ØÖ¸Ïò¸ÃÏûÏ¢µÄÖ¸Õ룻 |
7.5 ×÷Òµ
ÓÃÏûÏ¢ÓÊÏäʵÏÖ½«´¥ÃþÆÁµÃµ½µÄLCD×ø±êµÄֵͨ¹ý´®¿Ú´òÓ¡³öÀ´£¬ÒªÇóÓÃÁ½¸öÈÎÎñÍê³É¡£
×¢Ò⣺ҪʹÓô¥ÃþÆÁ£¬ÐèÒª½øÐÐÏàÓ¦µÄ³õʼ»¯¡£
7.6 ÏûÏ¢¶ÓÁÐ
ÏûÏ¢¶ÓÁÐÆäʵ¾ÍÊǶà¸öÏûÏ¢ÓÊÏäµÄ×éºÏ£¬ÏûÏ¢ÓÊÏäÒ»°ãÓÃÔÚ·¢ËÍ·½·¢ËͽÏÂý£¬½ÓÊÕ·½´¦ÀíÏûÏ¢½Ï¿ìµÄʱºò£»
ÏûÏ¢¶ÓÁжàÓÃÔÚ·¢ËÍ·½·¢ËÍÏûÏ¢½Ï¿ì£¬½ÓÊÕ·½´¦ÀíÏûÏ¢½ÏÂýµÄʱºò¡£
7.6.1 ´´½¨ÏûÏ¢¶ÓÁÐ
×÷Ó㺠½¨Á¢²¢³õʼ»¯Ò»¸öÏûÏ¢¶ÓÁС£ º¯ÊýÔÐÍ£º OS_EVENT *OSQCreate (void **start,INT16U size) OSQCreate()º¯Êý½¨Á¢Ò»¸öÏûÏ¢¶ÓÁС£ÈÎÎñ»òÖжϿÉÒÔͨ¹ýÏûÏ¢¶ÓÁÐÏòÆäËûÒ»¸ö»ò¶à¸öÈÎÎñ·¢ËÍÏûÏ¢¡£ÏûÏ¢ µÄº¬ÒåÊǺ;ßÌåµÄÓ¦ÓÃÃÜÇÐÏà¹ØµÄ¡£ ²ÎÊý£º start£º ÊÇÏûÏ¢ÄÚ´æÇøµÄ»ùµØÖ·£¬ÏûÏ¢ÄÚ´æÇøÊÇÒ»¸öÖ¸ÕëÊý×é¡£ size£º ÊÇÏûÏ¢ÄÚ´æÇøµÄ´óС¡£ |
7.6.2 °´¹æÔò·¢ËÍÏûÏ¢FIFO
×÷Ó㺠ÏòÓÊÏä·¢ËÍÒ»ÔòÏûÏ¢(FIFO)¡£ º¯ÊýÔÐÍ£º INT8U OSQPost (OS_EVENT *pevent,void *pmsg); OSQPost()º¯Êýͨ¹ýÏûÏ¢¶ÓÁÐÏòÈÎÎñ·¢ËÍÏûÏ¢¡£ÏûÏ¢ÊÇÒ»¸öÖ¸Õ볤¶ÈµÄ±äÁ¿£¬ÔÚ²»Í¬µÄ³ÌÐòÖÐÏûÏ¢µÄʹÓÃÒ² ¿ÉÄܲ»Í¬¡£ Èç¹û¶ÓÁÐÖÐÒѾ´æÂúÏûÏ¢£¬·µ»Ø´íÎóÂë;OSQPost()º¯ÊýÁ¢¼´·µ»Øµ÷ÓÃÕߣ¬ÏûϢҲûÓÐÄܹ»·¢µ½¶ÓÁС£ Èç¹ûÓÐÈκÎÈÎÎñÔڵȴý¶ÓÁÐÖеÄÏûÏ¢£¬×î¸ßÓÅÏȼ¶µÄÈÎÎñ½«µÃµ½Õâ¸öÏûÏ¢¡£ Èç¹ûµÈ´ýÏûÏ¢µÄÈÎÎñÓÅÏȼ¶±È·¢ËÍÏûÏ¢µÄÈÎÎñÓÅÏȼ¶¸ß£¬ÄÇô¸ßÓÅÏȼ¶µÄÈÎÎñ½«µÃµ½ÏûÏ¢¶ø»Ö¸´Ö´ÐУ¬Ò²¾ÍÊÇ˵£¬·¢ÉúÁËÒ»´ÎÈÎÎñÇл»¡£ ÏûÏ¢¶ÓÁÐÊÇÏÈÈëÏȳö£¨FIFO£©»úÖƵģ¬ÏȽøÈë¶ÓÁеÄÏûÏ¢Ïȱ»´«µÝ¸øÈÎÎñ¡£ ²ÎÊý£º pevent£º Ö¸ÏòÏûÏ¢¶ÓÁеÄÖ¸Õë¡£ pmsg£º ÊǼ´½«·¢Ë͸øÈÎÎñµÄÏûÏ¢¡£ÏûÏ¢ÊÇÒ»¸öÖ¸Õ볤¶ÈµÄ±äÁ¿£¬ÔÚ²»Í¬µÄ³ÌÐòÖÐÏûÏ¢µÄʹÓÃÒ²¿ÉÄܲ»Í¬¡£ ²»ÔÊÐí´«µÝÒ»¸ö¿ÕÖ¸Õë¡£ |
7.6.3 ·¢ËÍLIFOÏûÏ¢
×÷Ó㺠ÏòÓÊÏä·¢ËÍÒ»ÔòÏûÏ¢(LIFO)¡£ º¯ÊýÔÐÍ£º INT8U OSQPostFront (OS_EVENT *pevent,void *pmsg); OSQPostFront£¨£©º¯Êýͨ¹ýÏûÏ¢¶ÓÁÐÏòÈÎÎñ·¢ËÍÏûÏ¢¡£ OSQPostFront£¨£©º¯ÊýºÍ OSQPost£¨£©º¯Êý·Ç³£ÏàËÆ£¬ ²»Í¬Ö®´¦ÔÚÓÚ OSQPostFront£¨£©º¯Êý½«·¢Ë͵ÄÏûÏ¢²åµ½ÏûÏ¢¶ÓÁеÄ×îÇ°¶Ë¡£Ò²¾ÍÊÇ˵£¬OSQPostFront£¨£©º¯ÊýʹµÃÏûÏ¢¶ÓÁа´ÕÕºóÈëÏȳö£¨LIFO£©µÄ·½Ê½¹¤×÷£¬¶ø²»ÊÇÏÈÈëÏȳö£¨FIFO£©¡£ Èç¹û¶ÓÁÐÖÐÒѾ´æÂúÏûÏ¢£¬·µ»Ø´íÎóÂë¡£ OSQPost£¨£©º¯ÊýÁ¢¼´·µ»Øµ÷ÓÃÕߣ¬ÏûϢҲûÄÜ·¢µ½¶ÓÁС£Èç¹ûÓÐÈκÎÈÎÎñÔڵȴý¶ÓÁÐÖеÄÏûÏ¢£¬×î¸ßÓÅÏȼ¶µÄÈÎÎñ½«µÃµ½Õâ¸öÏûÏ¢¡£Èç¹ûµÈ´ýÏûÏ¢µÄÈÎÎñÓÅÏȼ¶±È·¢ËÍÏûÏ¢µÄÈÎÎñÓÅÏȼ¶¸ß£¬ÄÇô¸ßÓÅÏȼ¶µÄÈÎÎñ½«µÃµ½ÏûÏ¢¶ø»Ö¸´Ö´ÐУ¬Ò²¾ÍÊÇ˵£¬·¢ÉúÁËÒ»´ÎÈÎÎñÇл»¡£ |
7.6.4 ²é¿´ÏûÏ¢¶ÓÁÐ
×÷Ó㺠Î޵ȴý²é¿´ÏûÏ¢¶ÓÁÐÊÇ·ñÊÕµ½ÏûÏ¢¡£ º¯ÊýÔÐÍ£º void *OSQAccept (OS_EVENT *pevent,INT8U *perr); OSQAccept()º¯Êý¼ì²éÏûÏ¢¶ÓÁÐÖÐÊÇ·ñÒѾÓÐÐèÒªµÄÏûÏ¢¡£²»Í¬ÓÚ OSQPend()º¯Êý£¬Èç¹ûûÓÐÐèÒªµÄÏûÏ¢£¬ OSQAccept()º¯Êý²¢²»¹ÒÆðÈÎÎñ¡£Èç¹ûÏûÏ¢ÒѾµ½´ï£¬¸ÃÏûÏ¢±»´«µÝµ½Óû§ÈÎÎñ¡£Í¨³£Öжϵ÷Óøú¯Êý£¬ÒòΪÖÐ ¶Ï²»ÔÊÐí¹ÒÆðµÈ´ýÏûÏ¢¡£ ²ÎÊý£º pevent£º ÊÇÖ¸ÏòÐèÒª²é¿´µÄÏûÏ¢¶ÓÁеÄÖ¸Õë¡£µ±½¨Á¢ÏûÏ¢ÓÊÏäʱ£¬¸ÃÖ¸Õë·µ»Øµ½Óû§³ÌÐò¡££¨²Î¿¼ OSQCreate () º¯Êý£©¡£ perr£º Ö¸ÏòÒ»¸öÓÃÓÚ±£´æ´íÎó´úÂëµÄ±äÁ¿¡£ |
7.7 »¥³âÐÍÐźÅÁ¿
7.7.1 ´´½¨»¥³âÐźÅÁ¿
×÷Ó㺠½¨Á¢²¢³õʼ»¯Ò»¸ö»¥³âÐÍÐźÅÁ¿¡£ º¯ÊýÔÐÍ£º OS_EVENT *OSMutexCreate (INT8U prio,INT8U *perr); ²ÎÊý£º prio£º ½Ï¸ßµÄ¿ÕÏÐÓÅÏȼ¶£¬ÓÃÓÚÈÎÎñÌáȨ¡£ perr£º Ö¸ÏòÒ»¸öÓÃÓÚ±£´æ´íÎó´úÂëµÄ±äÁ¿¡£ |
7.7.2 ÉêÇ뻥³âÐźÅÁ¿
×÷Ó㺠Î޵ȴýÇëÇ󻥳âÐÍÐźÅÁ¿¡£ º¯ÊýÔÐÍ£º BOOLEAN OSMutexAccept (OS_EVENT *pevent,INT8U *perr); ²ÎÊý£º pevent£º Ö¸ÏòÒªÇëÇóµÄ»¥³âÐźÅÁ¿µÄÖ¸Õë¡£ perr£º Ö¸ÏòÒ»¸öÓÃÓÚ±£´æ´íÎó´úÂëµÄ±äÁ¿¡£ |
7.7.3 ÊÍ·Å»¥³âÐźÅÁ¿
×÷Ó㺠ÊÍ·ÅÒ»¸ö»¥³âÐÍÐźÅÁ¿¡£ º¯ÊýÔÐÍ£º INT8U OSMutexPost (OS_EVENT *pevent); ²ÎÊý£º pevent£º Ö¸ÏòÒ»¸ö»¥³âÐÍÐźÅÁ¿µÄÖ¸Õë¡£ |
7.8 Èí¼þ¶¨Ê±Æ÷
7.8.1 ´´½¨Èí¼þ¶¨Ê±Æ÷
×÷Ó㺠´´½¨Èí¼þ¶¨Ê±Æ÷¡£ º¯ÊýÔÐÍ£º OS_TMR *OSTmrCreate(INT32U dly, INT32U period, INT8U opt, OS_TMR_CALLBACK callback, void *callback_arg, INT8U *pname, INT8U *perr); ²ÎÊý£º dly£º Ö¸¶¨Ê¹ÓõļÆʱÆ÷³õʼÑÓ³Ùʱ¼ä¡£ l ÔÚµ¥´Î´¥·¢Ä£Ê½Ê±£¬ÕâÊǵ¥´Î¶¨Ê±µÄʱ¼ä¡£ l ÔÚÖÜÆÚģʽÏ£¬ÕâÊÇ×î³õ¶¨Ê±Æ÷½øÈëÖÜÆÚģʽ֮ǰµÄÑÓʱ¡£ l ÑÓʱµ¥Î»È¡¾öÓÚÄã¶à¾Ãµ÷ÓÃÒ»´Î OSTmrSignal£¨£©¡£Èç¹û OS_TMR_CFG_TICKS_PER_SEC ÉèÖÃΪ 10£¬Ôò DLY Ö¸¶¨ÑÓ³Ùʱ¼äΪ 1/10 Ã루Ҳ¾ÍÊÇ 100ms£©¡£ OS_TMR_CFG_TICKS_PER_SEC ÉèÖÃΪ¶à ÉÙ£¬¾ÍÊÇ 1/OS_TMR_CFG_TICKS_PER_SEC Ãë¡£ ÐèҪעÒâµÄÊÇÔÚ´´½¨Ê±µÄ¶¨Ê±Æ÷²»ÄÜÆô¶¯¡£ period£º Ö¸¶¨¼ÆʱÆ÷ÖÜÆÚÐÔ¶¨Ê±µÄʱ¼äÁ¿¡£ Èç¹ûÉèÖÃΪ 0£¬ÄÇô½«Ê¹Óõ¥´Îģʽ¡£ opt£º OS_TMR_OPT_PERIODIC£ºÖ¸¶¨ÖÜÆÚÐÔ¶¨Ê±Ä£Ê½¡£ OS_TMR_OPT_ONE_SHOT£ºÖ¸¶¨µ¥´Î¶¨Ê±Ä£Ê½¡£ Çë×¢Ò⣬±ØÐëÑ¡ÔñÆäÖÐÒ»¸öÑ¡Ïî¡£ callback£º n Ö¸¶¨Ò»¸ö»Øµ÷º¯ÊýµÄµØÖ·£¨¿ÉÑ¡£©£¬Õâ¸öº¯Êý½«±»µ÷Ó㬴¦Àí¶¨Ê±½áÊøµÄÏà¹ØÊÂÏ»Øµ÷º¯Êý±ØÐë ÉùÃ÷ÈçÏÂ: void MyCallback (void *ptmr, void *callback_arg); n Èç¹û²»ÐèÒª»Øµ÷º¯Êý£¬¿ÉÒÔ´«ÈëÒ»¸ö¿ÕÖ¸Õë¡£ callback_arg£º ÊÇ´«µÝ¸ø»Øµ÷º¯Êý²ÎÊý£¬Èç¹û»Øµ÷º¯Êý²»ÐèÒª²ÎÊý£¬¿ÉÒÔÊÇÒ»¸ö¿ÕÖ¸Õë¡£ pname : Ö¸ÏòÒ»¸ö ASCII ×Ö·û´®£¬ÓÃÓÚÉèÖö¨Ê±Æ÷Ãû³Æ¡£Í¨¹ýµ÷Óà ostmrnameget()»ñÈ¡Õâ¸öÃû³Æ¡£ perr£º Ö¸Ïò´æ·Å´íÎó´úÂëµÄÖ¸Õ룬 |
7.8.2 Æô¶¯Èí¼þ¶¨Ê±Æ÷
×÷Ó㺠Æô¶¯¼ÆʱÆ÷¡£ º¯ÊýÔÐÍ£º BOOLEAN OSTmrStart(OS_TMR *ptmr,INT8U *perr); ²ÎÊý£º ptmr£º Ö¸ÏòÏëÒªÆô¶¯µÄ¶¨Ê±Æ÷¡£¸ÃÖ¸ÕëµÄֵΪÔÚ´´½¨¶¨Ê±Æ÷ʱ·µ»ØµÄÖµ£¨¼û OSTmrCreate£¨£©£©¡£ perr£º Ö¸Ïò´æ·Å´íÎó´úÂëµÄ±äÁ¿¡£ |
7.9 ÁÙ½çºê
OS_CPU_SR cpu_sr; OS_ENTER_CRITICAL(); //ºËÐÄ´úÂë OS_EXIT_CRITICAL(); |
7.10 ×÷Òµ
ÐÅÓ¯´ïרעǶÈëʽ½ÌÓý10¶àÄ꣬ÔÚǶÈëʽÈí¡¢Ó²¼þÅàѵ½ÌÓý·½ÃæÓÐ×Å·áºñµÄ×ÊÔ´ºÍ¾Ñé»ýÀÛ¡£Ë³Ó¦Êг¡ÐèÇ󣬿ªÉèÓÐǶÈëʽÅàѵ¡¢ÎïÁªÍøÅàѵ¡¢ARMÅàѵ¡¢LinuxÅàѵ¡¢È˹¤ÖÇÄÜPythonÅàѵ¡¢JavaÅàѵ¡¢AndroidÅàѵ¡¢µ¥Æ¬»úÅàѵ¡¢Ó²¼þÅàѵ¡¢PCBÅàѵ¡¢µç×ÓÅàѵ¡¢FPGAÅàѵµÈÅàѵ¿Î³Ì£¬Èç¹ûÄãÏë³ÉΪһÃûÊÜÈË×ð¾´µÄit¿ª·¢¹¤³Ìʦ£¬À´ÐÅÓ¯´ï²Î¼ÓitÅàѵ¿Î³Ì£¬Î´À´µÄÄãÒ»¶¨»á¸Ð¼¤ÏÖÔÚµÄÑ¡Ôñ£¡