Example #1
0
void uart_sps_read(uint8_t *bufptr, uint32_t size, uint8_t *state, void (*callback) (uint8_t, uint32_t))
{
    // Sanity check
    ASSERT_ERR(bufptr != NULL);
    ASSERT_ERR(size != 0);
    ASSERT_ERR(uart_sps_env.rx.bufptr == NULL);

    // Prepare RX parameters
    uart_sps_env.rx.size 		= size;
    uart_sps_env.rx.bufptr 		= bufptr;
	  uart_sps_env.rx.state 		= state;
	  uart_sps_env.rx.callback 	= callback; 
	
    // Start data transaction
    uart_rec_data_avail_setf(1); //=SetBits16(UART_IER_DLH_REG, ETBEI_dlh0, 1); 
}
static void uart_rec_data_avail_isr(void)
{
    void (*callback) (uint8_t) = NULL;

    while (uart_data_rdy_getf())
    {
        // Read the received in the FIFO
        *uart_env.rx.bufptr = uart_rxdata_getf();

        // Update RX parameters
        uart_env.rx.size--;
        uart_env.rx.bufptr++;

        // Check if all expected data have been received
        if (uart_env.rx.size == 0)
        {
            // Reset RX parameters
            uart_env.rx.bufptr = NULL;

            // Disable Rx interrupt
            uart_rec_data_avail_setf(0);  //=SetBits16(UART_IER_DLH_REG, ETBEI_dlh0, 0); 

            // Retrieve callback pointer
            callback = uart_env.rx.callback;

            if(callback != NULL)
            {
                // Clear callback pointer
                uart_env.rx.callback = NULL;

                // Call handler
                callback(UART_STATUS_OK);
            }
            else
            {
                ASSERT_ERR(0);
            }

            // Exit loop
            break;
        }
    }
}