X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=FreeRTOS%2FDemo%2FCORTEX_LM3Sxxxx_IAR_Keil%2Fmain.c;h=825dcbb519a763a2a7794b71aa7dae817232efac;hb=533a8d2a52fe9f6958fcd4c165640b1058c293f1;hp=46c7d2c5f96b68430aabde499ee0447c32fc9faa;hpb=617d46d8432c30e925e24d1687d310be7aa39f6c;p=freertos diff --git a/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c b/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c index 46c7d2c5f..825dcbb51 100644 --- a/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c +++ b/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c @@ -1,67 +1,29 @@ /* - FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. - All rights reserved - - VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. - - *************************************************************************** - * * - * FreeRTOS provides completely free yet professionally developed, * - * robust, strictly quality controlled, supported, and cross * - * platform software that has become a de facto standard. * - * * - * Help yourself get started quickly and support the FreeRTOS * - * project by purchasing a FreeRTOS tutorial book, reference * - * manual, or both from: http://www.FreeRTOS.org/Documentation * - * * - * Thank you! * - * * - *************************************************************************** - - 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 from the following - link: http://www.freertos.org/a00114.html - - 1 tab == 4 spaces! - - *************************************************************************** - * * - * Having a problem? Start by reading the FAQ "My application does * - * not run, what could be wrong?" * - * * - * http://www.FreeRTOS.org/FAQHelp.html * - * * - *************************************************************************** - - http://www.FreeRTOS.org - Documentation, books, training, latest versions, - license and Real Time Engineers Ltd. contact details. - - 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.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High - Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS - licenses offer ticketed support, indemnification and 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! + */ /* @@ -94,11 +56,12 @@ * * "uIP" task - This is the task that handles the uIP stack. All TCP/IP * processing is performed in this task. + * + * Use the following command to execute in QEMU from the IAR IDE: + * qemu-system-arm -machine lm3s6965evb -s -S -kernel [pat_to]\RTOSDemo.out + * and set IAR connect GDB server to "localhost,1234" in project debug options. */ - - - /************************************************************************* * Please ensure to read http://www.freertos.org/portlm3sx965.html * which provides information on configuring and running this demo for the @@ -127,17 +90,17 @@ and the TCP/IP stack together cannot be accommodated with the 32K size limit. */ #include "hw_memmap.h" #include "hw_types.h" #include "hw_sysctl.h" +#include "hw_uart.h" #include "sysctl.h" #include "gpio.h" #include "grlib.h" #include "rit128x96x4.h" #include "osram128x64x4.h" #include "formike128x128x16.h" +#include "uart.h" /* Demo app includes. */ -#include "BlockQ.h" #include "death.h" -#include "integer.h" #include "blocktim.h" #include "flash.h" #include "partest.h" @@ -150,12 +113,15 @@ and the TCP/IP stack together cannot be accommodated with the 32K size limit. */ #include "recmutex.h" #include "IntQueue.h" #include "QueueSet.h" +#include "EventGroupsDemo.h" +#include "MessageBufferDemo.h" +#include "StreamBufferDemo.h" /*-----------------------------------------------------------*/ /* The time between cycles of the 'check' functionality (defined within the tick hook. */ -#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS ) +#define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS ) /* Size of the stack allocated to the uIP task. */ #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 3 ) @@ -167,9 +133,7 @@ tick hook. */ #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 ) #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 ) -#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 ) #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) -#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY ) #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY ) /* The maximum number of message that can be waiting for display at any one @@ -181,7 +145,7 @@ time. */ /* The period of the system clock in nano seconds. This is used to calculate the jitter time in nano seconds. */ -#define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) ) +#define mainNS_PER_CLOCK ( ( unsigned long ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) ) /* Constants used when writing strings to the display. */ #define mainCHARACTER_HEIGHT ( 9 ) @@ -221,17 +185,18 @@ extern void vSetupHighFrequencyTimer( void ); /* * Hook functions that can get called by the kernel. */ -void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); +void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName ); void vApplicationTickHook( void ); +static void prvPrintString( const char * pcString ); /*-----------------------------------------------------------*/ /* The queue used to send messages to the OLED task. */ -xQueueHandle xOLEDQueue; +QueueHandle_t xOLEDQueue; /* The welcome text. */ -const portCHAR * const pcWelcomeMessage = " www.FreeRTOS.org"; +const char * const pcWelcomeMessage = " www.FreeRTOS.org"; /*-----------------------------------------------------------*/ @@ -250,16 +215,17 @@ int main( void ) xOLEDQueue = xQueueCreate( mainOLED_QUEUE_SIZE, sizeof( xOLEDMessage ) ); /* Start the standard demo tasks. */ - vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY ); - vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY ); - vStartInterruptQueueTasks(); + vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY ); + vStartInterruptQueueTasks(); vStartRecursiveMutexTasks(); - vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); vCreateBlockTimeTasks(); vStartSemaphoreTasks( mainSEM_TEST_PRIORITY ); vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); vStartQueuePeekTasks(); vStartQueueSetTasks(); + vStartEventGroupTasks(); + vStartMessageBufferTasks( configMINIMAL_STACK_SIZE ); + vStartStreamBufferTasks(); /* Exclude some tasks if using the kickstart version to ensure we stay within the 32K code size limit. */ @@ -269,31 +235,29 @@ int main( void ) PHY. */ if( SysCtlPeripheralPresent( SYSCTL_PERIPH_ETH ) ) { - xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL ); + xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL ); } } #endif - - /* Start the tasks defined within this file/specific to this demo. */ - xTaskCreate( vOLEDTask, ( signed portCHAR * ) "OLED", mainOLED_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); + xTaskCreate( vOLEDTask, "OLED", mainOLED_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); /* The suicide tasks must be created last as they need to know how many tasks were running prior to their creation in order to ascertain whether or not the correct/expected number of tasks are running at any given time. */ - vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY ); + vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY ); - /* Configure the high frequency interrupt used to measure the interrupt - jitter time. */ - vSetupHighFrequencyTimer(); + /* Uncomment the following line to configure the high frequency interrupt + used to measure the interrupt jitter time. + vSetupHighFrequencyTimer(); */ /* Start the scheduler. */ vTaskStartScheduler(); - /* Will only get here if there was insufficient memory to create the idle - task. */ - return 0; + /* Will only get here if there was insufficient memory to create the idle + task. */ + for( ;; ); } /*-----------------------------------------------------------*/ @@ -317,13 +281,18 @@ void prvSetupHardware( void ) GPIOPadConfigSet( GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3 ), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD ); vParTestInitialise(); + + /* Initialise the UART - QEMU usage does not seem to require this + initialisation. */ + SysCtlPeripheralEnable( SYSCTL_PERIPH_UART0 ); + UARTEnable( UART0_BASE ); } /*-----------------------------------------------------------*/ void vApplicationTickHook( void ) { static xOLEDMessage xMessage = { "PASS" }; -static unsigned portLONG ulTicksSinceLastDisplay = 0; +static unsigned long ulTicksSinceLastDisplay = 0; portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; /* Called from every tick interrupt. Have enough ticks passed to make it @@ -334,6 +303,14 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; ulTicksSinceLastDisplay = 0; /* Has an error been found in any task? */ + if( xAreStreamBufferTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN STRM"; + } + else if( xAreMessageBufferTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN MSG"; + } if( xAreGenericQueueTasksStillRunning() != pdTRUE ) { xMessage.pcMessage = "ERROR IN GEN Q"; @@ -341,19 +318,11 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; else if( xIsCreateTaskStillRunning() != pdTRUE ) { xMessage.pcMessage = "ERROR IN CREATE"; - } - else if( xAreIntegerMathsTaskStillRunning() != pdTRUE ) - { - xMessage.pcMessage = "ERROR IN MATH"; } else if( xAreIntQueueTasksStillRunning() != pdTRUE ) { xMessage.pcMessage = "ERROR IN INT QUEUE"; } - else if( xAreBlockingQueuesStillRunning() != pdTRUE ) - { - xMessage.pcMessage = "ERROR IN BLOCK Q"; - } else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE ) { xMessage.pcMessage = "ERROR IN BLOCK TIME"; @@ -378,8 +347,10 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; { xMessage.pcMessage = "ERROR IN Q SET"; } - - configASSERT( strcmp( ( const char * ) xMessage.pcMessage, "PASS" ) == 0 ); + else if( xAreEventGroupTasksStillRunning() != pdTRUE ) + { + xMessage.pcMessage = "ERROR IN EVNT GRP"; + } /* Send the message to the OLED gatekeeper for display. */ xHigherPriorityTaskWoken = pdFALSE; @@ -389,22 +360,35 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; /* Write to a queue that is in use as part of the queue set demo to demonstrate using queue sets from an ISR. */ vQueueSetAccessQueueSetFromISR(); + + /* Call the event group ISR tests. */ + vPeriodicEventGroupsProcessing(); +} +/*-----------------------------------------------------------*/ + +static void prvPrintString( const char * pcString ) +{ + while( *pcString != 0x00 ) + { + UARTCharPut( UART0_BASE, *pcString ); + pcString++; + } } /*-----------------------------------------------------------*/ void vOLEDTask( void *pvParameters ) { xOLEDMessage xMessage; -unsigned portLONG ulY, ulMaxY; -static portCHAR cMessage[ mainMAX_MSG_LEN ]; -extern volatile unsigned portLONG ulMaxJitter; -const unsigned portCHAR *pucImage; +unsigned long ulY, ulMaxY; +static char cMessage[ mainMAX_MSG_LEN ]; +extern volatile unsigned long ulMaxJitter; +const unsigned char *pucImage; /* Functions to access the OLED. The one used depends on the dev kit being used. */ -void ( *vOLEDInit )( unsigned portLONG ) = NULL; -void ( *vOLEDStringDraw )( const portCHAR *, unsigned portLONG, unsigned portLONG, unsigned portCHAR ) = NULL; -void ( *vOLEDImageDraw )( const unsigned portCHAR *, unsigned portLONG, unsigned portLONG, unsigned portLONG, unsigned portLONG ) = NULL; +void ( *vOLEDInit )( unsigned long ) = NULL; +void ( *vOLEDStringDraw )( const char *, unsigned long, unsigned long, unsigned char ) = NULL; +void ( *vOLEDImageDraw )( const unsigned char *, unsigned long, unsigned long, unsigned long, unsigned long ) = NULL; void ( *vOLEDClear )( void ) = NULL; /* Map the OLED access functions to the driver functions that are appropriate @@ -464,14 +448,16 @@ void ( *vOLEDClear )( void ) = NULL; high priority time test. */ sprintf( cMessage, "%s [%uns]", xMessage.pcMessage, ulMaxJitter * mainNS_PER_CLOCK ); vOLEDStringDraw( cMessage, 0, ulY, mainFULL_SCALE ); + prvPrintString( cMessage ); } } /*-----------------------------------------------------------*/ -void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ) +volatile signed char *pcOverflowedTask = NULL; +void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName ) { ( void ) pxTask; - ( void ) pcTaskName; + pcOverflowedTask = pcTaskName; for( ;; ); } @@ -485,7 +471,7 @@ volatile unsigned long ulSetTo1InDebuggerToExit = 0; { while( ulSetTo1InDebuggerToExit == 0 ) { - /* Nothing do do here. Set the loop variable to a non zero value in + /* Nothing to do here. Set the loop variable to a non zero value in the debugger to step out of this function to the point that caused the assertion. */ ( void ) pcFile; @@ -494,3 +480,53 @@ volatile unsigned long ulSetTo1InDebuggerToExit = 0; } taskEXIT_CRITICAL(); } + +/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an +implementation of vApplicationGetIdleTaskMemory() to provide the memory that is +used by the Idle task. */ +void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) +{ +/* If the buffers to be provided to the Idle task are declared inside this +function then they must be declared static - otherwise they will be allocated on +the stack and so not exists after this function exits. */ +static StaticTask_t xIdleTaskTCB; +static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; + + /* Pass out a pointer to the StaticTask_t structure in which the Idle task's + state will be stored. */ + *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; + + /* Pass out the array that will be used as the Idle task's stack. */ + *ppxIdleTaskStackBuffer = uxIdleTaskStack; + + /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. + Note that, as the array is necessarily of type StackType_t, + configMINIMAL_STACK_SIZE is specified in words, not bytes. */ + *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; +} +/*-----------------------------------------------------------*/ + +/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the +application must provide an implementation of vApplicationGetTimerTaskMemory() +to provide the memory that is used by the Timer service task. */ +void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) +{ +/* If the buffers to be provided to the Timer task are declared inside this +function then they must be declared static - otherwise they will be allocated on +the stack and so not exists after this function exits. */ +static StaticTask_t xTimerTaskTCB; +static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; + + /* Pass out a pointer to the StaticTask_t structure in which the Timer + task's state will be stored. */ + *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; + + /* Pass out the array that will be used as the Timer task's stack. */ + *ppxTimerTaskStackBuffer = uxTimerTaskStack; + + /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. + Note that, as the array is necessarily of type StackType_t, + configMINIMAL_STACK_SIZE is specified in words, not bytes. */ + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; +} +