2 FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /******************************************************************************
\r
71 * This project provides two demo applications. A simple blinky style project,
\r
72 * and a more comprehensive test and demo application. The
\r
73 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
\r
74 * select between the two. The simply blinky demo is implemented and described
\r
75 * in main_blinky.c. The more comprehensive test and demo application is
\r
76 * implemented and described in main_full.c.
\r
78 * This file implements the code that is not demo specific, including the
\r
79 * hardware setup and FreeRTOS hook functions.
\r
80 *****************************************************************************/
\r
82 /* Kernel includes. */
\r
83 #include "FreeRTOS.h"
\r
88 /* Target includes. */
\r
90 #include "MEC14xx/mec14xx.h"
\r
91 #include "MEC14xx/mec14xx_jtvic.h"
\r
92 #include "MEC14xx/mec14xx_bbled.h"
\r
93 #include "MEC14xx/mec14xx_girqs.h"
\r
95 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
96 or 0 to run the more comprehensive test and demo application. */
\r
97 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
\r
99 /*-----------------------------------------------------------*/
\r
102 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
103 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
105 extern void main_blinky( void );
\r
106 extern void main_full( void );
\r
109 * Performs any hardware setup necessary.
\r
111 static void __attribute__((nomips16)) prvSetupHardware( void );
\r
114 * Add some thread safety to the LED toggle function.
\r
116 void vToggleLED( uint8_t ucLED );
\r
118 /*-----------------------------------------------------------*/
\r
122 /* Perform any hardware initialisation necessary. */
\r
123 prvSetupHardware();
\r
125 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
127 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
137 /* Should never be reached. */
\r
140 /*-----------------------------------------------------------*/
\r
142 void vToggleLED( uint8_t ucLED )
\r
144 taskENTER_CRITICAL();
\r
146 led_out_toggle( ucLED );
\r
148 taskEXIT_CRITICAL();
\r
150 /*-----------------------------------------------------------*/
\r
152 static void __attribute__((nomips16)) prvSetupHardware( void )
\r
154 volatile uint32_t ulTemp;
\r
156 /* Interrupts are automatically re-enabled when the scheduler is started. */
\r
157 __asm volatile( "di" );
\r
159 /* Enable M14K Vector Pre-fetch: CP0.IntCtl b[22]=1
\r
160 IRET (interrupt chaining): b[21]=1
\r
161 Enable Auto-Prolog: b[14]=1 */
\r
162 ulTemp = _CP0_GET_INTCTL();
\r
163 ulTemp |= ( 1ul << 22 ) + ( 1ul << 21 ) + ( 1ul << 14 );
\r
164 _CP0_SET_INTCTL( ulTemp );
\r
166 /* Configure 32KHz for Switched Clock Source always ON
\r
168 b[ 1 ] = EXT_32K_OSC_EN = 1
\r
169 b[ 2 ] = INT_32K_OSC_EN = 1
\r
170 b[ 3 ] = INT_32K_VTR_PWR_WELL_EMUL = 0
\r
171 b[ 4 ] = 32K_SWITCHER_CTRL = 0 */
\r
172 VBAT_REGS->CLOCK_ENABLE = 0x07;
\r
177 __asm volatile( "NOP" );
\r
178 __asm volatile( "NOP" );
\r
179 __asm volatile( "NOP" );
\r
180 __asm volatile( "NOP" );
\r
183 /* Disaggregate GIRQ23 & GIRQ24 for FreeRTOS. Second parameter is a bit-map
\r
184 for each GIRQ where
\r
185 0 = Aggregated, 1 = Dis-aggregate
\r
186 Bit position = GIRQ_Number - 8
\r
187 Example: GIRQ23 ( 23 - 8 ) = 15
\r
188 Dis-aggregate GIRQ23 & GIRQ24
\r
189 The symbols JTVIC_DISAGR_BITMAP is generated in header file mec14xx_girqm.h
\r
191 Each disaggregated interrupt handler is spaced 8-bytes apart starting at
\r
192 base address for that GIRQ. */
\r
193 jtvic_init( dflt_ih_table, ( JTVIC_DISAGR_BITMAP ), ( JTVIC_FLAG_DISAGR_SPACING_8 ) );
\r
195 /* Initialise the LEDs. */
\r
196 for( ulTemp = 0; ulTemp < LED_ID_MAX; ulTemp++ )
\r
198 led_sleep_en( ulTemp, ADISABLE );
\r
199 led_init( ulTemp );
\r
200 led_out_high( ulTemp );
\r
203 /*-----------------------------------------------------------*/
\r
205 void vApplicationMallocFailedHook( void )
\r
207 /* vApplicationMallocFailedHook() will only be called if
\r
208 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
209 function that will get called if a call to pvPortMalloc() fails.
\r
210 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
211 timer or semaphore is created. It is also called by various parts of the
\r
212 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
213 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
214 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
215 to query the size of free heap space that remains (although it does not
\r
216 provide information on how the remaining heap might be fragmented). */
\r
217 taskDISABLE_INTERRUPTS();
\r
220 /*-----------------------------------------------------------*/
\r
222 void vApplicationIdleHook( void )
\r
224 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
225 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
226 task. It is essential that code added to this hook function never attempts
\r
227 to block in any way (for example, call xQueueReceive() with a block time
\r
228 specified, or call vTaskDelay()). If the application makes use of the
\r
229 vTaskDelete() API function (as this demo application does) then it is also
\r
230 important that vApplicationIdleHook() is permitted to return to its calling
\r
231 function, because it is the responsibility of the idle task to clean up
\r
232 memory allocated by the kernel to any task that has since been deleted. */
\r
234 /*-----------------------------------------------------------*/
\r
236 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
238 ( void ) pcTaskName;
\r
241 /* Run time task stack overflow checking is performed if
\r
242 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
\r
243 called if a task stack overflow is detected. Note the system/interrupt
\r
244 stack is not checked. */
\r
245 taskDISABLE_INTERRUPTS();
\r
248 /*-----------------------------------------------------------*/
\r
250 void vApplicationTickHook( void )
\r
252 /* This function will be called by each tick interrupt if
\r
253 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
254 added here, but the tick hook is called from an interrupt context, so
\r
255 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
256 functions can be used (those that end in FromISR()). */
\r
258 /*-----------------------------------------------------------*/
\r
260 void vAssertCalled( const char * pcFile, unsigned long ulLine )
\r
262 volatile char *pcFileName;
\r
263 volatile unsigned long ulLineNumber;
\r
265 /* Prevent things that are useful to view in the debugger from being
\r
267 pcFileName = ( char * ) pcFile;
\r
268 ( void ) pcFileName;
\r
269 ulLineNumber = ulLine;
\r
271 /* Set ulLineNumber to 0 in the debugger to break out of this loop and
\r
272 return to the line that triggered the assert. */
\r
273 while( ulLineNumber != 0 )
\r
275 __asm volatile( "NOP" );
\r
276 __asm volatile( "NOP" );
\r
277 __asm volatile( "NOP" );
\r
278 __asm volatile( "NOP" );
\r
279 __asm volatile( "NOP" );
\r