hal.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /***************************************************************************//**
  2. * (c) Copyright 2007-2013 Microsemi SoC Products Group. All rights reserved.
  3. *
  4. * Hardware abstraction layer functions.
  5. *
  6. * SVN $Revision: 5258 $
  7. * SVN $Date: 2013-03-21 18:11:02 +0530 (Thu, 21 Mar 2013) $
  8. */
  9. #ifndef HAL_H_
  10. #define HAL_H_
  11. #include "cpu_types.h"
  12. #include "hw_reg_access.h"
  13. /***************************************************************************//**
  14. * Enable all interrupts at the processor level.
  15. */
  16. void HAL_enable_interrupts( void );
  17. /***************************************************************************//**
  18. * Disable all interrupts at the processor core level.
  19. * Return the interrupts enable state before disabling occured so that it can
  20. * later be restored.
  21. */
  22. psr_t HAL_disable_interrupts( void );
  23. /***************************************************************************//**
  24. * Restore the interrupts enable state at the processor core level.
  25. * This function is normally passed the value returned from a previous call to
  26. * HAL_disable_interrupts().
  27. */
  28. void HAL_restore_interrupts( psr_t saved_psr );
  29. /***************************************************************************//**
  30. */
  31. #define FIELD_OFFSET(FIELD_NAME) (FIELD_NAME##_OFFSET)
  32. #define FIELD_SHIFT(FIELD_NAME) (FIELD_NAME##_SHIFT)
  33. #define FIELD_MASK(FIELD_NAME) (FIELD_NAME##_MASK)
  34. /***************************************************************************//**
  35. * The macro HAL_set_32bit_reg() allows writing a 32 bits wide register.
  36. *
  37. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  38. * peripheral containing the register.
  39. * REG_NAME: A string identifying the register to write. These strings are
  40. * specified in a header file associated with the peripheral.
  41. * VALUE: A variable of type uint32_t containing the value to write.
  42. */
  43. #define HAL_set_32bit_reg(BASE_ADDR, REG_NAME, VALUE) \
  44. (HW_set_32bit_reg( ((BASE_ADDR) + (REG_NAME##_REG_OFFSET)), (VALUE) ))
  45. /***************************************************************************//**
  46. * The macro HAL_get_32bit_reg() is used to read the value of a 32 bits wide
  47. * register.
  48. *
  49. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  50. * peripheral containing the register.
  51. * REG_NAME: A string identifying the register to read. These strings are
  52. * specified in a header file associated with the peripheral.
  53. * RETURN: This function-like macro returns a uint32_t value.
  54. */
  55. #define HAL_get_32bit_reg(BASE_ADDR, REG_NAME) \
  56. (HW_get_32bit_reg( ((BASE_ADDR) + (REG_NAME##_REG_OFFSET)) ))
  57. /***************************************************************************//**
  58. * The macro HAL_set_32bit_reg_field() is used to write a field within a
  59. * 32 bits wide register. The field written can be one or more bits.
  60. *
  61. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  62. * peripheral containing the register.
  63. * FIELD_NAME: A string identifying the register field to write. These strings
  64. * are specified in a header file associated with the peripheral.
  65. * VALUE: A variable of type uint32_t containing the field value to write.
  66. */
  67. #define HAL_set_32bit_reg_field(BASE_ADDR, FIELD_NAME, VALUE) \
  68. (HW_set_32bit_reg_field(\
  69. (BASE_ADDR) + FIELD_OFFSET(FIELD_NAME),\
  70. FIELD_SHIFT(FIELD_NAME),\
  71. FIELD_MASK(FIELD_NAME),\
  72. (VALUE)))
  73. /***************************************************************************//**
  74. * The macro HAL_get_32bit_reg_field() is used to read a register field from
  75. * within a 32 bit wide peripheral register. The field can be one or more bits.
  76. *
  77. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  78. * peripheral containing the register.
  79. * FIELD_NAME: A string identifying the register field to write. These strings
  80. * are specified in a header file associated with the peripheral.
  81. * RETURN: This function-like macro returns a uint32_t value.
  82. */
  83. #define HAL_get_32bit_reg_field(BASE_ADDR, FIELD_NAME) \
  84. (HW_get_32bit_reg_field(\
  85. (BASE_ADDR) + FIELD_OFFSET(FIELD_NAME),\
  86. FIELD_SHIFT(FIELD_NAME),\
  87. FIELD_MASK(FIELD_NAME)))
  88. /***************************************************************************//**
  89. * The macro HAL_set_16bit_reg() allows writing a 16 bits wide register.
  90. *
  91. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  92. * peripheral containing the register.
  93. * REG_NAME: A string identifying the register to write. These strings are
  94. * specified in a header file associated with the peripheral.
  95. * VALUE: A variable of type uint_fast16_t containing the value to write.
  96. */
  97. #define HAL_set_16bit_reg(BASE_ADDR, REG_NAME, VALUE) \
  98. (HW_set_16bit_reg( ((BASE_ADDR) + (REG_NAME##_REG_OFFSET)), (VALUE) ))
  99. /***************************************************************************//**
  100. * The macro HAL_get_16bit_reg() is used to read the value of a 16 bits wide
  101. * register.
  102. *
  103. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  104. * peripheral containing the register.
  105. * REG_NAME: A string identifying the register to read. These strings are
  106. * specified in a header file associated with the peripheral.
  107. * RETURN: This function-like macro returns a uint16_t value.
  108. */
  109. #define HAL_get_16bit_reg(BASE_ADDR, REG_NAME) \
  110. (HW_get_16bit_reg( (BASE_ADDR) + (REG_NAME##_REG_OFFSET) ))
  111. /***************************************************************************//**
  112. * The macro HAL_set_16bit_reg_field() is used to write a field within a
  113. * 16 bits wide register. The field written can be one or more bits.
  114. *
  115. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  116. * peripheral containing the register.
  117. * FIELD_NAME: A string identifying the register field to write. These strings
  118. * are specified in a header file associated with the peripheral.
  119. * VALUE: A variable of type uint16_t containing the field value to write.
  120. */
  121. #define HAL_set_16bit_reg_field(BASE_ADDR, FIELD_NAME, VALUE) \
  122. (HW_set_16bit_reg_field(\
  123. (BASE_ADDR) + FIELD_OFFSET(FIELD_NAME),\
  124. FIELD_SHIFT(FIELD_NAME),\
  125. FIELD_MASK(FIELD_NAME),\
  126. (VALUE)))
  127. /***************************************************************************//**
  128. * The macro HAL_get_16bit_reg_field() is used to read a register field from
  129. * within a 8 bit wide peripheral register. The field can be one or more bits.
  130. *
  131. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  132. * peripheral containing the register.
  133. * FIELD_NAME: A string identifying the register field to write. These strings
  134. * are specified in a header file associated with the peripheral.
  135. * RETURN: This function-like macro returns a uint16_t value.
  136. */
  137. #define HAL_get_16bit_reg_field(BASE_ADDR, FIELD_NAME) \
  138. (HW_get_16bit_reg_field(\
  139. (BASE_ADDR) + FIELD_OFFSET(FIELD_NAME),\
  140. FIELD_SHIFT(FIELD_NAME),\
  141. FIELD_MASK(FIELD_NAME)))
  142. /***************************************************************************//**
  143. * The macro HAL_set_8bit_reg() allows writing a 8 bits wide register.
  144. *
  145. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  146. * peripheral containing the register.
  147. * REG_NAME: A string identifying the register to write. These strings are
  148. * specified in a header file associated with the peripheral.
  149. * VALUE: A variable of type uint_fast8_t containing the value to write.
  150. */
  151. #define HAL_set_8bit_reg(BASE_ADDR, REG_NAME, VALUE) \
  152. (HW_set_8bit_reg( ((BASE_ADDR) + (REG_NAME##_REG_OFFSET)), (VALUE) ))
  153. /***************************************************************************//**
  154. * The macro HAL_get_8bit_reg() is used to read the value of a 8 bits wide
  155. * register.
  156. *
  157. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  158. * peripheral containing the register.
  159. * REG_NAME: A string identifying the register to read. These strings are
  160. * specified in a header file associated with the peripheral.
  161. * RETURN: This function-like macro returns a uint8_t value.
  162. */
  163. #define HAL_get_8bit_reg(BASE_ADDR, REG_NAME) \
  164. (HW_get_8bit_reg( (BASE_ADDR) + (REG_NAME##_REG_OFFSET) ))
  165. /***************************************************************************//**
  166. */
  167. #define HAL_set_8bit_reg_field(BASE_ADDR, FIELD_NAME, VALUE) \
  168. (HW_set_8bit_reg_field(\
  169. (BASE_ADDR) + FIELD_OFFSET(FIELD_NAME),\
  170. FIELD_SHIFT(FIELD_NAME),\
  171. FIELD_MASK(FIELD_NAME),\
  172. (VALUE)))
  173. /***************************************************************************//**
  174. * The macro HAL_get_8bit_reg_field() is used to read a register field from
  175. * within a 8 bit wide peripheral register. The field can be one or more bits.
  176. *
  177. * BASE_ADDR: A variable of type addr_t specifying the base address of the
  178. * peripheral containing the register.
  179. * FIELD_NAME: A string identifying the register field to write. These strings
  180. * are specified in a header file associated with the peripheral.
  181. * RETURN: This function-like macro returns a uint8_t value.
  182. */
  183. #define HAL_get_8bit_reg_field(BASE_ADDR, FIELD_NAME) \
  184. (HW_get_8bit_reg_field(\
  185. (BASE_ADDR) + FIELD_OFFSET(FIELD_NAME),\
  186. FIELD_SHIFT(FIELD_NAME),\
  187. FIELD_MASK(FIELD_NAME)))
  188. #endif /*HAL_H_*/