]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/MB91460_Softune/SRC/main.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / MB91460_Softune / SRC / main.c
index 763a3092d47ace5e02b6268f4eb775dc1a09b48f..a9c4da9a8768a47a462d4e827c246e0aca168a78 100644 (file)
@@ -1,88 +1,48 @@
 /*\r
-    FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
-\r
-    FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT \r
-    http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\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 versions, license \r
-    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.0.0\r
+ * Copyright (C) 2017 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. If you wish to use our Amazon\r
+ * FreeRTOS name, please do so in a fair use way that does not cause confusion.\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
 /*\r
  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
  * documentation provides more details of the demo application tasks.\r
- * \r
+ *\r
  * In addition to the standard demo tasks, the follow demo specific tasks are\r
  * create:\r
  *\r
- * The "Check" task.  This only executes every three seconds but has the highest \r
- * priority so is guaranteed to get processor time.  Its main function is to \r
- * check that all the other tasks are still operational.  Most tasks maintain \r
- * a unique count that is incremented each time the task successfully completes \r
- * its function.  Should any error occur within such a task the count is \r
- * permanently halted.  The check task inspects the count of each task to ensure \r
- * it has changed since the last time the check task executed.  If all the count \r
- * variables have changed all the tasks are still executing error free, and the \r
- * check task toggles the onboard LED.  Should any task contain an error at any time \r
+ * The "Check" task.  This only executes every three seconds but has the highest\r
+ * priority so is guaranteed to get processor time.  Its main function is to\r
+ * check that all the other tasks are still operational.  Most tasks maintain\r
+ * a unique count that is incremented each time the task successfully completes\r
+ * its function.  Should any error occur within such a task the count is\r
+ * permanently halted.  The check task inspects the count of each task to ensure\r
+ * it has changed since the last time the check task executed.  If all the count\r
+ * variables have changed all the tasks are still executing error free, and the\r
+ * check task toggles the onboard LED.  Should any task contain an error at any time\r
  * the LED toggle rate will change from 3 seconds to 500ms.\r
  *\r
  * The "Register Check" tasks.  These tasks fill the CPU registers with known\r
@@ -91,7 +51,7 @@
  * context switch mechanism.  The register check tasks operate at low priority\r
  * so are switched in and out frequently.\r
  *\r
- * The "Trace Utility" task.  This can be used to obtain trace and debug \r
+ * The "Trace Utility" task.  This can be used to obtain trace and debug\r
  * information via UART5.\r
  */\r
 \r
 #include "taskutility.h"\r
 #include "partest.h"\r
 #include "crflash.h"\r
-       \r
+\r
 /* Demo task priorities. */\r
 #define mainWATCHDOG_TASK_PRIORITY             ( tskIDLE_PRIORITY + 5 )\r
 #define mainCHECK_TASK_PRIORITY                        ( tskIDLE_PRIORITY + 4 )\r
 #define mainGENERIC_QUEUE_PRIORITY             ( tskIDLE_PRIORITY )\r
 \r
 /* Baud rate used by the COM test tasks. */\r
-#define mainCOM_TEST_BAUD_RATE                 ( ( unsigned portLONG ) 19200 )\r
+#define mainCOM_TEST_BAUD_RATE                 ( ( unsigned long ) 19200 )\r
 \r
-/* The frequency at which the 'Check' tasks executes.  See the comments at the \r
+/* The frequency at which the 'Check' tasks executes.  See the comments at the\r
 top of the page.  When the system is operating error free the 'Check' task\r
 toggles an LED every three seconds.  If an error is discovered in any task the\r
-rate is increased to 500 milliseconds.  [in this case the '*' characters on the \r
+rate is increased to 500 milliseconds.  [in this case the '*' characters on the\r
 LCD represent LEDs]*/\r
-#define mainNO_ERROR_CHECK_DELAY               ( ( portTickType ) 3000 / portTICK_RATE_MS  )\r
-#define mainERROR_CHECK_DELAY                  ( ( portTickType ) 500 / portTICK_RATE_MS  )\r
+#define mainNO_ERROR_CHECK_DELAY               ( ( TickType_t ) 3000 / portTICK_PERIOD_MS  )\r
+#define mainERROR_CHECK_DELAY                  ( ( TickType_t ) 500 / portTICK_PERIOD_MS  )\r
 \r
 /* The total number of LEDs available. */\r
 #define mainNO_CO_ROUTINE_LEDs ( 8 )\r
@@ -160,20 +120,20 @@ LCD represent LEDs]*/
 \r
 /*---------------------------------------------------------------------------*/\r
 \r
