]> git.sur5r.net Git - freertos/blob - Source/portable/Rowley/MSP430F449/port.c
1caee04da2bec062dcae3420b8a51b617d6a0b61
[freertos] / Source / portable / Rowley / MSP430F449 / port.c
1 /*\r
2         FreeRTOS.org V4.2.1 - 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 /* Scheduler includes. */\r
37 #include "FreeRTOS.h"\r
38 #include "task.h"\r
39 \r
40 /*-----------------------------------------------------------\r
41  * Implementation of functions defined in portable.h for the MSP430 port.\r
42  *----------------------------------------------------------*/\r
43 \r
44 /* Constants required for hardware setup.  The tick ISR runs off the ACLK, \r
45 not the MCLK. */\r
46 #define portACLK_FREQUENCY_HZ                   ( ( portTickType ) 32768 )\r
47 #define portINITIAL_CRITICAL_NESTING    ( ( unsigned portSHORT ) 10 )\r
48 #define portFLAGS_INT_ENABLED                   ( ( portSTACK_TYPE ) 0x08 )\r
49 \r
50 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
51 any details of its type. */\r
52 typedef void tskTCB;\r
53 extern volatile tskTCB * volatile pxCurrentTCB;\r
54 \r
55 /* Each task maintains a count of the critical section nesting depth.  Each \r
56 time a critical section is entered the count is incremented.  Each time a \r
57 critical section is exited the count is decremented - with interrupts only \r
58 being re-enabled if the count is zero.\r
59 \r
60 usCriticalNesting will get set to zero when the scheduler starts, but must\r
61 not be initialised to zero as this will cause problems during the startup\r
62 sequence. */\r
63 volatile unsigned portSHORT usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
64 /*-----------------------------------------------------------*/\r
65 \r
66 \r
67 /*\r
68  * Sets up the periodic ISR used for the RTOS tick.  This uses timer 0, but\r
69  * could have alternatively used the watchdog timer or timer 1.\r
70  */\r
71 void prvSetupTimerInterrupt( void );\r
72 /*-----------------------------------------------------------*/\r
73 \r
74 /* \r
75  * Initialise the stack of a task to look exactly as if a call to \r
76  * portSAVE_CONTEXT had been called.\r
77  * \r
78  * See the header file portable.h.\r
79  */\r
80 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
81 {\r
82         /* \r
83                 Place a few bytes of known values on the bottom of the stack. \r
84                 This is just useful for debugging and can be included if required.\r
85 \r
86                 *pxTopOfStack = ( portSTACK_TYPE ) 0x1111;\r
87                 pxTopOfStack--;\r
88                 *pxTopOfStack = ( portSTACK_TYPE ) 0x2222;\r
89                 pxTopOfStack--;\r
90                 *pxTopOfStack = ( portSTACK_TYPE ) 0x3333;\r
91                 pxTopOfStack--; \r
92         */\r
93 \r
94         /* The msp430 automatically pushes the PC then SR onto the stack before \r
95         executing an ISR.  We want the stack to look just as if this has happened\r
96         so place a pointer to the start of the task on the stack first - followed\r
97         by the flags we want the task to use when it starts up. */\r
98         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;\r
99         pxTopOfStack--;\r
100         *pxTopOfStack = portFLAGS_INT_ENABLED;\r
101         pxTopOfStack--;\r
102 \r
103         /* Next the general purpose registers. */\r
104         *pxTopOfStack = ( portSTACK_TYPE ) 0x4444;\r
105         pxTopOfStack--;\r
106         *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;\r
107         pxTopOfStack--;\r
108         *pxTopOfStack = ( portSTACK_TYPE ) 0x6666;\r
109         pxTopOfStack--;\r
110         *pxTopOfStack = ( portSTACK_TYPE ) 0x7777;\r
111         pxTopOfStack--;\r
112         *pxTopOfStack = ( portSTACK_TYPE ) 0x8888;\r
113         pxTopOfStack--;\r
114         *pxTopOfStack = ( portSTACK_TYPE ) 0x9999;\r
115         pxTopOfStack--;\r
116         *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaa;\r
117         pxTopOfStack--;\r
118         *pxTopOfStack = ( portSTACK_TYPE ) 0xbbbb;\r
119         pxTopOfStack--;\r
120         *pxTopOfStack = ( portSTACK_TYPE ) 0xcccc;\r
121         pxTopOfStack--;\r
122         *pxTopOfStack = ( portSTACK_TYPE ) 0xdddd;\r
123         pxTopOfStack--;\r
124         *pxTopOfStack = ( portSTACK_TYPE ) 0xeeee;\r
125         pxTopOfStack--;\r
126 \r
127         /* When the task starts is will expect to find the function parameter in\r
128         R15. */\r
129         *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;\r
130         pxTopOfStack--;\r
131 \r
132         /* A variable is used to keep track of the critical section nesting.  \r
133         This variable has to be stored as part of the task context and is \r
134         initially set to zero. */\r
135         *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;     \r
136 \r
137         /* Return a pointer to the top of the stack we have generated so this can\r
138         be stored in the task control block for the task. */\r
139         return pxTopOfStack;\r
140 }\r
141 /*-----------------------------------------------------------*/\r
142 \r
143 void vPortEndScheduler( void )\r
144 {\r
145         /* It is unlikely that the MSP430 port will get stopped.  If required simply\r
146         disable the tick interrupt here. */\r
147 }\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 /*\r
151  * Hardware initialisation to generate the RTOS tick.  This uses timer 0\r
152  * but could alternatively use the watchdog timer or timer 1. \r
153  */\r
154 void prvSetupTimerInterrupt( void )\r
155 {\r
156         /* Ensure the timer is stopped. */\r
157         TACTL = 0;\r
158 \r
159         /* Run the timer of the ACLK. */\r
160         TACTL = TASSEL_1;\r
161 \r
162         /* Clear everything to start with. */\r
163         TACTL |= TACLR;\r
164 \r
165         /* Set the compare match value according to the tick rate we want. */\r
166         TACCR0 = portACLK_FREQUENCY_HZ / configTICK_RATE_HZ;\r
167 \r
168         /* Enable the interrupts. */\r
169         TACCTL0 = CCIE;\r
170 \r
171         /* Start up clean. */\r
172         TACTL |= TACLR;\r
173 \r
174         /* Up mode. */\r
175         TACTL |= MC_1;\r
176 }\r
177 /*-----------------------------------------------------------*/\r
178 \r
179 \r
180         \r