]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_STM32L152_IAR/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_STM32L152_IAR / main.c
index f67ab2b918b8dc6e786eada5d608ee7fce59b95c..023ccca6d4994279bf5bed9f33e969480421e648 100644 (file)
@@ -1,68 +1,29 @@
 /*\r
-    FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
-       \r
-\r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
-     *    Complete, revised, and edited pdf reference manuals are also       *\r
-     *    available.                                                         *\r
-     *                                                                       *\r
-     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
-     *    ensuring you get running as quickly as possible and with an        *\r
-     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
-     *    the FreeRTOS project to continue with its mission of providing     *\r
-     *    professional grade, cross platform, de facto standard solutions    *\r
-     *    for microcontrollers - completely free of charge!                  *\r
-     *                                                                       *\r
-     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
-     *                                                                       *\r
-     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
-\r
-    This file is part of the FreeRTOS distribution.\r
-\r
-    FreeRTOS is free software; you can redistribute it and/or modify it under\r
-    the terms of the GNU General Public License (version 2) as published by the\r
-    Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
-    >>>NOTE<<< The modification to the GPL is included to allow you to\r
-    distribute a combined work that includes FreeRTOS without being obliged to\r
-    provide the source code for proprietary components outside of the FreeRTOS\r
-    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
-    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
-    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
-    more details. You should have received a copy of the GNU General Public\r
-    License and the FreeRTOS license exception along with FreeRTOS; if not it\r
-    can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
-    by writing to Richard Barry, contact details for whom are available on the\r
-    FreeRTOS WEB site.\r
-\r
-    1 tab == 4 spaces!\r
-    \r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    Having a problem?  Start by reading the FAQ "My application does   *\r
-     *    not run, what could be wrong?                                      *\r
-     *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
-    \r
-    http://www.FreeRTOS.org - Documentation, training, latest information, \r
-    license and contact details.\r
-    \r
-    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
-    including FreeRTOS+Trace - an indispensable productivity tool.\r
-\r
-    Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
-    the code with commercial support, indemnification, and middleware, under \r
-    the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
-    provide a safety engineered and independently SIL3 certified version under \r
-    the SafeRTOS brand: http://www.SafeRTOS.com.\r
-*/\r
+ * FreeRTOS Kernel V10.3.0\r
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ *\r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+ * this software and associated documentation files (the "Software"), to deal in\r
+ * the Software without restriction, including without limitation the rights to\r
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+ * the Software, and to permit persons to whom the Software is furnished to do so,\r
+ * subject to the following conditions:\r
+ *\r
+ * The above copyright notice and this permission notice shall be included in all\r
+ * copies or substantial portions of the Software.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ *\r
+ * http://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
 \r
 /*\r
  * The documentation page for this demo available on http://www.FreeRTOS.org\r
@@ -222,7 +183,7 @@ unsigned long ulTIM6_OverflowCount = 0UL;
 \r
 /* The handle of the queue used to send messages from tasks and interrupts to\r
 the LCD task. */\r
-static xQueueHandle xLCDQueue = NULL;\r
+static QueueHandle_t xLCDQueue = NULL;\r
 \r
 /* The definition of each message sent from tasks and interrupts to the LCD\r
 task. */\r
@@ -239,11 +200,11 @@ void main( void )
        /* Configure the peripherals used by this demo application.  This includes\r
        configuring the joystick input select button to generate interrupts. */\r
        prvSetupHardware();\r
-       \r
+\r
        /* Create the queue used by tasks and interrupts to send strings to the LCD\r
        task. */\r
        xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );\r
-       \r
+\r
        /* If the queue could not be created then don't create any tasks that might\r
        attempt to use the queue. */\r
        if( xLCDQueue != NULL )\r
@@ -251,22 +212,22 @@ void main( void )
                /* Add the created queue to the queue registry so it can be viewed in\r
                the IAR FreeRTOS state viewer plug-in. */\r
                vQueueAddToRegistry( xLCDQueue, "LCDQueue" );\r
-               \r
+\r
                /* Create the LCD and button poll tasks, as described at the top of this\r
                file. */\r
