亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? os_sem.c

?? 多任務操作系統ucOS II移植到keil_c51上的源代碼,代碼條理清晰
?? C
字號:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*                                          SEMAPHORE MANAGEMENT
*
*                        (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
*                                           All Rights Reserved
*
*                                                  V2.00
*
* File : OS_SEM.C
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

#ifndef  OS_MASTER_FILE
#include "includes.h"
#endif

#if OS_SEM_EN
/*
*********************************************************************************************************
*                                           ACCEPT SEMAPHORE
*
* Description: This function checks the semaphore to see if a resource is available or, if an event
*              occurred.  Unlike OSSemPend(), OSSemAccept() does not suspend the calling task if the
*              resource is not available or the event did not occur.
*
* Arguments  : pevent     is a pointer to the event control block
*
* Returns    : >  0       if the resource is available or the event did not occur the semaphore is
*                         decremented to obtain the resource.
*              == 0       if the resource is not available or the event did not occur or,
*                         you didn't pass a pointer to a semaphore
*********************************************************************************************************
*/

INT16U OSSemAccept (OS_EVENT *pevent) KCREENTRANT
{
    INT16U cnt;


    OS_ENTER_CRITICAL();
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
        OS_EXIT_CRITICAL();
        return (0);
    }
    cnt = pevent->OSEventCnt;
    if (cnt > 0) {                                    /* See if resource is available                  */
        pevent->OSEventCnt--;                         /* Yes, decrement semaphore and notify caller    */
    }
    OS_EXIT_CRITICAL();
    return (cnt);                                     /* Return semaphore count                        */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                           CREATE A SEMAPHORE
*
* Description: This function creates a semaphore.
*
* Arguments  : cnt           is the initial value for the semaphore.  If the value is 0, no resource is
*                            available (or no event has occurred).  You initialize the semaphore to a 
*                            non-zero value to specify how many resources are available (e.g. if you have
*                            10 resources, you would initialize the semaphore to 10).
*
* Returns    : != (void *)0  is a pointer to the event control clock (OS_EVENT) associated with the
*                            created semaphore
*              == (void *)0  if no event control blocks were available
*********************************************************************************************************
*/

OS_EVENT *OSSemCreate (INT16U cnt) KCREENTRANT
{
    OS_EVENT *pevent;


    OS_ENTER_CRITICAL();
    pevent = OSEventFreeList;                              /* Get next free event control block        */
    if (OSEventFreeList != (OS_EVENT *)0) {                /* See if pool of free ECB pool was empty   */
        OSEventFreeList = (OS_EVENT *)OSEventFreeList->OSEventPtr;
    }
    OS_EXIT_CRITICAL();
    if (pevent != (OS_EVENT *)0) {                         /* Get an event control block               */
        pevent->OSEventType = OS_EVENT_TYPE_SEM;
        pevent->OSEventCnt  = cnt;                         /* Set semaphore value                      */
        OSEventWaitListInit(pevent);
    }
    return (pevent);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                           PEND ON SEMAPHORE
*
* Description: This function waits for a semaphore.
*
* Arguments  : pevent        is a pointer to the event control block associated with the desired 
*                            semaphore.
*
*              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
*                            wait for the resource up to the amount of time specified by this argument.  
*                            If you specify 0, however, your task will wait forever at the specified 
*                            semaphore or, until the resource becomes available (or the event occurs).
*
*              err           is a pointer to where an error message will be deposited.  Possible error
*                            messages are:
*
*                            OS_NO_ERR          The call was successful and your task owns the resource 
*                                               or, the event you are waiting for occurred.
*                            OS_TIMEOUT         The semaphore was not received within the specified 
*                                               timeout.
*                            OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a semaphore.
*                            OS_ERR_PEND_ISR    If you called this function from an ISR and the result
*                                               would lead to a suspension.
*
* Returns    : none
*********************************************************************************************************
*/

void OSSemPend (OS_EVENT *pevent, INT16U timeout, INT8U *err) KCREENTRANT
{
    OS_ENTER_CRITICAL();
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {   /* Validate event block type                     */
        OS_EXIT_CRITICAL();
        *err = OS_ERR_EVENT_TYPE;
    }
    if (pevent->OSEventCnt > 0) {                     /* If sem. is positive, resource available ...   */
        pevent->OSEventCnt--;                         /* ... decrement semaphore only if positive.     */
        OS_EXIT_CRITICAL();
        *err = OS_NO_ERR;
    } else if (OSIntNesting > 0) {                    /* See if called from ISR ...                    */
        OS_EXIT_CRITICAL();                           /* ... can't PEND from an ISR                    */
        *err = OS_ERR_PEND_ISR;
    } else {                                          /* Otherwise, must wait until event occurs       */
        OSTCBCur->OSTCBStat    |= OS_STAT_SEM;        /* Resource not available, pend on semaphore     */
        OSTCBCur->OSTCBDly      = timeout;            /* Store pend timeout in TCB                     */
        OSEventTaskWait(pevent);                      /* Suspend task until event or timeout occurs    */
        OS_EXIT_CRITICAL();
        OSSched();                                    /* Find next highest priority task ready         */
        OS_ENTER_CRITICAL();
        if (OSTCBCur->OSTCBStat & OS_STAT_SEM) {      /* Must have timed out if still waiting for event*/
            OSEventTO(pevent);
            OS_EXIT_CRITICAL();
            *err = OS_TIMEOUT;                        /* Indicate that didn't get event within TO      */
        } else {
            OSTCBCur->OSTCBEventPtr = (OS_EVENT *)0;
            OS_EXIT_CRITICAL();
            *err = OS_NO_ERR;
        }
    }
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                         POST TO A SEMAPHORE
*
* Description: This function signals a semaphore
*
* Arguments  : pevent        is a pointer to the event control block associated with the desired 
*                            semaphore.
*
* Returns    : OS_NO_ERR          The call was successful and the semaphore was signaled.
*              OS_SEM_OVF         If the semaphore count exceeded its limit.  In other words, you have 
*                                 signalled the semaphore more often than you waited on it with either
*                                 OSSemAccept() or OSSemPend().
*              OS_ERR_EVENT_TYPE  If you didn't pass a pointer to a semaphore
*********************************************************************************************************
*/

INT8U OSSemPost (OS_EVENT *pevent) KCREENTRANT
{
    OS_ENTER_CRITICAL();
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
        OS_EXIT_CRITICAL();
        return (OS_ERR_EVENT_TYPE);
    }
    if (pevent->OSEventGrp) {                              /* See if any task waiting for semaphore    */
        OSEventTaskRdy(pevent, (void *)0, OS_STAT_SEM);    /* Ready highest prio task waiting on event */
        OS_EXIT_CRITICAL();
        OSSched();                                    /* Find highest priority task ready to run       */
        return (OS_NO_ERR);
    } else {
        if (pevent->OSEventCnt < 65535) {             /* Make sure semaphore will not overflow         */
            pevent->OSEventCnt++;                     /* Increment semaphore count to register event   */
            OS_EXIT_CRITICAL();
            return (OS_NO_ERR);
        } else {                                      /* Semaphore value has reached its maximum       */
            OS_EXIT_CRITICAL();
            return (OS_SEM_OVF);
        }
    }
}
/*
*********************************************************************************************************
*                                          QUERY A SEMAPHORE
*
* Description: This function obtains information about a semaphore
*
* Arguments  : pevent        is a pointer to the event control block associated with the desired 
*                            semaphore
*
*              pdata         is a pointer to a structure that will contain information about the 
*                            semaphore.
*
* Returns    : OS_NO_ERR          The call was successful and the message was sent
*              OS_ERR_EVENT_TYPE  If you are attempting to obtain data from a non semaphore.
*********************************************************************************************************
*/

INT8U OSSemQuery (OS_EVENT *pevent, OS_SEM_DATA *pdata) KCREENTRANT
{
    INT8U  i;
    INT8U *psrc;
    INT8U *pdest;
    
    
    OS_ENTER_CRITICAL();
    if (pevent->OSEventType != OS_EVENT_TYPE_SEM) {        /* Validate event block type                */
        OS_EXIT_CRITICAL();
        return (OS_ERR_EVENT_TYPE);
    }
    pdata->OSEventGrp = pevent->OSEventGrp;                /* Copy message mailbox wait list           */
    psrc              = &pevent->OSEventTbl[0];
    pdest             = &pdata->OSEventTbl[0];
    for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
        *pdest++ = *psrc++;   
    }
    pdata->OSCnt      = pevent->OSEventCnt;                /* Get semaphore count                      */
    OS_EXIT_CRITICAL();
    return (OS_NO_ERR);
}
#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99久久er热在这里只有精品66| 日韩激情一区二区| 成人国产视频在线观看| 欧美激情综合在线| 91在线视频在线| 一区二区三区四区在线免费观看| 91免费视频大全| 亚洲观看高清完整版在线观看| 欧美久久久久免费| 久久成人18免费观看| 亚洲国产激情av| 在线免费亚洲电影| 免费人成在线不卡| 久久久精品蜜桃| 色婷婷久久99综合精品jk白丝| 亚洲资源中文字幕| 日韩小视频在线观看专区| 紧缚捆绑精品一区二区| 亚洲欧洲av色图| 欧美一区二区精美| 成人性生交大片免费| 亚洲制服丝袜av| 2023国产精品| 欧美最新大片在线看| 免费不卡在线视频| 中文字幕在线观看一区二区| 欧美日韩和欧美的一区二区| 国产福利一区二区| 婷婷成人综合网| 欧美国产乱子伦| 7777精品久久久大香线蕉| 成人午夜在线免费| 久久国产尿小便嘘嘘尿| 亚洲另类春色国产| 久久精品男人天堂av| 欧美日本高清视频在线观看| 丁香另类激情小说| 日本欧美一区二区| 一级中文字幕一区二区| 久久精品视频在线看| 7777精品伊人久久久大香线蕉经典版下载 | 蜜桃视频在线观看一区二区| 国产精品久久久久久久午夜片| 制服.丝袜.亚洲.中文.综合| 99久久久久久| 丁香一区二区三区| 九色综合国产一区二区三区| 亚洲一区二区在线视频| 综合亚洲深深色噜噜狠狠网站| 精品播放一区二区| 91精品国产综合久久精品图片| 91亚洲精品久久久蜜桃网站| 国产精品996| 精品亚洲免费视频| 日韩影院精彩在线| 亚洲高清一区二区三区| 亚洲欧美日韩小说| 国产精品久久久久7777按摩| 久久精品综合网| 久久婷婷国产综合国色天香 | 国产91色综合久久免费分享| 免费人成在线不卡| 日本中文一区二区三区| 亚洲电影在线播放| 夜夜嗨av一区二区三区网页| 亚洲精品福利视频网站| 日韩美女视频19| 国产精品护士白丝一区av| 国产精品区一区二区三| 欧美国产成人在线| 欧美高清在线视频| 国产精品无码永久免费888| 国产日韩欧美制服另类| 日本一区免费视频| 亚洲国产精品激情在线观看| 国产精品麻豆网站| 国产精品久久久久国产精品日日| 国产精品国产三级国产有无不卡| 国产精品女同一区二区三区| 欧美韩国一区二区| 亚洲视频综合在线| 亚洲综合清纯丝袜自拍| 天堂在线一区二区| 青青草伊人久久| 经典一区二区三区| 成人午夜av电影| 99久久婷婷国产综合精品| 色婷婷狠狠综合| 94-欧美-setu| 欧美日韩视频第一区| 在线成人小视频| 精品欧美乱码久久久久久1区2区| 精品国产一区a| 国产精品美女久久久久久久久| 中文字幕视频一区二区三区久| 亚洲图片你懂的| 婷婷国产在线综合| 国产精一品亚洲二区在线视频| 国产91在线观看丝袜| 在线国产亚洲欧美| 日韩精品专区在线影院观看| 国产视频不卡一区| 亚洲午夜久久久久久久久电影网| 日本一不卡视频| 国产精品一区三区| 一本色道综合亚洲| 日韩欧美aaaaaa| 国产精品麻豆欧美日韩ww| 午夜亚洲国产au精品一区二区| 激情久久五月天| 一本大道综合伊人精品热热| 欧美一级欧美三级| 国产精品国产自产拍在线| 视频一区二区欧美| 成人理论电影网| 欧美高清一级片在线| 国产女人aaa级久久久级 | 亚洲一区二区三区三| 国内一区二区在线| 欧美午夜片在线观看| 国产亚洲一二三区| 性做久久久久久| 暴力调教一区二区三区| 欧美一级一区二区| 一区二区三区四区在线| 国产一区二区久久| 6080午夜不卡| 亚洲人午夜精品天堂一二香蕉| 免费观看在线色综合| 色婷婷久久久综合中文字幕| 久久久亚洲精华液精华液精华液| 一个色综合av| 成人app下载| 日韩亚洲欧美中文三级| 亚洲自拍偷拍av| 99re这里只有精品视频首页| 精品成人一区二区三区| 日韩vs国产vs欧美| 欧美亚洲一区二区三区四区| 国产欧美精品一区二区色综合朱莉| 亚洲高清视频在线| 日本精品视频一区二区三区| 欧美激情一区二区| 国产精品主播直播| 精品日韩成人av| 秋霞av亚洲一区二区三| 欧美亚一区二区| 一二三区精品福利视频| 91色.com| 亚洲精品国产成人久久av盗摄 | 久久久久久亚洲综合| 日本成人中文字幕| 欧美精品丝袜久久久中文字幕| 亚洲欧美日韩国产成人精品影院| 国产成人av一区| 国产欧美视频一区二区| 国产高清一区日本| 欧美激情一区不卡| 成人免费av在线| 国产精品久久久久久久久快鸭| 成人性生交大片免费看中文网站| 国产女同性恋一区二区| 成人免费福利片| 亚洲视频一区在线| 色欲综合视频天天天| 一区二区国产盗摄色噜噜| 色老汉一区二区三区| 亚洲国产精品一区二区www在线| 欧美在线观看一二区| 亚洲高清视频在线| 91麻豆精品国产综合久久久久久| 日韩av在线免费观看不卡| 91麻豆精品国产91久久久| 另类调教123区| 久久久久9999亚洲精品| 成人永久免费视频| 亚洲欧美另类在线| 欧美日韩国产精品自在自线| 免费成人在线观看| 久久综合国产精品| 91蜜桃在线免费视频| 亚洲综合免费观看高清完整版在线| 欧美午夜电影网| 韩国三级在线一区| 国产精品视频观看| 欧美熟乱第一页| 精品系列免费在线观看| 国产精品免费看片| 在线观看精品一区| 六月婷婷色综合| 国产精品麻豆久久久| 欧美久久久久免费| 国产成人aaa| 亚洲综合色成人| 久久丝袜美腿综合| 色婷婷av一区二区| 久久国产精品色| 亚洲日本韩国一区| 欧美一区二区三区啪啪| 国产+成+人+亚洲欧洲自线|