Microchip® Advanced Software Framework

Initializing the FreeRTOS SPI driver

for asynchronous operation

This example configures the FreeRTOS SPI driver to:

  • Support simultaneous access from multiple RTOS tasks.
  • Exit the FreeRTOS transmit function as soon as the transmission is started.
  • Exit the receive function as soon as the receive has been requested.

If the driver is initialized with this configuration then only the freertos_spi_write_packet_async() and freertos_spi_read_packet_async() API functions can be used to transmit and receive data respectively. freertos_spi_write_packet() and freertos_spi_read_packet() must not be used.

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.

// Declare the variables used as parameters to the
// freertos_spi_master_init() function.
// Handle used to access the initialized port by other FreeRTOS ASF functions.
freertos_spi_if freertos_spi;
// Configuration structure.
// This peripheral is synchronous and so does not need a receive buffer.
// The receive_buffer value is just set to NULL.
// There isn't a receive buffer, so the receive_buffer_size value can
// take any value.
0,
// The interrupt priority. The FreeRTOS driver provides the interrupt
// service routine, and handles all interrupt interactions. The
// application writer does not need to provide any interrupt handling
// code, but does need to specify the priority of the DMA interrupt here.
// IMPORTANT!!! see <a href="http://www.freertos.org/RTOS-Cortex-M3-M4.html">how to set interrupt priorities to work with FreeRTOS</a>
0x0e,
// The operation_mode value.
// Flags set to allow access from multiple tasks. Note the
// WAIT_TX_COMPLETE and WAIT_RX_COMPLETE bits are *not* set.
};
// Call the SPI specific FreeRTOS ASF driver initialization function,
// storing the return value as the driver handle.
freertos_spi = freertos_spi_master_init(spi_base, &driver_options);
if (freertos_spi != NULL) {
// Calling freertos_spi_master_init() will enable the peripheral clock,
// and set the SPI into master mode. Other ASF configuration functions,
// such as spi_set_clock_polarity(), and spi_set_baudrate_div() can then
// be called here.
}