FreeRTOSplus用法举例

更新时间:2023-07-17 00:58:31 阅读: 评论:0

FreeRTOSplus⽤法举例
FreeRTOS_open
Peripheral_Descriptor_t FreeRTOS_open( const int8_t *pcPath, const uint32_t ulFlags );
Opens a peripheral for u with FreeRTOS+IO. The board support package defines which peripherals are available on any particular platform.
Parameters:
pcPath The text name of the peripheral being opened, as defined by the board support package.
ulFlags Mode flags. This parameter is not currently ud. It is included for two reasons - so the FreeRTOS_open() prototype complies with the standard open() prototype, and to ensure backward compatibility after future FreeRTOS+IO developments. Returns:
NULL if the peripheral could not be opened, otherwi a variable of type Peripheral_Descriptor_t that can be ud to access the opened peripheral in future calls to FreeRTOS_read(), FreeRTOS_write() and FreeRTOS_ioctl().
Example usage:
/* FreeRTOS+IO includes. */英语四六级
#include "FreeRTOS_IO.h"
void vAFunction( void )
{
/* The Peripheral_Descriptor_t type is the FreeRTOS+IO equivalent of a descriptor. */
Peripheral_Descriptor_t xOpenedPort;
/* Open the SPI port identified in the board support package as using the
path string "/SPI2/". The cond parameter is not currently ud and can
be t to anything, although, for future compatibility, it is recommended
that it is t to NULL. */
xOpenedPort = FreeRTOS_open( "/SPI2/", NULL );
if( xOpenedPort != NULL )
26个大写字母{
/* xOpenedPort now contains a valid descriptor that can be ud with
cslr
other FreeRTOS+IO API functions. */
. . .
}
el
beach怎么读
{
/* The port was not opened successfully. */
}
}
FreeRTOS_read
size_t FreeRTOS_open( Peripheral_Descriptor_t const pxPeripheral,
void * const pvBuffer,
const size_t xBytes );
Reads one or more bytes from an open peripheral.
The board support package defines the peripherals that are available to be opened. FreeRTOS_ioctl() is ud to lect between interrupt driven and polled read modes.
Parameters:
pxPeripheral The descriptor associated with the peripheral from which bytes are being read. The descriptor will have been returned from the FreeRTOS_open() call ud to open the peripheral.
pvBuffer The buffer into which read data are placed.
xBytes The total number of bytes requested.
When an interrupt driven transfer mode is ud, the total number of bytes actually read will be less than the total number requested if the total number requested are not available before the peripheral's read timeout expires. FreeRTOS_ioctl() is ud to t the read timeout value.
Returns:
The total number of bytes read. This will be less than the number of bytes requested by the xBytes parameter if the requested number of bytes cannot be read before the peripheral's read timeout expires. FreeRTOS_ioctl() is ud to t the read timeout value.
Example usage:
The example 1 code snippet demonstrates how to perform a read when a peripheral is configured to u the polled transfer mode. Peripherals default to polled mode when they are opened.
/* By default the port is opened in polled mode. Read sizeof( ucBuffer ) bytes into
ucBuffer using polled mode. */
finn
xBytesRead = FreeRTOS_read( xPort, ucBuffer, sizeof( ucBuffer ) );
/* The port is currently in polled mode, so FreeRTOS_read() will only have
returned once all the requested bytes had been read (barring any errors on
the peripheral). Note that, becau polling mode is being ud, the task
making the FreeRTOS_read() call will not have entered the Blocked
state if it had to wait for the requested number of bytes. */
configASSERT( xBytes == sizeof( ucBuffer ) );
Example 1: Reading bytes from a peripheral that is configured to u the polled transfer mode.
The example 2 code snippet demonstrates how to perform a read when a peripheral is configured to u either the interrupt driven character queue transfer mode, or the interrupt driven circular buffer transfer mode. In the modes, the task making the FreeRTOS_read() call is held in the Blocked state (not using any CPU time) until either the requested number of bytes have been read, or the rea
d timeout expires. FreeRTOS_ioctl() is ud with the iocltSET_RX_TIMEOUT request code to configure the read timeout.
/* Read some bytes in one of the interrupt driven transfer modes. If the
character queue transfer mode is being ud, this will remove bytes from the
queue that had previously been placed into the queue by the FreeRTOS+IO interrupt
rvice routine. If the circular buffer transfer mode is being ud, this will
remove bytes from the circular buffer that had previously been placed into the
buffer by the FreeRTOS+IO interrupt rvice routine. In both cas, read bytes
are placed in ucBuffer. */
xBytesRead = FreeRTOS_read( xPort, ucBuffer, sizeof( ucBuffer ) );
if( xBytesRead < sizeof( ucBuffer ) )
{
/* The Rx timeout must have expired before sizeof( ucBuffer ) bytes could
be read. xBytesRead number of bytes will have been placed into ucBuffer. */
}
el
{
/* The requested number of bytes were read before the read timeout expired.
All the requested bytes have been placed in ucBuffer. */
}
Example 2: Reading bytes from a peripheral that is configured to ud either the interrupt driven character queue transfer mode, or the interrupt driven
circular buffer transfer mode.
FreeRTOS_write
size_t FreeRTOS_write( Peripheral_Descriptor_t const pxPeripheral,
const void *pvBuffer,
const size_t xBytes );
Writes one or more bytes to an open peripheral.
The board support package defines the peripherals that are available to be opened. FreeRTOS_ioctl() is ud to lect between interrupt driven and polled write modes.
Parameters:
pxPeripheral The descriptor associated with the peripheral to which bytes are being written. The descriptor will have been returned from the FreeRTOS_open() call ud to open the peripheral.
pvBuffer A pointer to the first byte of data to write.
xBytes The total number of bytes to write.
When an interrupt driven transfer mode is being ud, the actual number of bytes written to a periph
eral may be less than the requested number if not all the bytes could be written before the peripheral's write timeout expired. FreeRTOS_ioctl() is ud to t the write timeout value.
Returns:
When the polled transfer mode is ud, the returned value is the total number of bytes actually written to the peripheral. This will be the total number requested assuming no errors occurred.
When the interrupt driven character queue transfer mode is ud, the returned value is the total number of bytes actually written to the write queue. This will be less than the requested number of bytes if there was not enough space in the queue for all the bytes to be written immediately, and the peripheral's write timeout expired before enough space became available. The actual transmission of data is controlled by the FreeRTOS+IO interrupt rvice routine, and may complete after the call to FreeRTOS_write() has returned. When the interrupt driven zero copy transfer mode is ud, then:
If the task calling FreeRTOS_write() holds the write mutex, the returned value will be the total number of bytes to transmit, assuming no errors occurred. The actual transmission of data is controlled by the FreeRTOS+IO interrupt rvice routine, and may complete after the call to FreeRTOS_write() has returned. If the task calling FreeRTOS_write() does not hold the write mutex,
or if FreeRTOSIOConfig.h is not configured to include the zero copy write transfer mode for the peripheral, then zero is returned.
FreeRTOS_ioctl() is ud to t the write timeout value.
map worldExample usage:
The example 1 code snippet demonstrates how to perform a write when a peripheral is configured to u the polled transfer mode. Peripherals default to polled mode when they are opened.
/* By default the port is opened in polled mode. Write some bytes in polled
mode. */
xBytesWritten = FreeRTOS_write( xPort, ucBuffer, sizeof( ucBuffer ) );
/* The port is currently in polled mode, so FreeRTOS_write() will only have
returned once all the requested bytes had been written (barring any errors on
the peripheral). Note that becau polling mode is being ud, the task
making the FreeRTOS_write() call will not have entered the Blocked
drive angry
state during the write process. The bytes written to the peripheral come from
the ucBuffer buffer. */
configASSERT( xBytes == sizeof( ucBuffer ) );
Example 1: Writing bytes to a peripheral that is configured to u the polled transfer mode.
The example 2 code snippet demonstrates how to perform a write when a peripheral is configured to u the interrupt driven character queue transfer mode. In this mode, the task making the FreeRTOS_write() call is held in the Blocked state (not using any CPU time) until either all the requested number of bytes have been nt to the queue, or the write timeout expires. FreeRTOS_ioctl() is ud with the ioctlSET_TX_TIMEOUT request code to configure the write timeout, and the
ioctlWAIT_PREVIOUS_WRITE_COMPLETE request code wait for the write queue to be empty.
/* Write some bytes in interrupt driven character queue Tx mode. */
xBytesWritten = FreeRTOS_write( xPort, ucBuffer, sizeof( ucBuffer ) );
if( xBytesWritten < sizeof( ucBuffer ) )
{
/* The Tx timeout must have expired before sizeof( ucBuffer ) bytes could
be written to the write queue. */
}
el
{
lung/* The requested number of bytes were nt to the write queue before
sixt
the write timeout expired. */
}
Example 2: Writing bytes to a peripheral that is configured to u the interrupt driven character queue transfer mode.
The example 3 code snippet demonstrates how to perform a write when a peripheral is configured to u the interrupt driven zero copy transfer mode. In this mode, the task making the FreeRTOS_write() call will always return immediately. If the
returned value equals the number of bytes that are to be written, then the FreeRTOS_write() call successfully started the interrupt driven transmission. If the returned value equals zero, then the FreeRTOS_write() call could not start the transmission, either becau it did not hold the write mutex, or becau FreeRTOSIOConfig.h was not configured to support it.
/* As zero copy Tx is being ud, a mutex must be obtained before a write can
be requested. This call requests the mutex, and will wait a maximum of 50
milliconds for the mutex to be obtained. FreeRTOS_ioctl() will return pdPASS
or pdFAIL. */
xMutexObtained = FreeRTOS_ioctl( xPort,
ioctlOBTAIN_WRITE_MUTEX,
( void * ) ( 50 / portTICK_RATE_MS ) );
if( xMutexObtained != pdFAIL )
{
英语考试总结/* The mutex was obtained, so a write can be performed. This
time bytes are written directly from ucBuffer. */
xBytesWritten = FreeRTOS_write( xPort, ucBuffer, sizeof( ucBuffer ) );
/* Interrupt driven zero copy Tx is being ud, so FreeRTOS_write() should
return the number of requested bytes, even though the FreeRTOS+IO interrupt
rvice routine might still be nding the data. */
configASSERT( xBytesWritten == sizeof( ucBuffer ) );
/
* The mutex will only be available again after all the data has been
transmitted by the peripheral. Attempting to obtain the mutex again is therefore
a good way of knowing when all the data has been nt, and when the buffer being
written can be updated without corrupting the data transmission. The FreeRTOS_ioctl()
ioctlWAIT_PREVIOUS_WRITE_COMPLETE and ioctlOBTAIN_WRITE_MUTEX can both
be ud for this purpo - the difference between the two being that
ioctlWAIT_PREVIOUS_WRITE_COMPLETE will not result in the calling task holding
the mutex if the FreeRTOS_ioctl() call is successful. */
xMutexObtained = FreeRTOS_ioctl( xPort,
ioctlOBTAIN_WRITE_MUTEX,
( void * ) ( 50 / portTICK_RATE_MS ) );
/
* Or xMutexObtained = FreeRTOS_ioctl( xPort,
ioctlWAIT_PREVIOUS_WRITE_COMPLETE,
( void * ) ( 50 / portTICK_RATE_MS ) ); */
if( xMutexObtained != pdFAIL )
{
/* If another write is going to be performed, it can be performed now,

本文发布于:2023-07-17 00:58:31,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/179704.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:英语考试   总结
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图