]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX62N-RDK_IAR/main-blinky.c
03b8b938a760499c3280b9926fe2582383f65f9b
[freertos] / FreeRTOS / Demo / RX600_RX62N-RDK_IAR / main-blinky.c
1 /*\r
2  * FreeRTOS Kernel V10.2.1\r
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\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
34  *\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
37  * IDE.\r
38 */\r
39 \r
40 /* Hardware specific includes. */\r
41 #include <iorx62n.h>\r
42 \r
43 /* Kernel includes. */\r
44 #include "FreeRTOS.h"\r
45 #include "task.h"\r
46 #include "queue.h"\r
47 \r
48 /* Demo includes. */\r
49 #include "partest.h"\r
50 \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
54 \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
57 \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
60 queue empty. */\r
61 #define mainQUEUE_LENGTH                                        ( 1 )\r
62 \r
63 /*\r
64  * The tasks as defined at the top of this file.\r
65  */\r
66 static void prvQueueReceiveTask( void *pvParameters );\r
67 static void prvQueueSendTask( void *pvParameters );\r
68 \r
69 /* The queue used by both tasks. */\r
70 static QueueHandle_t xQueue = NULL;\r
71 \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
76 \r
77 void main(void)\r
78 {\r
79 extern void HardwareSetup( void );\r
80 \r
81         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
82         here. */\r
83         HardwareSetup();\r
84 \r
85         /* Create the queue. */\r
86         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
87 \r
88         if( xQueue != NULL )\r
89         {\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
93 \r
94                 /* Start the tasks running. */\r
95                 vTaskStartScheduler();\r
96         }\r
97 \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
101         for( ;; );\r
102 }\r
103 /*-----------------------------------------------------------*/\r
104 \r
105 static void prvQueueSendTask( void *pvParameters )\r
106 {\r
107 TickType_t xNextWakeTime;\r
108 const unsigned long ulValueToSend = 100UL;\r
109 \r
110         /* Initialise xNextWakeTime - this only needs to be done once. */\r
111         xNextWakeTime = xTaskGetTickCount();\r
112 \r
113         for( ;; )\r
114         {\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
117                 to ms. */\r
118                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
119 \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
124         }\r
125 }\r
126 /*-----------------------------------------------------------*/\r
127 \r
128 static void prvQueueReceiveTask( void *pvParameters )\r
129 {\r
130 unsigned long ulReceivedValue;\r
131 \r
132         for( ;; )\r
133         {\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
138 \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
142                 {\r
143                         vParTestToggleLED( 0 );\r
144                 }\r
145         }\r
146 }\r
147 /*-----------------------------------------------------------*/\r
148 \r
149 void vApplicationSetupTimerInterrupt( void )\r
150 {\r
151         /* Enable compare match timer 0. */\r
152         MSTP( CMT0 ) = 0;\r
153 \r
154         /* Interrupt on compare match. */\r
155         CMT0.CMCR.BIT.CMIE = 1;\r
156 \r
157         /* Set the compare match value. */\r
158         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
159 \r
160         /* Divide the PCLK by 8. */\r
161         CMT0.CMCR.BIT.CKS = 0;\r
162 \r
163         /* Enable the interrupt... */\r
164         _IEN( _CMT0_CMI0 ) = 1;\r
165 \r
166         /* ...and set its priority to the application defined kernel priority. */\r
167         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
168 \r
169         /* Start the timer. */\r
170         CMT.CMSTR0.BIT.STR0 = 1;\r
171 }\r
172 /*-----------------------------------------------------------*/\r
173 \r
174 /* This function is explained by the comments above its prototype at the top\r
175 of this file. */\r
176 void vApplicationMallocFailedHook( void )\r
177 {\r
178         for( ;; );\r
179 }\r
180 /*-----------------------------------------------------------*/\r
181 \r
182 /* This function is explained by the comments above its prototype at the top\r
183 of this file. */\r
184 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
185 {\r
186         for( ;; );\r
187 }\r
188 /*-----------------------------------------------------------*/\r
189 \r
190 /* This function is explained by the comments above its prototype at the top\r
191 of this file. */\r
192 void vApplicationIdleHook( void )\r
193 {\r
194         /* Just to prevent the variable getting optimised away. */\r
195         ( void ) ulHighFrequencyTickCount;\r
196 }\r
197 /*-----------------------------------------------------------*/\r
198 \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
202 be ignored. */\r
203 void vT0_1InterruptHandler( void ) {}\r
204 void vT2_3InterruptHandler( void ) {}