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