rthw.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2006-03-18 Bernard the first version
  9. * 2006-04-25 Bernard add rt_hw_context_switch_interrupt declaration
  10. * 2006-09-24 Bernard add rt_hw_context_switch_to declaration
  11. * 2012-12-29 Bernard add rt_hw_exception_install declaration
  12. * 2017-10-17 Hichard add some micros
  13. */
  14. #ifndef __RT_HW_H__
  15. #define __RT_HW_H__
  16. #include <rtthread.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /*
  21. * Some macros define
  22. */
  23. #ifndef HWREG32
  24. #define HWREG32(x) (*((volatile rt_uint32_t *)(x)))
  25. #endif
  26. #ifndef HWREG16
  27. #define HWREG16(x) (*((volatile rt_uint16_t *)(x)))
  28. #endif
  29. #ifndef HWREG8
  30. #define HWREG8(x) (*((volatile rt_uint8_t *)(x)))
  31. #endif
  32. #ifndef RT_CPU_CACHE_LINE_SZ
  33. #define RT_CPU_CACHE_LINE_SZ 32
  34. #endif
  35. enum RT_HW_CACHE_OPS
  36. {
  37. RT_HW_CACHE_FLUSH = 0x01,
  38. RT_HW_CACHE_INVALIDATE = 0x02,
  39. };
  40. /*
  41. * CPU interfaces
  42. */
  43. void rt_hw_cpu_icache_enable(void);
  44. void rt_hw_cpu_icache_disable(void);
  45. rt_base_t rt_hw_cpu_icache_status(void);
  46. void rt_hw_cpu_icache_ops(int ops, void* addr, int size);
  47. void rt_hw_cpu_dcache_enable(void);
  48. void rt_hw_cpu_dcache_disable(void);
  49. rt_base_t rt_hw_cpu_dcache_status(void);
  50. void rt_hw_cpu_dcache_ops(int ops, void* addr, int size);
  51. void rt_hw_cpu_reset(void);
  52. void rt_hw_cpu_shutdown(void);
  53. rt_uint8_t *rt_hw_stack_init(void *entry,
  54. void *parameter,
  55. rt_uint8_t *stack_addr,
  56. void *exit);
  57. /*
  58. * Interrupt handler definition
  59. */
  60. typedef void (*rt_isr_handler_t)(int vector, void *param);
  61. struct rt_irq_desc
  62. {
  63. rt_isr_handler_t handler;
  64. void *param;
  65. #ifdef RT_USING_INTERRUPT_INFO
  66. char name[RT_NAME_MAX];
  67. rt_uint32_t counter;
  68. #endif
  69. };
  70. /*
  71. * Interrupt interfaces
  72. */
  73. void rt_hw_interrupt_init(void);
  74. void rt_hw_interrupt_mask(int vector);
  75. void rt_hw_interrupt_umask(int vector);
  76. rt_isr_handler_t rt_hw_interrupt_install(int vector,
  77. rt_isr_handler_t handler,
  78. void *param,
  79. const char *name);
  80. rt_base_t rt_hw_interrupt_disable(void);
  81. void rt_hw_interrupt_enable(rt_base_t level);
  82. /*
  83. * Context interfaces
  84. */
  85. void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
  86. void rt_hw_context_switch_to(rt_ubase_t to);
  87. void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to);
  88. void rt_hw_console_output(const char *str);
  89. void rt_hw_backtrace(rt_uint32_t *fp, rt_ubase_t thread_entry);
  90. void rt_hw_show_memory(rt_uint32_t addr, rt_size_t size);
  91. /*
  92. * Exception interfaces
  93. */
  94. void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context));
  95. /*
  96. * delay interfaces
  97. */
  98. void rt_hw_us_delay(rt_uint32_t us);
  99. #define RT_DEFINE_SPINLOCK(x)
  100. #define RT_DECLARE_SPINLOCK(x) rt_ubase_t x
  101. #define rt_hw_spin_lock(lock) *(lock) = rt_hw_interrupt_disable()
  102. #define rt_hw_spin_unlock(lock) rt_hw_interrupt_enable(*(lock))
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif