/** ******************************************************************************* * @brief Create a semaphore * @param[in] initCnt Semaphore valid counter. * @param[in] maxCnt Semaphore max initialize counter. * @param[in] sortType Semaphore sort type. * @param[out] None * @retval E_CREATE_FAIL Create semaphore fail. * @retval others Create semaphore successful. * * @par Description * @details This function is called to create a semaphore. ******************************************************************************* */ OS_EventID CoCreateSem(U16 initCnt,U16 maxCnt,U8 sortType) { P_ECB pecb; #if CFG_PAR_CHECKOUT_EN >0 if(initCnt > maxCnt) { return E_CREATE_FAIL; /* Invalid 'initCnt' or 'maxCnt' */ } if ((sortType != EVENT_SORT_TYPE_FIFO) && (sortType != EVENT_SORT_TYPE_PRIO)) { return E_CREATE_FAIL; /* Illegal sort type,return error */ } #endif /* Create a semaphore type event control block */ pecb = CreatEvent(EVENT_TYPE_SEM,sortType,Co_NULL); if(pecb == Co_NULL) /* If failed to create event block */ { return E_CREATE_FAIL; } pecb->eventCounter = initCnt;/* Initialize event block */ pecb->initialEventCounter = maxCnt; return (pecb->id); /* Return event id */ }
/** ******************************************************************************* * @brief Create a mailbox * @param[in] sortType Mail box waiting list sort type. * @param[out] None * @retval E_CREATE_FAIL Create mailbox fail. * @retval others Create mailbox successful. * * @par Description * @details This function is called to create a mailbox. * @note ******************************************************************************* */ OS_EventID CoCreateMbox(U8 sortType) { P_ECB pecb; /* Create a mailbox type event control block */ pecb = CreatEvent(EVENT_TYPE_MBOX,sortType,NULL); if(pecb == NULL) /* If failed to create event block */ { return E_CREATE_FAIL; } pecb->eventCounter = 0; return (pecb->id); /* Create a mailbox successfully, return event ID */ }
/** ******************************************************************************* * @brief Create a queue * @param[in] qStart Pointer to mail pointer buffer. * @param[in] size The length of queue. * @param[in] sortType Mail queue waiting list sort type. * @param[out] None * @retval E_CREATE_FAIL Create queue fail. * @retval others Create queue successful. * * @par Description * @details This function is called to create a queue. * @note ******************************************************************************* */ OS_EventID CoCreateQueue(void **qStart, U16 size ,U8 sortType) { U8 i; P_ECB pecb; #if CFG_PAR_CHECKOUT_EN >0 if((qStart == NULL) || (size == 0)) { return E_CREATE_FAIL; } #endif OsSchedLock(); for(i = 0; i < CFG_MAX_QUEUE; i++) { /* Assign a free QUEUE control block */ if((QueueIDVessel & (1u << i)) == 0) { QueueIDVessel |= (1u<<i); OsSchedUnlock(); QueueTbl[i].qStart = qStart; /* Initialize the queue */ QueueTbl[i].id = i; QueueTbl[i].head = 0; QueueTbl[i].tail = 0; QueueTbl[i].qMaxSize = size; QueueTbl[i].qSize = 0; /* Get a event control block and initial the event content */ pecb = CreatEvent(EVENT_TYPE_QUEUE,sortType,&QueueTbl[i]); if(pecb == NULL ) /* If there is no free EVENT control block*/ { return E_CREATE_FAIL; } return (pecb->id); } } OsSchedUnlock(); return E_CREATE_FAIL; /* There is no free QUEUE control block */ }