UCOSIIµÄÐźÅÁ¿
1.1 ÐźÅÁ¿µÄÀí½â
1. uc/os-iiµÄÐźÅÁ¿ÊÇÓÉÁ½¸ö²¿·Ö×é³É£ºÒ»²¿·ÖÊÇ16λµÄÎÞ·ûºÅÕûÐÍÐźÅÁ¿µÄ¼ÆÊýÖµ(0~65535)£»ÁíÒ»²¿·ÖÊǵȴý¸ÃÐźÅÁ¿µÄÈÎÎñ×é³ÉµÄµÈ´ýÈÎÎñ±í¡££¨ÁíÍâ²Î¿¼Ê¼þ¿ØÖÆ¿éECB£©
2. ÐźÅÁ¿¿ÉÒÔÊÇ2ÖµµÄ±äÁ¿£¨³ÆΪ¶þÖµÐźÅÁ¿£©£¬Ê¹ÓÃOSMutextCreate´´½¨, Ò²¿ÉÒÔÊǼÆÊýʽµÄ, ʹÓÃOSSemCreate¡£¸ù¾ÝÐźÅÁ¿µÄÖµ£¬Äں˸ú×ÙÄÇЩµÈ´ýÐźÅÁ¿µÄÈÎÎñ¡£
3. ½¨Á¢ÐźÅÁ¿µÄ¹¤×÷±ØÐëÔÚÈÎÎñ¼¶´úÂëÖлòÕ߶àÈÎÎñÆô¶¯Ö®Ç°Íê³É¡£
4. ÈÎÎñÒªµÃµ½ÐźÅÁ¿µÄÎÊÌâ¡£
2 ÏëµÃµ½ÐźÅÁ¿µÄÈÎÎñ£¬±ØÐëÖ´Ðеȴý²Ù×÷£¨pend£©¡£Èç¹ûÐźÅÁ¿ÓÐЧ(·Ç0)£¬ÔòÐźÅÁ¿¼õ1£¬ÈÎÎñµÃÒÔ¼ÌÐøÔËÐС£Èç¹ûÐźÅÁ¿ÎÞЧ£¬ÔòµÈ´ýÐźÅÁ¿µÄÈÎÎñ¾Í±»ÁÐÈëµÈ´ýÐźÅÁ¿µÄÈÎÎñ±íÖС£¶àÉÙÄÚºËÔÊÐí¶¨ÒåµÈ´ý³¬Ê±£¬µ±µÈ´ýʱ¼ä³¬¹ýÁËÉ趨ֵ£¬¸ÃÐźÅÁ¿»¹ÊÇÎÞЧ£¬ÔòµÈ´ý¸ÃÐźÅÁ¿µÄÈÎÎñ½øÈë¾ÍÐ÷̬£¬×¼±¸ÔËÐУ¬²¢·µ»Ø³ö´í´úÂë(µÈ´ý³¬Ê±´íÎó)¡£
5. ÈÎÎñ¶ÔÐźÅÁ¿µÄÊÍ·ÅÎÊÌâ¡£
2 ÈÎÎñÖ´Ðз¢Ðźţ¨post£©²Ù×÷À´ÊÍ·ÅÐźÅÁ¿¡£Èç¹ûûÓÐÈÎÎñµÈ´ýÐźÅÁ¿£¬ÄÇôÐźÅÁ¿µÄÖµ½öÊǼòµ¥µÄ¼Ó1£¨ÔòÐźÅÁ¿´óÓÚ0£¬ÓÐЧ£©£»Èç¹ûÓÐÈÎÎñµÈ´ý¸ÃÐźÅÁ¿£¬ÄÇô¾Í»áÓÐÁíÒ»¸öÈÎÎñ½øÈë¾ÍÐ÷̬£¬ÐźÅÁ¿µÄÖµ¾Í²»¼Ó1¡£
2 Õâ¸öÊͷŵÄÐźÅÁ¿¸øÄǸöµÈ´ýÖеÄÈÎÎñ£¬Òª¿´ÄÚºËÈçºÎµ÷¶ÈµÄ¡£ÊÕµ½ÐźÅÁ¿µÄÈÎÎñ¿ÉÄÜÊÇÈçÏÂÁ½ÕßÖ®Ò»£º
l µÈ´ýÈÎÎñÖУ¬ÓÅÏȼ¶×î¸ßµÄ£»£¨uc/os-ii½öÖ§³ÖÕâÖÖ·½Ê½£©¡£
l ×îÔ翪ʼµÈ´ýÐźÅÁ¿µÄÈÎÎñ£¨Èç¹ûÊÇ°´ÏȽøÏȳöFIFOÔÔò£©¡£
1.2 ÐźÅÁ¿µÄÓÐЧÓëÎÞЧÎÊÌâ
Ø ÐźÅÁ¿ÓÐЧ£ºÐźÅÁ¿µÄ¼ÆËãÆ÷·Ç0£¨.OSEventCnt£¡=0£©¡£ÐźÅÁ¿ÓÐЧ±íʾÈÎÎñ¶Ô×ÊÔ´¿ÉÓá£
Ø ÐźÅÁ¿ÎÞЧ£ºÐźÅÁ¿µÄ¼ÆËãÆ÷Ϊ0¡£ÐźÅÁ¿ÎÞЧ±íʾÈÎÎñ¶ÔÄ¿Ç°×ÊÔ´²»¿ÉÓã¬ÐèÒªµÈ´ýÆäËûÁíÒ»¸öÈÎÎñ£¨»òÕßÖжϷþÎñ×Ó³ÌÐò£©·¢³ö¸ÃÐźÅÁ¿£¨OSSemPost£©¡£
1.3 ÐźÅÁ¿µÄÖµ£¨.OSEventCnt£©´óС±íʾʲô£¿
¶þÖµÐźÅÁ¿Mutext£¬±íʾÈÎÎñ¿ÉÒÔ¶ÀÕ¼¹²Ïí×ÊÔ´¡£
¼ÆÊýʽÐźÅÁ¿Semaphore£¬ÓÃÓÚij×ÊÔ´¿ÉͬʱΪN¸öÈÎÎñËùÓá£
1.4 ÐźÅÁ¿ÊÇÈçºÎʵÏÖÈÎÎñÖ®¼äµÄͨÐŵģ¿
1. ÐźÅÁ¿µÄ½¨Á¢±ØÐëÊÇÔÚÈÎÎñ¼¶Öн¨Á¢£¬
2. ÐźÅÁ¿ÀàÐÍΪOS_EVENT£¬ÐźÅÁ¿Öµ¿ÉÒÔΪ1ºÍ0(Mutex¶þÖµÐźÅÁ¿)£¬0~65535(¼ÆÊýʽÐźÅÁ¿Semaphore)µÄÖµ£¬²»Í¬µÄÖµ´ú±í²»Í¬µÄÒâÒå¡£
3. ÐźÅÁ¿£¨ÕâÀï½ö˵»¥³â£©¾ÍÁ½¸ö²Ù×÷£¬Ò»¸öÇëÇó£¬Ò»¸öÊÍ·Å¡£
4. Ò»¸öÈÎÎñÇëÇóÐźÅÁ¿Ê±£ºÈç¹û±»ÆäËüÈÎÎñÕ¼Óã¬Ôò¸ÃÈÎÎñµÈ´ý£¬Í¬Ê±µ¼ÖÂÈÎÎñÇл»£»Èç¹ûûÓб»ÆäËüÈÎÎñÕ¼Óã¬Ôò»ñµÃ£¬¼ÌÐøÖ´ÐС£
5. ÊÍ·ÅÐźÅÁ¿Ê±£¬Èç¹ûÆäËü¸ßÓÅÏȼ¶ÈÎÎñÕýÔÚÇëÇ󲢵ȴý¸ÃÐźÅÁ¿£¬Ôòµ¼ÖÂÈÎÎñÇл»¡£
6. OSTimeDlyÖ®À࣬²¢²»µ¼ÖÂÐźÅÁ¿µÄÊÍ·Å¡£Ö»ÓлñÈ¡ÐźÅÁ¿µÄÄǸöÈÎÎñµ÷ÓÃÊͷŹ¦ÄÜʱ£¬ÐźÅÁ¿²Å»áÊÍ·Å¡£
7. OSSemAccept£¨ÐźÅÁ¿£©Æð²éѯÐźÅÁ¿×÷Ó㬷µ»ØÐźÅÁ¿µÄÖµ¡£
8. OSSemPend(sem,timeout,&err)£¬timeout´ú±íµÈ´ýtimeout¸öÐźÅÁ¿ºó»¹Ã»µÃµ½ÐźÅÁ¿£¬»Ö¸´ÔËÐÐ״̬£¬Èç¹ûtimeout=0£¬±íʾÎÞÏ޵ȴýÐźÅÁ¿¡£OSSemPend(sem,0,&err);½«ÔÝÍ£µ±Ç°ÈÎÎñ£¬µÈ´ýÐźÅÁ¿µÄµ½À´¡£
1.5 ÐźÅÁ¿ÓйصÄÈý¸öÖØÒªº¯Êý·ÖÎö
Ø OSSemCreate() ´´½¨Ò»¸öÐźÅÁ¿£¨×¢£ºÓÉÈÎÎñ»òÆô¶¯´úÂë²Ù×÷£©
´´½¨¹¤×÷±ØÐëÔÚÈÎÎñ¼¶´úÂëÖлòÕ߶àÈÎÎñÆô¶¯Ö®Ç°Íê³É¡£¹¦ÄÜÖ»ÒªÊÇÏÈ»ñÈ¡Ò»¸öʼþ¿ØÖÆ¿éECB£¬Ð´ÈëһЩ²ÎÊý¡£ÆäÖе÷ÓÃÁËOS_EeventWaitListInt()º¯Êý£¬¶Ôʼþ¿ØÖÆ¿éµÄµÈ´ýÈÎÎñÁбí½øÐгõʼ»¯¡£Íê³É³õʼ»¯¹¤×÷ºó£¬·µ»ØÒ»¸ö¸ÃÐźÅÁ¿µÄ¾ä±ú(Handle)¡£
Ø OSSemPend( )»òÕßOSMutextPend() µÈ´ý/ÇëÇóÒ»¸öÐźÅÁ¿£¨×¢£ºÖ»ÄÜÓÉÈÎÎñ²Ù×÷£©
±¾º¯ÊýÓ¦ÓÃÓÚÈÎÎñÊÔͼ»ñµÃ¹²Ïí×ÊÔ´µÄʹÓÃȨ¡¢ÈÎÎñÐèÒªÓëÆäËûÈÎÎñ»òÖжÏͬ²½¼°ÈÎÎñÐèÒªµÈ´ýÌض¨Ê¼þ·¢ÉúµÄ³¡ºÏ¡£Èç¹ûÈÎÎñTask_Aµ÷ÓÃOSSemPend()£¬ÇÒÐźÅÁ¿µÄÖµÓÐЧ(·Ç0)£¬ÄÇôOSSemPend()µÝ¼õÐźÅÁ¿¼ÆÊýÆ÷£¨.OSEventCnt£©£¬²¢·µ»Ø¸ÃÖµ¡£»»¾ä»°Ëµ£¬Task_A»ñÈ¡µ½¹²Ïí×ÊÔ´µÄʹÓÃȨÁË£¬Ö®ºó¾ÍÖ´ÐиÃ×ÊÔ´¡£Èç¹ûÈç¹ûÈÎÎñTask_Aµ÷ÓÃOSSemPend()£¬ÐźÅÁ¿ÎÞЧ(Ϊ0)£¬ÄÇôOSSemPend()µ÷Óà OS_EventTaskWait()º¯Êý£¬°ÑTask_A·ÅÈëµÈ´ýÁбíÖС££¨µÈ´ýµ½Ê²Ã´Ê±ºòÄØ£¿Òª¿´OSSemPost()(»òÕߵȴý³¬Ê±Çé¿ö)£¬ÓÉËüÊÍ·ÅÐźÅÁ¿²¢¼ì²éÈÎÎñÖ´ÐÐȨ£¬¼ûÏÂ×ÊÁÏ£©
Ø OSSemPost()»òÕßOSMutextPost() ·¢³ö/ÊÍ·ÅÒ»¸öÐźÅÁ¿£¨×¢£ºÓÉÈÎÎñ»òÖжϲÙ×÷£©
±¾º¯ÊýÆäÖе÷ÓÃOS_EventTaskRdy()º¯Êý£¬°ÑÓÅÏȼ¶×î¸ßµÄÈÎÎñTask_A£¨ÔÚÕâ¼ÙÈçÊÇTask_A£¬ÁíÍâ¼ÙÉ赱ǰµ÷ÓÃOSSemPost()µÄÈÎÎñÊÇTask_B£©´ÓµÈ´ýÈÎÎñÁбíÖÐÈ¥³ý£¬²¢Ê¹Ëü½øÈë¾ÍÐ÷̬¡£È»ºóµ÷ÓÃOSSched()½øÐÐÈÎÎñµ÷¶È¡£Èç¹ûTask_AÊǵ±Ç°¾ÍÐ÷̬ÖÐÓÅÏȼ¶×î¸ßµÄÈÎÎñ£¬ÔòÄÚºËÖ´ÐÐTask_A£»·ñÔò£¬OSSched()Ö±½Ó·µ»Ø£¬Task_B¼ÌÐøÖ´ÐÐ.