Microchip® Advanced Software Framework

Transmitting using the FreeRTOS USART driver in

standard mode

This example demonstrates using the FreeRTOS USART API to send data using the standard operation mode. * See Initializing the FreeRTOS USART

The example below implements a function that transmits two strings, and then returns.

Refer to the FreeRTOS peripheral control projects in the Atmel ASF distribution for complete working examples, and the FreeRTOS web site for information on getting started with FreeRTOS.

// This examples assumes freertos_usart has already been set by a successful
// call to freertos_usart_serial_init(), and that freertos_usart_serial_init()
// configured the FreeRTOS USART driver to use the standard operation mode.
status_code_t write_two_strings(freertos_usart_if freertos_usart){
uint8_t write_buffer[5];
status_code_t result;
// Send a string to the USART. The string must be in RAM, so copy it into
// an array.
strcpy(write_buffer, "one");
// Using a block time of 10 / portTICK_RATE_MS means "don't block any
// longer than 10ms" to wait for access to the USART. Other FreeRTOS tasks
// will execute during the wait period.
result = freertos_usart_write_packet(freertos_usart, write_buffer,
strlen("one"), 10 / portTICK_RATE_MS);
if(result == STATUS_OK) {
// freertos_usart_write_packet() does not return until transmission
// of the string has completed (other FreeRTOS tasks will execute
// while the transmission is in progress), meaning the write_buffer
// array can be re-used immediately without any risk of corrupting
// the original transmission. Copy the second string to be
// transmitted into the RAM buffer.
strcpy(write_buffer, "two");
result = freertos_usart_write_packet(freertos_usart, write_buffer,
strlen("two"), 10 / portTICK_RATE_MS);
}
// freertos_usart_write_packet() does not return until transmission of
// the string has completed (other FreeRTOS task will execute while the
// transmission is in progress), meaning the function can exit even
// though the buffer being transmitted is declared on the function's
// stack because it is guaranteed that nothing is still using the data
// the buffer contains.
return result;
}