X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=FreeRTOS%2FDemo%2FCORTEX_MPU_Simulator_Keil_GCC%2Fmain.c;h=185ac7ba7069c4a171adbca7c17b914d63ab14b3;hb=61a5601b461eea61201ee14fc20615ddecf8c259;hp=9d12c451ba420764034d0665e04fa27401301093;hpb=601e593293ff64b639cd47a60a73ee6bd6194085;p=freertos diff --git a/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c b/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c index 9d12c451b..185ac7ba7 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c +++ b/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c @@ -1,71 +1,29 @@ /* - FreeRTOS V9.0.1 - Copyright (C) 2017 Real Time Engineers Ltd. - All rights reserved - - VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. - - This file is part of the FreeRTOS distribution. - - FreeRTOS is free software; you can redistribute it and/or modify it under - the terms of the GNU General Public License (version 2) as published by the - Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. - - *************************************************************************** - >>! NOTE: The modification to the GPL is included to allow you to !<< - >>! distribute a combined work that includes FreeRTOS without being !<< - >>! obliged to provide the source code for proprietary components !<< - >>! outside of the FreeRTOS kernel. !<< - *************************************************************************** - - FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. Full license text is available on the following - link: http://www.freertos.org/a00114.html - - *************************************************************************** - * * - * FreeRTOS provides completely free yet professionally developed, * - * robust, strictly quality controlled, supported, and cross * - * platform software that is more than just the market leader, it * - * is the industry's de facto standard. * - * * - * Help yourself get started quickly while simultaneously helping * - * to support the FreeRTOS project by purchasing a FreeRTOS * - * tutorial book, reference manual, or both: * - * http://www.FreeRTOS.org/Documentation * - * * - *************************************************************************** - - http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading - the FAQ page "My application does not run, what could be wrong?". Have you - defined configASSERT()? - - http://www.FreeRTOS.org/support - In return for receiving this top quality - embedded software for free we request you assist our global community by - participating in the support forum. - - http://www.FreeRTOS.org/training - Investing in training allows your team to - be as productive as possible as early as possible. Now you can receive - FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers - Ltd, and the world's leading authority on the world's leading RTOS. - - http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, - including FreeRTOS+Trace - an indispensable productivity tool, a DOS - compatible FAT file system, and our tiny thread aware UDP/IP stack. - - http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. - Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. - - http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High - Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS - licenses offer ticketed support, indemnification and commercial middleware. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and - mission critical applications that require provable dependability. - - 1 tab == 4 spaces! -*/ + * FreeRTOS Kernel V10.2.1 + * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * 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. + * + * http://www.FreeRTOS.org + * http://aws.amazon.com/freertos + * + * 1 tab == 4 spaces! + */ /* @@ -91,6 +49,7 @@ #include "semphr.h" #include "timers.h" #include "event_groups.h" +#include "stream_buffer.h" /*-----------------------------------------------------------*/ @@ -198,6 +157,8 @@ static void prvTaskToDelete( void *pvParameters ); static void prvExerciseEventGroupAPI( void ); static void prvExerciseSemaphoreAPI( void ); static void prvExerciseTaskNotificationAPI( void ); +static void prvExerciseStreamBufferAPI( void ); +static void prvExerciseTimerAPI( void ); /* * Just configures any clocks and IO necessary. @@ -236,6 +197,13 @@ static void prvTestMemoryRegions( void ); */ static void prvTimerCallback( TimerHandle_t xExpiredTimer ); +/* + * The callback function and a function that is pended used when exercising the + * timer API. + */ +static void prvPendedFunctionCall( void *pvParameter1, uint32_t ulParameter2 ); +static void prvTestTimerCallback( TimerHandle_t xTimer ); + /*-----------------------------------------------------------*/ /* The handle of the queue used to communicate between tasks and between tasks @@ -252,7 +220,11 @@ static TaskHandle_t xTaskToDelete = NULL; /* The timer that periodically sends data to the check task on the queue. */ static TimerHandle_t xTimer = NULL; +/* Just used to check start up code for initialised an uninitialised data. */ +volatile uint32_t ul1 = 0x123, ul2 = 0; + #if defined ( __GNUC__ ) + /* Memory map read directl from linker variables. */ extern uint32_t __FLASH_segment_start__[]; extern uint32_t __FLASH_segment_end__[]; extern uint32_t __SRAM_segment_start__[]; @@ -264,6 +236,7 @@ static TimerHandle_t xTimer = NULL; extern uint32_t __privileged_functions_actual_end__[]; extern uint32_t __privileged_data_actual_end__[]; #else + /* Must be set manually to match memory map. */ const uint32_t * __FLASH_segment_start__ = ( uint32_t * ) 0x00UL; const uint32_t * __FLASH_segment_end__ = ( uint32_t * ) 0x00080000UL; const uint32_t * __SRAM_segment_start__ = ( uint32_t * ) 0x20000000UL; @@ -428,10 +401,9 @@ static TaskParameters_t xTaskToDeleteParameters = /*-----------------------------------------------------------*/ -volatile uint32_t ul1 = 0x123, ul2 = 0; - int main( void ) { + /* Used to check linker configuration. */ configASSERT( ul1 == 0x123 ); configASSERT( ul2 == 0 ); prvSetupHardware(); @@ -515,7 +487,7 @@ a counter on each iteration of their loop. The counters are inside the array that this task has access to. */ volatile uint32_t *pulOverlaidCounter3 = ( uint32_t * ) &( cReadWriteArray[ 0 ] ), *pulOverlaidCounter4 = ( uint32_t * ) &( cReadWriteArray[ 4 ] ); -/* ulCycleCount is incremented on each cycle of the check task. It can be +/* ulCycleCount is incremented on each cycle of the check task. It can be viewed updating in the Keil watch window as the simulator does not print to the ITM port. */ volatile uint32_t ulCycleCount = 0; @@ -585,7 +557,7 @@ volatile uint32_t ulCycleCount = 0; /**** Print pcStatusMessage here. ****/ ( void ) pcStatusMessage; - + /* The cycle count can be viewed updating in the Keil watch window if ITM printf is not being used. */ ulCycleCount++; @@ -798,13 +770,126 @@ static void prvTaskToDelete( void *pvParameters ) prvExerciseEventGroupAPI(); prvExerciseSemaphoreAPI(); prvExerciseTaskNotificationAPI(); + prvExerciseStreamBufferAPI(); + prvExerciseTimerAPI(); /* For code coverage test purposes it is deleted by the Idle task. */ configASSERT( uxTaskGetStackHighWaterMark( NULL ) > 0 ); + configASSERT( uxTaskGetStackHighWaterMark2( NULL ) > 0 ); + /* Run time stats are not being gathered - this is just to exercise + API. */ + configASSERT( xTaskGetIdleRunTimeCounter() == 0 ); vTaskSuspend( NULL ); } /*-----------------------------------------------------------*/ +static void prvPendedFunctionCall( void *pvParameter1, uint32_t ulParameter2 ) +{ +uint32_t *pulCounter = ( uint32_t * ) pvParameter1; + + /* Increment the paramater to show the pended function has executed. */ + ( *pulCounter )++; +} +/*-----------------------------------------------------------*/ + +static void prvTestTimerCallback( TimerHandle_t xTimer ) +{ +uint32_t ulTimerID; + + /* Increment the timer's ID to show the callback has executed. */ + ulTimerID = ( uint32_t ) pvTimerGetTimerID( xTimer ); + ulTimerID++; + vTimerSetTimerID( xTimer, ( void * ) ulTimerID ); +} +/*-----------------------------------------------------------*/ + +static void prvExerciseTimerAPI( void ) +{ +TimerHandle_t xTimer; +const char * const pcTimerName = "TestTimer"; +const TickType_t x3ms = pdMS_TO_TICKS( 3 ); +uint32_t ulValueForTesting = 0; + + xTimer = xTimerCreate( pcTimerName, + x3ms, + pdFALSE, /* Created as a one-shot timer. */ + 0, + prvTestTimerCallback ); + configASSERT( xTimer ); + configASSERT( xTimerIsTimerActive( xTimer ) == pdFALSE ); + configASSERT( xTimerGetTimerDaemonTaskHandle() != NULL ); + configASSERT( strcmp( pcTimerName, pcTimerGetName( xTimer ) ) == 0 ); + configASSERT( xTimerGetPeriod( xTimer ) == x3ms ); + + /* Pend a function then wait for it to execute. All it does is increment + its parameter. */ + xTimerPendFunctionCall( prvPendedFunctionCall, &ulValueForTesting, 0, 0 ); + vTaskDelay( x3ms ); + configASSERT( ulValueForTesting == 1 ); + + /* Timer was created as a one-shot timer. Its callback just increments the + timer's ID - so set the ID to 0, let the timer run for a number of timeout + periods, then check the timer has only executed once. */ + vTimerSetTimerID( xTimer, ( void * ) 0 ); + xTimerStart( xTimer, 0 ); + vTaskDelay( 3UL * x3ms ); + configASSERT( ( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) ) == 1UL ); + + /* Now change the timer to be an auto-reload timer and check it executes + the expected number of times. */ + vTimerSetReloadMode( xTimer, pdTRUE ); + xTimerStart( xTimer, 0 ); + vTaskDelay( 3UL * x3ms ); + configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) > 3UL ); + configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL ); + + /* Clean up at the end. */ + xTimerDelete( xTimer, portMAX_DELAY ); +} +/*-----------------------------------------------------------*/ + +static void prvExerciseStreamBufferAPI( void ) +{ +uint8_t ucBuffer[ 10 ]; +BaseType_t x, xRead; +size_t xReturned; +StreamBufferHandle_t xStreamBuffer; + + /* Just makes API calls to ensure the MPU versions are used. */ + + xStreamBuffer = xStreamBufferCreate( sizeof( ucBuffer ) , 1 ); + configASSERT( xStreamBuffer ); + + for( x = 0; x < ( sizeof( ucBuffer ) * 2 ); x++ ) + { + /* Write and check the value is written, then read and check the value + read is expected. */ + xReturned = xStreamBufferSend( xStreamBuffer, + ( void * ) &x, + sizeof( x ), + 0 ); + configASSERT( xReturned == sizeof( x ) ); + + xReturned = xStreamBufferReceive( xStreamBuffer, + ( void * ) &xRead, + sizeof( xRead ), + 0 ); + configASSERT( xReturned == sizeof( xRead ) ); + configASSERT( xRead == x ); + configASSERT( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE ); + configASSERT( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE ); + configASSERT( xStreamBufferSpacesAvailable( xStreamBuffer ) == sizeof( ucBuffer ) ); + configASSERT( xStreamBufferBytesAvailable( xStreamBuffer ) == 0 ); + } + + /* Call the functions that have not been exercised yet before finishing by + deleting the stream buffer. */ + configASSERT( xStreamBufferSetTriggerLevel( xStreamBuffer, 0 ) == pdTRUE ); + configASSERT( xStreamBufferReset( xStreamBuffer ) == pdPASS ); + vStreamBufferDelete( xStreamBuffer ); +} +/*-----------------------------------------------------------*/ + void vApplicationIdleHook( void ) { volatile const uint32_t *pul; @@ -844,8 +929,12 @@ volatile uint32_t ulReadData; test purposes. */ if( xTaskToDelete != NULL ) { - vTaskDelete( xTaskToDelete ); - xTaskToDelete = NULL; + if( eTaskGetState( xTaskToDelete ) == eSuspended ) + { + /* The task has finished its tests and can be deleted. */ + vTaskDelete( xTaskToDelete ); + xTaskToDelete = NULL; + } } ( void ) ulReadData; @@ -1037,7 +1126,7 @@ void vApplicationMallocFailedHook( void ) } /*-----------------------------------------------------------*/ -static void prvTimerCallback( TaskHandle_t xExpiredTimer ) +static void prvTimerCallback( TimerHandle_t xExpiredTimer ) { uint32_t ulCount;