Exemplo n.º 1
0
TCPIP_MAC_RES TCPIP_MAC_Process(TCPIP_MAC_HANDLE hMac)
{
    if (OSAL_SEM_Pend(((const TCPIP_MAC_DCPT*)hMac)->pObj->semaphore, OSAL_WAIT_FOREVER) != OSAL_RESULT_TRUE)
    {
        // SYS_DEBUG message
    }
    TCPIP_MAC_RES res = (*((const TCPIP_MAC_DCPT*)hMac)->pObj->TCPIP_MAC_Process)(hMac);
    if (OSAL_SEM_Post(((const TCPIP_MAC_DCPT*)hMac)->pObj->semaphore) != OSAL_RESULT_TRUE)
    {
        // SYS_DEBUG message
    }
    return res;
}
Exemplo n.º 2
0
TCPIP_MAC_PACKET* TCPIP_MAC_PacketRx(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_RES* pRes, const TCPIP_MAC_PACKET_RX_STAT** ppPktStat)
{
    if (OSAL_SEM_Pend(((const TCPIP_MAC_DCPT*)hMac)->pObj->semaphore, OSAL_WAIT_FOREVER) != OSAL_RESULT_TRUE)
    {
        // SYS_DEBUG message
    }
    TCPIP_MAC_PACKET* res = (*((const TCPIP_MAC_DCPT*)hMac)->pObj->TCPIP_MAC_PacketRx)(hMac, pRes, ppPktStat);
    if (OSAL_SEM_Post(((const TCPIP_MAC_DCPT*)hMac)->pObj->semaphore) != OSAL_RESULT_TRUE)
    {
        // SYS_DEBUG message
    }
    return res;
}
Exemplo n.º 3
0
TCPIP_MAC_RES TCPIP_MAC_PacketTx(TCPIP_MAC_HANDLE hMac, TCPIP_MAC_PACKET * ptrPacket)
{
    if (OSAL_SEM_Pend(((const TCPIP_MAC_DCPT*)hMac)->pObj->semaphore, OSAL_WAIT_FOREVER) != OSAL_RESULT_TRUE)
    {
        // SYS_DEBUG message
    }
    TCPIP_MAC_RES res = (*((const TCPIP_MAC_DCPT*)hMac)->pObj->TCPIP_MAC_PacketTx)(hMac, ptrPacket);
    if (OSAL_SEM_Post(((const TCPIP_MAC_DCPT*)hMac)->pObj->semaphore) != OSAL_RESULT_TRUE)
    {
        // SYS_DEBUG message
    }
    return res;
}
Exemplo n.º 4
0
void WDRV_SemTake(OSAL_SEM_HANDLE_TYPE *SemID, uint16_t timeout)
{
    OSAL_SEM_Pend(SemID, timeout);
}
Exemplo n.º 5
0
// locks access to shared resources
static __inline__ void  __attribute__((always_inline))          _UserGblLock(void)
{
    // Shared Data Lock
    OSAL_SEM_Pend(&sSysTmrObject.userSem, OSAL_WAIT_FOREVER);
}    
Exemplo n.º 6
0
size_t DRV_USART_Read(const DRV_HANDLE hClient, void * destination, size_t nBytes)
{
    DRV_USART_CLIENT_OBJ * clientObj;
    DRV_USART_OBJ * hDriver;
    USART_MODULE_ID plibID;
    DRV_USART_BUFFER_OBJ * iterator, * bufferObj;
    size_t count = 0;
    uint8_t * data;
    bool status;

    /* Validate the driver handle */

    clientObj = _DRV_USART_DriverHandleValidate(hClient);
    if(clientObj == NULL)
    {
        SYS_DEBUG(0, "Invalid driver handle");
        return 0;
    }

    hDriver = (DRV_USART_OBJ *)clientObj->hDriver;
    plibID = hDriver->moduleId;

    if(!(clientObj->ioIntent & DRV_IO_INTENT_READ))
    {
        /* This client did not open the driver for
           reading */
        SYS_DEBUG(0, "Driver not opened for read");
        return 0;
    }

    if((destination == NULL) || (nBytes == 0))
    {
        /* We have a NULL pointer or dont have
           any data to write. */

        SYS_DEBUG(0, "NULL data pointer or no data to write");
        return 0;
    }

    data = (uint8_t *)destination;

    /* Grab he hardware instance mutex */

    if(OSAL_MUTEX_Lock(hDriver->mutexDriverInstance, OSAL_WAIT_FOREVER) == OSAL_RESULT_TRUE)
    {
        if(!(clientObj->ioIntent & DRV_IO_INTENT_NONBLOCKING))
        {
            /* This is a blocking implementation. We populate the client buffer
               object and add it to the queue. We then wait till the buffer is
               completely processed. */

            /* Because we are modifying the queue, we should disable the
               interrupt */

            status = _DRV_USART_InterruptSourceDisable(hDriver->rxInterruptSource);

            /* Get the queue head */

            iterator = hDriver->queueRead;

            /* If the queue is not empty, get to the end of the queue */

            if(iterator != NULL)
            {
                while(iterator->next != NULL)
                {
                    iterator = iterator->next;
                }
            }

            /* We should be at the end of the queue now. Populate the client
               buffer object */

            bufferObj = &clientObj->bufferObject;
            bufferObj->buffer = destination;
            bufferObj->nCurrentBytes = 0;
            bufferObj->size = nBytes;
            bufferObj->inUse = true;
            bufferObj->hClient = clientObj;
            bufferObj->flags = (0 | DRV_USART_BUFFER_OBJ_FLAG_READ_WRITE);

            /* Add this object to the queue and enable the RX interrupt */

            bufferObj->previous = iterator;
            bufferObj->next = NULL;

            /* If we are not at the start of the queue, then update the next
               pointer of the last object else set the queue head to point to
               this object */

            if(hDriver->queueRead == NULL)
            {
                hDriver->queueRead = bufferObj;
            }
            else
            {
                iterator->next = bufferObj;
                bufferObj->previous = iterator;
            }

            /* Now enable the interrupt and release the mutex so that the system
               can proceed */

            _DRV_USART_InterruptSourceEnable(hDriver->rxInterruptSource);
            OSAL_ASSERT((OSAL_MUTEX_Unlock(hDriver->mutexDriverInstance)),
                            "Unable to unlock hardware instance mutex");
            
            /* If we are in a bare metal configuration, then wait till the
               buffer is processed. If we are in RTOS configuration then pend on
               the client semaphore. */

            if(OSAL_SEM_Pend(clientObj->semReadDone, OSAL_WAIT_FOREVER) == OSAL_RESULT_TRUE)
            {
                /* This is the implementation of the blocking behavior. In a
                   RTOS configuration, if the code reaches here, it means then
                   that buffer has been processed. */ 
                
                while(bufferObj->inUse);
                if(bufferObj->nCurrentBytes != nBytes) 
                {
                    /* This means this buffer was terminated because of an
                       error. */
                    
                    return(DRV_USART_READ_ERROR);
                }
                     
                count = nBytes;
            }
        }
        else if(clientObj->ioIntent & DRV_IO_INTENT_NONBLOCKING)
        {
            /* This is a non blocking implementation*/

            if(hDriver->queueRead != NULL)
            {
                /* This means queue is not empty. We cannot read
                   data now. */
                count = 0;
            }
            else
            {

                while((PLIB_USART_ReceiverDataIsAvailable(plibID)) &&
                        (count < nBytes))
                {
                    /* This is not a blocking implementation. We read
                       the hardware till the FIFO is empty. */

                    data[count] = PLIB_USART_ReceiverByteReceive(plibID);
                    count ++;

                    /* We need to check for errors. Store the error
                       in the client error field. */

                    clientObj->error = PLIB_USART_ErrorsGet(plibID);

                    if(clientObj->error != DRV_USART_ERROR_NONE)
                    {
                        /* This means we have an error. Release the mutex and
                           exit */
                        OSAL_ASSERT((OSAL_MUTEX_Unlock(hDriver->mutexDriverInstance)),
                                "Unable to unlock hardware instance mutex");
                        return(DRV_USART_READ_ERROR);
                    }
                }
            }
        }
    }
    else
    {
        /* Timed out while waiting for read mutex.
         * We simply return 0 */
        count = 0;
    }

    return(count);
}