Beispiel #1
0
static int nio_serial_ioctl(void *dev_context, void *fp_context, unsigned long int request, va_list ap) {

    NIO_SERIAL_DEV_CONTEXT_STRUCT *serial_dev_context = (NIO_SERIAL_DEV_CONTEXT_STRUCT *)dev_context;

    switch (request) {
    case IOCTL_ABORT:
        #if PLATFORM_LPUART_ENABLED
        LPUART_DRV_AbortSendingData(serial_dev_context->instance);
        LPUART_DRV_AbortReceivingData(serial_dev_context->instance);
        #else
        UART_DRV_AbortSendingData(serial_dev_context->instance);
        UART_DRV_AbortReceivingData(serial_dev_context->instance);
        #endif
        break;
    default:
        break;
    }

    return 0;
}
Beispiel #2
0
uart_status_t UART_DRV_ReceiveDataBlocking(uint32_t instance, uint8_t * rxBuff,
                                           uint32_t rxSize, uint32_t timeout)
{
    assert(rxBuff);
    assert(instance < HW_UART_INSTANCE_COUNT);
    
    mico_uart_t uart;
    uart_state_t * uartState = (uart_state_t *)g_uartStatePtr[instance];
    uart_status_t error = kStatus_UART_Success;
    uint32_t baseAddr = g_uartBaseAddr[instance];
    OSStatus Status;
    
    if(instance == BOARD_APP_UART_INSTANCE) uart = MICO_UART_1;
    /* Indicates current transaction is blocking.*/
    uartState->isRxBlocking = true;

    if (uartState->isRxBusy)
    {
        return kStatus_UART_RxBusy;
    }
    uartState->rxBuff = rxBuff;
    uartState->rxSize = rxSize;
    uartState->isRxBusy = true;
    /* enable the receive data full interrupt */
    UART_HAL_SetRxDataRegFullIntCmd(baseAddr, true);

    /* Wait until all the data is received or for timeout.*/
    Status = mico_rtos_get_semaphore( &uart_interfaces[uart].rx_complete, timeout );

    if (Status != kNoErr)
    {
        /* Abort the transfer so it doesn't continue unexpectedly.*/
        UART_DRV_AbortReceivingData(instance);
        error = kStatus_UART_Timeout; // kGeneralErr;
    }
    return error;
}