]> begriffs open source - freertos/blob - portable/IAR/MSP430X/portext.s43
Fix typo in the include directory for the the GCC_ARM_CM55_TFM port (#764)
[freertos] / portable / IAR / MSP430X / portext.s43
1 /*
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of
8  * this software and associated documentation files (the "Software"), to deal in
9  * the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11  * the Software, and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * https://www.FreeRTOS.org
25  * https://github.com/FreeRTOS
26  *
27  */
28 #include "msp430.h"
29 #include "FreeRTOSConfig.h"
30 #include "data_model.h"
31
32     IMPORT xTaskIncrementTick
33     IMPORT vTaskSwitchContext
34     IMPORT vPortSetupTimerInterrupt
35     IMPORT pxCurrentTCB
36     IMPORT usCriticalNesting
37
38     EXPORT vPortTickISR
39     EXPORT vPortYield
40     EXPORT xPortStartScheduler
41
42 portSAVE_CONTEXT macro
43
44     /* Save the remaining registers. */
45     pushm_x #12, r15
46     mov.w   &usCriticalNesting, r14
47     push_x r14
48     mov_x   &pxCurrentTCB, r12
49     mov_x   sp, 0( r12 )
50     endm
51 /*-----------------------------------------------------------*/
52
53 portRESTORE_CONTEXT macro
54
55     mov_x   &pxCurrentTCB, r12
56     mov_x   @r12, sp
57     pop_x   r15
58     mov.w   r15, &usCriticalNesting
59     popm_x  #12, r15
60     nop
61     pop.w   sr
62     nop
63     reta
64     endm
65 /*-----------------------------------------------------------*/
66
67
68 /*
69  * The RTOS tick ISR.
70  *
71  * If the cooperative scheduler is in use this simply increments the tick
72  * count.
73  *
74  * If the preemptive scheduler is in use a context switch can also occur.
75  */
76
77     RSEG CODE
78     EVEN
79
80 vPortTickISR:
81
82     /* The sr is not saved in portSAVE_CONTEXT() because vPortYield() needs
83     to save it manually before it gets modified (interrupts get disabled).
84     Entering through this interrupt means the SR is already on the stack, but
85     this keeps the stack frames identical. */
86     push.w sr
87     portSAVE_CONTEXT
88
89     calla   #xTaskIncrementTick
90     cmp.w   #0x0, R12
91     jeq     SkipContextSwitch
92     calla   #vTaskSwitchContext
93 SkipContextSwitch:
94     portRESTORE_CONTEXT
95 /*-----------------------------------------------------------*/
96
97 /*
98  * Manual context switch called by the portYIELD() macro.
99  */
100     EVEN
101
102 vPortYield:
103
104     /* The sr needs saving before it is modified. */
105     push.w  sr
106
107     /* Now the SR is stacked interrupts can be disabled. */
108     dint
109     nop
110
111     /* Save the context of the current task. */
112     portSAVE_CONTEXT
113
114     /* Select the next task to run. */
115     calla   #vTaskSwitchContext
116
117     /* Restore the context of the new task. */
118     portRESTORE_CONTEXT
119 /*-----------------------------------------------------------*/
120
121
122 /*
123  * Start off the scheduler by initialising the RTOS tick timer, then restoring
124  * the context of the first task.
125  */
126     EVEN
127
128 xPortStartScheduler:
129
130     /* Setup the hardware to generate the tick.  Interrupts are disabled
131     when this function is called. */
132     calla   #vPortSetupTimerInterrupt
133
134     /* Restore the context of the first task that is going to run. */
135     portRESTORE_CONTEXT
136 /*-----------------------------------------------------------*/
137
138     END