]> git.sur5r.net Git - freertos/blob - Demo/RX600_RX62N-RDK_IAR/main-blinky.c
Added BSP generation files to MicroBlaze directory.
[freertos] / Demo / RX600_RX62N-RDK_IAR / main-blinky.c
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /*\r
55  * This is a very simple demo that creates two tasks and one queue.  One task\r
56  * (the queue receive task) blocks on the queue to wait for data to arrive,\r
57  * toggling an LED each time '100' is received.  The other task (the queue send\r
58  * task) repeatedly blocks for a fixed period before sending '100' to the queue\r
59  * (causing the first task to toggle the LED).\r
60  *\r
61  * For a much more complete and complex example select either the Debug or\r
62  * Debug_with_optimisation build configurations within the Embedded Workbench\r
63  * IDE.\r
64 */\r
65 \r
66 /* Hardware specific includes. */\r
67 #include <iorx62n.h>\r
68 \r
69 /* Kernel includes. */\r
70 #include "FreeRTOS.h"\r
71 #include "task.h"\r
72 #include "queue.h"\r
73 \r
74 /* Demo includes. */\r
75 #include "partest.h"\r
76 \r
77 /* Priorities at which the tasks are created. */\r
78 #define configQUEUE_RECEIVE_TASK_PRIORITY       ( tskIDLE_PRIORITY + 1 )\r
79 #define configQUEUE_SEND_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
80 \r
81 /* The rate at which data is sent to the queue, specified in milliseconds. */\r
82 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 500 / portTICK_RATE_MS )\r
83 \r
84 /* The number of items the queue can hold.  This is 1 as the receive task\r
85 will remove items as they are added so the send task should always find the\r
86 queue empty. */\r
87 #define mainQUEUE_LENGTH                                        ( 1 )\r
88 \r
89 /*\r
90  * The tasks as defined at the top of this file.\r
91  */\r
92 static void prvQueueReceiveTask( void *pvParameters );\r
93 static void prvQueueSendTask( void *pvParameters );\r
94 \r
95 /* The queue used by both tasks. */\r
96 static xQueueHandle xQueue = NULL;\r
97 \r
98 /* This variable is not used by this simple Blinky example.  It is defined\r
99 purely to allow the project to link as it is used by the full project. */\r
100 volatile unsigned long ulHighFrequencyTickCount = 0UL;\r
101 /*-----------------------------------------------------------*/\r
102 \r
103 void main(void)\r
104 {\r
105 extern void HardwareSetup( void );\r
106 \r
107         /* Renesas provided CPU configuration routine.  The clocks are configured in\r
108         here. */\r
109         HardwareSetup();\r
110 \r
111         /* Create the queue. */\r
112         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
113 \r
114         if( xQueue != NULL )\r
115         {\r
116                 /* Start the two tasks as described at the top of this file. */\r
117                 xTaskCreate( prvQueueReceiveTask, "Rx", configMINIMAL_STACK_SIZE, NULL, configQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
118                 xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, configQUEUE_SEND_TASK_PRIORITY, NULL );\r
119 \r
120                 /* Start the tasks running. */\r
121                 vTaskStartScheduler();\r
122         }\r
123 \r
124         /* If all is well we will never reach here as the scheduler will now be\r
125         running.  If we do reach here then it is likely that there was insufficient\r
126         heap available for the idle task to be created. */\r
127         for( ;; );\r
128 }\r
129 /*-----------------------------------------------------------*/\r
130 \r
131 static void prvQueueSendTask( void *pvParameters )\r
132 {\r
133 portTickType xNextWakeTime;\r
134 const unsigned long ulValueToSend = 100UL;\r
135 \r
136         /* Initialise xNextWakeTime - this only needs to be done once. */\r
137         xNextWakeTime = xTaskGetTickCount();\r
138 \r
139         for( ;; )\r
140         {\r
141                 /* Place this task in the blocked state until it is time to run again.\r
142                 The block state is specified in ticks, the constant used converts ticks\r
143                 to ms. */\r
144                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
145 \r
146                 /* Send to the queue - causing the queue receive task to flash its LED.  0\r
147                 is used so the send does not block - it shouldn't need to as the queue\r
148                 should always be empty here. */\r
149                 xQueueSend( xQueue, &ulValueToSend, 0 );\r
150         }\r
151 }\r
152 /*-----------------------------------------------------------*/\r
153 \r
154 static void prvQueueReceiveTask( void *pvParameters )\r
155 {\r
156 unsigned long ulReceivedValue;\r
157 \r
158         for( ;; )\r
159         {\r
160                 /* Wait until something arives in the queue - this will block\r
161                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
162                 FreeRTOSConfig.h. */\r
163                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
164 \r
165                 /*  To get here something must have arrived, but is it the expected\r
166                 value?  If it is, toggle the LED. */\r
167                 if( ulReceivedValue == 100UL )\r
168                 {\r
169                         vParTestToggleLED( 0 );\r
170                 }\r
171         }\r
172 }\r
173 /*-----------------------------------------------------------*/\r
174 \r
175 void vApplicationSetupTimerInterrupt( void )\r
176 {\r
177         /* Enable compare match timer 0. */\r
178         MSTP( CMT0 ) = 0;\r
179 \r
180         /* Interrupt on compare match. */\r
181         CMT0.CMCR.BIT.CMIE = 1;\r
182 \r
183         /* Set the compare match value. */\r
184         CMT0.CMCOR = ( unsigned short ) ( ( ( configPERIPHERAL_CLOCK_HZ / configTICK_RATE_HZ ) -1 ) / 8 );\r
185 \r
186         /* Divide the PCLK by 8. */\r
187         CMT0.CMCR.BIT.CKS = 0;\r
188 \r
189         /* Enable the interrupt... */\r
190         _IEN( _CMT0_CMI0 ) = 1;\r
191 \r
192         /* ...and set its priority to the application defined kernel priority. */\r
193         _IPR( _CMT0_CMI0 ) = configKERNEL_INTERRUPT_PRIORITY;\r
194 \r
195         /* Start the timer. */\r
196         CMT.CMSTR0.BIT.STR0 = 1;\r
197 }\r
198 /*-----------------------------------------------------------*/\r
199 \r
200 /* This function is explained by the comments above its prototype at the top\r
201 of this file. */\r
202 void vApplicationMallocFailedHook( void )\r
203 {\r
204         for( ;; );\r
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 /* This function is explained by the comments above its prototype at the top\r
209 of this file. */\r
210 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
211 {\r
212         for( ;; );\r
213 }\r
214 /*-----------------------------------------------------------*/\r
215 \r
216 /* This function is explained by the comments above its prototype at the top\r
217 of this file. */\r
218 void vApplicationIdleHook( void )\r
219 {\r
220         /* Just to prevent the variable getting optimised away. */\r
221         ( void ) ulHighFrequencyTickCount;\r
222 }\r
223 /*-----------------------------------------------------------*/\r
224 \r
225 /* The following two functions are here just to allow all three build\r
226 configurations to use the same vector table.  They are not used in this\r
227 demo, but linker errors will result if they are not defined.  They can\r
228 be ignored. */\r
229 void vT0_1InterruptHandler( void ) {}\r
230 void vT2_3InterruptHandler( void ) {}