--- /dev/null
+/*\r
+ FreeRTOS V7.1.0 - Copyright (C) 2011 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
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+/* \r
+ * This is a very simple demo that creates two tasks, one queue, and one \r
+ * software timer. For a much more complete and complex example select either \r
+ * the Debug or Debug_with_optimisation build configurations within the HEW,\r
+ * which build main_full.c in place of this file.\r
+ * \r
+ * One task (the queue receive task) blocks on the queue to wait for data to \r
+ * arrive, toggling LED0 each time '100' is received. The other task (the \r
+ * queue send task) repeatedly blocks for a fixed period before sending '100' \r
+ * to the queue (causing the first task to toggle the LED). \r
+ *\r
+ * The software timer is configured to auto-reload. The timer callback \r
+ * function periodically toggles LED1.\r
+ */\r
+\r
+/* Hardware specific includes. */\r
+#include "iodefine.h"\r
+\r
+/* Kernel includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "timers.h"\r
+#include "queue.h"\r
+\r
+/* Priorities at which the tasks are created. */\r
+#define configQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
+#define configQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+\r
+/* The rate at which data is sent to the queue, specified in milliseconds. */\r
+#define mainQUEUE_SEND_PERIOD_MS ( 500 / portTICK_RATE_MS )\r
+\r
+/* The period of the software timer, specified in milliseconds. */\r
+#define mainSOFTWARE_TIMER_PERIOD_MS ( 150 / portTICK_RATE_MS )\r
+\r
+/* The number of items the queue can hold. This is 1 as the receive task\r
+will remove items as they are added so the send task should always find the\r
+queue empty. */\r
+#define mainQUEUE_LENGTH ( 1 )\r
+\r
+/* The LEDs toggle by the task and timer respectively. */\r
+#define mainTASK_LED ( 0 )\r
+#define mainTIMER_LED ( 1 )\r
+\r
+/*\r
+ * The tasks as defined at the top of this file.\r
+ */\r
+static void prvQueueReceiveTask( void *pvParameters );\r
+static void prvQueueSendTask( void *pvParameters );\r
+\r
+/*\r
+ * The callback function used by the software timer.\r
+ */\r
+static void prvBlinkyTimerCallback( xTimerHandle xTimer );\r
+\r
+/* The queue used by both tasks. */\r
+static xQueueHandle xQueue = NULL;\r
+\r
+/* This variable is not used by this simple Blinky example. It is defined \r
+purely to allow the project to link as it is used by the full project. */\r
+volatile unsigned long ulHighFrequencyTickCount = 0UL;\r
+/*-----------------------------------------------------------*/\r
+\r
+void main(void)\r
+{\r
+xTimerHandle xTimer;\r
+\r
+ /* Turn all LEDs off. */\r
+ vParTestInitialise();\r
+ \r
+ /* Create the queue. */\r
+ xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
+\r
+ /* Create the software timer, as described at the top of this file. */\r
+ xTimer = xTimerCreate( "BlinkyTimer", /* Just a text name to make debugging easier - not used by the scheduler. */\r
+ mainSOFTWARE_TIMER_PERIOD_MS, /* The timer period. */\r
+ pdTRUE, /* Set to pdTRUE for periodic timer, or pdFALSE for one-shot timer. */\r
+ NULL, /* The timer ID is not required. */\r
+ prvBlinkyTimerCallback ); /* The function executed when the timer expires. */\r
+ \r
+ if( xTimer != NULL )\r
+ {\r
+ /* Start the timer - it will not actually start running until the\r
+ scheduler has started. The block time is set to 0, although, because\r
+ xTimerStart() is being called before the scheduler has been started,\r
+ the any block time specified would be ignored anyway. */\r
+ xTimerStart( xTimer, 0UL );\r
+ }\r
+ \r
+ if( xQueue != NULL )\r
+ {\r
+ /* Start the two tasks as described at the top of this file. */\r
+ xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */\r
+ "Rx", /* Just a text name to make debugging easier - not used by the scheduler. */\r
+ configMINIMAL_STACK_SIZE, /* The size of the task stack, in words. */\r
+ NULL, /* The task parameter is not used. */\r
+ configQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task when it is created. */\r
+ NULL ); /* The task handle is not used. */\r
+ \r
+ xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );\r
+\r
+ /* Start the tasks running. */\r
+ vTaskStartScheduler();\r
+ }\r
+ \r
+ /* If all is well we will never reach here as the scheduler will now be\r
+ running. If we do reach here then it is likely that there was insufficient\r
+ heap available for the idle task to be created. */\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvQueueSendTask( void *pvParameters )\r
+{\r
+portTickType xNextWakeTime;\r
+const unsigned long ulValueToSend = 100UL;\r
+\r
+ /* Initialise xNextWakeTime - this only needs to be done once. */\r
+ xNextWakeTime = xTaskGetTickCount();\r
+\r
+ for( ;; )\r
+ {\r
+ /* Place this task in the blocked state until it is time to run again. \r
+ The block state is specified in ticks, the constant used converts ticks\r
+ to ms. */\r
+ vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_PERIOD_MS );\r
+\r
+ /* Send to the queue - causing the queue receive task to flash its LED. 0\r
+ is used so the send does not block - it shouldn't need to as the queue\r
+ should always be empty here. */\r
+ xQueueSend( xQueue, &ulValueToSend, 0 );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvQueueReceiveTask( void *pvParameters )\r
+{\r
+unsigned long ulReceivedValue;\r
+\r
+ for( ;; )\r
+ {\r
+ /* Wait until something arives in the queue - this will block \r
+ indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
+ FreeRTOSConfig.h. */\r
+ xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
+\r
+ /* To get here something must have arrived, but is it the expected\r
+ value? If it is, toggle the LED. */\r
+ if( ulReceivedValue == 100UL )\r
+ {\r
+ vParTestToggleLED( mainTASK_LED );\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvBlinkyTimerCallback( xTimerHandle xTimer )\r
+{\r
+ /* The software timer does nothing but toggle an LED. */\r
+ vParTestToggleLED( mainTIMER_LED );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationSetupTimerInterrupt( void )\r
+{\r
+ /* Enable compare match timer 0. */\r
+ MSTP( CMT0 ) = 0;\r
+ \r
+ /* Interrupt on compare match. */\r
+ CMT0.CMCR.BIT.CMIE = 1;\r
+ \r
+ /* Set the compare match value. */\r
+ CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
+ \r
+ /* Divide the PCLK by 8. */\r
+ CMT0.CMCR.BIT.CKS = 0;\r
+ \r
+ /* Enable the interrupt... */\r
+ _IEN( _CMT0_CMI0 ) = 1;\r
+ \r
+ /* ...and set its priority to the application defined kernel priority. */\r
+ _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
+ \r
+ /* Start the timer. */\r
+ CMT.CMSTR0.BIT.STR0 = 1;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* This function is explained by the comments above its prototype at the top\r
+of this file. */\r
+void vApplicationMallocFailedHook( void )\r
+{\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* This function is explained by the comments above its prototype at the top\r
+of this file. */\r
+void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
+{\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* This function is explained by the comments above its prototype at the top\r
+of this file. */\r
+void vApplicationIdleHook( void )\r
+{\r
+ /* Just to prevent the variable getting optimised away. */\r
+ ( void ) ulHighFrequencyTickCount;\r
+}\r
+/*-----------------------------------------------------------*/\r