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