]> begriffs open source - cmsis-freertos/blob - Demo/RX600_RX62N-RSK_IAR/main-blinky.c
Updated to FreeRTOS V10.0.1
[cmsis-freertos] / Demo / RX600_RX62N-RSK_IAR / main-blinky.c
1 /*
2  * FreeRTOS Kernel V10.0.1
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
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.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /*
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).
34  *
35  * For a much more complete and complex example select either the Debug or
36  * Debug_with_optimisation build configurations within the HEW IDE.
37 */
38
39 /* Hardware specific includes. */
40 #include <iorx62n.h>
41
42 /* Kernel includes. */
43 #include "FreeRTOS.h"
44 #include "task.h"
45 #include "queue.h"
46
47 /* Demo includes. */
48 #include "partest.h"
49
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 )
53
54 /* The rate at which data is sent to the queue, specified in milliseconds. */
55 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 500 / portTICK_PERIOD_MS )
56
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
59 queue empty. */
60 #define mainQUEUE_LENGTH                                        ( 1 )
61
62 /*
63  * The tasks as defined at the top of this file.
64  */
65 static void prvQueueReceiveTask( void *pvParameters );
66 static void prvQueueSendTask( void *pvParameters );
67
68 /* The queue used by both tasks. */
69 static QueueHandle_t xQueue = NULL;
70
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 /*-----------------------------------------------------------*/
75
76 void main(void)
77 {
78 extern void HardwareSetup( void );
79
80         /* Renesas provided CPU configuration routine.  The clocks are configured in
81         here. */
82         HardwareSetup();
83
84         /* Create the queue. */
85         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
86
87         if( xQueue != NULL )
88         {
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 );
92
93                 /* Start the tasks running. */
94                 vTaskStartScheduler();
95         }
96
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. */
100         for( ;; );
101 }
102 /*-----------------------------------------------------------*/
103
104 static void prvQueueSendTask( void *pvParameters )
105 {
106 TickType_t xNextWakeTime;
107 const unsigned long ulValueToSend = 100UL;
108
109         /* Initialise xNextWakeTime - this only needs to be done once. */
110         xNextWakeTime = xTaskGetTickCount();
111
112         for( ;; )
113         {
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
116                 to ms. */
117                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
118
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 );
123         }
124 }
125 /*-----------------------------------------------------------*/
126
127 static void prvQueueReceiveTask( void *pvParameters )
128 {
129 unsigned long ulReceivedValue;
130
131         for( ;; )
132         {
133                 /* Wait until something arives in the queue - this will block
134                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
135                 FreeRTOSConfig.h. */
136                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
137
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 )
141                 {
142                         vParTestToggleLED( 0 );
143                 }
144         }
145 }
146 /*-----------------------------------------------------------*/
147
148 void vApplicationSetupTimerInterrupt( void )
149 {
150         /* Enable compare match timer 0. */
151         MSTP( CMT0 ) = 0;
152
153         /* Interrupt on compare match. */
154         CMT0.CMCR.BIT.CMIE = 1;
155
156         /* Set the compare match value. */
157         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );
158
159         /* Divide the PCLK by 8. */
160         CMT0.CMCR.BIT.CKS = 0;
161
162         /* Enable the interrupt... */
163         _IEN( _CMT0_CMI0 ) = 1;
164
165         /* ...and set its priority to the application defined kernel priority. */
166         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;
167
168         /* Start the timer. */
169         CMT.CMSTR0.BIT.STR0 = 1;
170 }
171 /*-----------------------------------------------------------*/
172
173 /* This function is explained by the comments above its prototype at the top
174 of this file. */
175 void vApplicationMallocFailedHook( void )
176 {
177         for( ;; );
178 }
179 /*-----------------------------------------------------------*/
180
181 /* This function is explained by the comments above its prototype at the top
182 of this file. */
183 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
184 {
185         for( ;; );
186 }
187 /*-----------------------------------------------------------*/
188
189 /* This function is explained by the comments above its prototype at the top
190 of this file. */
191 void vApplicationIdleHook( void )
192 {
193         /* Just to prevent the variable getting optimised away. */
194         ( void ) ulHighFrequencyTickCount;
195 }
196 /*-----------------------------------------------------------*/
197
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
201 be ignored. */
202 void vT0_1InterruptHandler( void ) {}
203 void vT2_3InterruptHandler( void ) {}