--- /dev/null
+/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */\r
+/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */\r
+/* ELIGIBILITY FOR ANY PURPOSES. */\r
+/* (C) Fujitsu Microelectronics Europe GmbH */\r
+/*------------------------------------------------------------------------\r
+ MAIN.C\r
+ - description\r
+ - See README.TXT for project description and disclaimer.\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
+ * Main.c also creates a task called "Check". This only executes every three \r
+ * seconds but has the highest priority so is guaranteed to get processor time. \r
+ * Its main function is to check that all the other tasks are still operational.\r
+ * Each task (other than the "flash" tasks) maintains a unique count that is \r
+ * incremented each time the task successfully completes its function. Should \r
+ * any error occur within such a task the count is permanently halted. The \r
+ * check task inspects the count of each task to ensure it has changed since\r
+ * the last time the check task executed. If all the count variables have \r
+ * changed all the tasks are still executing error free, and the check task\r
+ * 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
+ */\r
+\r
+\r
+/* Hardware specific includes. */\r
+#include "mb91467d.h"\r
+#include "vectors.h"\r
+#include "watchdog.h"\r
+\r
+/* Scheduler includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+\r
+/* Demo app includes. */\r
+#include "flash.h"\r
+#include "integer.h"\r
+#include "comtest.h"\r
+#include "PollQ.h"\r
+#include "semtest.h"\r
+#include "BlockQ.h"\r
+#include "dynamic.h"\r
+#include "flop.h"\r
+#include "crflash.h"\r
+#include "crhook.h"\r
+#include "GenQTest.h"\r
+#include "QPeek.h"\r
+#include "BlockTim.h"\r
+#include "death.h"\r
+#include "taskutility.h"\r
+ \r
+/* Demo task priorities. */\r
+#define mainWATCHDOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )\r
+#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )\r
+#define mainUTILITY_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
+#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
+#define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
+#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\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
+\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
+LCD represent LED's]*/\r
+#define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )\r
+#define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )\r
+\r
+/* The total number of LEDs available. */\r
+#define ledNUMBER_OF_LEDS ( 8 )\r
+\r
+/* The first LED used by the comtest tasks. */\r
+#define mainCOM_TEST_LED ( 0x05 )\r
+\r
+/* The LED used by the check task. */\r
+#define mainCHECK_TEST_LED ( 0x07 )\r
+\r
+/* The number of interrupt levels to use. */\r
+#define mainINTERRUPT_LEVELS ( 31 )\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
+static void vErrorChecks( 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
+\r
+/* \r
+ * Setup the microcontroller as used by this demo. \r
+ */\r
+static void prvSetupHardware( void );\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
+ prvSetupHardware();\r
+ \r
+ /* Start the standard demo application tasks. */\r
+ vStartLEDFlashTasks( mainLED_TASK_PRIORITY ); \r
+ vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
+ vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );\r
+ vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
+ vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
+ vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY ); \r
+ vStartDynamicPriorityTasks(); \r
+ vStartMathTasks( tskIDLE_PRIORITY ); \r
+ vStartFlashCoRoutines(ledNUMBER_OF_LEDS); \r
+ vStartHookCoRoutines();\r
+ vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );\r
+ vStartQueuePeekTasks();\r
+ vCreateBlockTimeTasks();\r
+ \r
+ /* Start the 'Check' task which is defined in this file. */\r
+ xTaskCreate( vErrorChecks, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); \r
+\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
+ vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );\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
+ vTaskStartScheduler( );\r
+ \r
+ /* vTaskStartScheduler() will only return if an error occurs while the \r
+ idle task is being created. */\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void vErrorChecks( void *pvParameters )\r
+{\r
+portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;\r
+\r
+ /* Cycle for ever, delaying then checking all the other tasks are still\r
+ operating without error. */\r
+ 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
+ detected the time is shortened resulting in a faster LED flash rate. */\r
+ vTaskDelay( xDelayPeriod );\r
+\r
+ /* 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
+ period - which has the effect of increasing the frequency of the\r
+ LED toggle. */\r
+ xDelayPeriod = mainERROR_CHECK_DELAY;\r
+ }\r
+\r
+ /* Flash! */\r
+ vParTestToggleLED(mainCHECK_TEST_LED);\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static portSHORT prvCheckOtherTasksAreStillRunning( void )\r
+{\r
+static portBASE_TYPE xErrorOccurred = pdFALSE;\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
+ 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
+\r
+ if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+\r
+ if( xArePollingQueuesStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+\r
+ if( xAreComTestTasksStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if( xAreMathsTaskStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if( xAreFlashCoRoutinesStillRunning() != pdTRUE ) \r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if( xAreHookCoRoutinesStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if( xIsCreateTaskStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ if ( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
+ {\r
+ xErrorOccurred = pdTRUE\r
+ }\r
+ \r
+ return sNoErrorFound;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvSetupHardware( void )\r
+{\r
+ /* Allow all interrupt levels. */\r
+ __set_il( mainINTERRUPT_LEVELS );\r
+\r
+ /* Initialise interrupts. */\r
+ InitIrqLevels();\r
+\r
+ /* Initialise the ports used by the LEDs. */\r
+ vParTestInitialise();\r
+\r
+ /* If we are going to use the watchdog, then initialise it now. */\r
+ #if WATCHDOG != WTC_NONE \r
+ InitWatchdog();\r
+ #endif\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The below callback function is called from Tick ISR if configUSE_TICK_HOOK \r
+is configured as 1. This function needs to be uncommented if the crhook.c\r
+is not used, since the crhook.c has also defined vApplicationTickHook(). */ \r
+#if configUSE_TICK_HOOK == 1\r
+ void vApplicationTickHook ( void )\r
+ {\r
+ /* Are we using the tick interrupt to kick the watchdog? */\r
+ #if WATCHDOG == WTC_IN_TICK\r
+ Kick_Watchdog();\r
+ #endif\r
+ }\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The below callback function is called from Delayed ISR if configUSE_IDLE_HOOK \r
+is configured as 1. */ \r
+#if configUSE_IDLE_HOOK == 1\r
+ void vApplicationIdleHook ( void )\r
+ {\r
+ /* Are we using the idle task to kick the watchdog? */\r
+ #if WATCHDOG == WTC_IN_IDLE\r
+ Kick_Watchdog();\r
+ #endif\r
+ \r
+ vCoRoutineSchedule();\r
+ }\r
+#endif\r