2018-11-16 20:30:56 +08:00
|
|
|
;
|
2022-01-18 13:35:13 +08:00
|
|
|
; Copyright (c) 2006-2022, RT-Thread Development Team
|
2018-11-16 20:30:56 +08:00
|
|
|
;
|
|
|
|
; SPDX-License-Identifier: Apache-2.0
|
|
|
|
;
|
|
|
|
; Change Logs:
|
|
|
|
; Date Author Notes
|
|
|
|
; 2018-09-01 xuzhuoyi the first version.
|
2019-07-03 19:31:54 +08:00
|
|
|
; 2019-06-17 zhaoxiaowei fix bugs of old c28x interrupt api.
|
|
|
|
; 2019-07-03 zhaoxiaowei add _rt_hw_calc_csb function to support __rt_ffs.
|
2019-12-05 21:50:48 +08:00
|
|
|
; 2019-12-05 xiaolifan add support for hardware fpu32
|
2022-08-21 01:16:41 +08:00
|
|
|
; 2022-06-21 guyunjie trim pendsv (RTOSINT_Handler)
|
2022-08-30 03:35:23 +08:00
|
|
|
; 2022-08-24 guyunjie fix bugs in context switching
|
2018-09-02 18:44:28 +08:00
|
|
|
|
|
|
|
.ref _rt_interrupt_to_thread
|
|
|
|
.ref _rt_interrupt_from_thread
|
|
|
|
.ref _rt_thread_switch_interrupt_flag
|
|
|
|
|
|
|
|
.def _RTOSINT_Handler
|
|
|
|
.def _rt_hw_get_st0
|
|
|
|
.def _rt_hw_get_st1
|
2019-07-03 19:31:54 +08:00
|
|
|
.def _rt_hw_calc_csb
|
2018-09-02 18:44:28 +08:00
|
|
|
.def _rt_hw_context_switch_interrupt
|
|
|
|
.def _rt_hw_context_switch
|
|
|
|
.def _rt_hw_context_switch_to
|
|
|
|
.def _rt_hw_interrupt_thread_switch
|
|
|
|
.def _rt_hw_interrupt_disable
|
|
|
|
.def _rt_hw_interrupt_enable
|
2022-01-18 13:35:13 +08:00
|
|
|
|
2019-12-05 21:50:48 +08:00
|
|
|
;workaround for importing fpu settings from the compiler
|
2019-12-09 09:29:12 +08:00
|
|
|
.cdecls C,NOLIST
|
|
|
|
%{
|
|
|
|
#ifdef __TMS320C28XX_FPU32__
|
|
|
|
#define __FPU32__ 1
|
|
|
|
#else
|
|
|
|
#define __FPU32__ 0
|
|
|
|
#endif
|
|
|
|
%}
|
2018-09-02 18:44:28 +08:00
|
|
|
|
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
RT_CTX_SAVE .macro
|
2018-09-02 18:44:28 +08:00
|
|
|
|
|
|
|
PUSH AR1H:AR0H
|
|
|
|
PUSH XAR2
|
|
|
|
PUSH XAR3
|
|
|
|
PUSH XAR4
|
|
|
|
PUSH XAR5
|
|
|
|
PUSH XAR6
|
|
|
|
PUSH XAR7
|
|
|
|
PUSH XT
|
|
|
|
PUSH RPC
|
2022-01-18 13:35:13 +08:00
|
|
|
|
2019-12-09 09:29:12 +08:00
|
|
|
.if __FPU32__
|
2022-01-18 13:35:13 +08:00
|
|
|
PUSH RB
|
|
|
|
MOV32 *SP++, STF
|
|
|
|
MOV32 *SP++, R0H
|
|
|
|
MOV32 *SP++, R1H
|
|
|
|
MOV32 *SP++, R2H
|
|
|
|
MOV32 *SP++, R3H
|
|
|
|
MOV32 *SP++, R4H
|
|
|
|
MOV32 *SP++, R5H
|
|
|
|
MOV32 *SP++, R6H
|
|
|
|
MOV32 *SP++, R7H
|
2019-12-09 09:29:12 +08:00
|
|
|
.endif
|
2022-01-18 13:35:13 +08:00
|
|
|
|
2018-09-02 18:44:28 +08:00
|
|
|
.endm
|
|
|
|
|
|
|
|
|
|
|
|
RT_CTX_RESTORE .macro
|
2019-12-05 21:50:48 +08:00
|
|
|
|
2019-12-09 09:29:12 +08:00
|
|
|
.if __FPU32__
|
2022-01-18 13:35:13 +08:00
|
|
|
MOV32 R7H, *--SP, UNCF
|
|
|
|
MOV32 R6H, *--SP, UNCF
|
|
|
|
MOV32 R5H, *--SP, UNCF
|
|
|
|
MOV32 R4H, *--SP, UNCF
|
|
|
|
MOV32 R3H, *--SP, UNCF
|
|
|
|
MOV32 R2H, *--SP, UNCF
|
|
|
|
MOV32 R1H, *--SP, UNCF
|
|
|
|
MOV32 R0H, *--SP, UNCF
|
|
|
|
MOV32 STF, *--SP
|
|
|
|
POP RB
|
2019-12-09 09:29:12 +08:00
|
|
|
.endif
|
2022-01-18 13:35:13 +08:00
|
|
|
|
2018-09-02 18:44:28 +08:00
|
|
|
POP RPC
|
|
|
|
POP XT
|
|
|
|
POP XAR7
|
|
|
|
POP XAR6
|
|
|
|
POP XAR5
|
|
|
|
POP XAR4
|
|
|
|
POP XAR3
|
|
|
|
POP XAR2
|
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
MOVZ AR0 , @SP
|
2018-09-02 18:44:28 +08:00
|
|
|
SUBB XAR0, #6
|
|
|
|
MOVL ACC , *XAR0
|
|
|
|
AND ACC, #0xFFFF << 16
|
|
|
|
MOV AL, IER
|
|
|
|
MOVL *XAR0, ACC
|
|
|
|
|
|
|
|
POP AR1H:AR0H
|
|
|
|
|
|
|
|
.endm
|
|
|
|
|
|
|
|
|
|
|
|
.text
|
|
|
|
.newblock
|
|
|
|
|
|
|
|
;
|
|
|
|
; rt_base_t rt_hw_interrupt_disable();
|
|
|
|
;
|
|
|
|
.asmfunc
|
|
|
|
_rt_hw_interrupt_disable:
|
2019-06-18 20:59:00 +08:00
|
|
|
PUSH ST1
|
|
|
|
SETC INTM,DBGM
|
|
|
|
MOV AL, *--SP
|
2018-09-02 18:44:28 +08:00
|
|
|
LRETR
|
|
|
|
.endasmfunc
|
|
|
|
|
|
|
|
;
|
|
|
|
; void rt_hw_interrupt_enable(rt_base_t level);
|
|
|
|
;
|
|
|
|
.asmfunc
|
|
|
|
_rt_hw_interrupt_enable:
|
2019-06-18 20:59:00 +08:00
|
|
|
MOV *SP++, AL
|
|
|
|
POP ST1
|
2018-09-02 18:44:28 +08:00
|
|
|
LRETR
|
|
|
|
.endasmfunc
|
2022-01-18 13:35:13 +08:00
|
|
|
|
2018-09-02 18:44:28 +08:00
|
|
|
;
|
|
|
|
; void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
|
2022-08-30 03:35:23 +08:00
|
|
|
; ACC --> from
|
|
|
|
; SP[4] --> to
|
|
|
|
;
|
2018-09-02 18:44:28 +08:00
|
|
|
.asmfunc
|
|
|
|
_rt_hw_context_switch_interrupt:
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL XAR0, ACC
|
2018-09-03 23:02:16 +08:00
|
|
|
MOVL XAR4, *-SP[4]
|
2019-04-10 22:33:25 +08:00
|
|
|
; set rt_thread_switch_interrupt_flag to 1
|
2018-09-03 23:02:16 +08:00
|
|
|
MOVL XAR5, #_rt_thread_switch_interrupt_flag
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL ACC, *XAR5
|
|
|
|
BF _reswitch, NEQ ; ACC!=0
|
|
|
|
MOVB ACC, #1
|
|
|
|
MOVL *XAR5, ACC
|
2018-09-02 18:44:28 +08:00
|
|
|
|
2018-09-03 23:02:16 +08:00
|
|
|
MOVL XAR5, #_rt_interrupt_from_thread ; set rt_interrupt_from_thread
|
|
|
|
MOVL *XAR5, XAR0
|
2018-09-02 18:44:28 +08:00
|
|
|
|
|
|
|
_reswitch:
|
2018-09-03 23:02:16 +08:00
|
|
|
MOVL XAR5, #_rt_interrupt_to_thread ; set rt_interrupt_to_thread
|
|
|
|
MOVL *XAR5, XAR4
|
2018-09-02 18:44:28 +08:00
|
|
|
|
2019-04-10 22:33:25 +08:00
|
|
|
LRETR
|
|
|
|
.endasmfunc
|
|
|
|
|
|
|
|
;
|
|
|
|
; void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
|
2022-08-30 03:35:23 +08:00
|
|
|
; ACC --> from
|
|
|
|
; SP[4] --> to
|
|
|
|
;
|
2019-04-10 22:33:25 +08:00
|
|
|
.asmfunc
|
|
|
|
_rt_hw_context_switch:
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL XAR0, ACC
|
2019-04-10 22:33:25 +08:00
|
|
|
MOVL XAR4, *-SP[4]
|
2022-01-18 13:35:13 +08:00
|
|
|
; set rt_thread_switch_interrupt_flag to 1
|
2019-04-10 22:33:25 +08:00
|
|
|
MOVL XAR5, #_rt_thread_switch_interrupt_flag
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL ACC, *XAR5
|
|
|
|
BF _reswitch2, NEQ ; ACC!=0
|
|
|
|
MOVB ACC, #1
|
|
|
|
MOVL *XAR5, ACC
|
2019-04-10 22:33:25 +08:00
|
|
|
|
|
|
|
MOVL XAR5, #_rt_interrupt_from_thread ; set rt_interrupt_from_thread
|
|
|
|
MOVL *XAR5, XAR0
|
|
|
|
|
|
|
|
_reswitch2:
|
|
|
|
MOVL XAR5, #_rt_interrupt_to_thread ; set rt_interrupt_to_thread
|
|
|
|
MOVL *XAR5, XAR4
|
|
|
|
|
2018-09-02 18:44:28 +08:00
|
|
|
TRAP #16
|
|
|
|
LRETR
|
|
|
|
.endasmfunc
|
2022-01-18 13:35:13 +08:00
|
|
|
|
2022-08-30 03:35:23 +08:00
|
|
|
;
|
|
|
|
; * void rt_hw_context_switch_to(rt_uint32 to);
|
|
|
|
; * ACC --> to
|
|
|
|
;
|
|
|
|
.asmfunc
|
|
|
|
_rt_hw_context_switch_to:
|
|
|
|
; get to thread
|
|
|
|
MOVL XAR1, #_rt_interrupt_to_thread
|
|
|
|
MOVL *XAR1, ACC
|
|
|
|
|
|
|
|
; set from thread to 0
|
|
|
|
MOVL XAR1, #_rt_interrupt_from_thread
|
|
|
|
MOVL XAR0, #0
|
|
|
|
MOVL *XAR1, XAR0
|
|
|
|
|
|
|
|
; set interrupt flag to 1
|
|
|
|
MOVL XAR1, #_rt_thread_switch_interrupt_flag
|
|
|
|
MOVL XAR0, #1
|
|
|
|
MOVL *XAR1, XAR0
|
|
|
|
|
|
|
|
TRAP #16
|
|
|
|
|
|
|
|
; never reach here!
|
|
|
|
.endasmfunc
|
|
|
|
|
|
|
|
.asmfunc
|
2018-09-02 18:44:28 +08:00
|
|
|
_RTOSINT_Handler:
|
2022-08-21 01:16:41 +08:00
|
|
|
; disable interrupt to protect context switch
|
|
|
|
; DINT ;this is done by hardware so not needed
|
2018-09-02 18:44:28 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
; get rt_thread_switch_interrupt_flag
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL XAR0, #_rt_thread_switch_interrupt_flag
|
|
|
|
MOVL ACC, *XAR0
|
|
|
|
BF rtosint_exit, EQ ; pendsv already handled
|
2018-09-02 18:44:28 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
; clear rt_thread_switch_interrupt_flag to 0
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL XAR1, #0
|
|
|
|
MOVL *XAR0, XAR1
|
2022-01-18 13:35:13 +08:00
|
|
|
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL XAR0, #_rt_interrupt_from_thread
|
|
|
|
MOVL ACC, *XAR0
|
|
|
|
BF switch_to_thread, EQ ; skip register save at the first time
|
2018-09-02 18:44:28 +08:00
|
|
|
|
2022-08-30 03:35:23 +08:00
|
|
|
RT_CTX_SAVE ; push cpu registers
|
2018-09-02 18:44:28 +08:00
|
|
|
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL ACC, *XAR0
|
|
|
|
MOVL XAR0, ACC
|
2018-09-02 18:44:28 +08:00
|
|
|
MOVZ AR1, @SP ; get from thread stack pointer
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL *XAR0, XAR1 ; update from thread stack pointer
|
2018-09-02 18:44:28 +08:00
|
|
|
|
|
|
|
switch_to_thread:
|
2022-08-30 03:35:23 +08:00
|
|
|
MOVL XAR1, #_rt_interrupt_to_thread
|
|
|
|
MOVL ACC, *XAR1
|
|
|
|
MOVL XAR1, ACC
|
|
|
|
MOVL ACC, *XAR1
|
|
|
|
MOV @SP, AL ; load thread stack pointer
|
2018-09-02 18:44:28 +08:00
|
|
|
|
2022-08-30 03:35:23 +08:00
|
|
|
RT_CTX_RESTORE ; pop cpu registers
|
2018-09-02 18:44:28 +08:00
|
|
|
|
|
|
|
rtosint_exit:
|
2022-08-21 01:16:41 +08:00
|
|
|
; do not restore interrupt here: to be restored according to the
|
|
|
|
; switched-to context during IRET (automaticlly by hardware)
|
2018-09-02 18:44:28 +08:00
|
|
|
|
|
|
|
IRET
|
|
|
|
.endasmfunc
|
|
|
|
|
|
|
|
.asmfunc
|
|
|
|
_rt_hw_get_st0:
|
|
|
|
PUSH ST0
|
|
|
|
POP AL
|
|
|
|
LRETR
|
|
|
|
.endasmfunc
|
|
|
|
|
|
|
|
.asmfunc
|
|
|
|
_rt_hw_get_st1:
|
|
|
|
PUSH ST1
|
|
|
|
POP AL
|
|
|
|
LRETR
|
|
|
|
.endasmfunc
|
|
|
|
|
2019-07-03 19:31:54 +08:00
|
|
|
; C28x do not have a build-in "__ffs" func in its C compiler.
|
|
|
|
; We can use the "Count Sign Bits" (CSB) instruction to make one.
|
|
|
|
; CSB will return the number of 0's minus 1 above the highest set bit.
|
|
|
|
; The count is placed in T. For example:
|
|
|
|
; ACC T maxbit
|
|
|
|
; 0x00000001 30 0
|
|
|
|
; 0x00000010 26 4
|
|
|
|
; 0x000001FF 22 8
|
|
|
|
; 0x000001F0 22 8
|
|
|
|
.asmfunc
|
|
|
|
_rt_hw_calc_csb:
|
|
|
|
MOV AH, #0
|
|
|
|
CSB ACC ; T = no. of sign bits - 1
|
|
|
|
MOVU ACC, T ; ACC = no. of sign bits - 1
|
|
|
|
SUBB ACC, #30 ; ACC = ACC - 30
|
|
|
|
ABS ACC ; ACC = |ACC|
|
|
|
|
lretr
|
|
|
|
.endasmfunc
|
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
; compatible with old version
|
2018-09-02 18:44:28 +08:00
|
|
|
.asmfunc
|
|
|
|
_rt_hw_interrupt_thread_switch:
|
|
|
|
LRETR
|
|
|
|
NOP
|
|
|
|
.endasmfunc
|
2022-01-18 13:35:13 +08:00
|
|
|
|
2018-09-02 18:44:28 +08:00
|
|
|
.end
|