]> begriffs open source - freertos/blob - portable/CCS/MSP430X/portext.asm
[AUTO][RELEASE]: Bump file header version to "11.2.0"
[freertos] / portable / CCS / MSP430X / portext.asm
1 ;/*
2 ; * FreeRTOS Kernel V11.2.0
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
29 ; * The definition of the "register test" tasks, as described at the top of
30 ; * main.c
31
32     .include data_model.h
33
34     .global xTaskIncrementTick
35     .global vTaskSwitchContext
36     .global vPortSetupTimerInterrupt
37     .global pxCurrentTCB
38     .global usCriticalNesting
39
40     .def vPortPreemptiveTickISR
41     .def vPortCooperativeTickISR
42     .def vPortYield
43     .def xPortStartScheduler
44
45 ;-----------------------------------------------------------
46
47 portSAVE_CONTEXT .macro
48
49     ;Save the remaining registers.
50     pushm_x #12, r15
51     movx.w   &usCriticalNesting, r14
52     push_x r14
53     mov_x   &pxCurrentTCB, r12
54     mov_x   sp, 0( r12 )
55     .endm
56 ;-----------------------------------------------------------
57
58 portRESTORE_CONTEXT .macro
59
60     mov_x   &pxCurrentTCB, r12
61     mov_x   @r12, sp
62     pop_x   r15
63     movx.w   r15, &usCriticalNesting
64     popm_x  #12, r15
65     nop
66     pop.w   sr
67     nop
68     ret_x
69     .endm
70 ;-----------------------------------------------------------
71
72 ;*
73 ;* The RTOS tick ISR.
74 ;*
75 ;* If the cooperative scheduler is in use this simply increments the tick
76 ;* count.
77 ;*
78 ;* If the preemptive scheduler is in use a context switch can also occur.
79 ;*/
80
81     .text
82     .align 2
83
84 vPortPreemptiveTickISR: .asmfunc
85
86     ; The sr is not saved in portSAVE_CONTEXT() because vPortYield() needs
87     ;to save it manually before it gets modified (interrupts get disabled).
88     push.w sr
89     portSAVE_CONTEXT
90
91     call_x  #xTaskIncrementTick
92     call_x  #vTaskSwitchContext
93
94     portRESTORE_CONTEXT
95     .endasmfunc
96 ;-----------------------------------------------------------
97
98     .align 2
99
100 vPortCooperativeTickISR: .asmfunc
101
102     ; The sr is not saved in portSAVE_CONTEXT() because vPortYield() needs
103     ;to save it manually before it gets modified (interrupts get disabled).
104     push.w sr
105     portSAVE_CONTEXT
106
107     call_x  #xTaskIncrementTick
108
109     portRESTORE_CONTEXT
110
111     .endasmfunc
112 ;-----------------------------------------------------------
113
114 ;
115 ; Manual context switch called by the portYIELD() macro.
116 ;
117
118     .align 2
119
120 vPortYield: .asmfunc
121
122     ; The sr needs saving before it is modified.
123     push.w  sr
124
125     ; Now the SR is stacked we can disable interrupts.
126     dint
127     nop
128
129     ; Save the context of the current task.
130     portSAVE_CONTEXT
131
132     ; Select the next task to run.
133     call_x  #vTaskSwitchContext
134
135     ; Restore the context of the new task.
136     portRESTORE_CONTEXT
137     .endasmfunc
138 ;-----------------------------------------------------------
139
140
141 ;
142 ; Start off the scheduler by initialising the RTOS tick timer, then restoring
143 ; the context of the first task.
144 ;
145
146     .align 2
147
148 xPortStartScheduler: .asmfunc
149
150     ; Setup the hardware to generate the tick.  Interrupts are disabled
151     ; when this function is called.
152     call_x  #vPortSetupTimerInterrupt
153
154     ; Restore the context of the first task that is going to run.
155     portRESTORE_CONTEXT
156     .endasmfunc
157 ;-----------------------------------------------------------
158
159     .end