summaryrefslogtreecommitdiff
path: root/ports/c667x/ccs/src/tx_timer_interrupt.asm
blob: 48df12d708251771ffa0573a26bc3aa300a1565c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
;/***************************************************************************
; * Copyright (c) 2024 Microsoft Corporation
; *
; * This program and the accompanying materials are made available under the
; * terms of the MIT License which is available at
; * https://opensource.org/licenses/MIT.
; *
; * SPDX-License-Identifier: MIT
; **************************************************************************/
;
;
;/**************************************************************************/
;/**************************************************************************/
;/**                                                                       */
;/** ThreadX Component                                                     */
;/**                                                                       */
;/**   Timer                                                               */
;/**                                                                       */
;/**************************************************************************/
;/**************************************************************************/
;
;#define TX_SOURCE_CODE
;
;
;/* Include necessary system files.  */
;
;#include "tx_api.h"
;#include "tx_timer.h"
;#include "tx_thread.h"
;
FP          .set    A15
DP          .set    B14
SP          .set    B15
;
;Define Assembly language external references...
;
    .global     _tx_timer_time_slice
    .global     _tx_timer_system_clock
    .global     _tx_timer_current_ptr
    .global     _tx_timer_list_start
    .global     _tx_timer_list_end
    .global     _tx_timer_expired_time_slice
    .global     _tx_timer_expired
    .global     _tx_timer_expiration_process
    .global     _tx_thread_time_slice
    .global     _tx_thread_context_save
    .global     _tx_thread_context_restore
;
;
    .sect   ".text"
