]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/MSP430X/port.c
Prepare for V7.3.0 release.
[freertos] / FreeRTOS / Source / portable / IAR / MSP430X / port.c
1 /*\r
2     FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3 \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
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\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
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \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
42     FreeRTOS WEB site.\r
43 \r
44     1 tab == 4 spaces!\r
45     \r
46     ***************************************************************************\r
47      *                                                                       *\r
48      *    Having a problem?  Start by reading the FAQ "My application does   *\r
49      *    not run, what could be wrong?"                                     *\r
50      *                                                                       *\r
51      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
52      *                                                                       *\r
53     ***************************************************************************\r
54 \r
55     \r
56     http://www.FreeRTOS.org - Documentation, training, latest versions, license \r
57     and contact details.  \r
58     \r
59     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
60     including FreeRTOS+Trace - an indispensable productivity tool.\r
61 \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
67 */\r
68 \r
69 /* Scheduler includes. */\r
70 #include "FreeRTOS.h"\r
71 #include "task.h"\r
72 \r
73 /*-----------------------------------------------------------\r
74  * Implementation of functions defined in portable.h for the MSP430X port.\r
75  *----------------------------------------------------------*/\r
76 \r
77 /* Constants required for hardware setup.  The tick ISR runs off the ACLK,\r
78 not the MCLK. */\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
82 \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
87 \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
92 \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
95 sequence. */\r
96 volatile unsigned short usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
97 /*-----------------------------------------------------------*/\r
98 \r
99 \r
100 /*\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
103  */\r
104 void vPortSetupTimerInterrupt( void );\r
105 /*-----------------------------------------------------------*/\r
106 \r
107 /*\r
108  * Initialise the stack of a task to look exactly as if a call to\r
109  * portSAVE_CONTEXT had been called.\r
110  *\r
111  * See the header file portable.h.\r
112  */\r
113 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
114 {\r
115 unsigned short *pusTopOfStack;\r
116 unsigned long *pulTopOfStack;\r
117 \r
118         /*\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
121         \r
122                 *pxTopOfStack = ( portSTACK_TYPE ) 0x1111;\r
123                 pxTopOfStack--;\r
124                 *pxTopOfStack = ( portSTACK_TYPE ) 0x2222;\r
125                 pxTopOfStack--;\r
126                 *pxTopOfStack = ( portSTACK_TYPE ) 0x3333;\r
127         */\r
128 \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
134         {\r
135                 /* Make room for a 20 bit value stored as a 32 bit value. */\r
136                 pusTopOfStack = ( unsigned short * ) pxTopOfStack;\r
137                 pusTopOfStack--;\r
138                 pulTopOfStack = ( unsigned long * ) pusTopOfStack;\r
139         }\r
140         else\r
141         {\r
142                 pulTopOfStack = ( unsigned long * ) pxTopOfStack;\r
143         }\r
144         *pulTopOfStack = ( unsigned long ) pxCode;\r
145         \r
146         pusTopOfStack = ( unsigned short * ) pulTopOfStack;\r
147         pusTopOfStack--;\r
148         *pusTopOfStack = portFLAGS_INT_ENABLED;\r
149         pusTopOfStack -= ( sizeof( portSTACK_TYPE ) / 2 );\r
150         \r
151         /* From here on the size of stacked items depends on the memory model. */\r
152         pxTopOfStack = ( portSTACK_TYPE * ) pusTopOfStack;\r
153 \r
154         /* Next the general purpose registers. */\r
155         #ifdef PRELOAD_REGISTER_VALUES\r
156                 *pxTopOfStack = ( portSTACK_TYPE ) 0xffff;\r
157                 pxTopOfStack--;\r
158                 *pxTopOfStack = ( portSTACK_TYPE ) 0xeeee;\r
159                 pxTopOfStack--;\r
160                 *pxTopOfStack = ( portSTACK_TYPE ) 0xdddd;\r
161                 pxTopOfStack--;\r
162                 *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;\r
163                 pxTopOfStack--;\r
164                 *pxTopOfStack = ( portSTACK_TYPE ) 0xbbbb;\r
165                 pxTopOfStack--;\r
166                 *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaa;\r
167                 pxTopOfStack--;\r
168                 *pxTopOfStack = ( portSTACK_TYPE ) 0x9999;\r
169                 pxTopOfStack--;\r
170                 *pxTopOfStack = ( portSTACK_TYPE ) 0x8888;\r
171                 pxTopOfStack--; \r
172                 *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;\r
173                 pxTopOfStack--;\r
174                 *pxTopOfStack = ( portSTACK_TYPE ) 0x6666;\r
175                 pxTopOfStack--;\r
176                 *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;\r
177                 pxTopOfStack--;\r
178                 *pxTopOfStack = ( portSTACK_TYPE ) 0x4444;\r
179                 pxTopOfStack--;\r
180         #else\r
181                 pxTopOfStack -= 3;\r
182                 *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;\r
183                 pxTopOfStack -= 9;\r
184         #endif\r
185 \r
186 \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
191 \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
195 }\r
196 /*-----------------------------------------------------------*/\r
197 \r
198 void vPortEndScheduler( void )\r
199 {\r
200         /* It is unlikely that the MSP430 port will get stopped.  If required simply\r
201         disable the tick interrupt here. */\r
202 }\r
203 /*-----------------------------------------------------------*/\r
204 \r
205 /*\r
206  * Hardware initialisation to generate the RTOS tick.\r
207  */\r
208 void vPortSetupTimerInterrupt( void )\r
209 {\r
210         vApplicationSetupTimerInterrupt();\r
211 }\r
212 /*-----------------------------------------------------------*/\r
213 \r
214 #pragma vector=configTICK_VECTOR\r
215 __interrupt __raw void vTickISREntry( void )\r
216 {\r
217 extern void vPortTickISR( void );\r
218 \r
219         __bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF );\r
220         vPortTickISR();\r
221 }\r
222 \r
223         \r