test/uart_flow_control/main.c
/*******************************************************************************
* # License
* Copyright 2019 Silicon Laboratories Inc. www.silabs.com
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
/* Documentation for this app is available online.
* See https://docs.silabs.com/gecko-os/4/standard/latest/sdk/examples/system/uart
*/
#include "gos.h"
#define UART_MAX_IRQ_EVENTS 3
#define UART_CONSUME_PERIOD 10
#define BAUD_RATE 115200
#define RING_BUFFER_SIZE 128
#define APPLICATION_START_LINE "\r\nuart flow control app started"
static uint8_t rx_buffer[RING_BUFFER_SIZE];
static uint8_t ring_buffer_data[RING_BUFFER_SIZE];
/*************************************************************************************************/
{
GOS_LOG(APPLICATION_START_LINE);
}
GOS_DEFINE_COMMAND(uart, flow_start)
{
{
.baud_rate = BAUD_RATE,
.data_width = GOS_UART_WIDTH_8BIT,
.parity = GOS_UART_NO_PARITY,
.stop_bits = GOS_UART_STOP_BITS_1,
.flow_control = GOS_UART_FLOW_CONTROL_CTSRTS,
};
{
.data = ring_buffer_data,
.size = sizeof(ring_buffer_data)
};
gos_event_enable_irq_events(UART_MAX_IRQ_EVENTS);
gos_uart_configure(PLATFORM_STD_UART, &config, &uart_buffer);
gos_event_register_periodic(uart_consume_event_handler, NULL, UART_CONSUME_PERIOD, 0);
GOS_LOG("type '$' to return to command mode");
}
static void uart_consume_event_handler(void *arg)
{
uint32_t bytes_available;
gos_uart_peek_bytes(PLATFORM_STD_UART, NULL, &bytes_available);
for ( uint32_t i=0; i<rx_len; ++i )
{
if ( rx_buffer[i] == '$' )
{
gos_event_unregister(uart_consume_event_handler, NULL);
gos_cmd_set_console_enabled(true);
return;
}
}
}