]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/CCS/MSP430X/port.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Source / portable / CCS / MSP430X / port.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* Scheduler includes. */\r
29 #include "FreeRTOS.h"\r
30 #include "task.h"\r
31 \r
32 /*-----------------------------------------------------------\r
33  * Implementation of functions defined in portable.h for the MSP430X port.\r
34  *----------------------------------------------------------*/\r
35 \r
36 /* Constants required for hardware setup.  The tick ISR runs off the ACLK,\r
37 not the MCLK. */\r
38 #define portACLK_FREQUENCY_HZ                   ( ( TickType_t ) 32768 )\r
39 #define portINITIAL_CRITICAL_NESTING    ( ( uint16_t ) 10 )\r
40 #define portFLAGS_INT_ENABLED                   ( ( StackType_t ) 0x08 )\r
41 \r
42 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
43 any details of its type. */\r
44 typedef void TCB_t;\r
45 extern volatile TCB_t * volatile pxCurrentTCB;\r
46 \r
47 /* Each task maintains a count of the critical section nesting depth.  Each\r
48 time a critical section is entered the count is incremented.  Each time a\r
49 critical section is exited the count is decremented - with interrupts only\r
50 being re-enabled if the count is zero.\r
51 \r
52 usCriticalNesting will get set to zero when the scheduler starts, but must\r
53 not be initialised to zero as this will cause problems during the startup\r
54 sequence. */\r
55 volatile uint16_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
56 /*-----------------------------------------------------------*/\r
57 \r
58 \r
59 /*\r
60  * Sets up the periodic ISR used for the RTOS tick.  This uses timer 0, but\r
61  * could have alternatively used the watchdog timer or timer 1.\r
62  */\r
63 void vPortSetupTimerInterrupt( void );\r
64 /*-----------------------------------------------------------*/\r
65 \r
66 /*\r
67  * Initialise the stack of a task to look exactly as if a call to\r
68  * portSAVE_CONTEXT had been called.\r
69  *\r
70  * See the header file portable.h.\r
71  */\r
72 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
73 {\r
74 uint16_t *pusTopOfStack;\r
75 uint32_t *pulTopOfStack, ulTemp;\r
76 \r
77         /*\r
78                 Place a few bytes of known values on the bottom of the stack.\r
79                 This is just useful for debugging and can be included if required.\r
80 \r
81                 *pxTopOfStack = ( StackType_t ) 0x1111;\r
82                 pxTopOfStack--;\r
83                 *pxTopOfStack = ( StackType_t ) 0x2222;\r
84                 pxTopOfStack--;\r
85                 *pxTopOfStack = ( StackType_t ) 0x3333;\r
86                 pxTopOfStack--;\r
87         */\r
88 \r
89         /* Data types are need either 16 bits or 32 bits depending on the data \r
90         and code model used. */\r
91         if( sizeof( pxCode ) == sizeof( uint16_t ) )\r
92         {\r
93                 pusTopOfStack = ( uint16_t * ) pxTopOfStack;\r
94                 ulTemp = ( uint32_t ) pxCode;\r
95                 *pusTopOfStack = ( uint16_t ) ulTemp;\r
96         }\r
97         else\r
98         {\r
99                 /* Make room for a 20 bit value stored as a 32 bit value. */\r
100                 pusTopOfStack = ( uint16_t * ) pxTopOfStack;            \r
101                 pusTopOfStack--;\r
102                 pulTopOfStack = ( uint32_t * ) pusTopOfStack;\r
103                 *pulTopOfStack = ( uint32_t ) pxCode;\r
104         }\r
105 \r
106         pusTopOfStack--;\r
107         *pusTopOfStack = portFLAGS_INT_ENABLED;\r
108         pusTopOfStack -= ( sizeof( StackType_t ) / 2 );\r
109         \r
110         /* From here on the size of stacked items depends on the memory model. */\r
111         pxTopOfStack = ( StackType_t * ) pusTopOfStack;\r
112 \r
113         /* Next the general purpose registers. */\r
114         #ifdef PRELOAD_REGISTER_VALUES\r
115                 *pxTopOfStack = ( StackType_t ) 0xffff;\r
116                 pxTopOfStack--;\r
117                 *pxTopOfStack = ( StackType_t ) 0xeeee;\r
118                 pxTopOfStack--;\r
119                 *pxTopOfStack = ( StackType_t ) 0xdddd;\r
120                 pxTopOfStack--;\r
121                 *pxTopOfStack = ( StackType_t ) pvParameters;\r
122                 pxTopOfStack--;\r
123                 *pxTopOfStack = ( StackType_t ) 0xbbbb;\r
124                 pxTopOfStack--;\r
125                 *pxTopOfStack = ( StackType_t ) 0xaaaa;\r
126                 pxTopOfStack--;\r
127                 *pxTopOfStack = ( StackType_t ) 0x9999;\r
128                 pxTopOfStack--;\r
129                 *pxTopOfStack = ( StackType_t ) 0x8888;\r
130                 pxTopOfStack--; \r
131                 *pxTopOfStack = ( StackType_t ) 0x5555;\r
132                 pxTopOfStack--;\r
133                 *pxTopOfStack = ( StackType_t ) 0x6666;\r
134                 pxTopOfStack--;\r
135                 *pxTopOfStack = ( StackType_t ) 0x5555;\r
136                 pxTopOfStack--;\r
137                 *pxTopOfStack = ( StackType_t ) 0x4444;\r
138                 pxTopOfStack--;\r
139         #else\r
140                 pxTopOfStack -= 3;\r
141                 *pxTopOfStack = ( StackType_t ) pvParameters;\r
142                 pxTopOfStack -= 9;\r
143         #endif\r
144 \r
145         /* A variable is used to keep track of the critical section nesting.\r
146         This variable has to be stored as part of the task context and is\r
147         initially set to zero. */\r
148         *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;        \r
149 \r
150         /* Return a pointer to the top of the stack we have generated so this can\r
151         be stored in the task control block for the task. */\r
152         return pxTopOfStack;\r
153 }\r
154 /*-----------------------------------------------------------*/\r
155 \r
156 void vPortEndScheduler( void )\r
157 {\r
158         /* It is unlikely that the MSP430 port will get stopped.  If required simply\r
159         disable the tick interrupt here. */\r
160 }\r
161 /*-----------------------------------------------------------*/\r
162 \r
163 /*\r
164  * Hardware initialisation to generate the RTOS tick.\r
165  */\r
166 void vPortSetupTimerInterrupt( void )\r
167 {\r
168         vApplicationSetupTimerInterrupt();\r
169 }\r
170 /*-----------------------------------------------------------*/\r
171 \r
172 #pragma vector=configTICK_VECTOR\r
173 interrupt void vTickISREntry( void )\r
174 {\r
175 extern void vPortTickISR( void );\r
176 \r
177         __bic_SR_register_on_exit( SCG1 + SCG0 + OSCOFF + CPUOFF );\r
178         #if configUSE_PREEMPTION == 1\r
179                 extern void vPortPreemptiveTickISR( void );\r
180                 vPortPreemptiveTickISR();\r
181         #else\r
182                 extern void vPortCooperativeTickISR( void );\r
183                 vPortCooperativeTickISR();\r
184         #endif\r
185 }\r
186 \r
187         \r