]> git.sur5r.net Git - freertos/blob - Source/portable/Rowley/MSP430F449/Port2/port.c
Update to V4.3.0 as described in http://www.FreeRTOS.org/History.txt
[freertos] / Source / portable / Rowley / MSP430F449 / Port2 / port.c
1 /*\r
2         FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section \r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27         See http://www.FreeRTOS.org for documentation, latest information, license \r
28         and contact details.  Please ensure to read the configuration and relevant \r
29         port sections of the online documentation.\r
30 \r
31         Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
32         with commercial development and support options.\r
33         ***************************************************************************\r
34 */\r
35 \r
36 \r
37 /*\r
38  * Milos Prokic\r
39  * \r
40  * File adopted from the MSP430 GCC port\r
41  * Interrupt handling, xPortStartScheduler, vPortYield, portSAVE_CONTEXT(), portRESTORE_CONTEXT() \r
42 /* Standard includes. */\r
43 \r
44 #include <stdlib.h>\r
45 \r
46 /* Scheduler includes. */\r
47 #include "FreeRTOS.h"\r
48 #include "task.h"\r
49 \r
50 /*-----------------------------------------------------------\r
51  * Implementation of functions defined in portable.h for the MSP430 port.\r
52  *----------------------------------------------------------*/\r
53 \r
54 /* Constants required for hardware setup.  The tick ISR runs off the ACLK, \r
55 not the MCLK. */\r
56 #define portACLK_FREQUENCY_HZ                   ( ( portTickType ) 32768 )\r
57 #define portINITIAL_CRITICAL_NESTING    ( ( unsigned portSHORT ) 10 )\r
58 #define portFLAGS_INT_ENABLED                   ( ( portSTACK_TYPE ) 0x08 )\r
59 \r
60 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
61 any details of its type. */\r
62 typedef void tskTCB;\r
63 extern volatile tskTCB * volatile pxCurrentTCB;\r
64 \r
65 unsigned portCHAR ucReschedule;\r
66 \r
67 /* Each task maintains a count of the critical section nesting depth.  Each \r
68 time a critical section is entered the count is incremented.  Each time a \r
69 critical section is exited the count is decremented - with interrupts only \r
70 being re-enabled if the count is zero.\r
71 \r
72 usCriticalNesting will get set to zero when the scheduler starts, but must\r
73 not be initialised to zero as this will cause problems during the startup\r
74 sequence. */\r
75 volatile unsigned portSHORT usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
76 /*-----------------------------------------------------------*/\r
77 \r
78 /*\r
79  * Sets up the periodic ISR used for the RTOS tick.  This uses timer 0, but\r
80  * could have alternatively used the watchdog timer or timer 1.\r
81  */\r
82 void prvSetupTimerInterrupt( void );\r
83 /*-----------------------------------------------------------*/\r
84 \r
85 /* \r
86  * Initialise the stack of a task to look exactly as if a call to \r
87  * portSAVE_CONTEXT had been called.\r
88  * \r
89  * See the header file portable.h.\r
90  */\r
91 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
92 {\r
93         /* \r
94                 Place a few bytes of known values on the bottom of the stack. \r
95                 This is just useful for debugging and can be included if required.\r
96 \r
97                 *pxTopOfStack = ( portSTACK_TYPE ) 0x1111;\r
98                 pxTopOfStack--;\r
99                 *pxTopOfStack = ( portSTACK_TYPE ) 0x2222;\r
100                 pxTopOfStack--;\r
101                 *pxTopOfStack = ( portSTACK_TYPE ) 0x3333;\r
102                 pxTopOfStack--; \r
103         */\r
104 \r
105         /* The msp430 automatically pushes the PC then SR onto the stack before \r
106         executing an ISR.  We want the stack to look just as if this has happened\r
107         so place a pointer to the start of the task on the stack first - followed\r
108         by the flags we want the task to use when it starts up. */\r
109         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;\r
110         pxTopOfStack--;\r
111         *pxTopOfStack = portFLAGS_INT_ENABLED;\r
112         pxTopOfStack--;\r
113 \r
114         /* Next the general purpose registers. */\r
115         *pxTopOfStack = ( portSTACK_TYPE ) 0x4444;\r
116         pxTopOfStack--;\r
117         *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;\r
118         pxTopOfStack--;\r
119         *pxTopOfStack = ( portSTACK_TYPE ) 0x6666;\r
120         pxTopOfStack--;\r
121         *pxTopOfStack = ( portSTACK_TYPE ) 0x7777;\r
122         pxTopOfStack--;\r
123         *pxTopOfStack = ( portSTACK_TYPE ) 0x8888;\r
124         pxTopOfStack--;\r
125         *pxTopOfStack = ( portSTACK_TYPE ) 0x9999;\r
126         pxTopOfStack--;\r
127         *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaa;\r
128         pxTopOfStack--;\r
129         *pxTopOfStack = ( portSTACK_TYPE ) 0xbbbb;\r
130         pxTopOfStack--;\r
131         *pxTopOfStack = ( portSTACK_TYPE ) 0xcccc;\r
132         pxTopOfStack--;\r
133         *pxTopOfStack = ( portSTACK_TYPE ) 0xdddd;\r
134         pxTopOfStack--;\r
135         *pxTopOfStack = ( portSTACK_TYPE ) 0xeeee;\r
136         pxTopOfStack--;\r
137 \r
138         /* When the task starts is will expect to find the function parameter in\r
139         R15. */\r
140         *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;\r
141         pxTopOfStack--;\r
142 \r
143         /* A variable is used to keep track of the critical section nesting.  \r
144         This variable has to be stored as part of the task context and is \r
145         initially set to zero. */\r
146         *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;     \r
147 \r
148         /* Return a pointer to the top of the stack we have generated so this can\r
149         be stored in the task control block for the task. */\r
150         return pxTopOfStack;\r
151 }\r
152 /*-----------------------------------------------------------*/\r
153 \r
154 void vPortEndScheduler( void )\r
155 {\r
156         /* It is unlikely that the MSP430 port will get stopped.  If required simply\r
157         disable the tick interrupt here. */\r
158 }\r
159 /*-----------------------------------------------------------*/\r
160 \r
161 /*\r
162  * Hardware initialisation to generate the RTOS tick.  This uses timer 0\r
163  * but could alternatively use the watchdog timer or timer 1. \r
164  */\r
165 void prvSetupTimerInterrupt( void )\r
166 {\r
167         /* Ensure the timer is stopped. */\r
168         TACTL = 0;\r
169 \r
170         /* Run the timer of the ACLK. */\r
171         TACTL = TASSEL_1;\r
172 \r
173         /* Clear everything to start with. */\r
174         TACTL |= TACLR;\r
175 \r
176         /* Set the compare match value according to the tick rate we want. */\r
177         TACCR0 = portACLK_FREQUENCY_HZ / configTICK_RATE_HZ;\r
178 \r
179         /* Enable the interrupts. */\r
180         TACCTL0 = CCIE;\r
181 \r
182         /* Start up clean. */\r
183         TACTL |= TACLR;\r
184 \r
185         /* Up mode. */\r
186         TACTL |= MC_1;\r
187 }\r
188 /*-----------------------------------------------------------*/\r
189 \r
190 /* \r
191  * The interrupt service routine used depends on whether the pre-emptive\r
192  * scheduler is being used or not.\r
193  */\r
194 \r
195 #if configUSE_PREEMPTION == 1\r
196 \r
197         /*\r
198          * Tick ISR for preemptive scheduler.  We can use a naked attribute as\r
199          * the context is saved at the start of vPortYieldFromTick().  The tick\r
200          * count is incremented after the context is saved.\r
201          */\r
202         void ISROsTick( void )\r
203         {\r
204                 /* Increment the tick count then switch to the highest priority task\r
205                 that is ready to run. */\r
206                 vTaskIncrementTick();\r
207                 vTaskSwitchContext();\r
208         }\r
209 \r
210 #else\r
211 \r
212         /*\r
213          * Tick ISR for the cooperative scheduler.  All this does is increment the\r
214          * tick count.  We don't need to switch context, this can only be done by\r
215          * manual calls to taskYIELD();\r
216          */\r
217         void ISROsTick( void )\r
218         {\r
219                 vTaskIncrementTick();\r
220         }\r
221 #endif\r
222 \r
223 \r
224         \r