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