]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/CCS/MSP430X/port.c
Update version number ready for release.
[freertos] / FreeRTOS / Source / portable / CCS / MSP430X / port.c
1 /*\r
2     FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\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
12      *                                                                       *\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
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \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
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \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
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \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
54 \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
58 \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
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /* Scheduler includes. */\r
67 #include "FreeRTOS.h"\r
68 #include "task.h"\r
69 \r
70 /*-----------------------------------------------------------\r
71  * Implementation of functions defined in portable.h for the MSP430X port.\r
72  *----------------------------------------------------------*/\r
73 \r
74 /* Constants required for hardware setup.  The tick ISR runs off the ACLK,\r
75 not the MCLK. */\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
79 \r
80 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
81 any details of its type. */\r
82 typedef void TCB_t;\r
83 extern volatile TCB_t * volatile pxCurrentTCB;\r
84 \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
89 \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
92 sequence. */\r
93 volatile uint16_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
94 /*-----------------------------------------------------------*/\r
95 \r
96 \r
97 /*\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
100  */\r
101 void vPortSetupTimerInterrupt( void );\r
102 /*-----------------------------------------------------------*/\r
103 \r
104 /*\r
105  * Initialise the stack of a task to look exactly as if a call to\r
106  * portSAVE_CONTEXT had been called.\r
107  *\r
108  * See the header file portable.h.\r
109  */\r
110 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
111 {\r
112 uint16_t *pusTopOfStack;\r
113 uint32_t *pulTopOfStack, ulTemp;\r
114 \r
115         /*\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
118 \r
119                 *pxTopOfStack = ( StackType_t ) 0x1111;\r
120                 pxTopOfStack--;\r
121                 *pxTopOfStack = ( StackType_t ) 0x2222;\r
122                 pxTopOfStack--;\r
123                 *pxTopOfStack = ( StackType_t ) 0x3333;\r
124                 pxTopOfStack--;\r
125         */\r
126 \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
130         {\r
131                 pusTopOfStack = ( uint16_t * ) pxTopOfStack;\r
132                 ulTemp = ( uint32_t ) pxCode;\r
133                 *pusTopOfStack = ( uint16_t ) ulTemp;\r
134         }\r
135         else\r
136         {\r
137                 /* Make room for a 20 bit value stored as a 32 bit value. */\r
138                 pusTopOfStack = ( uint16_t * ) pxTopOfStack;            \r
139                 pusTopOfStack--;\r
140                 pulTopOfStack = ( uint32_t * ) pusTopOfStack;\r
141                 *pulTopOfStack = ( uint32_t ) pxCode;\r
142         }\r
143 \r
144         pusTopOfStack--;\r
145         *pusTopOfStack = portFLAGS_INT_ENABLED;\r
146         pusTopOfStack -= ( sizeof( StackType_t ) / 2 );\r
147         \r
148         /* From here on the size of stacked items depends on the memory model. */\r
149         pxTopOfStack = ( StackType_t * ) pusTopOfStack;\r
150 \r
151         /* Next the general purpose registers. */\r
152         #ifdef PRELOAD_REGISTER_VALUES\r
153                 *pxTopOfStack = ( StackType_t ) 0xffff;\r
154                 pxTopOfStack--;\r
155                 *pxTopOfStack = ( StackType_t ) 0xeeee;\r
156                 pxTopOfStack--;\r
157                 *pxTopOfStack = ( StackType_t ) 0xdddd;\r
158                 pxTopOfStack--;\r
159                 *pxTopOfStack = ( StackType_t ) pvParameters;\r
160                 pxTopOfStack--;\r
161                 *pxTopOfStack = ( StackType_t ) 0xbbbb;\r
162                 pxTopOfStack--;\r
163                 *pxTopOfStack = ( StackType_t ) 0xaaaa;\r
164                 pxTopOfStack--;\r
165                 *pxTopOfStack = ( StackType_t ) 0x9999;\r
166                 pxTopOfStack--;\r
167                 *pxTopOfStack = ( StackType_t ) 0x8888;\r
168                 pxTopOfStack--; \r
169                 *pxTopOfStack = ( StackType_t ) 0x5555;\r
170                 pxTopOfStack--;\r
171                 *pxTopOfStack = ( StackType_t ) 0x6666;\r
172                 pxTopOfStack--;\r
173                 *pxTopOfStack = ( StackType_t ) 0x5555;\r
174                 pxTopOfStack--;\r
175                 *pxTopOfStack = ( StackType_t ) 0x4444;\r
176                 pxTopOfStack--;\r
177         #else\r
178                 pxTopOfStack -= 3;\r
179                 *pxTopOfStack = ( StackType_t ) pvParameters;\r
180                 pxTopOfStack -= 9;\r
181         #endif\r
182 \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
187 \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
191 }\r
192 /*-----------------------------------------------------------*/\r
193 \r
194 void vPortEndScheduler( void )\r
195 {\r
196         /* It is unlikely that the MSP430 port will get stopped.  If required simply\r
197         disable the tick interrupt here. */\r
198 }\r
199 /*-----------------------------------------------------------*/\r
200 \r
201 /*\r
202  * Hardware initialisation to generate the RTOS tick.\r
203  */\r
204 void vPortSetupTimerInterrupt( void )\r
205 {\r
206         vApplicationSetupTimerInterrupt();\r
207 }\r
208 /*-----------------------------------------------------------*/\r
209 \r
210 #pragma vector=configTICK_VECTOR\r
211 interrupt void vTickISREntry( void )\r
212 {\r
213 extern void vPortTickISR( void );\r
214 \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
219         #else\r
220                 extern void vPortCooperativeTickISR( void );\r
221                 vPortCooperativeTickISR();\r
222         #endif\r
223 }\r
224 \r
225         \r