2 FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * This is a very simple demo that creates two tasks, one queue, and one
\r
72 * software timer. For a much more complete and complex example select either
\r
73 * the Debug or Debug_with_optimisation build configurations within the HEW,
\r
74 * which build main_full.c in place of this file.
\r
76 * One task (the queue receive task) blocks on the queue to wait for data to
\r
77 * arrive, toggling LED0 each time '100' is received. The other task (the
\r
78 * queue send task) repeatedly blocks for a fixed period before sending '100'
\r
79 * to the queue (causing the first task to toggle the LED).
\r
81 * The software timer is configured to auto-reload. The timer callback
\r
82 * function periodically toggles LED1.
\r
85 /* Kernel includes. */
\r
86 #include "FreeRTOS.h"
\r
91 /* Priorities at which the tasks are created. */
\r
92 #define configQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
93 #define configQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
95 /* The rate at which data is sent to the queue, specified in milliseconds. */
\r
96 #define mainQUEUE_SEND_PERIOD_MS ( 500 / portTICK_PERIOD_MS )
\r
98 /* The period of the software timer, specified in milliseconds. */
\r
99 #define mainSOFTWARE_TIMER_PERIOD_MS ( 150 / portTICK_PERIOD_MS )
\r
101 /* The number of items the queue can hold. This is 1 as the receive task
\r
102 will remove items as they are added so the send task should always find the
\r
104 #define mainQUEUE_LENGTH ( 1 )
\r
106 /* The LEDs toggle by the task and timer respectively. */
\r
107 #define mainTASK_LED ( 0 )
\r
108 #define mainTIMER_LED ( 1 )
\r
111 * The tasks as defined at the top of this file.
\r
113 static void prvQueueReceiveTask( void *pvParameters );
\r
114 static void prvQueueSendTask( void *pvParameters );
\r
117 * The callback function used by the software timer.
\r
119 static void prvBlinkyTimerCallback( TimerHandle_t xTimer );
\r
121 /* The queue used by both tasks. */
\r
122 static QueueHandle_t xQueue = NULL;
\r
124 /* This variable is not used by this simple Blinky example. It is defined
\r
125 purely to allow the project to link as it is used by the full project. */
\r
126 volatile unsigned long ulHighFrequencyTickCount = 0UL;
\r
127 /*-----------------------------------------------------------*/
\r
131 TimerHandle_t xTimer;
\r
133 /* Turn all LEDs off. */
\r
134 vParTestInitialise();
\r
136 /* Create the queue. */
\r
137 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
139 /* Create the software timer, as described at the top of this file. */
\r
140 xTimer = xTimerCreate( "BlinkyTimer", /* Just a text name to make debugging easier - not used by the scheduler. */
\r
141 mainSOFTWARE_TIMER_PERIOD_MS, /* The timer period. */
\r
142 pdTRUE, /* Set to pdTRUE for periodic timer, or pdFALSE for one-shot timer. */
\r
143 NULL, /* The timer ID is not required. */
\r
144 prvBlinkyTimerCallback ); /* The function executed when the timer expires. */
\r
146 if( xTimer != NULL )
\r
148 /* Start the timer - it will not actually start running until the
\r
149 scheduler has started. The block time is set to 0, although, because
\r
150 xTimerStart() is being called before the scheduler has been started,
\r
151 the any block time specified would be ignored anyway. */
\r
152 xTimerStart( xTimer, 0UL );
\r
155 if( xQueue != NULL )
\r
157 /* Start the two tasks as described at the top of this file. */
\r
158 xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */
\r
159 "Rx", /* Just a text name to make debugging easier - not used by the scheduler. */
\r
160 configMINIMAL_STACK_SIZE, /* The size of the task stack, in words. */
\r
161 NULL, /* The task parameter is not used. */
\r
162 configQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task when it is created. */
\r
163 NULL ); /* The task handle is not used. */
\r
165 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
\r
167 /* Start the tasks running. */
\r
168 vTaskStartScheduler();
\r
171 /* If all is well we will never reach here as the scheduler will now be
\r
172 running. If we do reach here then it is likely that there was insufficient
\r
173 heap available for the idle task to be created. */
\r
176 /*-----------------------------------------------------------*/
\r
178 static void prvQueueSendTask( void *pvParameters )
\r
180 TickType_t xNextWakeTime;
\r
181 const unsigned long ulValueToSend = 100UL;
\r
183 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
184 xNextWakeTime = xTaskGetTickCount();
\r
188 /* Place this task in the blocked state until it is time to run again.
\r
189 The block state is specified in ticks, the constant used converts ticks
\r
191 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_PERIOD_MS );
\r
193 /* Send to the queue - causing the queue receive task to flash its LED. 0
\r
194 is used so the send does not block - it shouldn't need to as the queue
\r
195 should always be empty here. */
\r
196 xQueueSend( xQueue, &ulValueToSend, 0 );
\r
199 /*-----------------------------------------------------------*/
\r
201 static void prvQueueReceiveTask( void *pvParameters )
\r
203 unsigned long ulReceivedValue;
\r
207 /* Wait until something arives in the queue - this will block
\r
208 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
209 FreeRTOSConfig.h. */
\r
210 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
212 /* To get here something must have arrived, but is it the expected
\r
213 value? If it is, toggle the LED. */
\r
214 if( ulReceivedValue == 100UL )
\r
216 vParTestToggleLED( mainTASK_LED );
\r
220 /*-----------------------------------------------------------*/
\r
222 static void prvBlinkyTimerCallback( TimerHandle_t xTimer )
\r
224 /* The software timer does nothing but toggle an LED. */
\r
225 vParTestToggleLED( mainTIMER_LED );
\r
227 /*-----------------------------------------------------------*/
\r
229 void vApplicationSetupTimerInterrupt( void )
\r
231 /* Enable compare match timer 0. */
\r
234 /* Interrupt on compare match. */
\r
235 CMT0.CMCR.BIT.CMIE = 1;
\r
237 /* Set the compare match value. */
\r
238 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
\r
240 /* Divide the PCLK by 8. */
\r
241 CMT0.CMCR.BIT.CKS = 0;
\r
243 /* Enable the interrupt... */
\r
244 _IEN( _CMT0_CMI0 ) = 1;
\r
246 /* ...and set its priority to the application defined kernel priority. */
\r
247 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
\r
249 /* Start the timer. */
\r
250 CMT.CMSTR0.BIT.STR0 = 1;
\r
252 /*-----------------------------------------------------------*/
\r
254 /* This function is explained by the comments above its prototype at the top
\r
256 void vApplicationMallocFailedHook( void )
\r
260 /*-----------------------------------------------------------*/
\r
262 /* This function is explained by the comments above its prototype at the top
\r
264 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
268 /*-----------------------------------------------------------*/
\r
270 /* This function is explained by the comments above its prototype at the top
\r
272 void vApplicationIdleHook( void )
\r
274 /* Just to prevent the variable getting optimised away. */
\r
275 ( void ) ulHighFrequencyTickCount;
\r
277 /*-----------------------------------------------------------*/
\r