Migrates plain ThreadX to the upstream RISC-V ports
Keeps the Moonlight startup objects local to the board. Updates the plain and SMP VP regression harnesses for the new ThreadX revision and replaces generated ISR hooks with direct callbacks.
This commit is contained in:
1 parent
26fd407a1e
commit
d404e17e5a
22 files changed
+148
-2311
No files matched your search
@@ -1,85 +1,43 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 Microsoft Corporation
|
||||
*
|
||||
* 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
|
||||
**************************************************************************/
|
||||
.section .text
|
||||
.align 4
|
||||
#include "tx_port.h"
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* trap_entry RISC-V64/GNU */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Jer6y , luojun@oerv.isrc.iscas.ac.cn */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function is responsible for riscv processor trap handle */
|
||||
/* It will do the contex save and call c trap_handler and do contex */
|
||||
/* load */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* trap_handler */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* hardware exception */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 10-25-2024 Jerry Luo */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tx_port.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/** */
|
||||
/** ThreadX Component */
|
||||
/** */
|
||||
/** Initialize */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
.global trap_entry
|
||||
.extern _tx_thread_context_restore
|
||||
trap_entry:
|
||||
addi sp, sp, -TX_INTERRUPT_FRAME_SIZE
|
||||
#if __riscv_xlen == 64
|
||||
#define REG_STORE sd
|
||||
#define REG_LOAD ld
|
||||
#define REG_BYTES 8
|
||||
#else
|
||||
#define REG_STORE sw
|
||||
#define REG_LOAD lw
|
||||
#define REG_BYTES 4
|
||||
#endif
|
||||
|
||||
STORE x1, 28*REGBYTES(sp) // Store RA, 28*REGBYTES(because call will override ra [ra is a calle register in riscv])
|
||||
.section .text
|
||||
.balign 4
|
||||
.global trap_entry
|
||||
.type trap_entry, @function
|
||||
trap_entry:
|
||||
addi sp, sp, -TX_RISCV_TRAP_FRAME_SIZE
|
||||
REG_STORE ra, (28 * REG_BYTES)(sp)
|
||||
call _tx_thread_context_save
|
||||
|
||||
call _tx_thread_context_save
|
||||
csrr a0, mcause
|
||||
csrr a1, mepc
|
||||
csrr a2, mtval
|
||||
addi sp, sp, -TX_RISCV_TRAP_CALL_FRAME_SIZE
|
||||
REG_STORE ra, 0(sp)
|
||||
call trap_handler
|
||||
REG_LOAD ra, 0(sp)
|
||||
addi sp, sp, TX_RISCV_TRAP_CALL_FRAME_SIZE
|
||||
|
||||
csrr a0, mcause
|
||||
csrr a1, mepc
|
||||
csrr a2, mtval
|
||||
addi sp, sp, -16 // Keep the C handler stack aligned
|
||||
STORE ra, 0(sp)
|
||||
call trap_handler
|
||||
LOAD ra, 0(sp)
|
||||
addi sp, sp, 16
|
||||
call _tx_thread_context_restore
|
||||
// it will nerver return
|
||||
.weak trap_handler
|
||||
trap_handler:
|
||||
1:
|
||||
j 1b
|
||||
.section .text
|
||||
call _tx_thread_context_restore
|
||||
1: j 1b
|
||||
.size trap_entry, .-trap_entry
|
||||
@@ -1,24 +1,32 @@
|
||||
|
||||
#include "board.h"
|
||||
#include "csr.h"
|
||||
#include "hwtimer.h"
|
||||
#include "riscv-traps.h"
|
||||
#include "tx_port.h"
|
||||
#include "tx_api.h"
|
||||
#include "tx_initialize.h"
|
||||
#include "tx_thread.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern CHAR __heap_start;
|
||||
extern CHAR __heap_start[];
|
||||
extern void trap_entry(void);
|
||||
extern void _tx_timer_interrupt(void);
|
||||
|
||||
extern ULONG* _tx_thread_system_stack_ptr;
|
||||
extern ULONG* _tx_initialize_unused_memory;
|
||||
#ifdef TX_REGRESSION_TEST
|
||||
extern void test_interrupt_dispatch(void) __attribute__((weak));
|
||||
#endif
|
||||
|
||||
void handle_RISCV_INT_MTI(void)
|
||||
static void handle_RISCV_INT_MTI(void)
|
||||
{
|
||||
hwtimer_handler();
|
||||
#ifdef TX_REGRESSION_TEST
|
||||
if (test_interrupt_dispatch)
|
||||
test_interrupt_dispatch();
|
||||
#endif
|
||||
_tx_timer_interrupt();
|
||||
}
|
||||
void handle_RISCV_INT_MEI()
|
||||
|
||||
static void handle_RISCV_INT_MEI(void)
|
||||
{
|
||||
puts("[INTERRUPT]: handler ext irq error!\n");
|
||||
while (1)
|
||||
@@ -27,19 +35,19 @@ void handle_RISCV_INT_MEI()
|
||||
|
||||
VOID _tx_initialize_low_level(VOID)
|
||||
{
|
||||
_tx_thread_system_stack_ptr = (VOID*)(ULONG)riscv_get_sp();
|
||||
_tx_initialize_unused_memory = (VOID*)&__heap_start;
|
||||
_tx_thread_system_stack_ptr = (VOID*)(uintptr_t)riscv_get_sp();
|
||||
_tx_initialize_unused_memory = __heap_start;
|
||||
|
||||
// disable interrupts
|
||||
asm volatile("csrrc zero, mstatus, %0" : : "r"(MSTATUS_MIE));
|
||||
csr_clr_bits_mstatus(MSTATUS_MIE);
|
||||
// set previous interrupt enable and previous priv mode to be set when executing "mret"
|
||||
asm volatile("csrrs zero, mstatus, %0" : : "r"(MSTATUS_MPP_M | MSTATUS_MPIE));
|
||||
csr_set_bits_mstatus(MSTATUS_MPP_M | MSTATUS_MPIE);
|
||||
// enable timer, software and external interrupts
|
||||
asm volatile("csrrs zero, mie, %0" : : "r"(MIE_MTIE | MIE_MSIE | MIE_MEIE));
|
||||
csr_set_bits_mie(MIE_MTIE | MIE_MSIE | MIE_MEIE);
|
||||
|
||||
#ifdef __riscv_flen
|
||||
// enable f extension and reset state
|
||||
asm volatile("csrrs zero, mstatus, %0" : : "r"(MSTATUS_FS));
|
||||
csr_set_bits_mstatus(MSTATUS_FS);
|
||||
asm volatile("fscsr x0");
|
||||
#endif
|
||||
|
||||
@@ -47,5 +55,5 @@ VOID _tx_initialize_low_level(VOID)
|
||||
register_irq_handler(RISCV_INT_MTI, handle_RISCV_INT_MTI);
|
||||
register_irq_handler(RISCV_INT_MEI, handle_RISCV_INT_MEI);
|
||||
|
||||
asm volatile("csrw mtvec, %0" : : "r"((uintptr_t)trap_entry));
|
||||
}
|
||||
csr_write_mtvec((uintptr_t)trap_entry);
|
||||
}
|
||||
@@ -1,315 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** Thread */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tx_port.h"
|
||||
|
||||
.section .text
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _tx_thread_context_restore RISC-V64/GNU */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Scott Larson, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function restores the interrupt context if it is processing a */
|
||||
/* nested interrupt. If not, it returns to the interrupt thread if no */
|
||||
/* preemption is necessary. Otherwise, if preemption is necessary or */
|
||||
/* if no thread was running, the function returns to the scheduler. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _tx_thread_schedule Thread scheduling routine */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* ISRs Interrupt Service Routines */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/* VOID _tx_thread_context_restore(VOID)
|
||||
{ */
|
||||
.global _tx_thread_context_restore
|
||||
_tx_thread_context_restore:
|
||||
|
||||
/* Lockout interrupts. */
|
||||
|
||||
csrci mstatus, 0x08 // Disable interrupts
|
||||
|
||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
||||
call _tx_execution_isr_exit // Call the ISR execution exit function
|
||||
#endif
|
||||
|
||||
/* Determine if interrupts are nested. */
|
||||
/* if (--_tx_thread_system_state)
|
||||
{ */
|
||||
|
||||
la t0, _tx_thread_system_state // Pickup addr of nested interrupt count
|
||||
LOAD t1, 0(t0) // Pickup nested interrupt count
|
||||
addi t1, t1, -1 // Decrement the nested interrupt counter
|
||||
STORE t1, 0(t0) // Store new nested count
|
||||
beqz t1, _tx_thread_not_nested_restore // If 0, not nested restore
|
||||
|
||||
/* Interrupts are nested. */
|
||||
|
||||
/* Just recover the saved registers and return to the point of
|
||||
interrupt. */
|
||||
|
||||
/* Recover floating point registers. */
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
TX_FP_LOAD f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Recover ft0
|
||||
TX_FP_LOAD f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Recover ft1
|
||||
TX_FP_LOAD f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Recover ft2
|
||||
TX_FP_LOAD f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Recover ft3
|
||||
TX_FP_LOAD f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Recover ft4
|
||||
TX_FP_LOAD f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Recover ft5
|
||||
TX_FP_LOAD f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Recover ft6
|
||||
TX_FP_LOAD f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Recover ft7
|
||||
TX_FP_LOAD f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Recover fa0
|
||||
TX_FP_LOAD f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Recover fa1
|
||||
TX_FP_LOAD f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Recover fa2
|
||||
TX_FP_LOAD f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Recover fa3
|
||||
TX_FP_LOAD f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Recover fa4
|
||||
TX_FP_LOAD f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Recover fa5
|
||||
TX_FP_LOAD f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Recover fa6
|
||||
TX_FP_LOAD f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Recover fa7
|
||||
TX_FP_LOAD f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Recover ft8
|
||||
TX_FP_LOAD f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Recover ft9
|
||||
TX_FP_LOAD f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Recover ft10
|
||||
TX_FP_LOAD f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Recover ft11
|
||||
LOAD t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Recover fcsr
|
||||
csrw fcsr, t0 //
|
||||
#endif
|
||||
|
||||
/* Recover standard registers. */
|
||||
|
||||
/* Restore registers,
|
||||
Skip global pointer because that does not change.
|
||||
Also skip the saved registers since they have been restored by any function we called,
|
||||
except s0 since we use it ourselves. */
|
||||
|
||||
LOAD t0, 30*REGBYTES(sp) // Recover mepc
|
||||
csrw mepc, t0 // Setup mepc
|
||||
li t0, 0x1880 // Prepare MPIP
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
li t1, 1<<13
|
||||
or t0, t1, t0
|
||||
#endif
|
||||
csrw mstatus, t0 // Enable MPIP
|
||||
|
||||
LOAD x1, 28*REGBYTES(sp) // Recover RA
|
||||
LOAD x5, 19*REGBYTES(sp) // Recover t0
|
||||
LOAD x6, 18*REGBYTES(sp) // Recover t1
|
||||
LOAD x7, 17*REGBYTES(sp) // Recover t2
|
||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
||||
LOAD x10, 27*REGBYTES(sp) // Recover a0
|
||||
LOAD x11, 26*REGBYTES(sp) // Recover a1
|
||||
LOAD x12, 25*REGBYTES(sp) // Recover a2
|
||||
LOAD x13, 24*REGBYTES(sp) // Recover a3
|
||||
LOAD x14, 23*REGBYTES(sp) // Recover a4
|
||||
LOAD x15, 22*REGBYTES(sp) // Recover a5
|
||||
LOAD x16, 21*REGBYTES(sp) // Recover a6
|
||||
LOAD x17, 20*REGBYTES(sp) // Recover a7
|
||||
LOAD x28, 16*REGBYTES(sp) // Recover t3
|
||||
LOAD x29, 15*REGBYTES(sp) // Recover t4
|
||||
LOAD x30, 14*REGBYTES(sp) // Recover t5
|
||||
LOAD x31, 13*REGBYTES(sp) // Recover t6
|
||||
|
||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
||||
mret // Return to point of interrupt
|
||||
|
||||
/* } */
|
||||
_tx_thread_not_nested_restore:
|
||||
/* Determine if a thread was interrupted and no preemption is required. */
|
||||
/* else if (((_tx_thread_current_ptr) && (_tx_thread_current_ptr == _tx_thread_execute_ptr)
|
||||
|| (_tx_thread_preempt_disable))
|
||||
{ */
|
||||
|
||||
LOAD t1, _tx_thread_current_ptr // Pickup current thread pointer
|
||||
beqz t1, _tx_thread_idle_system_restore // If NULL, idle system restore
|
||||
|
||||
LWU t2, _tx_thread_preempt_disable // Pickup preempt disable flag
|
||||
bgtz t2, _tx_thread_no_preempt_restore // If set, restore interrupted thread
|
||||
|
||||
LOAD t2, _tx_thread_execute_ptr // Pickup thread execute pointer
|
||||
bne t1, t2, _tx_thread_preempt_restore // If higher-priority thread is ready, preempt
|
||||
|
||||
|
||||
_tx_thread_no_preempt_restore:
|
||||
/* Restore interrupted thread or ISR. */
|
||||
|
||||
/* Pickup the saved stack pointer. */
|
||||
/* SP = _tx_thread_current_ptr -> tx_thread_stack_ptr; */
|
||||
|
||||
LOAD sp, 2*REGBYTES(t1) // Switch back to thread's stack
|
||||
|
||||
/* Recover floating point registers. */
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
TX_FP_LOAD f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Recover ft0
|
||||
TX_FP_LOAD f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Recover ft1
|
||||
TX_FP_LOAD f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Recover ft2
|
||||
TX_FP_LOAD f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Recover ft3
|
||||
TX_FP_LOAD f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Recover ft4
|
||||
TX_FP_LOAD f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Recover ft5
|
||||
TX_FP_LOAD f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Recover ft6
|
||||
TX_FP_LOAD f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Recover ft7
|
||||
TX_FP_LOAD f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Recover fa0
|
||||
TX_FP_LOAD f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Recover fa1
|
||||
TX_FP_LOAD f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Recover fa2
|
||||
TX_FP_LOAD f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Recover fa3
|
||||
TX_FP_LOAD f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Recover fa4
|
||||
TX_FP_LOAD f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Recover fa5
|
||||
TX_FP_LOAD f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Recover fa6
|
||||
TX_FP_LOAD f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Recover fa7
|
||||
TX_FP_LOAD f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Recover ft8
|
||||
TX_FP_LOAD f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Recover ft9
|
||||
TX_FP_LOAD f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Recover ft10
|
||||
TX_FP_LOAD f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Recover ft11
|
||||
LOAD t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Recover fcsr
|
||||
csrw fcsr, t0 //
|
||||
#endif
|
||||
|
||||
/* Recover the saved context and return to the point of interrupt. */
|
||||
|
||||
/* Recover standard registers. */
|
||||
/* Restore registers,
|
||||
Skip global pointer because that does not change */
|
||||
|
||||
LOAD t0, 30*REGBYTES(sp) // Recover mepc
|
||||
csrw mepc, t0 // Setup mepc
|
||||
li t0, 0x1880 // Prepare MPIP
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
li t1, 1<<13
|
||||
or t0, t1, t0
|
||||
#endif
|
||||
csrw mstatus, t0 // Enable MPIP
|
||||
|
||||
LOAD x1, 28*REGBYTES(sp) // Recover RA
|
||||
LOAD x5, 19*REGBYTES(sp) // Recover t0
|
||||
LOAD x6, 18*REGBYTES(sp) // Recover t1
|
||||
LOAD x7, 17*REGBYTES(sp) // Recover t2
|
||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
||||
LOAD x10, 27*REGBYTES(sp) // Recover a0
|
||||
LOAD x11, 26*REGBYTES(sp) // Recover a1
|
||||
LOAD x12, 25*REGBYTES(sp) // Recover a2
|
||||
LOAD x13, 24*REGBYTES(sp) // Recover a3
|
||||
LOAD x14, 23*REGBYTES(sp) // Recover a4
|
||||
LOAD x15, 22*REGBYTES(sp) // Recover a5
|
||||
LOAD x16, 21*REGBYTES(sp) // Recover a6
|
||||
LOAD x17, 20*REGBYTES(sp) // Recover a7
|
||||
LOAD x28, 16*REGBYTES(sp) // Recover t3
|
||||
LOAD x29, 15*REGBYTES(sp) // Recover t4
|
||||
LOAD x30, 14*REGBYTES(sp) // Recover t5
|
||||
LOAD x31, 13*REGBYTES(sp) // Recover t6
|
||||
|
||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
||||
mret // Return to point of interrupt
|
||||
|
||||
/* }
|
||||
else
|
||||
{ */
|
||||
_tx_thread_preempt_restore:
|
||||
/* Instead of directly activating the thread again, ensure we save the
|
||||
entire stack frame by saving the remaining registers. */
|
||||
|
||||
LOAD t0, 2*REGBYTES(t1) // Pickup thread's stack pointer
|
||||
ori t3, x0, 1 // Build interrupt stack type
|
||||
STORE t3, 0(t0) // Store stack type
|
||||
|
||||
/* Store floating point preserved registers. */
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
TX_FP_STORE f8, TX_INTERRUPT_FP_OFFSET(8)(t0) // Store fs0
|
||||
TX_FP_STORE f9, TX_INTERRUPT_FP_OFFSET(9)(t0) // Store fs1
|
||||
TX_FP_STORE f18, TX_INTERRUPT_FP_OFFSET(18)(t0) // Store fs2
|
||||
TX_FP_STORE f19, TX_INTERRUPT_FP_OFFSET(19)(t0) // Store fs3
|
||||
TX_FP_STORE f20, TX_INTERRUPT_FP_OFFSET(20)(t0) // Store fs4
|
||||
TX_FP_STORE f21, TX_INTERRUPT_FP_OFFSET(21)(t0) // Store fs5
|
||||
TX_FP_STORE f22, TX_INTERRUPT_FP_OFFSET(22)(t0) // Store fs6
|
||||
TX_FP_STORE f23, TX_INTERRUPT_FP_OFFSET(23)(t0) // Store fs7
|
||||
TX_FP_STORE f24, TX_INTERRUPT_FP_OFFSET(24)(t0) // Store fs8
|
||||
TX_FP_STORE f25, TX_INTERRUPT_FP_OFFSET(25)(t0) // Store fs9
|
||||
TX_FP_STORE f26, TX_INTERRUPT_FP_OFFSET(26)(t0) // Store fs10
|
||||
TX_FP_STORE f27, TX_INTERRUPT_FP_OFFSET(27)(t0) // Store fs11
|
||||
#endif
|
||||
|
||||
/* Store standard preserved registers. */
|
||||
|
||||
STORE x9, 11*REGBYTES(t0) // Store s1
|
||||
STORE x18, 10*REGBYTES(t0) // Store s2
|
||||
STORE x19, 9*REGBYTES(t0) // Store s3
|
||||
STORE x20, 8*REGBYTES(t0) // Store s4
|
||||
STORE x21, 7*REGBYTES(t0) // Store s5
|
||||
STORE x22, 6*REGBYTES(t0) // Store s6
|
||||
STORE x23, 5*REGBYTES(t0) // Store s7
|
||||
STORE x24, 4*REGBYTES(t0) // Store s8
|
||||
STORE x25, 3*REGBYTES(t0) // Store s9
|
||||
STORE x26, 2*REGBYTES(t0) // Store s10
|
||||
STORE x27, 1*REGBYTES(t0) // Store s11
|
||||
// Note: s0 is already stored!
|
||||
|
||||
/* Save the remaining time-slice and disable it. */
|
||||
/* if (_tx_timer_time_slice)
|
||||
{ */
|
||||
|
||||
la t0, _tx_timer_time_slice // Pickup time slice variable address
|
||||
LOAD t2, 0(t0) // Pickup time slice
|
||||
beqz t2, _tx_thread_dont_save_ts // If 0, skip time slice processing
|
||||
|
||||
/* _tx_thread_current_ptr -> tx_thread_time_slice = _tx_timer_time_slice
|
||||
_tx_timer_time_slice = 0; */
|
||||
|
||||
STORE t2, 6*REGBYTES(t1) // Save current time slice
|
||||
STORE x0, 0(t0) // Clear global time slice
|
||||
|
||||
|
||||
/* } */
|
||||
_tx_thread_dont_save_ts:
|
||||
/* Clear the current task pointer. */
|
||||
/* _tx_thread_current_ptr = TX_NULL; */
|
||||
|
||||
/* Return to the scheduler. */
|
||||
/* _tx_thread_schedule(); */
|
||||
|
||||
STORE x0, _tx_thread_current_ptr, t0 // Clear current thread pointer*/
|
||||
/* } */
|
||||
|
||||
_tx_thread_idle_system_restore:
|
||||
/* Just return back to the scheduler! */
|
||||
j _tx_thread_schedule // Return to scheduler
|
||||
|
||||
/* } */
|
||||
@@ -1,233 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** Thread */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tx_port.h"
|
||||
|
||||
.section .text
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _tx_thread_context_save RISC-V64/GNU */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Scott Larson, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function saves the context of an executing thread in the */
|
||||
/* beginning of interrupt processing. The function also ensures that */
|
||||
/* the system stack is used upon return to the calling ISR. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* ISRs */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/* VOID _tx_thread_context_save(VOID)
|
||||
{ */
|
||||
.global _tx_thread_context_save
|
||||
_tx_thread_context_save:
|
||||
|
||||
/* Upon entry to this routine, it is assumed that interrupts are locked
|
||||
out and the interrupt stack fame has been allocated and x1 (ra) has
|
||||
been saved on the stack. */
|
||||
|
||||
STORE t0, 19*REGBYTES(sp) // First store t0 and t1
|
||||
STORE t1, 18*REGBYTES(sp)
|
||||
|
||||
la t0, _tx_thread_system_state // Pickup address of system state
|
||||
LOAD t1, 0(t0) // Pickup system state
|
||||
|
||||
/* Check for a nested interrupt condition. */
|
||||
/* if (_tx_thread_system_state++)
|
||||
{ */
|
||||
beqz t1, _tx_thread_not_nested_save // If 0, first interrupt condition
|
||||
addi t1, t1, 1 // Increment the interrupt counter
|
||||
STORE t1, 0(t0) // Store the interrupt counter
|
||||
|
||||
/* Nested interrupt condition.
|
||||
Save the reset of the scratch registers on the stack and return to the
|
||||
calling ISR. */
|
||||
|
||||
STORE x7, 17*REGBYTES(sp) // Store t2
|
||||
STORE x8, 12*REGBYTES(sp) // Store s0
|
||||
STORE x10, 27*REGBYTES(sp) // Store a0
|
||||
STORE x11, 26*REGBYTES(sp) // Store a1
|
||||
STORE x12, 25*REGBYTES(sp) // Store a2
|
||||
STORE x13, 24*REGBYTES(sp) // Store a3
|
||||
STORE x14, 23*REGBYTES(sp) // Store a4
|
||||
STORE x15, 22*REGBYTES(sp) // Store a5
|
||||
STORE x16, 21*REGBYTES(sp) // Store a6
|
||||
STORE x17, 20*REGBYTES(sp) // Store a7
|
||||
STORE x28, 16*REGBYTES(sp) // Store t3
|
||||
STORE x29, 15*REGBYTES(sp) // Store t4
|
||||
STORE x30, 14*REGBYTES(sp) // Store t5
|
||||
STORE x31, 13*REGBYTES(sp) // Store t6
|
||||
csrr t0, mepc // Load exception program counter
|
||||
STORE t0, 30*REGBYTES(sp) // Save it on the stack
|
||||
|
||||
/* Save floating point scratch registers. */
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
TX_FP_STORE f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Store ft0
|
||||
TX_FP_STORE f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Store ft1
|
||||
TX_FP_STORE f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Store ft2
|
||||
TX_FP_STORE f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Store ft3
|
||||
TX_FP_STORE f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Store ft4
|
||||
TX_FP_STORE f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Store ft5
|
||||
TX_FP_STORE f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Store ft6
|
||||
TX_FP_STORE f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Store ft7
|
||||
TX_FP_STORE f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Store fa0
|
||||
TX_FP_STORE f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Store fa1
|
||||
TX_FP_STORE f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Store fa2
|
||||
TX_FP_STORE f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Store fa3
|
||||
TX_FP_STORE f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Store fa4
|
||||
TX_FP_STORE f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Store fa5
|
||||
TX_FP_STORE f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Store fa6
|
||||
TX_FP_STORE f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Store fa7
|
||||
TX_FP_STORE f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Store ft8
|
||||
TX_FP_STORE f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Store ft9
|
||||
TX_FP_STORE f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Store ft10
|
||||
TX_FP_STORE f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Store ft11
|
||||
csrr t0, fcsr
|
||||
STORE t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Store fcsr
|
||||
#endif
|
||||
|
||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
||||
call _tx_execution_isr_enter // Call the ISR execution enter function
|
||||
#endif
|
||||
|
||||
ret // Return to calling ISR
|
||||
|
||||
_tx_thread_not_nested_save:
|
||||
/* } */
|
||||
|
||||
/* Otherwise, not nested, check to see if a thread was running. */
|
||||
/* else if (_tx_thread_current_ptr)
|
||||
{ */
|
||||
addi t1, t1, 1 // Increment the interrupt counter
|
||||
sw t1, 0(t0) // Store the interrupt counter
|
||||
|
||||
/* Not nested: Find the user thread that was running and load our SP */
|
||||
|
||||
LOAD t0, _tx_thread_current_ptr // Pickup current thread pointer
|
||||
beqz t0, _tx_thread_idle_system_save // If NULL, idle system was interrupted
|
||||
|
||||
/* Save the standard scratch registers. */
|
||||
|
||||
STORE x7, 17*REGBYTES(sp) // Store t2
|
||||
STORE x8, 12*REGBYTES(sp) // Store s0
|
||||
STORE x10, 27*REGBYTES(sp) // Store a0
|
||||
STORE x11, 26*REGBYTES(sp) // Store a1
|
||||
STORE x12, 25*REGBYTES(sp) // Store a2
|
||||
STORE x13, 24*REGBYTES(sp) // Store a3
|
||||
STORE x14, 23*REGBYTES(sp) // Store a4
|
||||
STORE x15, 22*REGBYTES(sp) // Store a5
|
||||
STORE x16, 21*REGBYTES(sp) // Store a6
|
||||
STORE x17, 20*REGBYTES(sp) // Store a7
|
||||
STORE x28, 16*REGBYTES(sp) // Store t3
|
||||
STORE x29, 15*REGBYTES(sp) // Store t4
|
||||
STORE x30, 14*REGBYTES(sp) // Store t5
|
||||
STORE x31, 13*REGBYTES(sp) // Store t6
|
||||
|
||||
csrr t0, mepc // Load exception program counter
|
||||
STORE t0, 30*REGBYTES(sp) // Save it on the stack
|
||||
|
||||
/* Save floating point scratch registers. */
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
TX_FP_STORE f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Store ft0
|
||||
TX_FP_STORE f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Store ft1
|
||||
TX_FP_STORE f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Store ft2
|
||||
TX_FP_STORE f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Store ft3
|
||||
TX_FP_STORE f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Store ft4
|
||||
TX_FP_STORE f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Store ft5
|
||||
TX_FP_STORE f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Store ft6
|
||||
TX_FP_STORE f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Store ft7
|
||||
TX_FP_STORE f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Store fa0
|
||||
TX_FP_STORE f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Store fa1
|
||||
TX_FP_STORE f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Store fa2
|
||||
TX_FP_STORE f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Store fa3
|
||||
TX_FP_STORE f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Store fa4
|
||||
TX_FP_STORE f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Store fa5
|
||||
TX_FP_STORE f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Store fa6
|
||||
TX_FP_STORE f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Store fa7
|
||||
TX_FP_STORE f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Store ft8
|
||||
TX_FP_STORE f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Store ft9
|
||||
TX_FP_STORE f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Store ft10
|
||||
TX_FP_STORE f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Store ft11
|
||||
csrr t0, fcsr
|
||||
STORE t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Store fcsr
|
||||
#endif
|
||||
|
||||
/* Save the current stack pointer in the thread's control block. */
|
||||
/* _tx_thread_current_ptr -> tx_thread_stack_ptr = sp; */
|
||||
|
||||
/* Switch to the system stack. */
|
||||
/* sp = _tx_thread_system_stack_ptr; */
|
||||
|
||||
LOAD t1, _tx_thread_current_ptr // Pickup current thread pointer
|
||||
STORE sp, 2*REGBYTES(t1) // Save stack pointer
|
||||
|
||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
||||
/* _tx_execution_isr_enter is called with thread stack pointer */
|
||||
call _tx_execution_isr_enter // Call the ISR execution enter function
|
||||
#endif
|
||||
|
||||
|
||||
LOAD sp, _tx_thread_system_stack_ptr // Switch to system stack
|
||||
ret // Return to calling ISR
|
||||
|
||||
/* }
|
||||
else
|
||||
{ */
|
||||
|
||||
_tx_thread_idle_system_save:
|
||||
|
||||
|
||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
||||
call _tx_execution_isr_enter // Call the ISR execution enter function
|
||||
#endif
|
||||
|
||||
/* Interrupt occurred in the scheduling loop. */
|
||||
|
||||
/* }
|
||||
} */
|
||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
||||
ret // Return to calling ISR
|
||||
@@ -1,81 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** Thread */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
RETURN_MASK = 0x000000000000000F
|
||||
SET_SR_MASK = 0xFFFFFFFFFFFFFFF0
|
||||
|
||||
.section .text
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _tx_thread_interrupt_control RISC-V64/GNU */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Scott Larson, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function is responsible for changing the interrupt lockout */
|
||||
/* posture of the system. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* new_posture New interrupt lockout posture */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* old_posture Old interrupt lockout posture */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* Application Code */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/* UINT _tx_thread_interrupt_control(UINT new_posture)
|
||||
{ */
|
||||
.global _tx_thread_interrupt_control
|
||||
_tx_thread_interrupt_control:
|
||||
/* Pickup current interrupt lockout posture. */
|
||||
|
||||
csrr t0, mstatus
|
||||
mv t1, t0 // Save original mstatus for return
|
||||
|
||||
/* Apply the new interrupt posture. */
|
||||
|
||||
li t2, SET_SR_MASK // Build set SR mask
|
||||
and t0, t0, t2 // Isolate interrupt lockout bits
|
||||
or t0, t0, a0 // Put new lockout bits in
|
||||
csrw mstatus, t0
|
||||
andi a0, t1, RETURN_MASK // Return original mstatus.
|
||||
ret
|
||||
/* } */
|
||||
@@ -1,250 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** Thread */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tx_port.h"
|
||||
|
||||
.section .text
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _tx_thread_schedule RISC-V64/GNU */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Scott Larson, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function waits for a thread control block pointer to appear in */
|
||||
/* the _tx_thread_execute_ptr variable. Once a thread pointer appears */
|
||||
/* in the variable, the corresponding thread is resumed. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* _tx_initialize_kernel_enter ThreadX entry function */
|
||||
/* _tx_thread_system_return Return to system from thread */
|
||||
/* _tx_thread_context_restore Restore thread's context */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/* VOID _tx_thread_schedule(VOID)
|
||||
{ */
|
||||
.global _tx_thread_schedule
|
||||
_tx_thread_schedule:
|
||||
|
||||
/* Enable interrupts. */
|
||||
csrsi mstatus, 0x08 // Enable interrupts
|
||||
|
||||
/* Wait for a thread to execute. */
|
||||
/* do
|
||||
{ */
|
||||
|
||||
la t0, _tx_thread_execute_ptr // Pickup address of execute ptr
|
||||
_tx_thread_schedule_loop:
|
||||
LOAD t1, 0(t0) // Pickup next thread to execute
|
||||
beqz t1, _tx_thread_schedule_loop // If NULL, wait for thread to execute
|
||||
|
||||
/* }
|
||||
while(_tx_thread_execute_ptr == TX_NULL); */
|
||||
|
||||
scheduler_found_thread:
|
||||
/* Yes! We have a thread to execute. Lockout interrupts and
|
||||
transfer control to it. */
|
||||
csrci mstatus, 0x08 // Lockout interrupts
|
||||
|
||||
/* Setup the current thread pointer. */
|
||||
/* _tx_thread_current_ptr = _tx_thread_execute_ptr; */
|
||||
|
||||
la t0, _tx_thread_current_ptr // Pickup current thread pointer address
|
||||
STORE t1, 0(t0) // Set current thread pointer
|
||||
|
||||
/* Increment the run count for this thread. */
|
||||
/* _tx_thread_current_ptr -> tx_thread_run_count++; */
|
||||
|
||||
LOAD t2, 1*REGBYTES(t1) // Pickup run count
|
||||
LOAD t3, 6*REGBYTES(t1) // Pickup time slice value
|
||||
addi t2, t2, 1 // Increment run count
|
||||
STORE t2, 1*REGBYTES(t1) // Store new run count
|
||||
|
||||
/* Setup time-slice, if present. */
|
||||
/* _tx_timer_time_slice = _tx_thread_current_ptr -> tx_thread_time_slice; */
|
||||
|
||||
la t2, _tx_timer_time_slice // Pickup time-slice variable address
|
||||
STORE t3, 0(t2) // Store new time-slice*/
|
||||
|
||||
/* Switch to the thread's stack. */
|
||||
/* SP = _tx_thread_execute_ptr -> tx_thread_stack_ptr; */
|
||||
|
||||
LOAD sp, 2*REGBYTES(t1) // Switch to thread's stack
|
||||
|
||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
||||
|
||||
call _tx_execution_thread_enter // Call the thread execution enter function
|
||||
#endif
|
||||
|
||||
/* Determine if an interrupt frame or a synchronous task suspension frame
|
||||
is present. */
|
||||
|
||||
LOAD t2, 0(sp) // Pickup stack type
|
||||
beqz t2, _tx_thread_synch_return // If 0, solicited thread return
|
||||
|
||||
/* Determine if floating point registers need to be recovered. */
|
||||
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
TX_FP_LOAD f0, TX_INTERRUPT_FP_OFFSET(0)(sp) // Recover ft0
|
||||
TX_FP_LOAD f1, TX_INTERRUPT_FP_OFFSET(1)(sp) // Recover ft1
|
||||
TX_FP_LOAD f2, TX_INTERRUPT_FP_OFFSET(2)(sp) // Recover ft2
|
||||
TX_FP_LOAD f3, TX_INTERRUPT_FP_OFFSET(3)(sp) // Recover ft3
|
||||
TX_FP_LOAD f4, TX_INTERRUPT_FP_OFFSET(4)(sp) // Recover ft4
|
||||
TX_FP_LOAD f5, TX_INTERRUPT_FP_OFFSET(5)(sp) // Recover ft5
|
||||
TX_FP_LOAD f6, TX_INTERRUPT_FP_OFFSET(6)(sp) // Recover ft6
|
||||
TX_FP_LOAD f7, TX_INTERRUPT_FP_OFFSET(7)(sp) // Recover ft7
|
||||
TX_FP_LOAD f8, TX_INTERRUPT_FP_OFFSET(8)(sp) // Recover fs0
|
||||
TX_FP_LOAD f9, TX_INTERRUPT_FP_OFFSET(9)(sp) // Recover fs1
|
||||
TX_FP_LOAD f10, TX_INTERRUPT_FP_OFFSET(10)(sp) // Recover fa0
|
||||
TX_FP_LOAD f11, TX_INTERRUPT_FP_OFFSET(11)(sp) // Recover fa1
|
||||
TX_FP_LOAD f12, TX_INTERRUPT_FP_OFFSET(12)(sp) // Recover fa2
|
||||
TX_FP_LOAD f13, TX_INTERRUPT_FP_OFFSET(13)(sp) // Recover fa3
|
||||
TX_FP_LOAD f14, TX_INTERRUPT_FP_OFFSET(14)(sp) // Recover fa4
|
||||
TX_FP_LOAD f15, TX_INTERRUPT_FP_OFFSET(15)(sp) // Recover fa5
|
||||
TX_FP_LOAD f16, TX_INTERRUPT_FP_OFFSET(16)(sp) // Recover fa6
|
||||
TX_FP_LOAD f17, TX_INTERRUPT_FP_OFFSET(17)(sp) // Recover fa7
|
||||
TX_FP_LOAD f18, TX_INTERRUPT_FP_OFFSET(18)(sp) // Recover fs2
|
||||
TX_FP_LOAD f19, TX_INTERRUPT_FP_OFFSET(19)(sp) // Recover fs3
|
||||
TX_FP_LOAD f20, TX_INTERRUPT_FP_OFFSET(20)(sp) // Recover fs4
|
||||
TX_FP_LOAD f21, TX_INTERRUPT_FP_OFFSET(21)(sp) // Recover fs5
|
||||
TX_FP_LOAD f22, TX_INTERRUPT_FP_OFFSET(22)(sp) // Recover fs6
|
||||
TX_FP_LOAD f23, TX_INTERRUPT_FP_OFFSET(23)(sp) // Recover fs7
|
||||
TX_FP_LOAD f24, TX_INTERRUPT_FP_OFFSET(24)(sp) // Recover fs8
|
||||
TX_FP_LOAD f25, TX_INTERRUPT_FP_OFFSET(25)(sp) // Recover fs9
|
||||
TX_FP_LOAD f26, TX_INTERRUPT_FP_OFFSET(26)(sp) // Recover fs10
|
||||
TX_FP_LOAD f27, TX_INTERRUPT_FP_OFFSET(27)(sp) // Recover fs11
|
||||
TX_FP_LOAD f28, TX_INTERRUPT_FP_OFFSET(28)(sp) // Recover ft8
|
||||
TX_FP_LOAD f29, TX_INTERRUPT_FP_OFFSET(29)(sp) // Recover ft9
|
||||
TX_FP_LOAD f30, TX_INTERRUPT_FP_OFFSET(30)(sp) // Recover ft10
|
||||
TX_FP_LOAD f31, TX_INTERRUPT_FP_OFFSET(31)(sp) // Recover ft11
|
||||
LOAD t0, TX_INTERRUPT_FCSR_OFFSET(sp) // Recover fcsr
|
||||
csrw fcsr, t0 //
|
||||
#endif
|
||||
|
||||
/* Recover standard registers. */
|
||||
|
||||
LOAD t0, 30*REGBYTES(sp) // Recover mepc
|
||||
csrw mepc, t0 // Store mepc
|
||||
li t0, 0x1880 // Prepare MPIP
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
li t1, 1<<13
|
||||
or t0, t1, t0
|
||||
#endif
|
||||
csrw mstatus, t0 // Enable MPIP
|
||||
|
||||
LOAD x1, 28*REGBYTES(sp) // Recover RA
|
||||
LOAD x5, 19*REGBYTES(sp) // Recover t0
|
||||
LOAD x6, 18*REGBYTES(sp) // Recover t1
|
||||
LOAD x7, 17*REGBYTES(sp) // Recover t2
|
||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
||||
LOAD x9, 11*REGBYTES(sp) // Recover s1
|
||||
LOAD x10, 27*REGBYTES(sp) // Recover a0
|
||||
LOAD x11, 26*REGBYTES(sp) // Recover a1
|
||||
LOAD x12, 25*REGBYTES(sp) // Recover a2
|
||||
LOAD x13, 24*REGBYTES(sp) // Recover a3
|
||||
LOAD x14, 23*REGBYTES(sp) // Recover a4
|
||||
LOAD x15, 22*REGBYTES(sp) // Recover a5
|
||||
LOAD x16, 21*REGBYTES(sp) // Recover a6
|
||||
LOAD x17, 20*REGBYTES(sp) // Recover a7
|
||||
LOAD x18, 10*REGBYTES(sp) // Recover s2
|
||||
LOAD x19, 9*REGBYTES(sp) // Recover s3
|
||||
LOAD x20, 8*REGBYTES(sp) // Recover s4
|
||||
LOAD x21, 7*REGBYTES(sp) // Recover s5
|
||||
LOAD x22, 6*REGBYTES(sp) // Recover s6
|
||||
LOAD x23, 5*REGBYTES(sp) // Recover s7
|
||||
LOAD x24, 4*REGBYTES(sp) // Recover s8
|
||||
LOAD x25, 3*REGBYTES(sp) // Recover s9
|
||||
LOAD x26, 2*REGBYTES(sp) // Recover s10
|
||||
LOAD x27, 1*REGBYTES(sp) // Recover s11
|
||||
LOAD x28, 16*REGBYTES(sp) // Recover t3
|
||||
LOAD x29, 15*REGBYTES(sp) // Recover t4
|
||||
LOAD x30, 14*REGBYTES(sp) // Recover t5
|
||||
LOAD x31, 13*REGBYTES(sp) // Recover t6
|
||||
|
||||
addi sp, sp, TX_INTERRUPT_FRAME_SIZE
|
||||
mret // Return to point of interrupt
|
||||
|
||||
_tx_thread_synch_return:
|
||||
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
TX_FP_LOAD f8, TX_SOLICITED_FP_OFFSET(0)(sp) // Recover fs0
|
||||
TX_FP_LOAD f9, TX_SOLICITED_FP_OFFSET(1)(sp) // Recover fs1
|
||||
TX_FP_LOAD f18, TX_SOLICITED_FP_OFFSET(2)(sp) // Recover fs2
|
||||
TX_FP_LOAD f19, TX_SOLICITED_FP_OFFSET(3)(sp) // Recover fs3
|
||||
TX_FP_LOAD f20, TX_SOLICITED_FP_OFFSET(4)(sp) // Recover fs4
|
||||
TX_FP_LOAD f21, TX_SOLICITED_FP_OFFSET(5)(sp) // Recover fs5
|
||||
TX_FP_LOAD f22, TX_SOLICITED_FP_OFFSET(6)(sp) // Recover fs6
|
||||
TX_FP_LOAD f23, TX_SOLICITED_FP_OFFSET(7)(sp) // Recover fs7
|
||||
TX_FP_LOAD f24, TX_SOLICITED_FP_OFFSET(8)(sp) // Recover fs8
|
||||
TX_FP_LOAD f25, TX_SOLICITED_FP_OFFSET(9)(sp) // Recover fs9
|
||||
TX_FP_LOAD f26, TX_SOLICITED_FP_OFFSET(10)(sp) // Recover fs10
|
||||
TX_FP_LOAD f27, TX_SOLICITED_FP_OFFSET(11)(sp) // Recover fs11
|
||||
LOAD t0, TX_SOLICITED_FCSR_OFFSET(sp) // Recover fcsr
|
||||
csrw fcsr, t0 //
|
||||
#endif
|
||||
|
||||
/* Recover standard preserved registers. */
|
||||
/* Recover standard registers. */
|
||||
|
||||
LOAD x1, 13*REGBYTES(sp) // Recover RA
|
||||
LOAD x8, 12*REGBYTES(sp) // Recover s0
|
||||
LOAD x9, 11*REGBYTES(sp) // Recover s1
|
||||
LOAD x18, 10*REGBYTES(sp) // Recover s2
|
||||
LOAD x19, 9*REGBYTES(sp) // Recover s3
|
||||
LOAD x20, 8*REGBYTES(sp) // Recover s4
|
||||
LOAD x21, 7*REGBYTES(sp) // Recover s5
|
||||
LOAD x22, 6*REGBYTES(sp) // Recover s6
|
||||
LOAD x23, 5*REGBYTES(sp) // Recover s7
|
||||
LOAD x24, 4*REGBYTES(sp) // Recover s8
|
||||
LOAD x25, 3*REGBYTES(sp) // Recover s9
|
||||
LOAD x26, 2*REGBYTES(sp) // Recover s10
|
||||
LOAD x27, 1*REGBYTES(sp) // Recover s11
|
||||
LOAD t0, 14*REGBYTES(sp) // Recover mstatus
|
||||
csrw mstatus, t0 // Store mstatus, enables interrupt
|
||||
addi sp, sp, TX_SOLICITED_FRAME_SIZE
|
||||
synch_return_exit_label:
|
||||
ret // Return to thread
|
||||
|
||||
/* } */
|
||||
@@ -1,143 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** Thread */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tx_port.h"
|
||||
|
||||
.section .text
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _tx_thread_stack_build RISC-V64/GNU */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Scott Larson, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function builds a stack frame on the supplied thread's stack. */
|
||||
/* The stack frame results in a fake interrupt return to the supplied */
|
||||
/* function pointer. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* thread_ptr Pointer to thread control blk */
|
||||
/* function_ptr Pointer to return function */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* _tx_thread_create Create thread service */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/* VOID _tx_thread_stack_build(TX_THREAD *thread_ptr, VOID (*function_ptr)(VOID))
|
||||
{ */
|
||||
.global _tx_thread_stack_build
|
||||
_tx_thread_stack_build:
|
||||
|
||||
/* Build a fake interrupt frame using this port's inc/tx_context_layout.h,
|
||||
included through tx_port.h. Integer slot indices below are multiplied
|
||||
by REGBYTES to obtain byte offsets from the saved stack pointer.
|
||||
Reg Integer slot
|
||||
Stack Top: 1 0 Interrupt stack frame type
|
||||
x27 1 Initial s11
|
||||
x26 2 Initial s10
|
||||
x25 3 Initial s9
|
||||
x24 4 Initial s8
|
||||
x23 5 Initial s7
|
||||
x22 6 Initial s6
|
||||
x21 7 Initial s5
|
||||
x20 8 Initial s4
|
||||
x19 9 Initial s3
|
||||
x18 10 Initial s2
|
||||
x9 11 Initial s1
|
||||
x8 12 Initial s0
|
||||
x31 13 Initial t6
|
||||
x30 14 Initial t5
|
||||
x29 15 Initial t4
|
||||
x28 16 Initial t3
|
||||
x7 17 Initial t2
|
||||
x6 18 Initial t1
|
||||
x5 19 Initial t0
|
||||
x17 20 Initial a7
|
||||
x16 21 Initial a6
|
||||
x15 22 Initial a5
|
||||
x14 23 Initial a4
|
||||
x13 24 Initial a3
|
||||
x12 25 Initial a2
|
||||
x11 26 Initial a1
|
||||
x10 27 Initial a0
|
||||
x1 28 Initial ra
|
||||
-- 29 reserved
|
||||
mepc 30 Initial mepc
|
||||
-- 31 Alignment padding
|
||||
|
||||
With FP support, f0..f31 follow at TX_INTERRUPT_FP_BASE. Each register
|
||||
occupies TX_FP_BYTES bytes; fN is at TX_INTERRUPT_FP_OFFSET(N). The
|
||||
fcsr slot is at TX_INTERRUPT_FCSR_OFFSET and occupies REGBYTES bytes.
|
||||
Trailing padding rounds the frame size up to a multiple of 16 bytes.
|
||||
Without FP support, the frame ends after integer slot 31.
|
||||
|
||||
Stack Bottom: saved stack pointer + TX_INTERRUPT_FRAME_SIZE
|
||||
(higher memory address) */
|
||||
|
||||
LOAD t0, 4*REGBYTES(a0) // Pickup end of stack area
|
||||
andi t0, t0, -16 // Ensure 16-byte alignment
|
||||
|
||||
/* Actually build the stack frame. */
|
||||
|
||||
addi t0, t0, -TX_INTERRUPT_FRAME_SIZE
|
||||
/* Clear the whole frame, including both halves of RV32D FP slots. */
|
||||
mv t1, t0
|
||||
addi t2, t0, TX_INTERRUPT_FRAME_SIZE
|
||||
.Lclear_initial_context:
|
||||
STORE x0, 0(t1)
|
||||
addi t1, t1, REGBYTES
|
||||
bltu t1, t2, .Lclear_initial_context
|
||||
|
||||
li t1, 1 // Build stack type
|
||||
STORE t1, 0*REGBYTES(t0) // Place stack type on the top
|
||||
STORE a1, 30*REGBYTES(t0) // Initial mepc
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
csrr a1, fcsr
|
||||
STORE a1, TX_INTERRUPT_FCSR_OFFSET(t0) // Initial fcsr
|
||||
#endif
|
||||
|
||||
/* Setup stack pointer. */
|
||||
/* thread_ptr -> tx_thread_stack_ptr = t0; */
|
||||
|
||||
STORE t0, 2*REGBYTES(a0) // Save stack pointer in thread's
|
||||
ret // control block and return
|
||||
/* } */
|
||||
@@ -1,155 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 */
|
||||
/** */
|
||||
/** Thread */
|
||||
/** */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "tx_port.h"
|
||||
|
||||
.section .text
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _tx_thread_system_return RISC-V64/GNU */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Scott Larson, Microsoft Corporation */
|
||||
/* */
|
||||
/* DESCRIPTION */
|
||||
/* */
|
||||
/* This function is target processor specific. It is used to transfer */
|
||||
/* control from a thread back to the system. Only a minimal context */
|
||||
/* is saved since the compiler assumes temp registers are going to get */
|
||||
/* slicked by a function call anyway. */
|
||||
/* */
|
||||
/* INPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* OUTPUT */
|
||||
/* */
|
||||
/* None */
|
||||
/* */
|
||||
/* CALLS */
|
||||
/* */
|
||||
/* _tx_thread_schedule Thread scheduling loop */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* ThreadX components */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
/* VOID _tx_thread_system_return(VOID)
|
||||
{ */
|
||||
.global _tx_thread_system_return
|
||||
_tx_thread_system_return:
|
||||
|
||||
/* Save minimal context on the stack. */
|
||||
|
||||
addi sp, sp, -TX_SOLICITED_FRAME_SIZE
|
||||
|
||||
/* Store floating point preserved registers. */
|
||||
#if TX_CONTEXT_FP_ENABLED
|
||||
TX_FP_STORE f8, TX_SOLICITED_FP_OFFSET(0)(sp) // Store fs0
|
||||
TX_FP_STORE f9, TX_SOLICITED_FP_OFFSET(1)(sp) // Store fs1
|
||||
TX_FP_STORE f18, TX_SOLICITED_FP_OFFSET(2)(sp) // Store fs2
|
||||
TX_FP_STORE f19, TX_SOLICITED_FP_OFFSET(3)(sp) // Store fs3
|
||||
TX_FP_STORE f20, TX_SOLICITED_FP_OFFSET(4)(sp) // Store fs4
|
||||
TX_FP_STORE f21, TX_SOLICITED_FP_OFFSET(5)(sp) // Store fs5
|
||||
TX_FP_STORE f22, TX_SOLICITED_FP_OFFSET(6)(sp) // Store fs6
|
||||
TX_FP_STORE f23, TX_SOLICITED_FP_OFFSET(7)(sp) // Store fs7
|
||||
TX_FP_STORE f24, TX_SOLICITED_FP_OFFSET(8)(sp) // Store fs8
|
||||
TX_FP_STORE f25, TX_SOLICITED_FP_OFFSET(9)(sp) // Store fs9
|
||||
TX_FP_STORE f26, TX_SOLICITED_FP_OFFSET(10)(sp) // Store fs10
|
||||
TX_FP_STORE f27, TX_SOLICITED_FP_OFFSET(11)(sp) // Store fs11
|
||||
csrr t0, fcsr
|
||||
STORE t0, TX_SOLICITED_FCSR_OFFSET(sp) // Store fcsr
|
||||
#endif
|
||||
|
||||
STORE x0, 0(sp) // Solicited stack type
|
||||
STORE x1, 13*REGBYTES(sp) // Save RA
|
||||
STORE x8, 12*REGBYTES(sp) // Save s0
|
||||
STORE x9, 11*REGBYTES(sp) // Save s1
|
||||
STORE x18, 10*REGBYTES(sp) // Save s2
|
||||
STORE x19, 9*REGBYTES(sp) // Save s3
|
||||
STORE x20, 8*REGBYTES(sp) // Save s4
|
||||
STORE x21, 7*REGBYTES(sp) // Save s5
|
||||
STORE x22, 6*REGBYTES(sp) // Save s6
|
||||
STORE x23, 5*REGBYTES(sp) // Save s7
|
||||
STORE x24, 4*REGBYTES(sp) // Save s8
|
||||
STORE x25, 3*REGBYTES(sp) // Save s9
|
||||
STORE x26, 2*REGBYTES(sp) // Save s10
|
||||
STORE x27, 1*REGBYTES(sp) // Save s11
|
||||
csrr t0, mstatus // Pickup mstatus
|
||||
STORE t0, 14*REGBYTES(sp) // Save mstatus
|
||||
|
||||
|
||||
/* Lockout interrupts. - will be enabled in _tx_thread_schedule */
|
||||
|
||||
csrci mstatus, 0xF
|
||||
|
||||
#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
|
||||
|
||||
call _tx_execution_thread_exit // Call the thread execution exit function
|
||||
#endif
|
||||
|
||||
la t0, _tx_thread_current_ptr // Pickup address of pointer
|
||||
LOAD t1, 0(t0) // Pickup current thread pointer
|
||||
la t2,_tx_thread_system_stack_ptr // Pickup stack pointer address
|
||||
|
||||
/* Save current stack and switch to system stack. */
|
||||
/* _tx_thread_current_ptr -> tx_thread_stack_ptr = SP;
|
||||
SP = _tx_thread_system_stack_ptr; */
|
||||
|
||||
STORE sp, 2*REGBYTES(t1) // Save stack pointer
|
||||
LOAD sp, 0(t2) // Switch to system stack
|
||||
|
||||
/* Determine if the time-slice is active. */
|
||||
/* if (_tx_timer_time_slice)
|
||||
{ */
|
||||
|
||||
la t4, _tx_timer_time_slice // Pickup time slice variable addr
|
||||
LOAD t3, 0(t4) // Pickup time slice value
|
||||
la t2, _tx_thread_schedule // Pickup address of scheduling loop
|
||||
beqz t3, _tx_thread_dont_save_ts // If no time-slice, don't save it
|
||||
|
||||
/* Save time-slice for the thread and clear the current time-slice. */
|
||||
/* _tx_thread_current_ptr -> tx_thread_time_slice = _tx_timer_time_slice;
|
||||
_tx_timer_time_slice = 0; */
|
||||
|
||||
STORE t3, 6*REGBYTES(t1) // Save current time-slice for thread
|
||||
STORE x0, 0(t4) // Clear time-slice variable
|
||||
|
||||
/* } */
|
||||
_tx_thread_dont_save_ts:
|
||||
|
||||
/* Clear the current thread pointer. */
|
||||
/* _tx_thread_current_ptr = TX_NULL; */
|
||||
|
||||
STORE x0, 0(t0) // Clear current thread pointer
|
||||
jr t2 // Return to thread scheduler
|
||||
|
||||
/* } */
|
||||
@@ -1,134 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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"
|
||||
|
||||
/**************************************************************************/
|
||||
/* */
|
||||
/* FUNCTION RELEASE */
|
||||
/* */
|
||||
/* _tx_timer_interrupt RISC-V64/GNU */
|
||||
/* 6.2.1 */
|
||||
/* AUTHOR */
|
||||
/* */
|
||||
/* Scott Larson, 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_timer_expiration_process Timer expiration processing */
|
||||
/* _tx_thread_time_slice Time slice interrupted thread */
|
||||
/* */
|
||||
/* CALLED BY */
|
||||
/* */
|
||||
/* interrupt vector */
|
||||
/* */
|
||||
/* RELEASE HISTORY */
|
||||
/* */
|
||||
/* DATE NAME DESCRIPTION */
|
||||
/* */
|
||||
/* 03-08-2023 Scott Larson Initial Version 6.2.1 */
|
||||
/* */
|
||||
/**************************************************************************/
|
||||
VOID _tx_timer_interrupt(VOID)
|
||||
{
|
||||
/* Increment system clock. */
|
||||
_tx_timer_system_clock++;
|
||||
|
||||
/* Test for time-slice expiration. */
|
||||
if (_tx_timer_time_slice)
|
||||
{
|
||||
/* Decrement the time_slice. */
|
||||
_tx_timer_time_slice--;
|
||||
|
||||
/* Check for expiration. */
|
||||
if (_tx_timer_time_slice == 0)
|
||||
{
|
||||
|
||||
/* Set the time-slice expired flag. */
|
||||
_tx_timer_expired_time_slice = TX_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Test for timer expiration. */
|
||||
if (*_tx_timer_current_ptr)
|
||||
{
|
||||
|
||||
/* Set expiration flag. */
|
||||
_tx_timer_expired = TX_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* No timer expired, increment the timer pointer. */
|
||||
_tx_timer_current_ptr++;
|
||||
|
||||
/* Check for wrap-around. */
|
||||
if (_tx_timer_current_ptr == _tx_timer_list_end)
|
||||
{
|
||||
|
||||
/* Wrap to beginning of list. */
|
||||
_tx_timer_current_ptr = _tx_timer_list_start;
|
||||
}
|
||||
}
|
||||
|
||||
/* See if anything has expired. */
|
||||
if ((_tx_timer_expired_time_slice) || (_tx_timer_expired))
|
||||
{
|
||||
|
||||
/* Did a timer expire? */
|
||||
if (_tx_timer_expired)
|
||||
{
|
||||
|
||||
/* Process timer expiration. */
|
||||
_tx_timer_expiration_process();
|
||||
}
|
||||
|
||||
/* Did time slice expire? */
|
||||
if (_tx_timer_expired_time_slice)
|
||||
{
|
||||
|
||||
/* Time slice interrupted thread. */
|
||||
_tx_thread_time_slice();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user