]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX62N-RDK_IAR/main-blinky.c
eb32a715c0aad5569339989189f37356ccf19041
[freertos] / FreeRTOS / Demo / RX600_RX62N-RDK_IAR / main-blinky.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 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. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /*\r
30  * This is a very simple demo that creates two tasks and one queue.  One task\r
31  * (the queue receive task) blocks on the queue to wait for data to arrive,\r
32  * toggling an LED each time '100' is received.  The other task (the queue send\r
33  * task) repeatedly blocks for a fixed period before sending '100' to the queue\r
34  * (causing the first task to toggle the LED).\r
35  *\r
36  * For a much more complete and complex example select either the Debug or\r
37  * Debug_with_optimisation build configurations within the Embedded Workbench\r
38  * IDE.\r
39 */\r
40 \r
41 /* Hardware specific includes. */\r
42 #include <iorx62n.h>\r
43 \r
44 /* Kernel includes. */\r
45 #include "FreeRTOS.h"\r
46 #include "task.h"\r
47 #include "queue.h"\r
48 \r
49 /* Demo includes. */\r
50 #include "partest.h"\r
51 \r
52 /* Priorities at which the tasks are created. */\r
53 #define configQUEUE_RECEIVE_TASK_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
54 #define configQUEUE_SEND_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
55 \r
56 /* The rate at which data is sent to the queue, specified in milliseconds. */\r
57 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 500 / portTICK_PERIOD_MS )\r
58 \r
59 /* The number of items the queue can hold.  This is 1 as the receive task\r
60 will remove items as they are added so the send task should always find the\r
61 queue empty. */\r
62 #define mainQUEUE_LENGTH                                        ( 1 )\r
63 \r
64 /*\r
65  * The tasks as defined at the top of this file.\r
66  */\r
67 static void prvQueueReceiveTask( void *pvParameters );\r
68 static void prvQueueSendTask( void *pvParameters );\r
69 \r
70 /* The queue used by both tasks. */\r
71 static QueueHandle_t xQueue = NULL;\r
72 \r
73 /* This variable is not used by this simple Blinky example.  It is defined\r
74 purely to allow the project to link as it is used by the full project. */\r
75 volatile unsigned long ulHighFrequencyTickCount = 0UL;\r
76 /*-----------------------------------------------------------*/\r
77 \r
78 void main(void)\r
79 {\r
80 extern void HardwareSetup( void );\r
81 \r
82         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
83         here. */\r
84         HardwareSetup();\r
85 \r
86         /* Create the queue. */\r
87         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
88 \r
89         if( xQueue != NULL )\r
90         {\r
91                 /* Start the two tasks as described at the top of this file. */\r
92                 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
93                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );\r
94 \r
95                 /* Start the tasks running. */\r
96                 vTaskStartScheduler();\r
97         }\r
98 \r
99         /* If all is well we will never reach here as the scheduler will now be\r
100         running.  If we do reach here then it is likely that there was insufficient\r
101         heap available for the idle task to be created. */\r
102         for( ;; );\r
103 }\r
104 /*-----------------------------------------------------------*/\r
105 \r
106 static void prvQueueSendTask( void *pvParameters )\r
107 {\r
108 TickType_t xNextWakeTime;\r
109 const unsigned long ulValueToSend = 100UL;\r
110 \r
111         /* Initialise xNextWakeTime - this only needs to be done once. */\r
112         xNextWakeTime = xTaskGetTickCount();\r
113 \r
114         for( ;; )\r
115         {\r
116                 /* Place this task in the blocked state until it is time to run again.\r
117                 The block state is specified in ticks, the constant used converts ticks\r
118                 to ms. */\r
119                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
120 \r
121                 /* Send to the queue - causing the queue receive task to flash its LED.  0\r
122                 is used so the send does not block - it shouldn't need to as the queue\r
123                 should always be empty here. */\r
124                 xQueueSend( xQueue, &ulValueToSend, 0 );\r
125         }\r
126 }\r
127 /*-----------------------------------------------------------*/\r
128 \r
129 static void prvQueueReceiveTask( void *pvParameters )\r
130 {\r
131 unsigned long ulReceivedValue;\r
132 \r
133         for( ;; )\r
134         {\r
135                 /* Wait until something arives in the queue - this will block\r
136                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
137                 FreeRTOSConfig.h. */\r
138                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
139 \r
140                 /*  To get here something must have arrived, but is it the expected\r
141                 value?  If it is, toggle the LED. */\r
142                 if( ulReceivedValue == 100UL )\r
143                 {\r
144                         vParTestToggleLED( 0 );\r
145                 }\r
146         }\r
147 }\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 void vApplicationSetupTimerInterrupt( void )\r
151 {\r
152         /* Enable compare match timer 0. */\r
153         MSTP( CMT0 ) = 0;\r
154 \r
155         /* Interrupt on compare match. */\r
156         CMT0.CMCR.BIT.CMIE = 1;\r
157 \r
158         /* Set the compare match value. */\r
159         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
160 \r
161         /* Divide the PCLK by 8. */\r
162         CMT0.CMCR.BIT.CKS = 0;\r
163 \r
164         /* Enable the interrupt... */\r
165         _IEN( _CMT0_CMI0 ) = 1;\r
166 \r
167         /* ...and set its priority to the application defined kernel priority. */\r
168         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
169 \r
170         /* Start the timer. */\r
171         CMT.CMSTR0.BIT.STR0 = 1;\r
172 }\r
173 /*-----------------------------------------------------------*/\r
174 \r
175 /* This function is explained by the comments above its prototype at the top\r
176 of this file. */\r
177 void vApplicationMallocFailedHook( void )\r
178 {\r
179         for( ;; );\r
180 }\r
181 /*-----------------------------------------------------------*/\r
182 \r
183 /* This function is explained by the comments above its prototype at the top\r
184 of this file. */\r
185 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
186 {\r
187         for( ;; );\r
188 }\r
189 /*-----------------------------------------------------------*/\r
190 \r
191 /* This function is explained by the comments above its prototype at the top\r
192 of this file. */\r
193 void vApplicationIdleHook( void )\r
194 {\r
195         /* Just to prevent the variable getting optimised away. */\r
196         ( void ) ulHighFrequencyTickCount;\r
197 }\r
198 /*-----------------------------------------------------------*/\r
199 \r
200 /* The following two functions are here just to allow all three build\r
201 configurations to use the same vector table.  They are not used in this\r
202 demo, but linker errors will result if they are not defined.  They can\r
203 be ignored. */\r
204 void vT0_1InterruptHandler( void ) {}\r
205 void vT2_3InterruptHandler( void ) {}