rthw.h 4.4 KB
Newer Older
1
/*
2
 * Copyright (c) 2006-2018, RT-Thread Development Team
B
Bernard Xiong 已提交
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
5 6 7 8 9 10
 *
 * 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
11
 * 2012-12-29     Bernard      add rt_hw_exception_install declaration
H
hichard 已提交
12
 * 2017-10-17     Hichard      add some micros
S
shaojinchun 已提交
13 14
 * 2018-11-17     Jesven       add rt_hw_spinlock_t
 *                             add smp support
15 16 17 18 19 20 21 22 23 24 25
 */

#ifndef __RT_HW_H__
#define __RT_HW_H__

#include <rtthread.h>

#ifdef __cplusplus
extern "C" {
#endif

H
hichard 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38
/*
 * Some macros define
 */
#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

T
tanek liang 已提交
39 40 41 42 43 44 45 46 47 48
#ifndef RT_CPU_CACHE_LINE_SZ
#define RT_CPU_CACHE_LINE_SZ	32
#endif

enum RT_HW_CACHE_OPS
{
    RT_HW_CACHE_FLUSH      = 0x01,
    RT_HW_CACHE_INVALIDATE = 0x02,
};

49 50 51
/*
 * CPU interfaces
 */
52 53 54
void rt_hw_cpu_icache_enable(void);
void rt_hw_cpu_icache_disable(void);
rt_base_t rt_hw_cpu_icache_status(void);
T
tanek liang 已提交
55 56
void rt_hw_cpu_icache_ops(int ops, void* addr, int size);

57 58 59
void rt_hw_cpu_dcache_enable(void);
void rt_hw_cpu_dcache_disable(void);
rt_base_t rt_hw_cpu_dcache_status(void);
T
tanek liang 已提交
60 61
void rt_hw_cpu_dcache_ops(int ops, void* addr, int size);

62 63 64
void rt_hw_cpu_reset(void);
void rt_hw_cpu_shutdown(void);

65 66 67 68
rt_uint8_t *rt_hw_stack_init(void       *entry,
                             void       *parameter,
                             rt_uint8_t *stack_addr,
                             void       *exit);
69

70 71 72 73 74
/*
 * Interrupt handler definition
 */
typedef void (*rt_isr_handler_t)(int vector, void *param);

Y
yiyue.fang 已提交
75 76 77 78
struct rt_irq_desc
{
    rt_isr_handler_t handler;
    void            *param;
79 80

#ifdef RT_USING_INTERRUPT_INFO
Y
yiyue.fang 已提交
81 82
    char             name[RT_NAME_MAX];
    rt_uint32_t      counter;
83 84 85 86 87 88
#endif
};

/*
 * Interrupt interfaces
 */
89 90 91
void rt_hw_interrupt_init(void);
void rt_hw_interrupt_mask(int vector);
void rt_hw_interrupt_umask(int vector);
Y
yiyue.fang 已提交
92 93 94
rt_isr_handler_t rt_hw_interrupt_install(int              vector,
                                         rt_isr_handler_t handler,
                                         void            *param,
95
                                         const char      *name);
96

S
shaojinchun 已提交
97 98 99 100 101 102 103 104
#ifdef RT_USING_SMP
rt_base_t rt_hw_local_irq_disable();
void rt_hw_local_irq_enable(rt_base_t level);

#define rt_hw_interrupt_disable rt_cpus_lock
#define rt_hw_interrupt_enable rt_cpus_unlock

#else
105 106
rt_base_t rt_hw_interrupt_disable(void);
void rt_hw_interrupt_enable(rt_base_t level);
S
shaojinchun 已提交
107
#endif /*RT_USING_SMP*/
108 109 110 111

/*
 * Context interfaces
 */
S
shaojinchun 已提交
112 113 114 115 116
#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
B
Bernard Xiong 已提交
117 118 119
void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
void rt_hw_context_switch_to(rt_ubase_t to);
void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to);
S
shaojinchun 已提交
120
#endif /*RT_USING_SMP*/
121

D
dzzxzz 已提交
122
void rt_hw_console_output(const char *str);
123

B
Bernard Xiong 已提交
124 125
void rt_hw_backtrace(rt_uint32_t *fp, rt_ubase_t thread_entry);
void rt_hw_show_memory(rt_uint32_t addr, rt_size_t size);
126

127
/*
128
 * Exception interfaces
129
 */
Y
yiyue.fang 已提交
130
void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context));
131

H
hichard 已提交
132 133 134 135 136
/*
 * delay interfaces
 */
void rt_hw_us_delay(rt_uint32_t us);

S
shaojinchun 已提交
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
#ifdef RT_USING_SMP
typedef union {
    unsigned long slock;
    struct __arch_tickets {
        unsigned short owner;
        unsigned short next;
    } tickets;
} rt_hw_spinlock_t;

void rt_hw_spin_lock(rt_hw_spinlock_t *lock);
void rt_hw_spin_unlock(rt_hw_spinlock_t *lock);

int rt_hw_cpu_id(void);

extern rt_hw_spinlock_t _cpus_lock;
extern rt_hw_spinlock_t _rt_critical_lock;

#define __RT_HW_SPIN_LOCK_INITIALIZER(lockname) {0}

#define __RT_HW_SPIN_LOCK_UNLOCKED(lockname) \
 (struct rt_hw_spinlock ) __RT_HW_SPIN_LOCK_INITIALIZER(lockname)

#define RT_DEFINE_SPINLOCK(x)  struct rt_hw_spinlock x = __RT_HW_SPIN_LOCK_UNLOCKED(x)

/**
 *  ipi function
 */
void rt_hw_ipi_send(int ipi_vector, unsigned int cpu_mask);

/**
 * boot secondary cpu
 */
void rt_hw_secondary_cpu_up(void);

/**
 * secondary cpu idle function
 */
void rt_hw_secondary_cpu_idle_exec(void);

#endif

178 179 180 181 182
#ifdef __cplusplus
}
#endif

#endif