root/webserver/example/freeRTOS/Source/portable/Rowley/MSP430F449/port.c

Revision 14, 6.8 kB (checked in by phil, 15 years ago)

added unmodified FreeRTOS package V5.4.1 with only web srv demo source for LPC2368 for CrossWorks?

Line 
1 /*
2         FreeRTOS V5.4.1 - Copyright (C) 2009 Real Time Engineers Ltd.
3
4         This file is part of the FreeRTOS distribution.
5
6         FreeRTOS is free software; you can redistribute it and/or modify it     under
7         the terms of the GNU General Public License (version 2) as published by the
8         Free Software Foundation and modified by the FreeRTOS exception.
9         **NOTE** The exception to the GPL is included to allow you to distribute a
10         combined work that includes FreeRTOS without being obliged to provide the
11         source code for proprietary components outside of the FreeRTOS kernel. 
12         Alternative commercial license and support terms are also available upon
13         request.  See the licensing section of http://www.FreeRTOS.org for full
14         license details.
15
16         FreeRTOS is distributed in the hope that it will be useful,     but WITHOUT
17         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19         more details.
20
21         You should have received a copy of the GNU General Public License along
22         with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
23         Temple Place, Suite 330, Boston, MA  02111-1307  USA.
24
25
26         ***************************************************************************
27         *                                                                         *
28         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *
29         * See http://www.FreeRTOS.org/Documentation for details                   *
30         *                                                                         *
31         ***************************************************************************
32
33         1 tab == 4 spaces!
34
35         Please ensure to read the configuration and relevant port sections of the
36         online documentation.
37
38         http://www.FreeRTOS.org - Documentation, latest information, license and
39         contact details.
40
41         http://www.SafeRTOS.com - A version that is certified for use in safety
42         critical systems.
43
44         http://www.OpenRTOS.com - Commercial support, development, porting,
45         licensing and training services.
46 */
47
48 /* Scheduler includes. */
49 #include "FreeRTOS.h"
50 #include "task.h"
51
52 /*-----------------------------------------------------------
53  * Implementation of functions defined in portable.h for the MSP430 port.
54  *----------------------------------------------------------*/
55
56 /* Constants required for hardware setup.  The tick ISR runs off the ACLK,
57 not the MCLK. */
58 #define portACLK_FREQUENCY_HZ                   ( ( portTickType ) 32768 )
59 #define portINITIAL_CRITICAL_NESTING    ( ( unsigned portSHORT ) 10 )
60 #define portFLAGS_INT_ENABLED                   ( ( portSTACK_TYPE ) 0x08 )
61
62 /* We require the address of the pxCurrentTCB variable, but don't want to know
63 any details of its type. */
64 typedef void tskTCB;
65 extern volatile tskTCB * volatile pxCurrentTCB;
66
67 /* Each task maintains a count of the critical section nesting depth.  Each
68 time a critical section is entered the count is incremented.  Each time a
69 critical section is exited the count is decremented - with interrupts only
70 being re-enabled if the count is zero.
71
72 usCriticalNesting will get set to zero when the scheduler starts, but must
73 not be initialised to zero as this will cause problems during the startup
74 sequence. */
75 volatile unsigned portSHORT usCriticalNesting = portINITIAL_CRITICAL_NESTING;
76 /*-----------------------------------------------------------*/
77
78
79 /*
80  * Sets up the periodic ISR used for the RTOS tick.  This uses timer 0, but
81  * could have alternatively used the watchdog timer or timer 1.
82  */
83 void prvSetupTimerInterrupt( void );
84 /*-----------------------------------------------------------*/
85
86 /*
87  * Initialise the stack of a task to look exactly as if a call to
88  * portSAVE_CONTEXT had been called.
89  *
90  * See the header file portable.h.
91  */
92 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
93 {
94         /*
95                 Place a few bytes of known values on the bottom of the stack.
96                 This is just useful for debugging and can be included if required.
97
98                 *pxTopOfStack = ( portSTACK_TYPE ) 0x1111;
99                 pxTopOfStack--;
100                 *pxTopOfStack = ( portSTACK_TYPE ) 0x2222;
101                 pxTopOfStack--;
102                 *pxTopOfStack = ( portSTACK_TYPE ) 0x3333;
103                 pxTopOfStack--;
104         */
105
106         /* The msp430 automatically pushes the PC then SR onto the stack before
107         executing an ISR.  We want the stack to look just as if this has happened
108         so place a pointer to the start of the task on the stack first - followed
109         by the flags we want the task to use when it starts up. */
110         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;
111         pxTopOfStack--;
112         *pxTopOfStack = portFLAGS_INT_ENABLED;
113         pxTopOfStack--;
114
115         /* Next the general purpose registers. */
116         *pxTopOfStack = ( portSTACK_TYPE ) 0x4444;
117         pxTopOfStack--;
118         *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;
119         pxTopOfStack--;
120         *pxTopOfStack = ( portSTACK_TYPE ) 0x6666;
121         pxTopOfStack--;
122         *pxTopOfStack = ( portSTACK_TYPE ) 0x7777;
123         pxTopOfStack--;
124         *pxTopOfStack = ( portSTACK_TYPE ) 0x8888;
125         pxTopOfStack--;
126         *pxTopOfStack = ( portSTACK_TYPE ) 0x9999;
127         pxTopOfStack--;
128         *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaa;
129         pxTopOfStack--;
130         *pxTopOfStack = ( portSTACK_TYPE ) 0xbbbb;
131         pxTopOfStack--;
132         *pxTopOfStack = ( portSTACK_TYPE ) 0xcccc;
133         pxTopOfStack--;
134         *pxTopOfStack = ( portSTACK_TYPE ) 0xdddd;
135         pxTopOfStack--;
136         *pxTopOfStack = ( portSTACK_TYPE ) 0xeeee;
137         pxTopOfStack--;
138
139         /* When the task starts is will expect to find the function parameter in
140         R15. */
141         *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
142         pxTopOfStack--;
143
144         /* A variable is used to keep track of the critical section nesting. 
145         This variable has to be stored as part of the task context and is
146         initially set to zero. */
147         *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;     
148
149         /* Return a pointer to the top of the stack we have generated so this can
150         be stored in the task control block for the task. */
151         return pxTopOfStack;
152 }
153 /*-----------------------------------------------------------*/
154
155 void vPortEndScheduler( void )
156 {
157         /* It is unlikely that the MSP430 port will get stopped.  If required simply
158         disable the tick interrupt here. */
159 }
160 /*-----------------------------------------------------------*/
161
162 /*
163  * Hardware initialisation to generate the RTOS tick.  This uses timer 0
164  * but could alternatively use the watchdog timer or timer 1.
165  */
166 void prvSetupTimerInterrupt( void )
167 {
168         /* Ensure the timer is stopped. */
169         TACTL = 0;
170
171         /* Run the timer of the ACLK. */
172         TACTL = TASSEL_1;
173
174         /* Clear everything to start with. */
175         TACTL |= TACLR;
176
177         /* Set the compare match value according to the tick rate we want. */
178         TACCR0 = portACLK_FREQUENCY_HZ / configTICK_RATE_HZ;
179
180         /* Enable the interrupts. */
181         TACCTL0 = CCIE;
182
183         /* Start up clean. */
184         TACTL |= TACLR;
185
186         /* Up mode. */
187         TACTL |= MC_1;
188 }
189 /*-----------------------------------------------------------*/
190
191
192        
Note: See TracBrowser for help on using the browser.