-               xTaskCreate( prvLCDTask, ( signed char * ) "LCD", mainLCD_TASK_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );\r
-               xTaskCreate( prvButtonPollTask, ( signed char * ) "ButPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
-               \r
+               xTaskCreate( prvLCDTask, "LCD", mainLCD_TASK_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );\r
+               xTaskCreate( prvButtonPollTask, "ButPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
+\r
                /* Create a subset of the standard demo tasks. */\r
                vStartDynamicPriorityTasks();\r
                vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
                vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
                vStartGenericQueueTasks( mainGENERIC_QUEUE_TEST_PRIORITY );\r
-               \r
+\r
                /* Start the scheduler. */\r
                vTaskStartScheduler();\r
        }\r
-       \r
+\r
        /* If all is well then this line will never be reached.  If it is reached\r
        then it is likely that there was insufficient (FreeRTOS) heap memory space\r
        to create the idle task.  This may have been trapped by the malloc() failed\r
@@ -290,9 +251,9 @@ static char cBuffer[ 512 ];
        /* This function is the only function that uses printf().  If printf() is\r
        used from any other function then some sort of mutual exclusion on stdout\r
        will be necessary.\r
-       \r
+\r
        This is also the only function that is permitted to access the LCD.\r
-       \r
+\r
        First print out the number of bytes that remain in the FreeRTOS heap.  This\r
        can be viewed in the terminal IO window within the IAR Embedded Workbench. */\r
        printf( "%d bytes of heap space remain unallocated\n", xPortGetFreeHeapSize() );\r
@@ -312,7 +273,7 @@ static char cBuffer[ 512 ];
                        LCD_Clear( Blue );\r
                        lLine = 0;\r
                }\r
-                               \r
+\r
                /* What is this message?  What does it contain? */\r
                switch( xReceivedMessage.cMessageID )\r
                {\r
@@ -331,9 +292,9 @@ static char cBuffer[ 512 ];
                                                                                                the terminal IO window in the IAR\r
                                                                                                embedded workbench. */\r
                                                                                                printf( "\nTask\t     Abs Time\t     %%Time\n*****************************************" );\r
-                                                                                               vTaskGetRunTimeStats( ( signed char * ) cBuffer );\r
+                                                                                               vTaskGetRunTimeStats( cBuffer );\r
                                                                                                printf( cBuffer );\r
-                                                                                               \r
+\r
                                                                                                /* Also print out a message to\r
                                                                                                the LCD - in this case the\r
                                                                                                pointer to the string to print\r
@@ -344,7 +305,7 @@ static char cBuffer[ 512 ];
                                                                                                technique. */\r
                                                                                                sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.lMessageValue );\r
                                                                                                break;\r
-                                                                                               \r
+\r
                        case mainMESSAGE_STATUS                 :       /* The tick interrupt hook\r
                                                                                                function has just informed this\r
                                                                                                task of the system status.\r
@@ -352,15 +313,15 @@ static char cBuffer[ 512 ];
                                                                                                with the status value. */\r
                                                                                                prvGenerateStatusMessage( cBuffer, xReceivedMessage.lMessageValue );\r
                                                                                                break;\r
-                                                                                               \r
+\r
                        default                                                 :       sprintf( cBuffer, "Unknown message" );\r
                                                                                                break;\r
                }\r
-               \r
+\r
                /* Output the message that was placed into the cBuffer array within the\r
                switch statement above. */\r
                LCD_DisplayStringLine( lLine, ( uint8_t * ) cBuffer );\r
-               \r
+\r
                /* Move onto the next LCD line, ready for the next iteration of this\r
                loop. */\r
                lLine += lFontHeight;\r
@@ -378,7 +339,7 @@ static void prvGenerateStatusMessage( char *pcBuffer, long lStatusValue )
                                                                                        break;\r
                case mainERROR_DYNAMIC_TASKS    :       sprintf( pcBuffer, "Error: Dynamic tasks" );\r
                                                                                        break;\r
-               case mainERROR_COM_TEST                 :       sprintf( pcBuffer, "Err: loop connected?" ); /* Error in COM test - is the Loopback connector connected? */                                                                                                             \r
+               case mainERROR_COM_TEST                 :       sprintf( pcBuffer, "Err: loop connected?" ); /* Error in COM test - is the Loopback connector connected? */\r
                                                                                        break;\r
                case mainERROR_GEN_QUEUE_TEST   :       sprintf( pcBuffer, "Error: Gen Q test" );\r
                                                                                        break;\r
@@ -397,9 +358,9 @@ long lHigherPriorityTaskWoken = pdFALSE;
        /* This is the interrupt handler for the joystick select button input.\r
        The button has been pushed, write a message to the LCD via the LCD task. */\r
        xQueueSendFromISR( xLCDQueue, &xMessage, &lHigherPriorityTaskWoken );\r
-       \r
+\r
        EXTI_ClearITPendingBit( SEL_BUTTON_EXTI_LINE );\r
