rthw.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /**
  2. * RT-Thread RuiChing
  3. *
  4. * COPYRIGHT (C) 2024-2025 Shanghai Real-Thread Electronic Technology Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * The license and distribution terms for this file may be
  8. * found in the file LICENSE in this distribution.
  9. */
  10. #ifndef __RTHW_H__
  11. #define __RTHW_H__
  12. #include <rtdef.h>
  13. #include <kpi.h>
  14. /*
  15. * Some macros define
  16. */
  17. #ifndef HWREG64
  18. #define HWREG64(x) (*((volatile rt_uint64_t *)(x)))
  19. #endif /* HWREG64 */
  20. #ifndef HWREG32
  21. #define HWREG32(x) (*((volatile rt_uint32_t *)(x)))
  22. #endif /* HWREG32 */
  23. #ifndef HWREG16
  24. #define HWREG16(x) (*((volatile rt_uint16_t *)(x)))
  25. #endif /* HWREG16 */
  26. #ifndef HWREG8
  27. #define HWREG8(x) (*((volatile rt_uint8_t *)(x)))
  28. #endif /* HWREG8 */
  29. enum RT_HW_CACHE_OPS
  30. {
  31. RT_HW_CACHE_FLUSH = 0x01,
  32. RT_HW_CACHE_INVALIDATE = 0x02,
  33. };
  34. /*
  35. * Cache interfaces
  36. */
  37. typedef void (*__kpi_rt_hw_cpu_icache_enable)(void);
  38. typedef void (*__kpi_rt_hw_cpu_icache_disable)(void);
  39. typedef rt_base_t (*__kpi_rt_hw_cpu_icache_status)(void);
  40. typedef void (*__kpi_rt_hw_cpu_icache_ops)(int ops, void* addr, int size);
  41. typedef void (*__kpi_rt_hw_cpu_dcache_enable)(void);
  42. typedef void (*__kpi_rt_hw_cpu_dcache_disable)(void);
  43. typedef rt_base_t (*__kpi_rt_hw_cpu_dcache_status)(void);
  44. typedef void (*__kpi_rt_hw_cpu_dcache_ops)(int ops, void* addr, int size);
  45. typedef void (*__kpi_rt_hw_isb)(void);
  46. typedef void (*__kpi_rt_hw_dmb)(void);
  47. typedef void (*__kpi_rt_hw_dsb)(void);
  48. typedef void (*__kpi_rt_hw_cpu_relax)(void);
  49. typedef void (*__kpi_rt_hw_rmb)(void);
  50. /*
  51. * Cpu interfaces
  52. */
  53. typedef void (*__kpi_rt_hw_cpu_reset)(void);
  54. typedef void (*__kpi_rt_hw_cpu_shutdown)(void);
  55. typedef const char *(*__kpi_rt_hw_cpu_arch)(void);
  56. typedef int (*__kpi_rt_hw_cpu_id)(void);
  57. /**
  58. * boot secondary cpu interfaces
  59. */
  60. #if 0
  61. void rt_hw_secondary_cpu_up(void);
  62. void rt_hw_secondary_cpu_idle_exec(void);
  63. /* stack interfaces */
  64. rt_uint8_t *rt_hw_stack_init(void *entry, void *parameter,
  65. rt_uint8_t *stack_addr, void *exit);
  66. void rt_hw_stack_guard_init(rt_thread_t thread);
  67. #endif
  68. /*
  69. * Interrupt interfaces
  70. */
  71. typedef void (*__kpi_rt_hw_interrupt_init)(void);
  72. typedef void (*__kpi_rt_hw_interrupt_mask)(int vector);
  73. typedef void (*__kpi_rt_hw_interrupt_umask)(int vector);
  74. typedef rt_isr_handler_t (*__kpi_rt_hw_interrupt_install)(int vector,
  75. rt_isr_handler_t handler, void *param, const char *name);
  76. typedef void (*__kpi_rt_hw_interrupt_uninstall)(int vector,
  77. rt_isr_handler_t handler, void *param);
  78. typedef rt_base_t (*__kpi_rt_hw_local_irq_disable)(void);
  79. typedef void (*__kpi_rt_hw_local_irq_enable)(rt_base_t level);
  80. typedef rt_base_t (*__kpi_rt_hw_interrupt_disable)(void);
  81. typedef void (*__kpi_rt_hw_interrupt_enable)(rt_base_t level);
  82. typedef rt_bool_t (*__kpi_rt_hw_interrupt_is_disabled)(void);
  83. typedef void (*__kpi_rt_hw_ipi_send)(int ipi_vector, unsigned int cpu_mask);
  84. typedef void (*__kpi_rt_hw_ipi_handler_install)(int ipi_vector,
  85. rt_isr_handler_t ipi_isr_handler);
  86. /*
  87. * Exception interfaces
  88. */
  89. typedef void (*__kpi_rt_hw_exception_install)(
  90. rt_err_t (*exception_handle)(void *context));
  91. /*
  92. * Context interfaces
  93. */
  94. #if 0
  95. #ifdef RT_USING_SMP
  96. void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread);
  97. void rt_hw_context_switch_to(rt_ubase_t to, struct rt_thread *to_thread);
  98. void rt_hw_context_switch_interrupt(void *context, rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread);
  99. #else
  100. void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
  101. void rt_hw_context_switch_to(rt_ubase_t to);
  102. void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to, rt_thread_t from_thread, rt_thread_t to_thread);
  103. #endif /* RT_USING_SMP */
  104. #endif
  105. /**
  106. * Hardware Layer Backtrace Service
  107. */
  108. #if 0
  109. rt_err_t rt_hw_backtrace_frame_get(rt_thread_t thread,
  110. struct rt_hw_backtrace_frame *frame);
  111. rt_err_t rt_hw_backtrace_frame_unwind(rt_thread_t thread,
  112. struct rt_hw_backtrace_frame *frame);
  113. void rt_hw_console_output(const char *str);
  114. #endif
  115. /*
  116. * delay interfaces
  117. */
  118. typedef void (*__kpi_rt_hw_us_delay)(rt_uint32_t us);
  119. /*
  120. * timer interfaces
  121. */
  122. typedef rt_uint32_t (*__kpi_rt_hw_global_timer_get)(void);
  123. /*
  124. * spinlock interfaces
  125. */
  126. extern rt_hw_spinlock_t _cpus_lock;
  127. #define RT_DEFINE_HW_SPINLOCK(x) rt_hw_spinlock_t x = {0}
  128. #if 0
  129. void rt_hw_spin_lock_init(rt_hw_spinlock_t *lock);
  130. void rt_hw_spin_lock(rt_hw_spinlock_t *lock);
  131. void rt_hw_spin_unlock(rt_hw_spinlock_t *lock);
  132. #endif
  133. /*
  134. * atomic interfaces
  135. */
  136. #if 0
  137. rt_atomic_t rt_hw_atomic_load(volatile rt_atomic_t *ptr);
  138. void rt_hw_atomic_store(volatile rt_atomic_t *ptr, rt_atomic_t val);
  139. rt_atomic_t rt_hw_atomic_add(volatile rt_atomic_t *ptr, rt_atomic_t val);
  140. rt_atomic_t rt_hw_atomic_sub(volatile rt_atomic_t *ptr, rt_atomic_t val);
  141. rt_atomic_t rt_hw_atomic_and(volatile rt_atomic_t *ptr, rt_atomic_t val);
  142. rt_atomic_t rt_hw_atomic_or(volatile rt_atomic_t *ptr, rt_atomic_t val);
  143. rt_atomic_t rt_hw_atomic_xor(volatile rt_atomic_t *ptr, rt_atomic_t val);
  144. rt_atomic_t rt_hw_atomic_exchange(volatile rt_atomic_t *ptr, rt_atomic_t val);
  145. void rt_hw_atomic_flag_clear(volatile rt_atomic_t *ptr);
  146. rt_atomic_t rt_hw_atomic_flag_test_and_set(volatile rt_atomic_t *ptr);
  147. rt_atomic_t rt_hw_atomic_compare_exchange_strong(volatile rt_atomic_t *ptr,
  148. rt_atomic_t *expected, rt_atomic_t desired);
  149. #endif
  150. KPI_EXTERN(rt_hw_cpu_icache_enable);
  151. KPI_EXTERN(rt_hw_cpu_icache_disable);
  152. KPI_EXTERN(rt_hw_cpu_icache_ops);
  153. KPI_EXTERN(rt_hw_cpu_icache_status);
  154. KPI_EXTERN(rt_hw_cpu_dcache_enable);
  155. KPI_EXTERN(rt_hw_cpu_dcache_disable);
  156. KPI_EXTERN(rt_hw_cpu_dcache_status);
  157. KPI_EXTERN(rt_hw_cpu_dcache_ops);
  158. KPI_EXTERN(rt_hw_isb);
  159. KPI_EXTERN(rt_hw_dmb);
  160. KPI_EXTERN(rt_hw_dsb);
  161. KPI_EXTERN(rt_hw_cpu_relax);
  162. KPI_EXTERN(rt_hw_rmb);
  163. KPI_EXTERN(rt_hw_cpu_reset);
  164. KPI_EXTERN(rt_hw_cpu_shutdown);
  165. KPI_EXTERN(rt_hw_cpu_arch);
  166. KPI_EXTERN(rt_hw_cpu_id);
  167. KPI_EXTERN(rt_hw_local_irq_disable);
  168. KPI_EXTERN(rt_hw_local_irq_enable);
  169. KPI_EXTERN(rt_hw_interrupt_disable);
  170. KPI_EXTERN(rt_hw_interrupt_enable);
  171. KPI_EXTERN(rt_hw_interrupt_is_disabled);
  172. KPI_EXTERN(rt_hw_ipi_send);
  173. KPI_EXTERN(rt_hw_ipi_handler_install);
  174. KPI_EXTERN(rt_hw_interrupt_mask);
  175. KPI_EXTERN(rt_hw_interrupt_umask);
  176. KPI_EXTERN(rt_hw_interrupt_install);
  177. KPI_EXTERN(rt_hw_interrupt_uninstall);
  178. KPI_EXTERN(rt_hw_exception_install);
  179. KPI_EXTERN(rt_hw_us_delay);
  180. KPI_EXTERN(rt_hw_global_timer_get);
  181. #endif /* __RTHW_H__ */