2009-07-03 06:48:23 +08:00
|
|
|
/*
|
2021-03-08 17:22:21 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2013-06-24 17:06:09 +08:00
|
|
|
*
|
2018-09-14 22:37:43 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2009-07-03 06:48:23 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2006-03-18 Bernard the first version
|
|
|
|
* 2006-04-25 Bernard add rt_hw_context_switch_interrupt declaration
|
|
|
|
* 2006-09-24 Bernard add rt_hw_context_switch_to declaration
|
2012-12-29 17:36:16 +08:00
|
|
|
* 2012-12-29 Bernard add rt_hw_exception_install declaration
|
2022-03-29 21:29:08 +08:00
|
|
|
* 2017-10-17 Hichard add some macros
|
2018-11-22 14:40:43 +08:00
|
|
|
* 2018-11-17 Jesven add rt_hw_spinlock_t
|
|
|
|
* add smp support
|
2022-12-03 12:07:44 +08:00
|
|
|
* 2019-05-18 Bernard add empty definition for not enable cache case
|
2023-10-25 20:31:25 +08:00
|
|
|
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
|
2023-10-21 20:14:45 +08:00
|
|
|
* 2023-10-16 Shell Support a new backtrace framework
|
2009-07-03 06:48:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __RT_HW_H__
|
|
|
|
#define __RT_HW_H__
|
|
|
|
|
2023-06-09 09:44:43 +08:00
|
|
|
#include <rtdef.h>
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2023-10-21 20:14:45 +08:00
|
|
|
#if defined (RT_USING_CACHE) || defined(RT_USING_SMP)
|
|
|
|
#include <cpuport.h> /* include spinlock, cache ops, etc. */
|
|
|
|
#endif
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-10-18 09:08:21 +08:00
|
|
|
/*
|
|
|
|
* Some macros define
|
|
|
|
*/
|
2022-03-29 11:08:25 +08:00
|
|
|
#ifndef HWREG64
|
|
|
|
#define HWREG64(x) (*((volatile rt_uint64_t *)(x)))
|
|
|
|
#endif
|
2017-10-18 09:08:21 +08:00
|
|
|
#ifndef HWREG32
|
|
|
|
#define HWREG32(x) (*((volatile rt_uint32_t *)(x)))
|
|
|
|
#endif
|
|
|
|
#ifndef HWREG16
|
|
|
|
#define HWREG16(x) (*((volatile rt_uint16_t *)(x)))
|
|
|
|
#endif
|
|
|
|
#ifndef HWREG8
|
|
|
|
#define HWREG8(x) (*((volatile rt_uint8_t *)(x)))
|
|
|
|
#endif
|
|
|
|
|
2017-11-01 21:23:14 +08:00
|
|
|
#ifndef RT_CPU_CACHE_LINE_SZ
|
2019-12-16 13:59:46 +08:00
|
|
|
#define RT_CPU_CACHE_LINE_SZ 32
|
2017-11-01 21:23:14 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
enum RT_HW_CACHE_OPS
|
|
|
|
{
|
|
|
|
RT_HW_CACHE_FLUSH = 0x01,
|
|
|
|
RT_HW_CACHE_INVALIDATE = 0x02,
|
|
|
|
};
|
|
|
|
|
2013-03-26 08:52:33 +08:00
|
|
|
/*
|
|
|
|
* CPU interfaces
|
|
|
|
*/
|
2022-12-03 12:07:44 +08:00
|
|
|
#ifdef RT_USING_CACHE
|
2023-01-09 10:08:55 +08:00
|
|
|
|
2023-02-20 13:48:00 +08:00
|
|
|
#ifdef RT_USING_SMART
|
2023-01-09 10:08:55 +08:00
|
|
|
#include <cache.h>
|
|
|
|
#endif
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
void rt_hw_cpu_icache_enable(void);
|
|
|
|
void rt_hw_cpu_icache_disable(void);
|
|
|
|
rt_base_t rt_hw_cpu_icache_status(void);
|
2017-11-01 21:23:14 +08:00
|
|
|
void rt_hw_cpu_icache_ops(int ops, void* addr, int size);
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
void rt_hw_cpu_dcache_enable(void);
|
|
|
|
void rt_hw_cpu_dcache_disable(void);
|
|
|
|
rt_base_t rt_hw_cpu_dcache_status(void);
|
2017-11-01 21:23:14 +08:00
|
|
|
void rt_hw_cpu_dcache_ops(int ops, void* addr, int size);
|
2022-12-03 12:07:44 +08:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* define cache ops as empty */
|
|
|
|
#define rt_hw_cpu_icache_enable(...)
|
|
|
|
#define rt_hw_cpu_icache_disable(...)
|
|
|
|
#define rt_hw_cpu_icache_ops(...)
|
|
|
|
#define rt_hw_cpu_dcache_enable(...)
|
|
|
|
#define rt_hw_cpu_dcache_disable(...)
|
|
|
|
#define rt_hw_cpu_dcache_ops(...)
|
|
|
|
|
|
|
|
#define rt_hw_cpu_icache_status(...) 0
|
|
|
|
#define rt_hw_cpu_dcache_status(...) 0
|
|
|
|
|
|
|
|
#endif
|
2017-11-01 21:23:14 +08:00
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
void rt_hw_cpu_reset(void);
|
|
|
|
void rt_hw_cpu_shutdown(void);
|
|
|
|
|
2023-03-27 17:09:37 +08:00
|
|
|
const char *rt_hw_cpu_arch(void);
|
|
|
|
|
2012-09-05 13:54:47 +08:00
|
|
|
rt_uint8_t *rt_hw_stack_init(void *entry,
|
|
|
|
void *parameter,
|
|
|
|
rt_uint8_t *stack_addr,
|
|
|
|
void *exit);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2023-10-30 20:24:55 +08:00
|
|
|
#ifdef RT_USING_HW_STACK_GUARD
|
|
|
|
void rt_hw_stack_guard_init(rt_thread_t thread);
|
|
|
|
#endif
|
|
|
|
|
2013-03-26 08:52:33 +08:00
|
|
|
/*
|
|
|
|
* Interrupt handler definition
|
|
|
|
*/
|
|
|
|
typedef void (*rt_isr_handler_t)(int vector, void *param);
|
|
|
|
|
2013-06-29 13:33:06 +08:00
|
|
|
struct rt_irq_desc
|
|
|
|
{
|
|
|
|
rt_isr_handler_t handler;
|
|
|
|
void *param;
|
2013-03-26 08:52:33 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_INTERRUPT_INFO
|
2013-06-29 13:33:06 +08:00
|
|
|
char name[RT_NAME_MAX];
|
|
|
|
rt_uint32_t counter;
|
2023-10-25 20:31:25 +08:00
|
|
|
#ifdef RT_USING_SMP
|
|
|
|
rt_ubase_t cpu_counter[RT_CPUS_NR];
|
|
|
|
#endif
|
2013-03-26 08:52:33 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt interfaces
|
|
|
|
*/
|
2009-07-03 06:48:23 +08:00
|
|
|
void rt_hw_interrupt_init(void);
|
|
|
|
void rt_hw_interrupt_mask(int vector);
|
|
|
|
void rt_hw_interrupt_umask(int vector);
|
2013-06-29 13:33:06 +08:00
|
|
|
rt_isr_handler_t rt_hw_interrupt_install(int vector,
|
|
|
|
rt_isr_handler_t handler,
|
|
|
|
void *param,
|
2018-12-05 20:34:19 +08:00
|
|
|
const char *name);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2018-11-22 14:40:43 +08:00
|
|
|
#ifdef RT_USING_SMP
|
2024-02-21 11:45:04 +08:00
|
|
|
rt_base_t rt_hw_local_irq_disable(void);
|
2018-11-22 14:40:43 +08:00
|
|
|
void rt_hw_local_irq_enable(rt_base_t level);
|
|
|
|
|
2023-10-25 20:31:25 +08:00
|
|
|
rt_base_t rt_cpus_lock(void);
|
|
|
|
void rt_cpus_unlock(rt_base_t level);
|
|
|
|
|
2018-11-22 14:40:43 +08:00
|
|
|
#define rt_hw_interrupt_disable rt_cpus_lock
|
|
|
|
#define rt_hw_interrupt_enable rt_cpus_unlock
|
|
|
|
#else
|
2009-07-03 06:48:23 +08:00
|
|
|
rt_base_t rt_hw_interrupt_disable(void);
|
|
|
|
void rt_hw_interrupt_enable(rt_base_t level);
|
2023-10-25 20:31:25 +08:00
|
|
|
|
|
|
|
#define rt_hw_local_irq_disable rt_hw_interrupt_disable
|
|
|
|
#define rt_hw_local_irq_enable rt_hw_interrupt_enable
|
|
|
|
|
2018-11-22 14:40:43 +08:00
|
|
|
#endif /*RT_USING_SMP*/
|
2023-06-21 22:42:50 +08:00
|
|
|
rt_bool_t rt_hw_interrupt_is_disabled(void);
|
2013-03-26 08:52:33 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Context interfaces
|
|
|
|
*/
|
2018-11-22 14:40:43 +08:00
|
|
|
#ifdef RT_USING_SMP
|
|
|
|
void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread);
|
|
|
|
void rt_hw_context_switch_to(rt_ubase_t to, struct rt_thread *to_thread);
|
|
|
|
void rt_hw_context_switch_interrupt(void *context, rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread);
|
|
|
|
#else
|
2018-10-26 06:35:42 +08:00
|
|
|
void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
|
|
|
|
void rt_hw_context_switch_to(rt_ubase_t to);
|
2022-12-03 12:07:44 +08:00
|
|
|
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-11-22 14:40:43 +08:00
|
|
|
#endif /*RT_USING_SMP*/
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2023-10-21 20:14:45 +08:00
|
|
|
/**
|
|
|
|
* Hardware Layer Backtrace Service
|
|
|
|
*/
|
|
|
|
struct rt_hw_backtrace_frame {
|
|
|
|
rt_base_t fp;
|
|
|
|
rt_base_t pc;
|
|
|
|
};
|
|
|
|
|
|
|
|
rt_err_t rt_hw_backtrace_frame_get(rt_thread_t thread, struct rt_hw_backtrace_frame *frame);
|
|
|
|
|
|
|
|
rt_err_t rt_hw_backtrace_frame_unwind(rt_thread_t thread, struct rt_hw_backtrace_frame *frame);
|
|
|
|
|
2011-09-23 13:57:31 +08:00
|
|
|
void rt_hw_console_output(const char *str);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2018-10-26 06:35:42 +08:00
|
|
|
void rt_hw_show_memory(rt_uint32_t addr, rt_size_t size);
|
2009-07-03 06:48:23 +08:00
|
|
|
|
2012-12-29 17:36:16 +08:00
|
|
|
/*
|
2013-03-26 08:52:33 +08:00
|
|
|
* Exception interfaces
|
2012-12-29 17:36:16 +08:00
|
|
|
*/
|
2013-06-29 13:33:06 +08:00
|
|
|
void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context));
|
2012-12-29 17:36:16 +08:00
|
|
|
|
2017-10-18 09:08:21 +08:00
|
|
|
/*
|
|
|
|
* delay interfaces
|
|
|
|
*/
|
|
|
|
void rt_hw_us_delay(rt_uint32_t us);
|
|
|
|
|
2023-06-05 16:43:31 +08:00
|
|
|
int rt_hw_cpu_id(void);
|
|
|
|
|
|
|
|
#if defined(RT_USING_SMP) || defined(RT_USING_AMP)
|
|
|
|
/**
|
|
|
|
* ipi function
|
|
|
|
*/
|
|
|
|
void rt_hw_ipi_send(int ipi_vector, unsigned int cpu_mask);
|
|
|
|
#endif
|
|
|
|
|
2018-11-22 14:40:43 +08:00
|
|
|
#ifdef RT_USING_SMP
|
|
|
|
|
2019-09-26 18:13:07 +08:00
|
|
|
void rt_hw_spin_lock_init(rt_hw_spinlock_t *lock);
|
2018-11-22 14:40:43 +08:00
|
|
|
void rt_hw_spin_lock(rt_hw_spinlock_t *lock);
|
|
|
|
void rt_hw_spin_unlock(rt_hw_spinlock_t *lock);
|
|
|
|
|
|
|
|
extern rt_hw_spinlock_t _cpus_lock;
|
|
|
|
|
|
|
|
#define __RT_HW_SPIN_LOCK_INITIALIZER(lockname) {0}
|
|
|
|
|
2019-05-09 08:38:42 +08:00
|
|
|
#define __RT_HW_SPIN_LOCK_UNLOCKED(lockname) \
|
|
|
|
(rt_hw_spinlock_t) __RT_HW_SPIN_LOCK_INITIALIZER(lockname)
|
2018-11-22 14:40:43 +08:00
|
|
|
|
2023-10-25 20:31:25 +08:00
|
|
|
#define RT_DEFINE_HW_SPINLOCK(x) rt_hw_spinlock_t x = __RT_HW_SPIN_LOCK_UNLOCKED(x)
|
2018-11-22 14:40:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* boot secondary cpu
|
|
|
|
*/
|
|
|
|
void rt_hw_secondary_cpu_up(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secondary cpu idle function
|
|
|
|
*/
|
|
|
|
void rt_hw_secondary_cpu_idle_exec(void);
|
2019-05-12 21:44:28 +08:00
|
|
|
#else
|
|
|
|
|
2023-10-25 20:31:25 +08:00
|
|
|
#define RT_DEFINE_HW_SPINLOCK(x) rt_ubase_t x
|
2019-05-12 21:44:28 +08:00
|
|
|
|
|
|
|
#define rt_hw_spin_lock(lock) *(lock) = rt_hw_interrupt_disable()
|
|
|
|
#define rt_hw_spin_unlock(lock) rt_hw_interrupt_enable(*(lock))
|
2018-11-22 14:40:43 +08:00
|
|
|
|
2023-10-25 20:31:25 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
#endif
|
|
|
|
|
2023-10-21 20:14:45 +08:00
|
|
|
#ifndef RT_USING_CACHE
|
2024-02-21 11:45:04 +08:00
|
|
|
#define rt_hw_isb(void)
|
|
|
|
#define rt_hw_dmb(void)
|
|
|
|
#define rt_hw_dsb(void)
|
2018-11-22 14:40:43 +08:00
|
|
|
#endif
|
|
|
|
|
2009-07-03 06:48:23 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|