2 FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /* Scheduler includes. */
\r
67 #include "FreeRTOS.h"
\r
70 /*-----------------------------------------------------------
\r
71 * Implementation of functions defined in portable.h for the MSP430X port.
\r
72 *----------------------------------------------------------*/
\r
74 /* Constants required for hardware setup. The tick ISR runs off the ACLK,
\r
76 #define portACLK_FREQUENCY_HZ ( ( TickType_t ) 32768 )
\r
77 #define portINITIAL_CRITICAL_NESTING ( ( uint16_t ) 10 )
\r
78 #define portFLAGS_INT_ENABLED ( ( StackType_t ) 0x08 )
\r
80 /* We require the address of the pxCurrentTCB variable, but don't want to know
\r
81 any details of its type. */
\r
83 extern volatile TCB_t * volatile pxCurrentTCB;
\r
85 /* Each task maintains a count of the critical section nesting depth. Each
\r
86 time a critical section is entered the count is incremented. Each time a
\r
87 critical section is exited the count is decremented - with interrupts only
\r
88 being re-enabled if the count is zero.
\r
90 usCriticalNesting will get set to zero when the scheduler starts, but must
\r
91 not be initialised to zero as this will cause problems during the startup
\r
93 volatile uint16_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;
\r
94 /*-----------------------------------------------------------*/
\r
98 * Sets up the periodic ISR used for the RTOS tick. This uses timer 0, but
\r
99 * could have alternatively used the watchdog timer or timer 1.
\r
101 void vPortSetupTimerInterrupt( void );
\r
102 /*-----------------------------------------------------------*/
\r
105 * Initialise the stack of a task to look exactly as if a call to
\r
106 * portSAVE_CONTEXT had been called.
\r
108 * See the header file portable.h.
\r
110 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
112 uint16_t *pusTopOfStack;
\r
113 uint32_t *pulTopOfStack, ulTemp;
\r
116 Place a few bytes of known values on the bottom of the stack.
\r
117 This is just useful for debugging and can be included if required.
\r
119 *pxTopOfStack = ( StackType_t ) 0x1111;
\r
121 *pxTopOfStack = ( StackType_t ) 0x2222;
\r
123 *pxTopOfStack = ( StackType_t ) 0x3333;
\r
127 /* Data types are need either 16 bits or 32 bits depending on the data
\r
128 and code model used. */
\r
129 if( sizeof( pxCode ) == sizeof( uint16_t ) )
\r
131 pusTopOfStack = ( uint16_t * ) pxTopOfStack;
\r
132 ulTemp = ( uint32_t ) pxCode;
\r
133 *pusTopOfStack = ( uint16_t ) ulTemp;
\r
137 /* Make room for a 20 bit value stored as a 32 bit value. */
\r
138 pusTopOfStack = ( uint16_t * ) pxTopOfStack;
\r
140 pulTopOfStack = ( uint32_t * ) pusTopOfStack;
\r
141 *pulTopOfStack = ( uint32_t ) pxCode;
\r
145 *pusTopOfStack = portFLAGS_INT_ENABLED;
\r
146 pusTopOfStack -= ( sizeof( StackType_t ) / 2 );
\r
148 /* From here on the size of stacked items depends on the memory model. */
\r
149 pxTopOfStack = ( StackType_t * ) pusTopOfStack;
\r
151 /* Next the general purpose registers. */
\r
152 #ifdef PRELOAD_REGISTER_VALUES
\r
153 *pxTopOfStack = ( StackType_t ) 0xffff;
\r
155 *pxTopOfStack = ( StackType_t ) 0xeeee;
\r
157 *pxTopOfStack = ( StackType_t ) 0xdddd;
\r
159 *pxTopOfStack = ( StackType_t ) pvParameters;
\r
161 *pxTopOfStack = ( StackType_t ) 0xbbbb;
\r
163 *pxTopOfStack = ( StackType_t ) 0xaaaa;
\r
165 *pxTopOfStack = ( StackType_t ) 0x9999;
\r
167 *pxTopOfStack = ( StackType_t ) 0x8888;
\r
169 *pxTopOfStack = ( StackType_t ) 0x5555;
\r
171 *pxTopOfStack = ( StackType_t ) 0x6666;
\r
173 *pxTopOfStack = ( StackType_t ) 0x5555;
\r
175 *pxTopOfStack = ( StackType_t ) 0x4444;
\r
179 *pxTopOfStack = ( StackType_t ) pvParameters;
\r
183 /* A variable is used to keep track of the critical section nesting.
\r
184 This variable has to be stored as part of the task context and is
\r
185 initially set to zero. */
\r
186 *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;
\r
188 /* Return a pointer to the top of the stack we have generated so this can
\r
189 be stored in the task control block for the task. */
\r
190 return pxTopOfStack;
\r
192 /*-----------------------------------------------------------*/
\r
194 void vPortEndScheduler( void )
\r
196 /* It is unlikely that the MSP430 port will get stopped. If required simply
\r
197 disable the tick interrupt here. */
\r
199 /*-----------------------------------------------------------*/
\r
202 * Hardware initialisation to generate the RTOS tick.
\r
204 void vPortSetupTimerInterrupt( void )
\r
206 vApplicationSetupTimerInterrupt();
\r
208 /*-----------------------------------------------------------*/
\r
210 #pragma vector=configTICK_VECTOR
\r
211 interrupt void vTickISREntry( void )
\r
213 extern void vPortTickISR( void );
\r
215 __bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF );
\r
216 #if configUSE_PREEMPTION == 1
\r
217 extern void vPortPreemptiveTickISR( void );
\r
218 vPortPreemptiveTickISR();
\r
220 extern void vPortCooperativeTickISR( void );
\r
221 vPortCooperativeTickISR();
\r