Ejemplo n.º 1
0
/**
 *******************************************************************************
 * @brief       Post a semaphore	 
 * @param[in]   id   id of event control block associated with the desired semaphore.	 	 
 * @param[out]  None   
 * @retval      E_INVALID_ID   Parameter id passed was invalid event ID.
 * @retval      E_SEM_FULL     Semaphore full. 
 * @retval      E_OK           Semaphore had post successful.
 *
 * @par Description
 * @details    This function is called to post a semaphore to corresponding event. 
 *
 * @note 
 *******************************************************************************
 */
StatusType CoPostSem(OS_EventID id)
{
    P_ECB pecb;
#if CFG_PAR_CHECKOUT_EN >0
    if(id >= CFG_MAX_EVENT)	                  
    {
        return E_INVALID_ID;
    }
#endif

    pecb = &EventTbl[id];
#if CFG_PAR_CHECKOUT_EN >0
    if(pecb->eventType != EVENT_TYPE_SEM) /* Invalid event control block type */
    {
        return E_INVALID_ID;	
    }
#endif

    /* Make sure semaphore will not overflow */
    if(pecb->eventCounter == pecb->initialEventCounter) 
    {
        return E_SEM_FULL;    /* The counter of Semaphore reach the max number*/
    }
    OsSchedLock();
    pecb->eventCounter++;     /* Increment semaphore count to register event  */
    EventTaskToRdy(pecb);     /* Check semaphore event waiting list           */
    OsSchedUnlock();
    return E_OK;
		
}
Ejemplo n.º 2
0
/**
 *******************************************************************************
 * @brief      Post a mailbox	  
 * @param[in]  id      Event ID.
 * @param[in]  pmail   Pointer to mail that want to send.		 
 * @param[out] None   
 * @retval     E_INVALID_ID	
 * @retval     E_OK		 
 *
 * @par Description
 * @details    This function is called to post a mail. 
 * @note 
 *******************************************************************************
 */
StatusType CoPostMail(OS_EventID id,void* pmail)
{
    P_ECB pecb;
#if CFG_PAR_CHECKOUT_EN >0
    if(id >= CFG_MAX_EVENT)	                
    {
        return E_INVALID_ID;            /* Invalid id,return error            */
    }
#endif

    pecb = &EventTbl[id];
#if CFG_PAR_CHECKOUT_EN >0
    if(pecb->eventType != EVENT_TYPE_MBOX)/* Validate event control block type*/
    {
        return E_INVALID_ID;              /* Event is not mailbox,return error*/
    }
#endif

    if(pecb->eventCounter == 0)   /* If mailbox doesn't already have a message*/	
    {
        OsSchedLock();
        pecb->eventPtr     = pmail;       /* Place message in mailbox         */
        pecb->eventCounter = 1;
        EventTaskToRdy(pecb);             /* Check waiting list               */
        OsSchedUnlock();
        return E_OK;	
    }
    else                          /* If there is already a message in mailbox */              
    {
        return E_MBOX_FULL;       /* Mailbox is full,and return "E_MBOX_FULL" */
    }
}
Ejemplo n.º 3
0
/**
 *******************************************************************************
 * @brief      Post a mail to queue	   
 * @param[in]  id      Event ID.
 * @param[in]  pmail   Pointer to mail that want to send.	 	 
 * @param[out] None   
 * @retval     E_OK
 * @retval     E_INVALID_ID
 * @retval     E_QUEUE_FULL		 
 *
 * @par Description
 * @details    This function is called to post a mail to queue.
 * @note 
 *******************************************************************************
 */
StatusType CoPostQueueMail(OS_EventID id,void* pmail)
{	
    P_ECB pecb;
    P_QCB pqcb;
#if CFG_PAR_CHECKOUT_EN >0                     
    if(id >= CFG_MAX_EVENT)	
    {
        return E_INVALID_ID;          
    }
#endif

    pecb = &EventTbl[id];
#if CFG_PAR_CHECKOUT_EN >0
    if(pecb->eventType != EVENT_TYPE_QUEUE)   
    {
        return E_INVALID_ID;            /* The event type isn't queue,return  */	
    }	
#endif
    pqcb = (P_QCB)pecb->eventPtr;	
    if(pqcb->qSize == pqcb->qMaxSize)   /* If queue is full                   */
    {
        return E_QUEUE_FULL;
    }
    else                                /* If queue is not full               */
    {
        OsSchedLock();
        *(pqcb->qStart + pqcb->tail) = pmail;   /* Insert message into queue  */
        pqcb->tail++;                           /* Update queue tail          */
        pqcb->qSize++;          /* Update the number of messages in the queue */
        if(pqcb->tail == pqcb->qMaxSize)        /* Check queue tail           */   
        {
            pqcb->tail = 0;	
        }
        EventTaskToRdy(pecb);           /* Check the event waiting list       */
        OsSchedUnlock();
        return E_OK;
    }
}