-       \r
+\r
        /* If writing to xLCDQueue caused a task to unblock, and the unblocked task\r
        has a priority equal to or above the task that this interrupt interrupted,\r
        then lHigherPriorityTaskWoken will have been set to pdTRUE internally within\r
@@ -412,7 +373,7 @@ long lHigherPriorityTaskWoken = pdFALSE;
 void vApplicationTickHook( void )\r
 {\r
 static unsigned long ulCounter = 0;\r
-static const unsigned long ulCheckFrequency = 5000UL / portTICK_RATE_MS;\r
+static const unsigned long ulCheckFrequency = 5000UL / portTICK_PERIOD_MS;\r
 long lHigherPriorityTaskWoken = pdFALSE;\r
 \r
 /* Define the status message that is sent to the LCD task.  By default the\r
@@ -433,17 +394,17 @@ static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS };
                {\r
                        xStatusMessage.lMessageValue = mainERROR_DYNAMIC_TASKS;\r
                }\r
-               \r
+\r
                if( xAreComTestTasksStillRunning() != pdPASS )\r
                {\r
                        xStatusMessage.lMessageValue = mainERROR_COM_TEST;\r
                }\r
-               \r
+\r
                if( xAreGenericQueueTasksStillRunning() != pdPASS )\r
                {\r
                        xStatusMessage.lMessageValue = mainERROR_GEN_QUEUE_TEST;\r
                }\r
-               \r
+\r
                /* As this is the tick hook the lHigherPriorityTaskWoken parameter is not\r
                needed (a context switch is going to be performed anyway), but it must\r
                still be provided. */\r
@@ -473,10 +434,10 @@ xQueueMessage xMessage;
                        lLastState = lState;\r
                        xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );\r
                }\r
-               \r
+\r
                /* Block for 10 milliseconds so this task does not utilise all the CPU\r
                time and debouncing of the button is not necessary. */\r
-               vTaskDelay( 10 / portTICK_RATE_MS );\r
+               vTaskDelay( 10 / portTICK_PERIOD_MS );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -486,7 +447,7 @@ static void prvSetupHardware( void )
        /* Ensure that all 4 interrupt priority bits are used as the pre-emption\r
        priority. */\r
        NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );\r
-       \r
+\r
        /* Initialise the LEDs. */\r
        vParTestInitialise();\r
 \r
@@ -495,7 +456,7 @@ static void prvSetupHardware( void )
        STM_EVAL_PBInit( BUTTON_DOWN, BUTTON_MODE_GPIO );\r
        STM_EVAL_PBInit( BUTTON_LEFT, BUTTON_MODE_GPIO );\r
        STM_EVAL_PBInit( BUTTON_RIGHT, BUTTON_MODE_GPIO );\r
-       \r
+\r
        /* The select button in the middle of the joystick is configured to generate\r
        an interrupt.  The Eval board library will configure the interrupt\r
        priority to be the lowest priority available so the priority need not be\r
@@ -505,7 +466,7 @@ static void prvSetupHardware( void )
        STM_EVAL_PBInit( BUTTON_SEL, BUTTON_MODE_EXTI );\r
 \r
        /* Initialize the LCD */\r
-       STM32L152_LCD_Init();   \r
+       STM32L152_LCD_Init();\r
        LCD_Clear( Blue );\r
        LCD_SetBackColor( Blue );\r
        LCD_SetTextColor( White );\r
@@ -525,7 +486,7 @@ NVIC_InitTypeDef NVIC_InitStructure;
        significant two bytes are given by the current TIM6 counter value.  Care\r
        must be taken with data consistency when combining the two in case a timer\r
        overflow occurs as the value is being read.\r
-       \r
+\r
        The portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro (in FreeRTOSConfig.h) is\r
        defined to call this function, so the kernel will call this function\r
        automatically at the appropriate time. */\r
@@ -539,22 +500,22 @@ NVIC_InitTypeDef NVIC_InitStructure;
        TIM_TimeBaseStructure.TIM_Prescaler = 5000;\r
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;\r
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;\r
-       \r
+\r
        TIM_TimeBaseInit( TIM6, &TIM_TimeBaseStructure );\r
-       \r
+\r
        /* Only interrupt on overflow events. */\r
        TIM6->CR1 |= TIM_CR1_URS;\r
-       \r
+\r
        /* Enable the interrupt. */\r
        TIM_ITConfig( TIM6, TIM_IT_Update, ENABLE );\r
-       \r
+\r
        /* Enable the TIM6 global Interrupt */\r
        NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;\r
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY;\r
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00; /* Not used as 4 bits are used for the pre-emption priority. */\r
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;\r
        NVIC_Init(&NVIC_InitStructure);\r
-       \r
+\r
        TIM_ClearITPendingBit( TIM6, TIM_IT_Update );\r
        TIM_Cmd( TIM6, ENABLE );\r
 }\r
@@ -563,7 +524,7 @@ NVIC_InitTypeDef NVIC_InitStructure;
 void TIM6_IRQHandler( void )\r
 {\r
        /* Interrupt handler for TIM 6\r
-       \r
+\r
        The time base for the run time stats is generated by the 16 bit timer 6.\r
        Each time the timer overflows ulTIM6_OverflowCount is incremented.\r
        Therefore, when converting the total run time to a 32 bit number, the most\r
@@ -579,11 +540,11 @@ void TIM6_IRQHandler( void )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
 {\r
        ( void ) pcTaskName;\r
        ( void ) pxTask;\r
-       \r
+\r
        /* Run time stack overflow checking is performed if\r
        configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
        function is called if a stack overflow is detected. */\r