// ----------------------------------------------------------------------------
//   INIT/DEINIT FUNCTIONS
// ----------------------------------------------------------------------------
void Serial_Init(void)
{

    /* Before using the ring buffers, initialize them using the ring
       buffer init function */
    RingBuffer_init(&rxring, rxbuff, UART_RRB_SIZE, sizeof(uint8_t));
    RingBuffer_init(&txring, txbuff, UART_SRB_SIZE, sizeof(uint8_t));

    /* creation of Serial object is chip/board specific, this is example for LPC */
    Serial = UARTSerial(LPC_USART, UART0_IRQn, 0, &rxring, &txring);
}
Ejemplo n.º 2
0
void RingBuffer_test(void)
{
    // Return Value
    int rv;
    // External buffer to register as Ring Buffer
    char ext_buffer[20] = {0};
    // Temporary buffers for test purposes
    char read_buffer[40] = {0};
    char write_buffer[40] = {0};

    // Initialize Ring Buffer module
    rv = RingBuffer_init(ext_buffer, sizeof(ext_buffer));
    if (rv != RING_BUFFER_E_SUCCESS)
    {
        // TODO: Complete this statement
    }

    // Write 20 bytes to the Temporary Write buffer
    strcat(write_buffer, "Test Ring Buffer 20");

    // Write 10 bytes to the Ring Buffer
    rv = RingBuffer_write(write_buffer, 10);
    if (rv != 10)
    {
        // TODO: Complete this statement
    }

    // Read-back 5 first bytes from the Ring buffer
    rv = RingBuffer_read(read_buffer, 5);
    if (rv != 5)
    {
        // TODO: Complete this statement
    }

    // Read-back 5 last bytes from the Ring Buffer
    rv = RingBuffer_read(read_buffer + 5, 5);
    if (rv != 5)
    {
        // TODO: Complete this statement
    }

    // Compare the read byte with initial written data
    rv = memcmp(write_buffer, read_buffer, 10);
    if (rv != 0)
    {
        // Buffers are different, test FAILED
        // TODO: Complete this statement
    }
    else
    {
        // Buffers are identical, test PASSED
        // TODO: Complete this statement
    }
}