2018-12-08 10:41:38 +08:00
|
|
|
/*
|
2023-01-05 10:06:09 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2018-12-08 10:41:38 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018/10/28 Bernard The unify RISC-V porting code.
|
2020-11-20 12:05:37 +08:00
|
|
|
* 2020/11/20 BalanceTWK Add FPU support
|
2023-01-05 10:06:09 +08:00
|
|
|
* 2023/01/04 WangShun Adapt to CH32
|
2018-12-08 10:41:38 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rthw.h>
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
#include "cpuport.h"
|
2023-03-01 14:32:43 +08:00
|
|
|
#include "rt_hw_stack_frame.h"
|
2018-12-08 10:41:38 +08:00
|
|
|
|
2018-12-28 09:06:32 +08:00
|
|
|
#ifndef RT_USING_SMP
|
2018-12-08 10:41:38 +08:00
|
|
|
volatile rt_ubase_t rt_interrupt_from_thread = 0;
|
|
|
|
volatile rt_ubase_t rt_interrupt_to_thread = 0;
|
|
|
|
volatile rt_uint32_t rt_thread_switch_interrupt_flag = 0;
|
2018-12-28 09:06:32 +08:00
|
|
|
#endif
|
2018-12-08 10:41:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will initialize thread stack
|
|
|
|
*
|
|
|
|
* @param tentry the entry of thread
|
|
|
|
* @param parameter the parameter of entry
|
|
|
|
* @param stack_addr the beginning stack address
|
|
|
|
* @param texit the function will be called when thread exit
|
|
|
|
*
|
|
|
|
* @return stack address
|
|
|
|
*/
|
|
|
|
rt_uint8_t *rt_hw_stack_init(void *tentry,
|
|
|
|
void *parameter,
|
|
|
|
rt_uint8_t *stack_addr,
|
|
|
|
void *texit)
|
|
|
|
{
|
|
|
|
struct rt_hw_stack_frame *frame;
|
|
|
|
rt_uint8_t *stk;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
stk = stack_addr + sizeof(rt_ubase_t);
|
|
|
|
stk = (rt_uint8_t *)RT_ALIGN_DOWN((rt_ubase_t)stk, REGBYTES);
|
|
|
|
stk -= sizeof(struct rt_hw_stack_frame);
|
|
|
|
|
|
|
|
frame = (struct rt_hw_stack_frame *)stk;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(struct rt_hw_stack_frame) / sizeof(rt_ubase_t); i++)
|
|
|
|
{
|
|
|
|
((rt_ubase_t *)frame)[i] = 0xdeadbeef;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->ra = (rt_ubase_t)texit;
|
|
|
|
frame->a0 = (rt_ubase_t)parameter;
|
|
|
|
frame->epc = (rt_ubase_t)tentry;
|
|
|
|
|
|
|
|
/* force to machine mode(MPP=11) and set MPIE to 1 */
|
2023-01-05 10:06:09 +08:00
|
|
|
#ifdef ARCH_RISCV_FPU
|
2023-03-01 14:32:43 +08:00
|
|
|
frame->mstatus = 0x7880;
|
2023-01-05 10:06:09 +08:00
|
|
|
#else
|
2023-03-01 14:32:43 +08:00
|
|
|
frame->mstatus = 0x1880;
|
2023-01-05 10:06:09 +08:00
|
|
|
#endif
|
2018-12-08 10:41:38 +08:00
|
|
|
|
|
|
|
return stk;
|
|
|
|
}
|
|
|
|
|
2023-03-01 14:32:43 +08:00
|
|
|
rt_weak void rt_trigger_software_interrupt(void)
|
|
|
|
{
|
|
|
|
while (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_weak void rt_hw_do_after_save_above(void)
|
|
|
|
{
|
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
|
2018-12-28 09:06:32 +08:00
|
|
|
/*
|
|
|
|
* #ifdef RT_USING_SMP
|
|
|
|
* void rt_hw_context_switch_interrupt(void *context, rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread);
|
|
|
|
* #else
|
|
|
|
* void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to);
|
|
|
|
* #endif
|
|
|
|
*/
|
|
|
|
#ifndef RT_USING_SMP
|
2022-12-12 02:12:03 +08:00
|
|
|
rt_weak void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to, rt_thread_t from_thread, rt_thread_t to_thread)
|
2018-12-08 10:41:38 +08:00
|
|
|
{
|
|
|
|
if (rt_thread_switch_interrupt_flag == 0)
|
|
|
|
rt_interrupt_from_thread = from;
|
|
|
|
|
|
|
|
rt_interrupt_to_thread = to;
|
|
|
|
rt_thread_switch_interrupt_flag = 1;
|
2023-03-01 14:32:43 +08:00
|
|
|
|
|
|
|
rt_trigger_software_interrupt();
|
|
|
|
|
2018-12-08 10:41:38 +08:00
|
|
|
return ;
|
|
|
|
}
|
2018-12-28 09:06:32 +08:00
|
|
|
#endif /* end of RT_USING_SMP */
|