2 * FreeRTOS Kernel V10.1.1
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 * This is a very simple demo that creates two tasks and one queue. One task
\r
30 * (the queue receive task) blocks on the queue to wait for data to arrive,
\r
31 * toggling an LED each time '100' is received. The other task (the queue send
\r
32 * task) repeatedly blocks for a fixed period before sending '100' to the queue
\r
33 * (causing the first task to toggle the LED).
\r
35 * For a much more complete and complex example select either the Debug or
\r
36 * Debug_with_optimisation build configurations within the Embedded Workbench
\r
40 /* Hardware specific includes. */
\r
41 #include <iorx62n.h>
\r
43 /* Kernel includes. */
\r
44 #include "FreeRTOS.h"
\r
48 /* Demo includes. */
\r
49 #include "partest.h"
\r
51 /* Priorities at which the tasks are created. */
\r
52 #define configQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
53 #define configQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
55 /* The rate at which data is sent to the queue, specified in milliseconds. */
\r
56 #define mainQUEUE_SEND_FREQUENCY_MS ( 500 / portTICK_PERIOD_MS )
\r
58 /* The number of items the queue can hold. This is 1 as the receive task
\r
59 will remove items as they are added so the send task should always find the
\r
61 #define mainQUEUE_LENGTH ( 1 )
\r
64 * The tasks as defined at the top of this file.
\r
66 static void prvQueueReceiveTask( void *pvParameters );
\r
67 static void prvQueueSendTask( void *pvParameters );
\r
69 /* The queue used by both tasks. */
\r
70 static QueueHandle_t xQueue = NULL;
\r
72 /* This variable is not used by this simple Blinky example. It is defined
\r
73 purely to allow the project to link as it is used by the full project. */
\r
74 volatile unsigned long ulHighFrequencyTickCount = 0UL;
\r
75 /*-----------------------------------------------------------*/
\r
79 extern void HardwareSetup( void );
\r
81 /* Renesas provided CPU configuration routine. The clocks are configured in
\r
85 /* Create the queue. */
\r
86 xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
\r
88 if( xQueue != NULL )
\r
90 /* Start the two tasks as described at the top of this file. */
\r
91 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );
\r
92 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );
\r
94 /* Start the tasks running. */
\r
95 vTaskStartScheduler();
\r
98 /* If all is well we will never reach here as the scheduler will now be
\r
99 running. If we do reach here then it is likely that there was insufficient
\r
100 heap available for the idle task to be created. */
\r
103 /*-----------------------------------------------------------*/
\r
105 static void prvQueueSendTask( void *pvParameters )
\r
107 TickType_t xNextWakeTime;
\r
108 const unsigned long ulValueToSend = 100UL;
\r
110 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
111 xNextWakeTime = xTaskGetTickCount();
\r
115 /* Place this task in the blocked state until it is time to run again.
\r
116 The block state is specified in ticks, the constant used converts ticks
\r
118 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
\r
120 /* Send to the queue - causing the queue receive task to flash its LED. 0
\r
121 is used so the send does not block - it shouldn't need to as the queue
\r
122 should always be empty here. */
\r
123 xQueueSend( xQueue, &ulValueToSend, 0 );
\r
126 /*-----------------------------------------------------------*/
\r
128 static void prvQueueReceiveTask( void *pvParameters )
\r
130 unsigned long ulReceivedValue;
\r
134 /* Wait until something arives in the queue - this will block
\r
135 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
\r
136 FreeRTOSConfig.h. */
\r
137 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
\r
139 /* To get here something must have arrived, but is it the expected
\r
140 value? If it is, toggle the LED. */
\r
141 if( ulReceivedValue == 100UL )
\r
143 vParTestToggleLED( 0 );
\r
147 /*-----------------------------------------------------------*/
\r
149 void vApplicationSetupTimerInterrupt( void )
\r
151 /* Enable compare match timer 0. */
\r
154 /* Interrupt on compare match. */
\r
155 CMT0.CMCR.BIT.CMIE = 1;
\r
157 /* Set the compare match value. */
\r
158 CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
\r
160 /* Divide the PCLK by 8. */
\r
161 CMT0.CMCR.BIT.CKS = 0;
\r
163 /* Enable the interrupt... */
\r
164 _IEN( _CMT0_CMI0 ) = 1;
\r
166 /* ...and set its priority to the application defined kernel priority. */
\r
167 _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
\r
169 /* Start the timer. */
\r
170 CMT.CMSTR0.BIT.STR0 = 1;
\r
172 /*-----------------------------------------------------------*/
\r
174 /* This function is explained by the comments above its prototype at the top
\r
176 void vApplicationMallocFailedHook( void )
\r
180 /*-----------------------------------------------------------*/
\r
182 /* This function is explained by the comments above its prototype at the top
\r
184 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
188 /*-----------------------------------------------------------*/
\r
190 /* This function is explained by the comments above its prototype at the top
\r
192 void vApplicationIdleHook( void )
\r
194 /* Just to prevent the variable getting optimised away. */
\r
195 ( void ) ulHighFrequencyTickCount;
\r
197 /*-----------------------------------------------------------*/
\r
199 /* The following two functions are here just to allow all three build
\r
200 configurations to use the same vector table. They are not used in this
\r
201 demo, but linker errors will result if they are not defined. They can
\r
203 void vT0_1InterruptHandler( void ) {}
\r
204 void vT2_3InterruptHandler( void ) {}