;/**************************************************************************/
;/*                                                                        */
;/*  FUNCTION                                               RELEASE        */
;/*                                                                        */
;/*    _tx_timer_interrupt                                 C667x/TI        */
;/*                                                           6.1          */
;/*  AUTHOR                                                                */
;/*                                                                        */
;/*    William E. Lamie, Microsoft Corporation                             */
;/*                                                                        */
;/*  DESCRIPTION                                                           */
;/*                                                                        */
;/*    This function processes the hardware timer interrupt.  This         */
;/*    processing includes incrementing the system clock and checking for  */
;/*    time slice and/or timer expiration.  If either is found, the        */
;/*    interrupt context save/restore functions are called along with the  */
;/*    expiration functions.                                               */
;/*                                                                        */
;/*  INPUT                                                                 */
;/*                                                                        */
;/*    None                                                                */
;/*                                                                        */
;/*  OUTPUT                                                                */
;/*                                                                        */
;/*    None                                                                */
;/*                                                                        */
;/*  CALLS                                                                 */
;/*                                                                        */
;/*    _tx_thread_context_save               Context save                  */
;/*    _tx_thread_context_restore            Context restore               */
;/*    _tx_thread_time_slice                 Time slice interrupted thread */
;/*    _tx_timer_expiration_process          Timer expiration processing   */
;/*                                                                        */
;/*  CALLED BY                                                             */
;/*                                                                        */
;/*    interrupt vector                                                    */
;/*                                                                        */
;/*  RELEASE HISTORY                                                       */
;/*                                                                        */
;/*    DATE              NAME                      DESCRIPTION             */
;/*                                                                        */
;/*  09-30-2020     William E. Lamie         Initial Version 6.1           */
;/*                                                                        */
;/**************************************************************************/
;VOID   _tx_timer_interrupt(VOID)
;{
    .global _tx_timer_interrupt
_tx_timer_interrupt:
;
;    /* Upon entry to this routine, it is assumed that registers B3, A0-A4 have
;       already been saved and the space for saving additional registers has
;       already been reserved.  In addition, interrupts are locked out and must
;       remain so until context save returns.  */
;
;    /* Increment the system clock.  */
;    _tx_timer_system_clock++;
;
        MVKL        _tx_timer_system_clock,A0           ; Build address of system clock
        MVKH        _tx_timer_system_clock,A0           ;
        LDW         *A0,A2                              ; Pickup system clock
        MVKL        _tx_timer_time_slice,A3             ; Build address of time slice
        MVKH        _tx_timer_time_slice,A3             ;
        LDW         *A3,A1                              ; Pickup time slice
        NOP         2                                   ; Delay
        ADD         1,A2,A2                             ; Increment the system clock
        STW         A2,*A0                              ; Store it back in memory
;
;    /* Test for time-slice expiration.  */
;    if (_tx_timer_time_slice)
;    {
;
 [!A1]  B           _tx_timer_no_time_slice             ; If 0, skip time slice processing
        SUB         A1,1,A1                             ; Decrement time-slice value
        NOP         4                                   ; Delay slots
;
;       /* Decrement the time_slice.  */
;       _tx_timer_time_slice--;
;
;       /* Check for expiration.  */
;       if (_tx_timer_time_slice == 0)
;
 [A1]   B           _tx_timer_no_time_slice             ; If non-zero, not expired yet
        STW         A1,*A3                              ; Store new time-slice
        MVKL        _tx_timer_expired_time_slice,A0     ; Build address of expired flag
        MVKH        _tx_timer_expired_time_slice,A0     ;
        MVKL        1,A4                                ; Expired flag
        NOP                                             ; Delay
;
;       /* Set the time-slice expired flag.  */
;       _tx_timer_expired_time_slice =  TX_TRUE;
;
        STW         A4,*A0                              ; Set expired flag
;    }
;
_tx_timer_no_time_slice:
;
;    /* Test for timer expiration.  */
;    if (*_tx_timer_current_ptr)
;    {
;
        MVKL        _tx_timer_current_ptr,A2            ; Build address of current timer pointer
        MVKH        _tx_timer_current_ptr,A2            ;
        LDW         *A2,A0                              ; Pickup timer list address
        MVKL        _tx_timer_expired,A3                ; Build address of expired flag
        MVKH        _tx_timer_expired,A3                ;
        NOP         2                                   ; Delay slots
        LDW         *A0,A1                              ; Pickup current timer entry
        ADD         4,A0,A0                             ; Increment the current pointer
        NOP         3                                   ; Delay slots
 [A1]   B           _tx_timer_done                      ; If non-NULL, something has expired
;
;
;        /* Set expiration flag.  */
;        _tx_timer_expired =  TX_TRUE;
;
        MVKL        1,A4                                ; Build expired flag
 [A1]   STW         A4,*A3                              ; Set expired flag
        NOP         3                                   ; Delay slots
;
;    }
;    else
;    {
_tx_timer_no_timer:
;
;        /* No timer expired, increment the timer pointer.  */
;        _tx_timer_current_ptr++;
;
;        /* Check for wrap-around.  */
;        if (_tx_timer_current_ptr == _tx_timer_list_end)
;
        MVKL        _tx_timer_list_end,A3               ; Build timer list end address
        MVKH        _tx_timer_list_end,A3               ;
        LDW         *A3,A4                              ; Pickup list end address
        MVKL        _tx_timer_list_start,A3             ; Build timer list start address
        MVKH        _tx_timer_list_start,A3             ;
        NOP         2                                   ; Delay slots
        CMPEQ       A4,A0,A1                            ; Compare current pointer with end
 [A1]   LDW         *A3,A0                              ; If at the end, pickup timer list start
        NOP         4                                   ; Delay slots
;
;            /* Wrap to beginning of list.  */
;            _tx_timer_current_ptr =  _tx_timer_list_start;
;
_tx_timer_skip_wrap:
;
;
        STW         A0,*A2                              ; Store current timer pointer
;    }
;
_tx_timer_done:
;
;
;    /* See if anything has expired.  */
;    if ((_tx_timer_expired_time_slice) || (_tx_timer_expired))
;    {
;
        MVKL        _tx_timer_expired_time_slice,A3     ; Build time-slice expired flag
        MVKH        _tx_timer_expired_time_slice,A3     ;
        LDW         *A3,A4                              ; Pickup time-slice expired flag
        MVKL        _tx_timer_expired,A0                ; Build timer expired flag
        MVKH        _tx_timer_expired,A0                ;
        LDW         *A0,A2                              ; Pickup timer expired flag
        NOP         4                                   ; Delay slots
        OR          A2,A4,A1                            ; Combine expired flags
 [!A1]  B           _tx_timer_nothing_expired
        NOP         5                                   ; Delay slots
;
_tx_something_expired:
;
;
;    /* Something expired, call context save.  */
;    _tx_thread_context_save();
;
        B           _tx_thread_context_save             ; Call context save routine
        MVKL        _tx_timer_ISR_return,B3             ; Build return address
        MVKH        _tx_timer_ISR_return,B3             ;
        NOP         3                                   ; Delay slots
_tx_timer_ISR_return:
;
;    /* Did a timer expire?  */
;    if (_tx_timer_expired)
;    {
;
        MVKL        _tx_timer_expired,A0                ; Build timer expired address
        MVKH        _tx_timer_expired,A0                ;
        LDW         *A0,A1                              ; Pickup expired flag
        NOP         4                                   ; Delay slots
 [!A1]  B           _tx_timer_dont_activate             ; If not set, skip timer activation
        NOP         5                                   ; Delay slots
;
;        /* Process timer expiration.  */
;        _tx_timer_expiration_process();
;
        B           _tx_timer_expiration_process        ; Process timer expiration
        MVKL        _tx_timer_ISR_return_1,B3           ; Build return address
        MVKH        _tx_timer_ISR_return_1,B3           ;
        NOP         3                                   ; Delay slots
_tx_timer_ISR_return_1:
;
;    }
_tx_timer_dont_activate:
;
;    /* Did time slice expire?  */
;    if (_tx_timer_expired_time_slice)
;    {
;
        MVKL        _tx_timer_expired_time_slice,A0     ; Build address of expired flag
        MVKH        _tx_timer_expired_time_slice,A0     ;
        LDW         *A0,A1                              ; Pickup expired flag
        NOP         4                                   ; Delay slots
 [!A1]  B           _tx_timer_not_ts_expiration         ; If not set, skip time-slice processing
        NOP         5                                   ; Delay slots
;
;        /* Time slice interrupted thread.  */
;        _tx_thread_time_slice();
;
        B           _tx_thread_time_slice               ; Call time-slice processing
        MVKL        _tx_timer_ISR_return_2,B3           ; Build return address
        MVKH        _tx_timer_ISR_return_2,B3           ;
        NOP         3                                   ; Delay slots
_tx_timer_ISR_return_2:
;
;    }
;
_tx_timer_not_ts_expiration:
;
;
;    /* Call context restore.  */
;    _tx_thread_context_restore();
;
        B           _tx_thread_context_restore          ; Jump to context restore - no return!
        NOP         5                                   ; Delay slots
;
;    }
;
_tx_timer_nothing_expired:
;
        LDW         *+SP(20),A0                         ; Recover A0
        LDW         *+SP(24),A1                         ; Recover A1
        LDW         *+SP(28),A2                         ; Recover A2
        LDW         *+SP(32),A3                         ; Recover A3
        B           IRP                                 ; Return to point of interrupt
||      LDW         *+SP(36),A4                         ; Recover A4
        LDW         *+SP(96),B3                         ; Recover B3
        ADDK.S2     288,SP                              ; Recover stack space
        NOP         3                                   ; Delay slots
;
;}