Data Direction
The interrupt driven circular buffer transfer mode can be used with FreeRTOS_read().
Description
ioconfigUSE_CIRCULAR_BUFFER_RX must be set to 1 in
FreeRTOSIOConfig.h
for the circular buffer transfer mode to be available. It
must also be explicitly enabled for the peripheral being used within the
same configuration file.
When the circular buffer transfer mode is selected, FreeRTOS_read() does not read
bytes directly from the peripheral, but from a circular buffer that is
filled by the FreeRTOS-Plus-IO interrupt service routine as data is received.
The interrupt service routine, and the FreeRTOS circular buffer, are
implemented by the FreeRTOS-Plus-IO code, and do not need to be provided by
the application writer.
Interrupt Driven Circular Buffer Transfer Mode
|
Advantages
|
Disadvantages
|
-
Simple usage model
-
Automatically places the calling task into the
Blocked
state to wait for the read operation
to complete - if it cannot complete immediately. This
ensures the task calling FreeRTOS_read()
only uses CPU time when there are bytes
in the circular buffer.
-
A read timeout can be set to ensure
FreeRTOS_read() calls do not block indefinitely.
-
A simple RAM buffer is used, resulting in a moderately
efficient receive method - although a copy into the
buffer and a copy out of the buffer are required.
-
Bytes received by the peripheral are automatically
buffered, and not lost, even if a FreeRTOS_read()
operation is not in progress when the
bytes are received.
|
-
The FreeRTOS-Plus-IO driver requires RAM for the circular
buffer. The buffer length is configured by the
third parameter of the FreeRTOS_ioctl() call used to
select the transfer mode.
|
The ioctlUSE_CIRCULAR_BUFFER_RX request code is used in a call to FreeRTOS_ioctl()
to configure a peripheral
to use the interrupt driven circular buffer transfer mode for reads.
Note this request code will result in the peripheral's
interrupt being enabled, and the peripheral's interrupt priority being set to the
lowest possible. The ioctlSET_INTERRUPT_PRIORITY request code can be used
to raise the peripheral's priority if necessary.
Example Usage
#include "FreeRTOS_IO.h"
void vAFunction( void )
{
Peripheral_Descriptor_t xOpenedPort;
BaseType_t xReturned;
const uint32_t ulMaxBlock100ms = ( 100UL / portTICK_PERIOD_MS );
xOpenedPort = FreeRTOS_open( "/SPI2/", NULL );
if( xOpenedPort != NULL )
{
FreeRTOS_ioctl( xOpenedPort, ioctlUSE_CIRCULAR_BUFFER_RX, ( void * ) 20 );
FreeRTOS_ioctl( xOpenedPort, ioctlSET_RX_TIMEOUT, ( void * ) ulMaxBlock100ms );
for( ;; )
{
xBytesTransferred = FreeRTOS_read( xOpenedPort, ucBuffer, 10 );
if( xBytesTransferred == 10 )
{
}
else
{
}
}
}
else
{
}
}
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.