2 FreeRTOS V9.0.0 - Copyright (C) 2016 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 /* Standard includes. */
\r
73 /* Scheduler includes. */
\r
74 #include "FreeRTOS.h"
\r
77 /* The critical nesting value is initialised to a non zero value to ensure
\r
78 interrupts don't accidentally become enabled before the scheduler is started. */
\r
79 #define portINITIAL_CRITICAL_NESTING (( uint16_t ) 10)
\r
81 /* Initial PSW value allocated to a newly created task.
\r
83 * ||||||||-------------- Fill byte
\r
84 * |||||||--------------- Carry Flag cleared
\r
85 * |||||----------------- In-service priority Flags set to low level
\r
86 * ||||------------------ Register bank Select 0 Flag cleared
\r
87 * |||------------------- Auxiliary Carry Flag cleared
\r
88 * ||-------------------- Register bank Select 1 Flag cleared
\r
89 * |--------------------- Zero Flag set
\r
90 * ---------------------- Global Interrupt Flag set (enabled)
\r
92 #define portPSW (0xc6UL)
\r
94 /* We require the address of the pxCurrentTCB variable, but don't want to know
\r
95 any details of its type. */
\r
97 extern volatile TCB_t * volatile pxCurrentTCB;
\r
99 /* Most ports implement critical sections by placing the interrupt flags on
\r
100 the stack before disabling interrupts. Exiting the critical section is then
\r
101 simply a case of popping the flags from the stack. As 78K0 IAR does not use
\r
102 a frame pointer this cannot be done as modifying the stack will clobber all
\r
103 the stack variables. Instead each task maintains a count of the critical
\r
104 section nesting depth. Each time a critical section is entered the count is
\r
105 incremented. Each time a critical section is left the count is decremented -
\r
106 with interrupts only being re-enabled if the count is zero.
\r
108 usCriticalNesting will get set to zero when the scheduler starts, but must
\r
109 not be initialised to zero as this will cause problems during the startup
\r
111 volatile uint16_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;
\r
112 /*-----------------------------------------------------------*/
\r
115 * Sets up the periodic ISR used for the RTOS tick.
\r
117 static void prvSetupTimerInterrupt( void );
\r
118 /*-----------------------------------------------------------*/
\r
121 * Initialise the stack of a task to look exactly as if a call to
\r
122 * portSAVE_CONTEXT had been called.
\r
124 * See the header file portable.h.
\r
126 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
128 uint32_t *pulLocal;
\r
130 #if configMEMORY_MODE == 1
\r
132 /* Parameters are passed in on the stack, and written using a 32bit value
\r
133 hence a space is left for the second two bytes. */
\r
136 /* Write in the parameter value. */
\r
137 pulLocal = ( uint32_t * ) pxTopOfStack;
\r
138 *pulLocal = ( uint32_t ) pvParameters;
\r
141 /* These values are just spacers. The return address of the function
\r
142 would normally be written here. */
\r
143 *pxTopOfStack = ( StackType_t ) 0xcdcd;
\r
145 *pxTopOfStack = ( StackType_t ) 0xcdcd;
\r
148 /* The start address / PSW value is also written in as a 32bit value,
\r
149 so leave a space for the second two bytes. */
\r
152 /* Task function start address combined with the PSW. */
\r
153 pulLocal = ( uint32_t * ) pxTopOfStack;
\r
154 *pulLocal = ( ( ( uint32_t ) pxCode ) | ( portPSW << 24UL ) );
\r
157 /* An initial value for the AX register. */
\r
158 *pxTopOfStack = ( StackType_t ) 0x1111;
\r
163 /* Task function address is written to the stack first. As it is
\r
164 written as a 32bit value a space is left on the stack for the second
\r
168 /* Task function start address combined with the PSW. */
\r
169 pulLocal = ( uint32_t * ) pxTopOfStack;
\r
170 *pulLocal = ( ( ( uint32_t ) pxCode ) | ( portPSW << 24UL ) );
\r
173 /* The parameter is passed in AX. */
\r
174 *pxTopOfStack = ( StackType_t ) pvParameters;
\r
179 /* An initial value for the HL register. */
\r
180 *pxTopOfStack = ( StackType_t ) 0x2222;
\r
183 /* CS and ES registers. */
\r
184 *pxTopOfStack = ( StackType_t ) 0x0F00;
\r
187 /* Finally the remaining general purpose registers DE and BC */
\r
188 *pxTopOfStack = ( StackType_t ) 0xDEDE;
\r
190 *pxTopOfStack = ( StackType_t ) 0xBCBC;
\r
193 /* Finally the critical section nesting count is set to zero when the task
\r
195 *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;
\r
197 /* Return a pointer to the top of the stack we have generated so this can
\r
198 be stored in the task control block for the task. */
\r
199 return pxTopOfStack;
\r
201 /*-----------------------------------------------------------*/
\r
203 BaseType_t xPortStartScheduler( void )
\r
205 /* Setup the hardware to generate the tick. Interrupts are disabled when
\r
206 this function is called. */
\r
207 prvSetupTimerInterrupt();
\r
209 /* Restore the context of the first task that is going to run. */
\r
212 /* Should not get here as the tasks are now running! */
\r
215 /*-----------------------------------------------------------*/
\r
217 void vPortEndScheduler( void )
\r
219 /* It is unlikely that the 78K0R port will get stopped. If required simply
\r
220 disable the tick interrupt here. */
\r
222 /*-----------------------------------------------------------*/
\r
224 static void prvSetupTimerInterrupt( void )
\r
226 /* Setup channel 5 of the TAU to generate the tick interrupt. */
\r
228 /* First the Timer Array Unit has to be enabled. */
\r
231 /* To configure the Timer Array Unit all Channels have to first be stopped. */
\r
234 /* Interrupt of Timer Array Unit Channel 5 is disabled to set the interrupt
\r
238 /* Clear Timer Array Unit Channel 5 interrupt flag. */
\r
241 /* Set Timer Array Unit Channel 5 interrupt priority */
\r
245 /* Set Timer Array Unit Channel 5 Mode as interval timer. */
\r
248 /* Set the compare match value according to the tick rate we want. */
\r
249 TDR05 = ( TickType_t ) ( configCPU_CLOCK_HZ / configTICK_RATE_HZ );
\r
251 /* Set Timer Array Unit Channel 5 output mode */
\r
254 /* Set Timer Array Unit Channel 5 output level */
\r
257 /* Set Timer Array Unit Channel 5 output enable */
\r
260 /* Interrupt of Timer Array Unit Channel 5 enabled */
\r
263 /* Start Timer Array Unit Channel 5.*/
\r
266 /*-----------------------------------------------------------*/
\r