-/* \r
+/*\r
  * The function that implements the Check task.  See the comments at the head\r
  * of the page for implementation details.\r
- */ \r
+ */\r
 static void prvErrorChecks( void *pvParameters );\r
 \r
 /*\r
  * Called by the Check task.  Returns pdPASS if all the other tasks are found\r
  * to be operating without error - otherwise returns pdFAIL.\r
  */\r
-static portSHORT prvCheckOtherTasksAreStillRunning( void );\r
+static short prvCheckOtherTasksAreStillRunning( void );\r
 \r
-/* \r
- * Setup the microcontroller as used by this demo. \r
+/*\r
+ * Setup the microcontroller as used by this demo.\r
  */\r
 static void prvSetupHardware( void );\r
 \r
@@ -188,57 +148,57 @@ static void vSecondRegisterTestTask( void *pvParameters );
 \r
 /*---------------------------------------------------------------------------*/\r
 \r
-/* The variable that is set to true should an error be found in one of the \r
+/* The variable that is set to true should an error be found in one of the\r
 register test tasks. */\r
-unsigned portLONG ulRegTestError = pdFALSE;\r
+unsigned long ulRegTestError = pdFALSE;\r
 \r
 /*---------------------------------------------------------------------------*/\r
 \r
 /* Start all the demo application tasks, then start the scheduler. */\r
 void main(void)\r
 {\r
-       /* Initialise the hardware ready for the demo. */       \r
+       /* Initialise the hardware ready for the demo. */\r
        prvSetupHardware();\r
 \r
        /* Start the standard demo application tasks. */\r
-       vStartLEDFlashTasks( mainLED_TASK_PRIORITY );   \r
+       vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
        vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
        vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );\r
        vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
-       vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );  \r
-       vStartDynamicPriorityTasks();   \r
-       vStartMathTasks( tskIDLE_PRIORITY );    \r
+       vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );\r
+       vStartDynamicPriorityTasks();\r
+       vStartMathTasks( tskIDLE_PRIORITY );\r
        vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );\r
        vStartQueuePeekTasks();\r
        vCreateBlockTimeTasks();\r
        vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );\r
 \r
        /* Start the 'Check' task which is defined in this file. */\r
