mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-14 08:47:45 -04:00
Add uncrustify github workflow (#659)
* Add uncrustify github workflow * Fix exclusion pattern * fix find expression * exclude uncrustify files * Uncrustify common demo and test files * exlude white space checking files * Fix EOL whitespace checker * Remove whitespaces from EOL * Fix space at EOL * Fix find spaces at EOL Co-authored-by: Archit Aggarwal <architag@amazon.com>
This commit is contained in:
parent
dd80d615b5
commit
ae92d8c6ee
191 changed files with 17540 additions and 17102 deletions
|
@ -19,8 +19,8 @@
|
|||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -57,11 +57,11 @@
|
|||
#include "timers.h"
|
||||
|
||||
#ifndef configUSE_TIMERS
|
||||
#error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
|
||||
#error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
|
||||
#endif
|
||||
|
||||
#if configUSE_TIMERS != 1
|
||||
#error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
|
||||
#error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -71,240 +71,246 @@
|
|||
#include "partest.h"
|
||||
|
||||
/* The size of the stack given to the Rx task. */
|
||||
#define comSTACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define comSTACK_SIZE configMINIMAL_STACK_SIZE
|
||||
|
||||
/* See the comment above the declaration of the uxBaseLED variable. */
|
||||
#define comTX_LED_OFFSET ( 0 )
|
||||
#define comRX_LED_OFFSET ( 1 )
|
||||
#define comTX_LED_OFFSET ( 0 )
|
||||
#define comRX_LED_OFFSET ( 1 )
|
||||
|
||||
/* The Tx timer transmits the sequence of characters at a pseudo random
|
||||
interval that is capped between comTX_MAX_BLOCK_TIME and
|
||||
comTX_MIN_BLOCK_TIME. */
|
||||
#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
|
||||
#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
|
||||
#define comOFFSET_TIME ( ( TickType_t ) 3 )
|
||||
* interval that is capped between comTX_MAX_BLOCK_TIME and
|
||||
* comTX_MIN_BLOCK_TIME. */
|
||||
#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
|
||||
#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
|
||||
#define comOFFSET_TIME ( ( TickType_t ) 3 )
|
||||
|
||||
/* States for the simple state machine implemented in the Rx task. */
|
||||
#define comtstWAITING_START_OF_STRING 0
|
||||
#define comtstWAITING_END_OF_STRING 1
|
||||
#define comtstWAITING_START_OF_STRING 0
|
||||
#define comtstWAITING_END_OF_STRING 1
|
||||
|
||||
/* A short delay in ticks - this delay is used to allow the Rx queue to fill up
|
||||
a bit so more than one character can be processed at a time. This is relative
|
||||
to comTX_MIN_BLOCK_TIME to ensure it is never longer than the shortest gap
|
||||
between transmissions. It could be worked out more scientifically from the
|
||||
baud rate being used. */
|
||||
#define comSHORT_DELAY ( comTX_MIN_BLOCK_TIME >> ( TickType_t ) 2 )
|
||||
* a bit so more than one character can be processed at a time. This is relative
|
||||
* to comTX_MIN_BLOCK_TIME to ensure it is never longer than the shortest gap
|
||||
* between transmissions. It could be worked out more scientifically from the
|
||||
* baud rate being used. */
|
||||
#define comSHORT_DELAY ( comTX_MIN_BLOCK_TIME >> ( TickType_t ) 2 )
|
||||
|
||||
/* The string that is transmitted and received. */
|
||||
#define comTRANSACTED_STRING "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
#define comTRANSACTED_STRING "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
|
||||
/* A block time of 0 simply means "don't block". */
|
||||
#define comtstDONT_BLOCK ( TickType_t ) 0
|
||||
#define comtstDONT_BLOCK ( TickType_t ) 0
|
||||
|
||||
/* Handle to the com port used by both tasks. */
|
||||
static xComPortHandle xPort = NULL;
|
||||
|
||||
/* The callback function allocated to the transmit timer, as described in the
|
||||
comments at the top of this file. */
|
||||
* comments at the top of this file. */
|
||||
static void prvComTxTimerCallback( TimerHandle_t xTimer );
|
||||
|
||||
/* The receive task as described in the comments at the top of this file. */
|
||||
static void vComRxTask( void *pvParameters );
|
||||
static void vComRxTask( void * pvParameters );
|
||||
|
||||
/* The Rx task will toggle LED ( uxBaseLED + comRX_LED_OFFSET). The Tx task
|
||||
will toggle LED ( uxBaseLED + comTX_LED_OFFSET ). */
|
||||
* will toggle LED ( uxBaseLED + comTX_LED_OFFSET ). */
|
||||
static UBaseType_t uxBaseLED = 0;
|
||||
|
||||
/* The Rx task toggles uxRxLoops on each successful iteration of its defined
|
||||
function - provided no errors have ever been latched. If this variable stops
|
||||
incrementing, then an error has occurred. */
|
||||
* function - provided no errors have ever been latched. If this variable stops
|
||||
* incrementing, then an error has occurred. */
|
||||
static volatile UBaseType_t uxRxLoops = 0UL;
|
||||
|
||||
/* The timer used to periodically transmit the string. This is the timer that
|
||||
has prvComTxTimerCallback allocated to it as its callback function. */
|
||||
* has prvComTxTimerCallback allocated to it as its callback function. */
|
||||
static TimerHandle_t xTxTimer = NULL;
|
||||
|
||||
/* The string length is held at file scope so the Tx timer does not need to
|
||||
calculate it each time it executes. */
|
||||
* calculate it each time it executes. */
|
||||
static size_t xStringLength = 0U;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartComTestStringsTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED )
|
||||
void vStartComTestStringsTasks( UBaseType_t uxPriority,
|
||||
uint32_t ulBaudRate,
|
||||
UBaseType_t uxLED )
|
||||
{
|
||||
/* Store values that are used at run time. */
|
||||
uxBaseLED = uxLED;
|
||||
/* Store values that are used at run time. */
|
||||
uxBaseLED = uxLED;
|
||||
|
||||
/* Calculate the string length here, rather than each time the Tx timer
|
||||
executes. */
|
||||
xStringLength = strlen( comTRANSACTED_STRING );
|
||||
/* Calculate the string length here, rather than each time the Tx timer
|
||||
* executes. */
|
||||
xStringLength = strlen( comTRANSACTED_STRING );
|
||||
|
||||
/* Include the null terminator in the string length as this is used to
|
||||
detect the end of the string in the Rx task. */
|
||||
xStringLength++;
|
||||
/* Include the null terminator in the string length as this is used to
|
||||
* detect the end of the string in the Rx task. */
|
||||
xStringLength++;
|
||||
|
||||
/* Initialise the com port, then spawn the Rx task and create the Tx
|
||||
timer. */
|
||||
xSerialPortInitMinimal( ulBaudRate, ( xStringLength * 2U ) );
|
||||
/* Initialise the com port, then spawn the Rx task and create the Tx
|
||||
* timer. */
|
||||
xSerialPortInitMinimal( ulBaudRate, ( xStringLength * 2U ) );
|
||||
|
||||
/* Create the Rx task and the Tx timer. The timer is started from the
|
||||
Rx task. */
|
||||
xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
|
||||
xTxTimer = xTimerCreate( "TxTimer", comTX_MIN_BLOCK_TIME, pdFALSE, NULL, prvComTxTimerCallback );
|
||||
configASSERT( xTxTimer );
|
||||
/* Create the Rx task and the Tx timer. The timer is started from the
|
||||
* Rx task. */
|
||||
xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
|
||||
xTxTimer = xTimerCreate( "TxTimer", comTX_MIN_BLOCK_TIME, pdFALSE, NULL, prvComTxTimerCallback );
|
||||
configASSERT( xTxTimer );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvComTxTimerCallback( TimerHandle_t xTimer )
|
||||
{
|
||||
TickType_t xTimeToWait;
|
||||
TickType_t xTimeToWait;
|
||||
|
||||
/* The parameter is not used in this case. */
|
||||
( void ) xTimer;
|
||||
/* The parameter is not used in this case. */
|
||||
( void ) xTimer;
|
||||
|
||||
/* Send the string. How this is actually performed depends on the
|
||||
sample driver provided with this demo. However - as this is a timer,
|
||||
it executes in the context of the timer task and therefore must not
|
||||
block. */
|
||||
vSerialPutString( xPort, comTRANSACTED_STRING, xStringLength );
|
||||
/* Send the string. How this is actually performed depends on the
|
||||
* sample driver provided with this demo. However - as this is a timer,
|
||||
* it executes in the context of the timer task and therefore must not
|
||||
* block. */
|
||||
vSerialPutString( xPort, comTRANSACTED_STRING, xStringLength );
|
||||
|
||||
/* Toggle an LED to give a visible indication that another transmission
|
||||
has been performed. */
|
||||
vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
|
||||
/* Toggle an LED to give a visible indication that another transmission
|
||||
* has been performed. */
|
||||
vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
|
||||
|
||||
/* Wait a pseudo random time before sending the string again. */
|
||||
xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
|
||||
/* Wait a pseudo random time before sending the string again. */
|
||||
xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
|
||||
|
||||
/* Ensure the time to wait is not greater than comTX_MAX_BLOCK_TIME. */
|
||||
xTimeToWait %= comTX_MAX_BLOCK_TIME;
|
||||
/* Ensure the time to wait is not greater than comTX_MAX_BLOCK_TIME. */
|
||||
xTimeToWait %= comTX_MAX_BLOCK_TIME;
|
||||
|
||||
/* Ensure the time to wait is not less than comTX_MIN_BLOCK_TIME. */
|
||||
if( xTimeToWait < comTX_MIN_BLOCK_TIME )
|
||||
{
|
||||
xTimeToWait = comTX_MIN_BLOCK_TIME;
|
||||
}
|
||||
/* Ensure the time to wait is not less than comTX_MIN_BLOCK_TIME. */
|
||||
if( xTimeToWait < comTX_MIN_BLOCK_TIME )
|
||||
{
|
||||
xTimeToWait = comTX_MIN_BLOCK_TIME;
|
||||
}
|
||||
|
||||
/* Reset the timer to run again xTimeToWait ticks from now. This function
|
||||
is called from the context of the timer task, so the block time must not
|
||||
be anything other than zero. */
|
||||
xTimerChangePeriod( xTxTimer, xTimeToWait, comtstDONT_BLOCK );
|
||||
/* Reset the timer to run again xTimeToWait ticks from now. This function
|
||||
* is called from the context of the timer task, so the block time must not
|
||||
* be anything other than zero. */
|
||||
xTimerChangePeriod( xTxTimer, xTimeToWait, comtstDONT_BLOCK );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void vComRxTask( void *pvParameters )
|
||||
static void vComRxTask( void * pvParameters )
|
||||
{
|
||||
BaseType_t xState = comtstWAITING_START_OF_STRING, xErrorOccurred = pdFALSE;
|
||||
char *pcExpectedByte, cRxedChar;
|
||||
const xComPortHandle xPort = NULL;
|
||||
BaseType_t xState = comtstWAITING_START_OF_STRING, xErrorOccurred = pdFALSE;
|
||||
char * pcExpectedByte, cRxedChar;
|
||||
const xComPortHandle xPort = NULL;
|
||||
|
||||
/* The parameter is not used in this example. */
|
||||
( void ) pvParameters;
|
||||
/* The parameter is not used in this example. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Start the Tx timer. This only needs to be started once, as it will
|
||||
reset itself thereafter. */
|
||||
xTimerStart( xTxTimer, portMAX_DELAY );
|
||||
/* Start the Tx timer. This only needs to be started once, as it will
|
||||
* reset itself thereafter. */
|
||||
xTimerStart( xTxTimer, portMAX_DELAY );
|
||||
|
||||
/* The first expected Rx character is the first in the string that is
|
||||
transmitted. */
|
||||
pcExpectedByte = comTRANSACTED_STRING;
|
||||
/* The first expected Rx character is the first in the string that is
|
||||
* transmitted. */
|
||||
pcExpectedByte = comTRANSACTED_STRING;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Wait for the next character. */
|
||||
if( xSerialGetChar( xPort, &cRxedChar, ( comTX_MAX_BLOCK_TIME * 2 ) ) == pdFALSE )
|
||||
{
|
||||
/* A character definitely should have been received by now. As a
|
||||
character was not received an error must have occurred (which might
|
||||
just be that the loopback connector is not fitted). */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
for( ; ; )
|
||||
{
|
||||
/* Wait for the next character. */
|
||||
if( xSerialGetChar( xPort, &cRxedChar, ( comTX_MAX_BLOCK_TIME * 2 ) ) == pdFALSE )
|
||||
{
|
||||
/* A character definitely should have been received by now. As a
|
||||
* character was not received an error must have occurred (which might
|
||||
* just be that the loopback connector is not fitted). */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
switch( xState )
|
||||
{
|
||||
case comtstWAITING_START_OF_STRING:
|
||||
if( cRxedChar == *pcExpectedByte )
|
||||
{
|
||||
/* The received character was the first character of the
|
||||
string. Move to the next state to check each character
|
||||
as it comes in until the entire string has been received. */
|
||||
xState = comtstWAITING_END_OF_STRING;
|
||||
pcExpectedByte++;
|
||||
switch( xState )
|
||||
{
|
||||
case comtstWAITING_START_OF_STRING:
|
||||
|
||||
/* Block for a short period. This just allows the Rx queue
|
||||
to contain more than one character, and therefore prevent
|
||||
thrashing reads to the queue, and repetitive context
|
||||
switches as each character is received. */
|
||||
vTaskDelay( comSHORT_DELAY );
|
||||
}
|
||||
break;
|
||||
if( cRxedChar == *pcExpectedByte )
|
||||
{
|
||||
/* The received character was the first character of the
|
||||
* string. Move to the next state to check each character
|
||||
* as it comes in until the entire string has been received. */
|
||||
xState = comtstWAITING_END_OF_STRING;
|
||||
pcExpectedByte++;
|
||||
|
||||
case comtstWAITING_END_OF_STRING:
|
||||
if( cRxedChar == *pcExpectedByte )
|
||||
{
|
||||
/* The received character was the expected character. Was
|
||||
it the last character in the string - i.e. the null
|
||||
terminator? */
|
||||
if( cRxedChar == 0x00 )
|
||||
{
|
||||
/* The entire string has been received. If no errors
|
||||
have been latched, then increment the loop counter to
|
||||
show this task is still healthy. */
|
||||
if( xErrorOccurred == pdFALSE )
|
||||
{
|
||||
uxRxLoops++;
|
||||
/* Block for a short period. This just allows the Rx queue
|
||||
* to contain more than one character, and therefore prevent
|
||||
* thrashing reads to the queue, and repetitive context
|
||||
* switches as each character is received. */
|
||||
vTaskDelay( comSHORT_DELAY );
|
||||
}
|
||||
|
||||
/* Toggle an LED to give a visible sign that a
|
||||
complete string has been received. */
|
||||
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
|
||||
}
|
||||
break;
|
||||
|
||||
/* Go back to wait for the start of the next string. */
|
||||
pcExpectedByte = comTRANSACTED_STRING;
|
||||
xState = comtstWAITING_START_OF_STRING;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Wait for the next character in the string. */
|
||||
pcExpectedByte++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The character received was not that expected. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
break;
|
||||
case comtstWAITING_END_OF_STRING:
|
||||
|
||||
default:
|
||||
/* Should not get here. Stop the Rx loop counter from
|
||||
incrementing to latch the error. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( cRxedChar == *pcExpectedByte )
|
||||
{
|
||||
/* The received character was the expected character. Was
|
||||
* it the last character in the string - i.e. the null
|
||||
* terminator? */
|
||||
if( cRxedChar == 0x00 )
|
||||
{
|
||||
/* The entire string has been received. If no errors
|
||||
* have been latched, then increment the loop counter to
|
||||
* show this task is still healthy. */
|
||||
if( xErrorOccurred == pdFALSE )
|
||||
{
|
||||
uxRxLoops++;
|
||||
|
||||
/* Toggle an LED to give a visible sign that a
|
||||
* complete string has been received. */
|
||||
vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
|
||||
}
|
||||
|
||||
/* Go back to wait for the start of the next string. */
|
||||
pcExpectedByte = comTRANSACTED_STRING;
|
||||
xState = comtstWAITING_START_OF_STRING;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Wait for the next character in the string. */
|
||||
pcExpectedByte++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The character received was not that expected. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
/* Should not get here. Stop the Rx loop counter from
|
||||
* incrementing to latch the error. */
|
||||
xErrorOccurred = pdTRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xAreComTestTasksStillRunning( void )
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
BaseType_t xReturn;
|
||||
|
||||
/* If the count of successful reception loops has not changed than at
|
||||
some time an error occurred (i.e. a character was received out of sequence)
|
||||
and false is returned. */
|
||||
if( uxRxLoops == 0UL )
|
||||
{
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
xReturn = pdTRUE;
|
||||
}
|
||||
/* If the count of successful reception loops has not changed than at
|
||||
* some time an error occurred (i.e. a character was received out of sequence)
|
||||
* and false is returned. */
|
||||
if( uxRxLoops == 0UL )
|
||||
{
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
xReturn = pdTRUE;
|
||||
}
|
||||
|
||||
/* Reset the count of successful Rx loops. When this function is called
|
||||
again it should have been incremented again. */
|
||||
uxRxLoops = 0UL;
|
||||
/* Reset the count of successful Rx loops. When this function is called
|
||||
* again it should have been incremented again. */
|
||||
uxRxLoops = 0UL;
|
||||
|
||||
return xReturn;
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue