]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/RL78_E2Studio_GCC/src/main.c
Complete RL78/G14 demo.
[freertos] / FreeRTOS / Demo / RL78_E2Studio_GCC / src / main.c
index cfea1f0844fbebe6cb6b6ffcc0b5179bc3f67b41..aedbc70cd7aece6264d33ea680a963cd6f1588ee 100644 (file)
     mission critical applications that require provable dependability.\r
 */\r
 \r
-/*\r
+/******************************************************************************\r
+ * This project provides two demo applications.  A simple blinky style project,\r
+ * and a more comprehensive test and demo application.  The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
+ * select between the two.  The simply blinky demo is implemented and described\r
+ * in main_blinky.c.  The more comprehensive test and demo application is\r
+ * implemented and described in main_full.c.\r
+ *\r
+ * This file implements the code that is not demo specific, including the\r
+ * hardware setup and FreeRTOS hook functions.\r
+ *\r
  *\r
  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
  *\r
- *\r
- * main() creates the demo application tasks and timers, then starts the\r
- * scheduler.\r
- *\r
- * This demo is configured to run on the RL78/G13 Promotion Board, which is\r
- * fitted with a R5F100LEA microcontroller.  The R5F100LEA contains a little\r
- * under 4K bytes of usable internal RAM.  The RAM size restricts the number of\r
- * demo tasks that can be created, and the demo creates 13 tasks, 4 queues and\r
- * two timers.  The RL78 range does however include parts with up to 32K bytes\r
- * of RAM (at the time of writing).  Using FreeRTOS on such a part will allow an\r
- * application to make a more comprehensive use of FreeRTOS tasks, and other\r
- * FreeRTOS features.\r
- *\r
- * In addition to the standard demo tasks, the following tasks, tests and timers\r
- * are created within this file:\r
- *\r
- * "Reg test" tasks - These fill the registers with known values, then check\r
- * that each register still contains its expected value.  Each task uses a\r
- * different set of values.  The reg test tasks execute with a very low priority,\r
- * so get preempted very frequently.  A register containing an unexpected value\r
- * is indicative of an error in the context switching mechanism.\r
- *\r
- * The "Demo" Timer and Callback Function:\r
- * The demo timer callback function does nothing more than increment a variable.\r
- * The period of the demo timer is set relative to the period of the check timer\r
- * (described below).  This allows the check timer to know how many times the\r
- * demo timer callback function should execute between each execution of the\r
- * check timer callback function.  The variable incremented in the demo timer\r
- * callback function is used to determine how many times the callback function\r
- * has executed.\r
- *\r
- * The "Check" Timer and Callback Function:\r
- * The check timer period is initially set to three seconds.  The check timer\r
- * callback function checks that all the standard demo tasks, the reg test tasks,\r
- * and the demo timer are not only still executing, but are executing without\r
- * reporting any errors.  If the check timer discovers that a task or timer has\r
- * stalled, or reported an error, then it changes its own period from the\r
- * initial three seconds, to just 200ms.  The check timer callback function also\r
- * toggles the user LED each time it is called.  This provides a visual\r
- * indication of the system status:  If the LED toggles every three seconds,\r
- * then no issues have been discovered.  If the LED toggles every 200ms, then an\r
- * issue has been discovered with at least one task.\r
- *\r
  */\r
 \r
 /* Scheduler include files. */\r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
-#include "timers.h"\r
-\r
-/* Standard demo includes. */\r
-#include "dynamic.h"\r
-#include "PollQ.h"\r
-#include "blocktim.h"\r
-\r
-/* Hardware includes. */\r
-#include "port_iodefine.h"\r
-#include "port_iodefine_ext.h"\r
-#include "LED.h"\r
 \r
