Quick FreeRTOS-Plus-IO Examples
This page contains basic source code examples to demonstrate
the FreeRTOS-Plus-IO concept. More detailed examples are provided in the
API Reference and
Transfer Mode section sections of this site.
Comprehensive application examples are provided with board support packages, with notable projects documented
on the
Featured Demos pages.
Example 1 demonstrates how to read bytes from a peripheral that has
already been opened and configured. The example is valid for all
the data transfer modes.
#include "FreeRTOS_IO.h"
#define BUFFER_SIZE 200
const int8_t cBuffer[ 200 ] = { 0 };
void vReadExample( Peripheral_Descriptor_t xOpenPort )
{
size_t xBytesTransferred;
xBytesTransferred = FreeRTOS_read( xOpenPort, cBuffer, BUFFER_SIZE );
}
Example 1: Reading bytes from a descriptor that has already been opened
and configured.
Example 2 demonstrates how to write bytes to a peripheral that has
already been opened and configured to use the
interrupt driven zero copy write
transfer mode.
#include "FreeRTOS_IO.h"
#define BUFFER_SIZE 200
const int8_t cBuffer[ 200 ] = { 0 };
void vWriteExample( Peripheral_Descriptor_t xOpenPort )
{
size_t xBytesTransferred;
BaseType_t xReturn;
xReturn = FreeRTOS_ioctl( xOpenPort, iocltOBTAIN_WRITE_MUTEX, ( void * ) ( 200 / portTICK_PERIOD_MS ) );
if( xReturn != pdFAIL )
{
xBytesTransferred = FreeRTOS_write( xOpenPort, cBuffer, BUFFER_SIZE );
}
}
Example 2: Writing bytes to a descriptor that has already been opened and
configured to use the zero copy write transfer mode.
Example 3 demonstrates how to open and configure a descriptor.
First an I2C port is opened. Then, assuming the open was successful,
the port is configured for zero copy write transfers and circular buffer
read transfers. The read timeout and the write timeout are both
set to 200ms.
#include "FreeRTOS_IO.h"
Peripheral_Descriptor_t xOpenAndConfigureI2CPort( void )
{
Peripheral_Descriptor_t xI2CPort;
xI2CPort = FreeRTOS_open( "/I2C0/", NULL );
configASSERT( xI2CPort );
FreeRTOS_ioctl( xI2CPort, iocltUSE_ZERO_COPY_TX, NULL );
FreeRTOS_ioctl( xI2CPort, iocltUSE_CIRCULAR_BUFFER_RX, ( void * ) 100 );
FreeRTOS_ioctl( xI2CPort, iocltSET_RX_TIMEOUT, ( void * ) ( 200 / portTICK_PERIOD_MS ) );
FreeRTOS_ioctl( xI2CPort, iocltSET_SPEED, ( void * ) 400000 );
FreeRTOS_ioctl( xI2CPort, iocltSET_I2C_SLAVE_ADDRESS, ( void * ) 50 );
return xI2CPort;
}
Example 3: Opening and configuring a descriptor
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.