]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RX600_RX62N-RSK_IAR/main-blinky.c
c94309e227f62a369393b3d30cf34b8461227916
[freertos] / FreeRTOS / Demo / RX600_RX62N-RSK_IAR / main-blinky.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 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 HEW IDE.\r
37 */\r
38 \r
39 /* Hardware specific includes. */\r
40 #include <iorx62n.h>\r
41 \r
42 /* Kernel includes. */\r
43 #include "FreeRTOS.h"\r
44 #include "task.h"\r
45 #include "queue.h"\r
46 \r
47 /* Demo includes. */\r
48 #include "partest.h"\r
49 \r
50 /* Priorities at which the tasks are created. */\r
51 #define configQUEUE_RECEIVE_TASK_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
52 #define configQUEUE_SEND_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
53 \r
54 /* The rate at which data is sent to the queue, specified in milliseconds. */\r
55 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 500 / portTICK_PERIOD_MS )\r
56 \r
57 /* The number of items the queue can hold.  This is 1 as the receive task\r
58 will remove items as they are added so the send task should always find the\r
59 queue empty. */\r
60 #define mainQUEUE_LENGTH                                        ( 1 )\r
61 \r
62 /*\r
63  * The tasks as defined at the top of this file.\r
64  */\r
65 static void prvQueueReceiveTask( void *pvParameters );\r
66 static void prvQueueSendTask( void *pvParameters );\r
67 \r
68 /* The queue used by both tasks. */\r
69 static QueueHandle_t xQueue = NULL;\r
70 \r
71 /* This variable is not used by this simple Blinky example.  It is defined \r
72 purely to allow the project to link as it is used by the full project. */\r
73 volatile unsigned long ulHighFrequencyTickCount = 0UL;\r
74 /*-----------------------------------------------------------*/\r
75 \r
76 void main(void)\r
77 {\r
78 extern void HardwareSetup( void );\r
79 \r
80         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
81         here. */\r
82         HardwareSetup();\r
83 \r
84         /* Create the queue. */\r
85         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
86 \r
87         if( xQueue != NULL )\r
88         {\r
89                 /* Start the two tasks as described at the top of this file. */\r
90                 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
91                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );\r
92 \r
93                 /* Start the tasks running. */\r
94                 vTaskStartScheduler();\r
95         }\r
96 \r
97         /* If all is well we will never reach here as the scheduler will now be\r
98         running.  If we do reach here then it is likely that there was insufficient\r
99         heap available for the idle task to be created. */\r
100         for( ;; );\r
101 }\r
102 /*-----------------------------------------------------------*/\r
103 \r
104 static void prvQueueSendTask( void *pvParameters )\r
105 {\r
106 TickType_t xNextWakeTime;\r
107 const unsigned long ulValueToSend = 100UL;\r
108 \r
109         /* Initialise xNextWakeTime - this only needs to be done once. */\r
110         xNextWakeTime = xTaskGetTickCount();\r
111 \r
112         for( ;; )\r
113         {\r
114                 /* Place this task in the blocked state until it is time to run again.\r
115                 The block state is specified in ticks, the constant used converts ticks\r
116                 to ms. */\r
117                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
118 \r
119                 /* Send to the queue - causing the queue receive task to flash its LED.  0\r
120                 is used so the send does not block - it shouldn't need to as the queue\r
121                 should always be empty here. */\r
122                 xQueueSend( xQueue, &ulValueToSend, 0 );\r
123         }\r
124 }\r
125 /*-----------------------------------------------------------*/\r
126 \r
127 static void prvQueueReceiveTask( void *pvParameters )\r
128 {\r
129 unsigned long ulReceivedValue;\r
130 \r
131         for( ;; )\r
132         {\r
133                 /* Wait until something arives in the queue - this will block\r
134                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
135                 FreeRTOSConfig.h. */\r
136                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
137 \r
138                 /*  To get here something must have arrived, but is it the expected\r
139                 value?  If it is, toggle the LED. */\r
140                 if( ulReceivedValue == 100UL )\r
141                 {\r
142                         vParTestToggleLED( 0 );\r
143                 }\r
144         }\r
145 }\r
146 /*-----------------------------------------------------------*/\r
147 \r
148 void vApplicationSetupTimerInterrupt( void )\r
149 {\r
150         /* Enable compare match timer 0. */\r
151         MSTP( CMT0 ) = 0;\r
152 \r
153         /* Interrupt on compare match. */\r
154         CMT0.CMCR.BIT.CMIE = 1;\r
155 \r
156         /* Set the compare match value. */\r
157         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
158 \r
159         /* Divide the PCLK by 8. */\r
160         CMT0.CMCR.BIT.CKS = 0;\r
161 \r
162         /* Enable the interrupt... */\r
163         _IEN( _CMT0_CMI0 ) = 1;\r
164 \r
165         /* ...and set its priority to the application defined kernel priority. */\r
166         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
167 \r
168         /* Start the timer. */\r
169         CMT.CMSTR0.BIT.STR0 = 1;\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 /* This function is explained by the comments above its prototype at the top\r
174 of this file. */\r
175 void vApplicationMallocFailedHook( void )\r
176 {\r
177         for( ;; );\r
178 }\r
179 /*-----------------------------------------------------------*/\r
180 \r
181 /* This function is explained by the comments above its prototype at the top\r
182 of this file. */\r
183 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
184 {\r
185         for( ;; );\r
186 }\r
187 /*-----------------------------------------------------------*/\r
188 \r
189 /* This function is explained by the comments above its prototype at the top\r
190 of this file. */\r
191 void vApplicationIdleHook( void )\r
192 {\r
193         /* Just to prevent the variable getting optimised away. */\r
194         ( void ) ulHighFrequencyTickCount;\r
195 }\r
196 /*-----------------------------------------------------------*/\r
197 \r
198 /* The following two functions are here just to allow all three build\r
199 configurations to use the same vector table.  They are not used in this\r
200 demo, but linker errors will result if they are not defined.  They can\r
201 be ignored. */\r
202 void vT0_1InterruptHandler( void ) {}\r
203 void vT2_3InterruptHandler( void ) {}