-/* The period at which the check timer will expire, in ms, provided no errors\r
-have been reported by any of the standard demo tasks.  ms are converted to the\r
-equivalent in ticks using the portTICK_RATE_MS constant. */\r
-#define mainCHECK_TIMER_PERIOD_MS                      ( 3000UL / portTICK_RATE_MS )\r
-\r
-/* The period at which the check timer will expire, in ms, if an error has been\r
-reported in one of the standard demo tasks, the check tasks, or the demo timer.\r
-ms are converted to the equivalent in ticks using the portTICK_RATE_MS\r
-constant. */\r
-#define mainERROR_CHECK_TIMER_PERIOD_MS        ( 200UL / portTICK_RATE_MS )\r
-\r
-/* These two definitions are used to set the period of the demo timer.  The demo\r
-timer period is always relative to the check timer period, so the check timer\r
-can determine if the demo timer has expired the expected number of times between\r
-its own executions. */\r
-#define mainDEMO_TIMER_INCREMENTS_PER_CHECK_TIMER_TIMEOUT      ( 100UL )\r
-#define mainDEMO_TIMER_PERIOD_MS                       ( mainCHECK_TIMER_PERIOD_MS / mainDEMO_TIMER_INCREMENTS_PER_CHECK_TIMER_TIMEOUT )\r
-\r
-/* A block time of zero simple means "don't block". */\r
-#define mainDONT_BLOCK                                         ( 0U )\r
-\r
-/* Values that are passed as parameters into the reg test tasks (purely to\r
-ensure task parameters are passed correctly). */\r
-#define mainREG_TEST_1_PARAMETER                       ( ( void * ) 0x1234 )\r
-#define mainREG_TEST_2_PARAMETER                       ( ( void * ) 0x5678 )\r
+/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
+or 0 to run the more comprehensive test and demo application. */\r
+#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY     0\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
- * The 'check' timer callback function, as described at the top of this file.\r
- */\r
-static void prvCheckTimerCallback( xTimerHandle xTimer );\r
-\r
-/*\r
- * The 'demo' timer callback function, as described at the top of this file.\r
- */\r
-static void prvDemoTimerCallback( xTimerHandle xTimer );\r
-\r
-/*\r
- * Functions that define the RegTest tasks, as described at the top of this\r
- * file.  The RegTest tasks are written (necessarily) in assembler.  Their\r
- * entry points are written in C to allow for easy checking of the task\r
- * parameter values.\r
+ * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
+ * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
  */\r
-extern void vRegTest1Task( void );\r
-extern void vRegTest2Task( void );\r
-static void prvRegTest1Entry( void *pvParameters );\r
-static void prvRegTest2Entry( void *pvParameters );\r
+extern void main_blinky( void );\r
+extern void main_full( void );\r
 \r
