OS_CORE.C(1)
生活随笔
收集整理的這篇文章主要介紹了
OS_CORE.C(1)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第一個函數(獲得信號量、互斥量、郵箱或者隊列名字的函數)的流程圖和分析圖如下所示:
/*$PAGE*/ /* ********************************************************************************************************* * GET THE NAME OF A SEMAPHORE, MUTEX, MAILBOX or QUEUE * 獲得信號量、互斥量、郵箱或隊列的名稱 * Description: This function is used to obtain the name assigned to a semaphore, mutex, mailbox or queue. *該功能用來獲得信號量、互斥量、郵箱或者隊列的名稱 * Arguments : pevent is a pointer to the event group. 'pevent' can point either to a semaphore, * 參數 a mutex, a mailbox or a queue. Where this function is concerned, the actual * type is irrelevant. * pevent是一個指向事件組的指針,也可以指向信號量、互斥量、郵箱或隊列。在功能方面,實際的類型無關 * pname is a pointer to a pointer to an ASCII string that will receive the name of the semaphore, * mutex, mailbox or queue. * pname是一個指向代表信號量、互斥量、郵箱或隊列名稱的ASCII碼字符串的指針 * perr is a pointer to an error code that can contain one of the following values: * perr是一個指向錯誤碼的指針。錯誤碼包括以下幾種: * OS_ERR_NONE if the name was copied to 'pname' --名字被復制到pname,無錯誤 * OS_ERR_EVENT_TYPE if 'pevent' is not pointing to the proper event * control block type. --pevent指向的事件控制塊(ECB)類型錯誤 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'--pname指針為空 * OS_ERR_PEVENT_NULL if you passed a NULL pointer for 'pevent'--pevent指針為空指針 * OS_ERR_NAME_GET_ISR if you are trying to call this function from an ISR --調用中斷函數 * * Returns : The length of the string or 0 if the 'pevent' is a NULL pointer. 返回值:當pevent不是空指針時返回0或者字符串長度 ********************************************************************************************************* */#if (OS_EVENT_EN) && (OS_EVENT_NAME_EN > 0u) /*如果可以產生事件并且可以給事件命名*/ INT8U OSEventNameGet(OS_EVENT *pevent, /*獲得時間名稱函數(指向事件組的指針,事件名稱,錯誤碼指針)*/INT8U **pname, INT8U *perr) {INT8U len; #if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register 中斷類型為3,斷點*/OS_CPU_SR cpu_sr = 0u; #endif#ifdef OS_SAFETY_CRITICAL /*定義安全中斷*/if (perr == (INT8U *)0) { /*如果錯誤碼為0.調用安全中斷異常函數OS_SAFETY_CRITICAL_EXCEPTION()*/OS_SAFETY_CRITICAL_EXCEPTION();} #endif#if OS_ARG_CHK_EN > 0u /*檢查參數*/if (pevent == (OS_EVENT *)0) { /* Is 'pevent' a NULL pointer? 如果指向事件的指針為空 */*perr = OS_ERR_PEVENT_NULL; /*將錯誤碼指針設為OS_ERR_PEVENT_NULL*/return (0u); }if (pname == (INT8U **)0) { /* Is 'pname' a NULL pointer? 如果pname為空指針 */*perr = OS_ERR_PNAME_NULL; /*將錯誤碼指針設為OS_ERR_PNAME_NULL*/return (0u);} #endifif (OSIntNesting > 0u) { /* See if trying to call from an ISR 如果嵌套中斷>0,即檢測是否要調用中斷函數*/*perr = OS_ERR_NAME_GET_ISR; /*將錯誤碼指針設為 OS_ERR_NAME_GET_ISR*/return (0u);}switch (pevent->OSEventType) { /*如果pevent指向的是事件類型*/case OS_EVENT_TYPE_SEM: /*OS_EVENT_TYPE_SEM,OS_EVENT_TYPE_MUTEX,OS_EVENT_TYPE_MBOX,OS_EVENT_TYPE_Q四個+*/case OS_EVENT_TYPE_MUTEX: /*+事件類型處理為空*/case OS_EVENT_TYPE_MBOX:case OS_EVENT_TYPE_Q:break;default: /*默認情況下,將錯誤碼設置成OS_ERR_EVENT_TYPE*/*perr = OS_ERR_EVENT_TYPE;return (0u);}//====以上是各種if下的情況,下面是該函數主體===//OS_ENTER_CRITICAL(); /*關中斷*/*pname = pevent->OSEventName; /*將事件名字賦給pname指針*/len = OS_StrLen(*pname); /*得到名字的長度len*/OS_EXIT_CRITICAL(); /*開中斷*/*perr = OS_ERR_NONE; /*將錯誤碼設置為OS_ERR_NONE,即無錯誤*/return (len); /*返回len*/ } #endif/*$PAGE*/ /* ********************************************************************************************************* * ASSIGN A NAME TO A SEMAPHORE, MUTEX, MAILBOX or QUEUE * 給信號量、互斥量、郵箱或隊列設置名字 * Description: This function assigns a name to a semaphore, mutex, mailbox or queue. *描述:該功能是給信號量、互斥量、郵箱或隊列設置名字 * Arguments : pevent is a pointer to the event group. 'pevent' can point either to a semaphore, * a mutex, a mailbox or a queue. Where this function is concerned, it doesn't * matter the actual type. * pervent是指向事件組的指針,也可以指向信號量、互斥量、郵箱或隊列。 * pname is a pointer to an ASCII string that will be used as the name of the semaphore, * mutex, mailbox or queue. * pname是一個指向代表信號量、互斥量、郵箱或隊列名稱的ASCII碼字符串的指針 * perr is a pointer to an error code that can contain one of the following values: * perr是一個指向錯誤碼的指針。錯誤碼包括以下幾種: * OS_ERR_NONE if the requested task is resumed--所請求的任務是恢復 * OS_ERR_EVENT_TYPE if 'pevent' is not pointing to the proper event * control block type.--pevent沒有正確指向事件控制塊類型 * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'--pname指針為空 * OS_ERR_PEVENT_NULL if you passed a NULL pointer for 'pevent'--pevent為空指針 * OS_ERR_NAME_SET_ISR if you called this function from an ISR--中斷 * * Returns : None--無返回值 ********************************************************************************************************* */#if (OS_EVENT_EN) && (OS_EVENT_NAME_EN > 0u) /*如果可以生成時間并且可以設置名稱*/ void OSEventNameSet(OS_EVENT *pevent, /*調用設置名稱函數(指向事件組的指針,指向名稱的指針,指向錯誤碼的指針)*/INT8U *pname,INT8U *perr) { #if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register 將中斷類型設置為3 */OS_CPU_SR cpu_sr = 0u; #endif#ifdef OS_SAFETY_CRITICAL /*定義安全中斷*/if (perr == (INT8U *)0) { /*如果錯誤碼為0*/OS_SAFETY_CRITICAL_EXCEPTION(); /*調用安全中斷異常函數OS_SAFETY_CRITICAL_EXCEPTION()*/} #endif#if OS_ARG_CHK_EN > 0u /*檢查參數*/if (pevent == (OS_EVENT *)0) { /* Is 'pevent' a NULL pointer? --pevent是空指針么? */*perr = OS_ERR_PEVENT_NULL; /*將錯誤碼設為OS_ERR_PEVENT_NULL*/return; /*無返回值*/}if (pname == (INT8U *)0) { /* Is 'pname' a NULL pointer? --pname是空指針么? */*perr = OS_ERR_PNAME_NULL; /*將錯誤碼設為OS_ERR_PNAME_NULL*/return; /*無返回值*/} #endifif (OSIntNesting > 0u) { /* See if trying to call from an ISR 檢查是否要進行中斷 */*perr = OS_ERR_NAME_SET_ISR; /*將錯誤碼設為OS_ERR_NAME_SET_ISR*/return; /*無返回值*/}switch (pevent->OSEventType) {case OS_EVENT_TYPE_SEM:case OS_EVENT_TYPE_MUTEX:case OS_EVENT_TYPE_MBOX:case OS_EVENT_TYPE_Q:break;default:*perr = OS_ERR_EVENT_TYPE;return;}OS_ENTER_CRITICAL(); /*關中斷*/pevent->OSEventName = pname; /*設置名稱*/OS_EXIT_CRITICAL(); /*開中斷*/*perr = OS_ERR_NONE; /*將錯誤碼設置為OS_ERR_NONE*/ } #endif總結
以上是生活随笔為你收集整理的OS_CORE.C(1)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: errno_t open_s()打开文件
- 下一篇: opengl关于obj文件相关知识