2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
69 /* Scheduler includes. */
\r
70 #include "FreeRTOS.h"
\r
73 /*-----------------------------------------------------------
\r
74 * Implementation of functions defined in portable.h for the MSP430X port.
\r
75 *----------------------------------------------------------*/
\r
77 /* Constants required for hardware setup. The tick ISR runs off the ACLK,
\r
79 #define portACLK_FREQUENCY_HZ ( ( portTickType ) 32768 )
\r
80 #define portINITIAL_CRITICAL_NESTING ( ( unsigned short ) 10 )
\r
81 #define portFLAGS_INT_ENABLED ( ( portSTACK_TYPE ) 0x08 )
\r
83 /* We require the address of the pxCurrentTCB variable, but don't want to know
\r
84 any details of its type. */
\r
85 typedef void tskTCB;
\r
86 extern volatile tskTCB * volatile pxCurrentTCB;
\r
88 /* Each task maintains a count of the critical section nesting depth. Each
\r
89 time a critical section is entered the count is incremented. Each time a
\r
90 critical section is exited the count is decremented - with interrupts only
\r
91 being re-enabled if the count is zero.
\r
93 usCriticalNesting will get set to zero when the scheduler starts, but must
\r
94 not be initialised to zero as this will cause problems during the startup
\r
96 volatile unsigned short usCriticalNesting = portINITIAL_CRITICAL_NESTING;
\r
97 /*-----------------------------------------------------------*/
\r
101 * Sets up the periodic ISR used for the RTOS tick. This uses timer 0, but
\r
102 * could have alternatively used the watchdog timer or timer 1.
\r
104 void vPortSetupTimerInterrupt( void );
\r
105 /*-----------------------------------------------------------*/
\r
108 * Initialise the stack of a task to look exactly as if a call to
\r
109 * portSAVE_CONTEXT had been called.
\r
111 * See the header file portable.h.
\r
113 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
115 unsigned short *pusTopOfStack;
\r
116 unsigned long *pulTopOfStack;
\r
119 Place a few bytes of known values on the bottom of the stack.
\r
120 This is just useful for debugging and can be included if required.
\r
122 *pxTopOfStack = ( portSTACK_TYPE ) 0x1111;
\r
124 *pxTopOfStack = ( portSTACK_TYPE ) 0x2222;
\r
126 *pxTopOfStack = ( portSTACK_TYPE ) 0x3333;
\r
129 /* portSTACK_TYPE is either 16 bits or 32 bits depending on the data model.
\r
130 Some stacked items do not change size depending on the data model so have
\r
131 to be explicitly cast to the correct size so this function will work
\r
132 whichever data model is being used. */
\r
133 if( sizeof( portSTACK_TYPE ) == sizeof( unsigned short ) )
\r
135 /* Make room for a 20 bit value stored as a 32 bit value. */
\r
136 pusTopOfStack = ( unsigned short * ) pxTopOfStack;
\r
138 pulTopOfStack = ( unsigned long * ) pusTopOfStack;
\r
142 pulTopOfStack = ( unsigned long * ) pxTopOfStack;
\r
144 *pulTopOfStack = ( unsigned long ) pxCode;
\r
146 pusTopOfStack = ( unsigned short * ) pulTopOfStack;
\r
148 *pusTopOfStack = portFLAGS_INT_ENABLED;
\r
149 pusTopOfStack -= ( sizeof( portSTACK_TYPE ) / 2 );
\r
151 /* From here on the size of stacked items depends on the memory model. */
\r
152 pxTopOfStack = ( portSTACK_TYPE * ) pusTopOfStack;
\r
154 /* Next the general purpose registers. */
\r
155 #ifdef PRELOAD_REGISTER_VALUES
\r
156 *pxTopOfStack = ( portSTACK_TYPE ) 0xffff;
\r
158 *pxTopOfStack = ( portSTACK_TYPE ) 0xeeee;
\r
160 *pxTopOfStack = ( portSTACK_TYPE ) 0xdddd;
\r
162 *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
\r
164 *pxTopOfStack = ( portSTACK_TYPE ) 0xbbbb;
\r
166 *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaa;
\r
168 *pxTopOfStack = ( portSTACK_TYPE ) 0x9999;
\r
170 *pxTopOfStack = ( portSTACK_TYPE ) 0x8888;
\r
172 *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;
\r
174 *pxTopOfStack = ( portSTACK_TYPE ) 0x6666;
\r
176 *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;
\r
178 *pxTopOfStack = ( portSTACK_TYPE ) 0x4444;
\r
182 *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
\r
187 /* A variable is used to keep track of the critical section nesting.
\r
188 This variable has to be stored as part of the task context and is
\r
189 initially set to zero. */
\r
190 *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;
\r
192 /* Return a pointer to the top of the stack we have generated so this can
\r
193 be stored in the task control block for the task. */
\r
194 return pxTopOfStack;
\r
196 /*-----------------------------------------------------------*/
\r
198 void vPortEndScheduler( void )
\r
200 /* It is unlikely that the MSP430 port will get stopped. If required simply
\r
201 disable the tick interrupt here. */
\r
203 /*-----------------------------------------------------------*/
\r
206 * Hardware initialisation to generate the RTOS tick.
\r
208 void vPortSetupTimerInterrupt( void )
\r
210 vApplicationSetupTimerInterrupt();
\r
212 /*-----------------------------------------------------------*/
\r
214 #pragma vector=configTICK_VECTOR
\r
215 __interrupt __raw void vTickISREntry( void )
\r
217 extern void vPortTickISR( void );
\r
219 __bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF );
\r