-/*\r
- * Called if a RegTest task discovers an error as a mechanism to stop the\r
- * tasks loop counter incrementing (so the check task can detect that an\r
- * error exists).\r
- */\r
-void vRegTestError( void );\r
+/* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
+within this file. */\r
+void vApplicationMallocFailedHook( void );\r
+void vApplicationIdleHook( void );\r
+void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );\r
+void vApplicationTickHook( void );\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/* Variables that are incremented on each cycle of the two reg tests to allow\r
-the check timer to know that they are still executing. */\r
-unsigned short usRegTest1LoopCounter = 0, usRegTest2LoopCounter;\r
-\r
-/* The check timer.  This uses prvCheckTimerCallback() as its callback\r
-function. */\r
-static xTimerHandle xCheckTimer = NULL;\r
-\r
-/* The demo timer.  This uses prvDemoTimerCallback() as its callback function. */\r
-static xTimerHandle xDemoTimer = NULL;\r
-\r
-/* This variable is incremented each time the demo timer expires. */\r
-static volatile unsigned long ulDemoSoftwareTimerCounter = 0UL;\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-short main( void )\r
+int main( void )\r
 {\r
-       /* Creates all the tasks and timers, then starts the scheduler. */\r
-\r
-       /* First create the 'standard demo' tasks.  These are used to demonstrate\r
-       API functions being used and also to test the kernel port.  More information\r
-       is provided on the FreeRTOS.org WEB site. */\r
-       vStartDynamicPriorityTasks();\r
-       vStartPolledQueueTasks( tskIDLE_PRIORITY );\r
-       vCreateBlockTimeTasks();\r
-\r
-       /* Create the RegTest tasks as described at the top of this file. */\r
-       xTaskCreate( prvRegTest1Entry, "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
-       xTaskCreate( prvRegTest2Entry, "Reg2", configMINIMAL_STACK_SIZE, mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
-\r
-       /* Create the software timer that performs the 'check' functionality,\r
-       as described at the top of this file. */\r
-       xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */\r
-                                                               ( mainCHECK_TIMER_PERIOD_MS ),          /* The timer period, in this case 3000ms (3s). */\r
-                                                               pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
-                                                               ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
-                                                               prvCheckTimerCallback                           /* The callback function that inspects the status of all the other tasks. */\r
-                                                         );\r
-\r
-       /* Create the software timer that just increments a variable for demo\r
-       purposes. */\r
-       xDemoTimer = xTimerCreate( ( const signed char * ) "DemoTimer",/* A text name, purely to help debugging. */\r
-                                                               ( mainDEMO_TIMER_PERIOD_MS ),           /* The timer period, in this case it is always calculated relative to the check timer period (see the definition of mainDEMO_TIMER_PERIOD_MS). */\r
-                                                               pdTRUE,                                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
-                                                               ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
-                                                               prvDemoTimerCallback                            /* The callback function that inspects the status of all the other tasks. */\r
-                                                         );\r
-\r
-       /* Start both the check timer and the demo timer.  The timers won't actually\r
-       start until the scheduler is started. */\r
-       xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
-       xTimerStart( xDemoTimer, mainDONT_BLOCK );\r
-\r
-       /* Finally start the scheduler running. */\r
-       vTaskStartScheduler();\r
-\r
-       /* If all is well execution will never reach here as the scheduler will be\r
-       running.  If this null loop is reached then it is likely there was\r
-       insufficient FreeRTOS heap available for the idle task and/or timer task to\r
-       be created.  See http://www.freertos.org/a00111.html. */\r
-       for( ;; );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvDemoTimerCallback( xTimerHandle xTimer )\r
-{\r
-       /* The demo timer has expired.  All it does is increment a variable.  The\r
-       period of the demo timer is relative to that of the check timer, so the\r
-       check timer knows how many times this variable should have been incremented\r
-       between each execution of the check timer's own callback. */\r
-       ulDemoSoftwareTimerCounter++;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvCheckTimerCallback( xTimerHandle xTimer )\r
-{\r
-static portBASE_TYPE xChangedTimerPeriodAlready = pdFALSE, xErrorStatus = pdPASS;\r
-static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;\r
-\r
-       /* Inspect the status of the standard demo tasks. */\r
-       if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
+       /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
+       of this file. */\r
+       #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
        {\r
-               xErrorStatus = pdFAIL;\r
+               main_blinky();\r
        }\r
-\r
-       if( xArePollingQueuesStillRunning() != pdTRUE )\r
-       {\r
-               xErrorStatus = pdFAIL;\r
-       }\r
-\r
-       if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
-       {\r
-               xErrorStatus = pdFAIL;\r
-       }\r
-\r
-       /* Indicate an error if either of the reg test loop counters have not\r
-       incremented since the last time this function was called. */\r
-       if( usLastRegTest1Counter == usRegTest1LoopCounter )\r
-       {\r
-               xErrorStatus = pdFAIL;\r
-       }\r
-       else\r
-       {\r
-               usLastRegTest1Counter = usRegTest1LoopCounter;\r
-       }\r
-\r
-       if( usLastRegTest2Counter == usRegTest2LoopCounter )\r
+       #else\r
        {\r
-               xErrorStatus = pdFAIL;\r
-       }\r
-       else\r
-       {\r
-               usLastRegTest2Counter = usRegTest2LoopCounter;\r
-       }\r
-\r
-       /* Ensure that the demo software timer has expired\r
-       mainDEMO_TIMER_INCREMENTS_PER_CHECK_TIMER_TIMEOUT times in between\r
-       each call of this function.  A critical section is not required to access\r
-       ulDemoSoftwareTimerCounter as the variable is only accessed from another\r
-       software timer callback, and only one software timer callback can be\r
-       executing at any time. */\r
-       if( ( ulDemoSoftwareTimerCounter < ( mainDEMO_TIMER_INCREMENTS_PER_CHECK_TIMER_TIMEOUT - 1 ) ) ||\r
-           ( ulDemoSoftwareTimerCounter > ( mainDEMO_TIMER_INCREMENTS_PER_CHECK_TIMER_TIMEOUT + 1 ) )\r
-         )\r
-       {\r
-               xErrorStatus = pdFAIL;\r
-       }\r
-       else\r
-       {\r
-               ulDemoSoftwareTimerCounter = 0UL;\r
-       }\r
-\r
-       if( ( xErrorStatus == pdFAIL ) && ( xChangedTimerPeriodAlready == pdFALSE ) )\r
-       {\r
-               /* An error has occurred, but the timer's period has not yet been changed,\r
-               change it now, and remember that it has been changed.  Shortening the\r
-               timer's period means the LED will toggle at a faster rate, giving a\r
-               visible indication that something has gone wrong. */\r
-               xChangedTimerPeriodAlready = pdTRUE;\r
-\r
-               /* This call to xTimerChangePeriod() uses a zero block time.  Functions\r
-               called from inside of a timer callback function must *never* attempt to\r
-               block. */\r
-               xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
+               main_full();\r
        }\r
+       #endif\r
 \r
-       /* Toggle the LED.  The toggle rate will depend on whether or not an error\r
-       has been found in any tasks. */\r
-       LED_BIT = !LED_BIT;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vRegTestError( void )\r
-{\r
-       /* Called by both reg test tasks if an error is found.  There is no way out\r
-       of this function so the loop counter of the calling task will stop\r
-       incrementing, which will result in the check timer signaling an error. */\r
-       for( ;; );\r
+       /* Should not get here.  See the definitions of main_blinky() and\r
+       main_full(). */\r
+       return 0;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -395,50 +173,16 @@ volatile size_t xFreeHeapSpace;
        configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
        RAM. */\r
        xFreeHeapSpace = xPortGetFreeHeapSize();\r
-}\r
-/*-----------------------------------------------------------*/\r
 \r
-static void prvRegTest1Entry( void *pvParameters )\r
-{\r
-       /* If the parameter has its expected value then start the first reg test\r
-       task (this is only done to test that the RTOS port is correctly handling\r
-       task parameters. */\r
-       if( pvParameters == mainREG_TEST_1_PARAMETER )\r
-       {\r
-               vRegTest1Task();\r
-       }\r
-       else\r
-       {\r
-               vRegTestError();\r
-       }\r
-\r
-       /* It is not possible to get here as neither of the two functions called\r
-       above will ever return. */\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvRegTest2Entry( void *pvParameters )\r
-{\r
-       /* If the parameter has its expected value then start the first reg test\r
-       task (this is only done to test that the RTOS port is correctly handling\r
-       task parameters. */\r
-       if( pvParameters == mainREG_TEST_2_PARAMETER )\r
-       {\r
-               vRegTest2Task();\r
-       }\r
-       else\r
-       {\r
-               vRegTestError();\r
-       }\r
-\r
-       /* It is not possible to get here as neither of the two functions called\r
-       above will ever return. */\r
+       /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
+       ( void ) xFreeHeapSpace;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 void vAssertCalled( void )\r
 {\r
 volatile unsigned long ul = 0;\r
+\r
        taskENTER_CRITICAL();\r
        {\r
                /* Set ul to a non-zero value using the debugger to step out of this\r