2 * FreeRTOS Kernel V10.0.1
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
29 * This is a very simple demo that creates two tasks and one queue. One task
30 * (the queue receive task) blocks on the queue to wait for data to arrive,
31 * toggling an LED each time '100' is received. The other task (the queue send
32 * task) repeatedly blocks for a fixed period before sending '100' to the queue
33 * (causing the first task to toggle the LED).
35 * For a much more complete and complex example select either the Debug or
36 * Debug_with_optimisation build configurations within the HEW IDE.
39 /* Hardware specific includes. */
42 /* Kernel includes. */
50 /* Priorities at which the tasks are created. */
51 #define configQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
52 #define configQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
54 /* The rate at which data is sent to the queue, specified in milliseconds. */
55 #define mainQUEUE_SEND_FREQUENCY_MS ( 500 / portTICK_PERIOD_MS )
57 /* The number of items the queue can hold. This is 1 as the receive task
58 will remove items as they are added so the send task should always find the
60 #define mainQUEUE_LENGTH ( 1 )
63 * The tasks as defined at the top of this file.
65 static void prvQueueReceiveTask( void *pvParameters );
66 static void prvQueueSendTask( void *pvParameters );
68 /* The queue used by both tasks. */
69 static QueueHandle_t xQueue = NULL;
71 /* This variable is not used by this simple Blinky example. It is defined
72 purely to allow the project to link as it is used by the full project. */
73 volatile unsigned long ulHighFrequencyTickCount = 0UL;
74 /*-----------------------------------------------------------*/
78 extern void HardwareSetup( void );
80 /* Renesas provided CPU configuration routine. The clocks are configured in
84 /* Create the queue. */
85 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
89 /* Start the two tasks as described at the top of this file. */
90 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );
91 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
93 /* Start the tasks running. */
94 vTaskStartScheduler();
97 /* If all is well we will never reach here as the scheduler will now be
98 running. If we do reach here then it is likely that there was insufficient
99 heap available for the idle task to be created. */
102 /*-----------------------------------------------------------*/
104 static void prvQueueSendTask( void *pvParameters )
106 TickType_t xNextWakeTime;
107 const unsigned long ulValueToSend = 100UL;
109 /* Initialise xNextWakeTime - this only needs to be done once. */
110 xNextWakeTime = xTaskGetTickCount();
114 /* Place this task in the blocked state until it is time to run again.
115 The block state is specified in ticks, the constant used converts ticks
117 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
119 /* Send to the queue - causing the queue receive task to flash its LED. 0
120 is used so the send does not block - it shouldn't need to as the queue
121 should always be empty here. */
122 xQueueSend( xQueue, &ulValueToSend, 0 );
125 /*-----------------------------------------------------------*/
127 static void prvQueueReceiveTask( void *pvParameters )
129 unsigned long ulReceivedValue;
133 /* Wait until something arives in the queue - this will block
134 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
136 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
138 /* To get here something must have arrived, but is it the expected
139 value? If it is, toggle the LED. */
140 if( ulReceivedValue == 100UL )
142 vParTestToggleLED( 0 );
146 /*-----------------------------------------------------------*/
148 void vApplicationSetupTimerInterrupt( void )
150 /* Enable compare match timer 0. */
153 /* Interrupt on compare match. */
154 CMT0.CMCR.BIT.CMIE = 1;
156 /* Set the compare match value. */
157 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
159 /* Divide the PCLK by 8. */
160 CMT0.CMCR.BIT.CKS = 0;
162 /* Enable the interrupt... */
163 _IEN( _CMT0_CMI0 ) = 1;
165 /* ...and set its priority to the application defined kernel priority. */
166 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
168 /* Start the timer. */
169 CMT.CMSTR0.BIT.STR0 = 1;
171 /*-----------------------------------------------------------*/
173 /* This function is explained by the comments above its prototype at the top
175 void vApplicationMallocFailedHook( void )
179 /*-----------------------------------------------------------*/
181 /* This function is explained by the comments above its prototype at the top
183 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
187 /*-----------------------------------------------------------*/
189 /* This function is explained by the comments above its prototype at the top
191 void vApplicationIdleHook( void )
193 /* Just to prevent the variable getting optimised away. */
194 ( void ) ulHighFrequencyTickCount;
196 /*-----------------------------------------------------------*/
198 /* The following two functions are here just to allow all three build
199 configurations to use the same vector table. They are not used in this
200 demo, but linker errors will result if they are not defined. They can
202 void vT0_1InterruptHandler( void ) {}
203 void vT2_3InterruptHandler( void ) {}