From 1fcd6afe0a56aadf38ef501ebb8820370e15a455 Mon Sep 17 00:00:00 2001 From: rtel Date: Tue, 11 Feb 2014 11:37:42 +0000 Subject: [PATCH] Add a small amount of randomisation into the Zynq demo. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2200 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../RTOSDemo/src/Full_Demo/main_full.c | 44 +++++++++++++++++++ .../CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c | 6 +-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/Full_Demo/main_full.c b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/Full_Demo/main_full.c index 7c716b613..a6d353fc7 100644 --- a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/Full_Demo/main_full.c +++ b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/Full_Demo/main_full.c @@ -218,6 +218,13 @@ extern void vRegisterSampleCLICommands( void ); */ extern void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority ); +/* + * A high priority task that does nothing other than execute at a pseudo random + * time to ensure the other test tasks don't just execute in a repeating + * pattern. + */ +static void prvPseudoRandomiser( void *pvParameters ); + /*-----------------------------------------------------------*/ /* The following two variables are used to communicate the status of the @@ -257,6 +264,9 @@ void main_full( void ) xTaskCreate( prvRegTestTaskEntry1, "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_1_PARAMETER, tskIDLE_PRIORITY, NULL ); xTaskCreate( prvRegTestTaskEntry2, "Reg2", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_2_PARAMETER, tskIDLE_PRIORITY, NULL ); + /* Create the task that just adds a little random behaviour. */ + xTaskCreate( prvPseudoRandomiser, "Rnd", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL ); + /* Create the task that performs the 'check' functionality, as described at the top of this file. */ xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); @@ -450,6 +460,40 @@ static void prvRegTestTaskEntry2( void *pvParameters ) } /*-----------------------------------------------------------*/ +static void prvPseudoRandomiser( void *pvParameters ) +{ +const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL, ulMinDelay = ( 35 / portTICK_PERIOD_MS ); +volatile uint32_t ulNextRand = ( uint32_t ) &pvParameters, ulValue; + + /* This task does nothing other than ensure there is a little bit of + disruption in the scheduling pattern of the other tasks. Normally this is + done by generating interrupts at pseudo random times. */ + for( ;; ) + { + ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement; + ulValue = ( ulNextRand >> 16UL ) & 0xffUL; + + if( ulValue < ulMinDelay ) + { + ulValue = ulMinDelay; + } + + vTaskDelay( ulValue ); + + while( ulValue > 0 ) + { + __asm volatile( "NOP" ); + __asm volatile( "NOP" ); + __asm volatile( "NOP" ); + __asm volatile( "NOP" ); + + ulValue--; + } + } +} + + + diff --git a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c index 29d160a68..079ba9953 100644 --- a/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c +++ b/FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c @@ -316,7 +316,7 @@ size_t x; for( x = 0; x < ulBytes; x++ ) { - *pcDest = ( unsigned char ) c; + *pcDest = ( unsigned char ) iValue; pcDest++; } @@ -324,7 +324,7 @@ size_t x; } /*-----------------------------------------------------------*/ -int memcmp( const void *pvMem1, const void *pvMem2 ,size_t ulBytes ) +int memcmp( const void *pvMem1, const void *pvMem2, size_t ulBytes ) { const unsigned char *pucMem1 = pvMem1, *pucMem2 = pvMem2; size_t x; @@ -337,7 +337,7 @@ size_t x; } } - return n - x; + return ulBytes - x; } -- 2.39.5