]> begriffs open source - freertos/blob - portable/Rowley/MSP430F449/port.c
RP2040: Fix compiler warning and comment (#509)
[freertos] / portable / Rowley / MSP430F449 / port.c
1 /*
2  * FreeRTOS SMP Kernel V202110.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /* Scheduler includes. */
29 #include "FreeRTOS.h"
30 #include "task.h"
31
32 /*-----------------------------------------------------------
33  * Implementation of functions defined in portable.h for the MSP430 port.
34  *----------------------------------------------------------*/
35
36 /* Constants required for hardware setup.  The tick ISR runs off the ACLK, 
37 not the MCLK. */
38 #define portACLK_FREQUENCY_HZ                   ( ( TickType_t ) 32768 )
39 #define portINITIAL_CRITICAL_NESTING    ( ( uint16_t ) 10 )
40 #define portFLAGS_INT_ENABLED                   ( ( StackType_t ) 0x08 )
41
42 /* We require the address of the pxCurrentTCB variable, but don't want to know
43 any details of its type. */
44 typedef void TCB_t;
45 extern volatile TCB_t * volatile pxCurrentTCB;
46
47 /* Each task maintains a count of the critical section nesting depth.  Each 
48 time a critical section is entered the count is incremented.  Each time a 
49 critical section is exited the count is decremented - with interrupts only 
50 being re-enabled if the count is zero.
51
52 usCriticalNesting will get set to zero when the scheduler starts, but must
53 not be initialised to zero as this will cause problems during the startup
54 sequence. */
55 volatile uint16_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;
56 /*-----------------------------------------------------------*/
57
58
59 /*
60  * Sets up the periodic ISR used for the RTOS tick.  This uses timer 0, but
61  * could have alternatively used the watchdog timer or timer 1.
62  */
63 void prvSetupTimerInterrupt( void );
64 /*-----------------------------------------------------------*/
65
66 /* 
67  * Initialise the stack of a task to look exactly as if a call to 
68  * portSAVE_CONTEXT had been called.
69  * 
70  * See the header file portable.h.
71  */
72 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
73 {
74         /* 
75                 Place a few bytes of known values on the bottom of the stack. 
76                 This is just useful for debugging and can be included if required.
77
78                 *pxTopOfStack = ( StackType_t ) 0x1111;
79                 pxTopOfStack--;
80                 *pxTopOfStack = ( StackType_t ) 0x2222;
81                 pxTopOfStack--;
82                 *pxTopOfStack = ( StackType_t ) 0x3333;
83                 pxTopOfStack--; 
84         */
85
86         /* The msp430 automatically pushes the PC then SR onto the stack before 
87         executing an ISR.  We want the stack to look just as if this has happened
88         so place a pointer to the start of the task on the stack first - followed
89         by the flags we want the task to use when it starts up. */
90         *pxTopOfStack = ( StackType_t ) pxCode;
91         pxTopOfStack--;
92         *pxTopOfStack = portFLAGS_INT_ENABLED;
93         pxTopOfStack--;
94
95         /* Next the general purpose registers. */
96         *pxTopOfStack = ( StackType_t ) 0x4444;
97         pxTopOfStack--;
98         *pxTopOfStack = ( StackType_t ) 0x5555;
99         pxTopOfStack--;
100         *pxTopOfStack = ( StackType_t ) 0x6666;
101         pxTopOfStack--;
102         *pxTopOfStack = ( StackType_t ) 0x7777;
103         pxTopOfStack--;
104         *pxTopOfStack = ( StackType_t ) 0x8888;
105         pxTopOfStack--;
106         *pxTopOfStack = ( StackType_t ) 0x9999;
107         pxTopOfStack--;
108         *pxTopOfStack = ( StackType_t ) 0xaaaa;
109         pxTopOfStack--;
110         *pxTopOfStack = ( StackType_t ) 0xbbbb;
111         pxTopOfStack--;
112         *pxTopOfStack = ( StackType_t ) 0xcccc;
113         pxTopOfStack--;
114         *pxTopOfStack = ( StackType_t ) 0xdddd;
115         pxTopOfStack--;
116         *pxTopOfStack = ( StackType_t ) 0xeeee;
117         pxTopOfStack--;
118
119         /* When the task starts is will expect to find the function parameter in
120         R15. */
121         *pxTopOfStack = ( StackType_t ) pvParameters;
122         pxTopOfStack--;
123
124         /* A variable is used to keep track of the critical section nesting.  
125         This variable has to be stored as part of the task context and is 
126         initially set to zero. */
127         *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;        
128
129         /* Return a pointer to the top of the stack we have generated so this can
130         be stored in the task control block for the task. */
131         return pxTopOfStack;
132 }
133 /*-----------------------------------------------------------*/
134
135 void vPortEndScheduler( void )
136 {
137         /* It is unlikely that the MSP430 port will get stopped.  If required simply
138         disable the tick interrupt here. */
139 }
140 /*-----------------------------------------------------------*/
141
142 /*
143  * Hardware initialisation to generate the RTOS tick.  This uses timer 0
144  * but could alternatively use the watchdog timer or timer 1. 
145  */
146 void prvSetupTimerInterrupt( void )
147 {
148         /* Ensure the timer is stopped. */
149         TACTL = 0;
150
151         /* Run the timer of the ACLK. */
152         TACTL = TASSEL_1;
153
154         /* Clear everything to start with. */
155         TACTL |= TACLR;
156
157         /* Set the compare match value according to the tick rate we want. */
158         TACCR0 = portACLK_FREQUENCY_HZ / configTICK_RATE_HZ;
159
160         /* Enable the interrupts. */
161         TACCTL0 = CCIE;
162
163         /* Start up clean. */
164         TACTL |= TACLR;
165
166         /* Up mode. */
167         TACTL |= MC_1;
168 }
169 /*-----------------------------------------------------------*/
170
171
172