-       xTaskCreate( prvErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );    \r
+       xTaskCreate( prvErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
 \r
        /* Start the 'Register Test' tasks as described at the top of this file. */\r
-       xTaskCreate( vFirstRegisterTestTask, ( signed portCHAR * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
-       xTaskCreate( vSecondRegisterTestTask, ( signed portCHAR * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
+       xTaskCreate( vFirstRegisterTestTask, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
+       xTaskCreate( vSecondRegisterTestTask, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
 \r
-       /* Start the task that write trace information to the UART. */  \r
+       /* Start the task that write trace information to the UART. */\r
        vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );\r
 \r
        /* If we are going to service the watchdog from within a task, then create\r
-       the task here. */       \r
-       #if WATCHDOG == WTC_IN_TASK     \r
+       the task here. */\r
+       #if WATCHDOG == WTC_IN_TASK\r
                vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );\r
-       #endif          \r
-       \r
+       #endif\r
+\r
        /* The suicide tasks must be started last as they record the number of other\r
        tasks that exist within the system.  The value is then used to ensure at run\r
        time the number of tasks that exists is within expected bounds. */\r
        vCreateSuicidalTasks( mainDEATH_PRIORITY );\r
 \r
        /* Now start the scheduler.  Following this call the created tasks should\r
-       be executing. */        \r
+       be executing. */\r
        vTaskStartScheduler( );\r
-       \r
-       /* vTaskStartScheduler() will only return if an error occurs while the \r
+\r
+       /* vTaskStartScheduler() will only return if an error occurs while the\r
        idle task is being created. */\r
        for( ;; );\r
 }\r
@@ -246,7 +206,7 @@ void main(void)
 \r
 static void prvErrorChecks( void *pvParameters )\r
 {\r
-portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;\r
+TickType_t xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;\r
 \r
        /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()\r
        works correctly. */\r
@@ -257,7 +217,7 @@ portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
        for( ;; )\r
        {\r
                /* Wait until it is time to check again.  The time we wait here depends\r
-               on whether an error has been detected or not.  When an error is \r
+               on whether an error has been detected or not.  When an error is\r
                detected the time is shortened resulting in a faster LED flash rate. */\r
                /* Perform this check every mainCHECK_DELAY milliseconds. */\r
                vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );\r
@@ -265,7 +225,7 @@ portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
                /* See if the other tasks are all ok. */\r
                if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
                {\r
-                       /* An error occurred in one of the tasks so shorten the delay \r
+                       /* An error occurred in one of the tasks so shorten the delay\r
                        period - which has the effect of increasing the frequency of the\r
                        LED toggle. */\r
                        xDelayPeriod = mainERROR_CHECK_DELAY;\r
@@ -277,12 +237,12 @@ portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static portSHORT prvCheckOtherTasksAreStillRunning( void )\r
+static short prvCheckOtherTasksAreStillRunning( void )\r
 {\r
 portBASE_TYPE lReturn = pdPASS;\r
 \r
        /* The demo tasks maintain a count that increments every cycle of the task\r
-       provided that the task has never encountered an error.  This function \r
+       provided that the task has never encountered an error.  This function\r
        checks the counts maintained by the tasks to ensure they are still being\r
        incremented.  A count remaining at the same value between calls therefore\r
        indicates that an error has been detected. */\r
@@ -296,42 +256,42 @@ portBASE_TYPE lReturn = pdPASS;
        {\r
                lReturn = pdFAIL;\r
        }\r
-       \r
+\r
        if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
        {\r
                lReturn = pdFAIL;\r
        }\r
-       \r
+\r
        if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
        {\r
                lReturn = pdFAIL;\r
        }\r
-       \r
+\r
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
        {\r
                lReturn = pdFAIL;\r
        }\r
-       \r
+\r
        if( xAreMathsTaskStillRunning() != pdTRUE )\r
        {\r
                lReturn = pdFAIL;\r
        }\r
-       \r
+\r
        if( xIsCreateTaskStillRunning() != pdTRUE )\r
        {\r
                lReturn = pdFAIL;\r
        }\r
-       \r
+\r
        if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
        {\r
                lReturn = pdFAIL;\r
        }\r
-       \r
+\r
        if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
        {\r
                lReturn = pdFAIL;\r
        }\r
-       \r
+\r
        if ( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
        {\r
                lReturn = pdFAIL;\r
@@ -359,7 +319,7 @@ static void prvSetupHardware( void )
        vParTestInitialise();\r
 \r
        /* If we are going to use the watchdog, then initialise it now. */\r
-       #if WATCHDOG != WTC_NONE        \r
+       #if WATCHDOG != WTC_NONE\r
                InitWatchdog();\r
        #endif\r
 }\r
@@ -408,7 +368,7 @@ static void prvSetupHardware( void )
 \r
 static void vFirstRegisterTestTask( void *pvParameters )\r
 {\r
-extern volatile unsigned portLONG ulCriticalNesting;\r
+extern volatile unsigned long ulCriticalNesting;\r
 \r
        /* Fills the registers with known values (different to the values\r
        used in vSecondRegisterTestTask()), then checks that the registers still\r
@@ -432,7 +392,7 @@ extern volatile unsigned portLONG ulCriticalNesting;
                        LDI     #0xbbbbbbbb, R10\r
                        LDI     #0xcccccccc, R11\r
                        LDI     #0xdddddddd, R12\r
-                       \r
+\r
                        ;Check each register still contains the expected value.\r
                        LDI #0x11111111, R13\r
                        CMP R13, R0\r
@@ -491,7 +451,7 @@ extern volatile unsigned portLONG ulCriticalNesting;
                First_Set_Error:\r
 \r
                        ; Latch that an error has occurred.\r
-                       LDI #_ulRegTestError, R0                        \r
+                       LDI #_ulRegTestError, R0\r
                        LDI #0x00000001, R1\r
                        ST R1, @R0\r
 \r
@@ -506,7 +466,7 @@ extern volatile unsigned portLONG ulCriticalNesting;
 \r
 static void vSecondRegisterTestTask( void *pvParameters )\r
 {\r
-extern volatile unsigned portLONG ulCriticalNesting;\r
+extern volatile unsigned long ulCriticalNesting;\r
 \r
        /* Fills the registers with known values (different to the values\r
        used in vFirstRegisterTestTask()), then checks that the registers still\r
@@ -532,7 +492,7 @@ extern volatile unsigned portLONG ulCriticalNesting;
                        LDI     #0xbbbbbbbb, R11\r
                        LDI     #0xcccccccc, R12\r
                        LDI     #0xdddddddd, R0\r
-                       \r
+\r
                        ;Check each register still contains the expected value.\r
                        LDI #0x11111111, R13\r
                        CMP R13, R1\r
@@ -595,7 +555,7 @@ extern volatile unsigned portLONG ulCriticalNesting;
                Second_Set_Error:\r
 \r
                        ; Latch that an error has occurred.\r
-                       LDI #_ulRegTestError, R0                        \r
+                       LDI #_ulRegTestError, R0\r
                        LDI #0x00000001, R1\r
                        ST R1, @R0\r
 \r