]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/MSP430/port.c
Prepare for V7.3.0 release.
[freertos] / FreeRTOS / Source / portable / IAR / MSP430 / port.c
1 /*\r
2     FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT \r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32     >>>NOTE<<< The modification to the GPL is included to allow you to\r
33     distribute a combined work that includes FreeRTOS without being obliged to\r
34     provide the source code for proprietary components outside of the FreeRTOS\r
35     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
36     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
37     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
38     more details. You should have received a copy of the GNU General Public\r
39     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
40     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
41     by writing to Richard Barry, contact details for whom are available on the\r
42     FreeRTOS WEB site.\r
43 \r
44     1 tab == 4 spaces!\r
45     \r
46     ***************************************************************************\r
47      *                                                                       *\r
48      *    Having a problem?  Start by reading the FAQ "My application does   *\r
49      *    not run, what could be wrong?"                                     *\r
50      *                                                                       *\r
51      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
52      *                                                                       *\r
53     ***************************************************************************\r
54 \r
55     \r
56     http://www.FreeRTOS.org - Documentation, training, latest versions, license \r
57     and contact details.  \r
58     \r
59     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
60     including FreeRTOS+Trace - an indispensable productivity tool.\r
61 \r
62     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
63     the code with commercial support, indemnification, and middleware, under \r
64     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
65     provide a safety engineered and independently SIL3 certified version under \r
66     the SafeRTOS brand: http://www.SafeRTOS.com.\r
67 */\r
68 \r
69 /* Scheduler includes. */\r
70 #include "FreeRTOS.h"\r
71 #include "task.h"\r
72 \r
73 /*-----------------------------------------------------------\r
74  * Implementation of functions defined in portable.h for the MSP430 port.\r
75  *----------------------------------------------------------*/\r
76 \r
77 /* Constants required for hardware setup.  The tick ISR runs off the ACLK,\r
78 not the MCLK. */\r
79 #define portACLK_FREQUENCY_HZ                   ( ( portTickType ) 32768 )\r
80 #define portINITIAL_CRITICAL_NESTING    ( ( unsigned short ) 10 )\r
81 #define portFLAGS_INT_ENABLED                   ( ( portSTACK_TYPE ) 0x08 )\r
82 \r
83 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
84 any details of its type. */\r
85 typedef void tskTCB;\r
86 extern volatile tskTCB * volatile pxCurrentTCB;\r
87 \r
88 /* Each task maintains a count of the critical section nesting depth.  Each\r
89 time a critical section is entered the count is incremented.  Each time a\r
90 critical section is exited the count is decremented - with interrupts only\r
91 being re-enabled if the count is zero.\r
92 \r
93 usCriticalNesting will get set to zero when the scheduler starts, but must\r
94 not be initialised to zero as this will cause problems during the startup\r
95 sequence. */\r
96 volatile unsigned short usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
97 /*-----------------------------------------------------------*/\r
98 \r
99 \r
100 /*\r
101  * Sets up the periodic ISR used for the RTOS tick.  This uses timer 0, but\r
102  * could have alternatively used the watchdog timer or timer 1.\r
103  */\r
104 void vPortSetupTimerInterrupt( void );\r
105 /*-----------------------------------------------------------*/\r
106 \r
107 /*\r
108  * Initialise the stack of a task to look exactly as if a call to\r
109  * portSAVE_CONTEXT had been called.\r
110  *\r
111  * See the header file portable.h.\r
112  */\r
113 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\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 = ( portSTACK_TYPE ) 0x1111;\r
120                 pxTopOfStack--;\r
121                 *pxTopOfStack = ( portSTACK_TYPE ) 0x2222;\r
122                 pxTopOfStack--;\r
123                 *pxTopOfStack = ( portSTACK_TYPE ) 0x3333;\r
124                 pxTopOfStack--;\r
125         */\r
126 \r
127         /* The msp430 automatically pushes the PC then SR onto the stack before\r
128         executing an ISR.  We want the stack to look just as if this has happened\r
129         so place a pointer to the start of the task on the stack first - followed\r
130         by the flags we want the task to use when it starts up. */\r
131         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;\r
132         pxTopOfStack--;\r
133         *pxTopOfStack = portFLAGS_INT_ENABLED;\r
134         pxTopOfStack--;\r
135 \r
136         /* Next the general purpose registers. */\r
137         *pxTopOfStack = ( portSTACK_TYPE ) 0x4444;\r
138         pxTopOfStack--;\r
139         *pxTopOfStack = ( portSTACK_TYPE ) 0x5555;\r
140         pxTopOfStack--;\r
141         *pxTopOfStack = ( portSTACK_TYPE ) 0x6666;\r
142         pxTopOfStack--;\r
143         *pxTopOfStack = ( portSTACK_TYPE ) 0x7777;\r
144         pxTopOfStack--;\r
145         *pxTopOfStack = ( portSTACK_TYPE ) 0x8888;\r
146         pxTopOfStack--;\r
147         *pxTopOfStack = ( portSTACK_TYPE ) 0x9999;\r
148         pxTopOfStack--;\r
149         *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaa;\r
150         pxTopOfStack--;\r
151         *pxTopOfStack = ( portSTACK_TYPE ) 0xbbbb;\r
152         pxTopOfStack--; \r
153         \r
154         /* When the task starts is will expect to find the function parameter in\r
155         R15. */\r
156         *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;\r
157         pxTopOfStack--;\r
158         \r
159         *pxTopOfStack = ( portSTACK_TYPE ) 0xdddd;\r
160         pxTopOfStack--;\r
161         *pxTopOfStack = ( portSTACK_TYPE ) 0xeeee;\r
162         pxTopOfStack--;\r
163         *pxTopOfStack = ( portSTACK_TYPE ) 0xffff;\r
164         pxTopOfStack--;\r
165 \r
166         /* A variable is used to keep track of the critical section nesting.\r
167         This variable has to be stored as part of the task context and is\r
168         initially set to zero. */\r
169         *pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;     \r
170 \r
171         /* Return a pointer to the top of the stack we have generated so this can\r
172         be stored in the task control block for the task. */\r
173         return pxTopOfStack;\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r
177 void vPortEndScheduler( void )\r
178 {\r
179         /* It is unlikely that the MSP430 port will get stopped.  If required simply\r
180         disable the tick interrupt here. */\r
181 }\r
182 /*-----------------------------------------------------------*/\r
183 \r
184 /*\r
185  * Hardware initialisation to generate the RTOS tick.  This uses timer 0\r
186  * but could alternatively use the watchdog timer or timer 1.\r
187  */\r
188 void vPortSetupTimerInterrupt( void )\r
189 {\r
190         /* Ensure the timer is stopped. */\r
191         TACTL = 0;\r
192 \r
193         /* Run the timer of the ACLK. */\r
194         TACTL = TASSEL_1;\r
195 \r
196         /* Clear everything to start with. */\r
197         TACTL |= TACLR;\r
198 \r
199         /* Set the compare match value according to the tick rate we want. */\r
200         TACCR0 = portACLK_FREQUENCY_HZ / configTICK_RATE_HZ;\r
201 \r
202         /* Enable the interrupts. */\r
203         TACCTL0 = CCIE;\r
204 \r
205         /* Start up clean. */\r
206         TACTL |= TACLR;\r
207 \r
208         /* Up mode. */\r
209         TACTL |= MC_1;\r
210 }\r
211 /*-----------------------------------------------------------*/\r
212 \r
213 \r
214         \r