csi_reg.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. * @file csi_reg.h
  18. * @brief CSI Header File for reg.
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #ifndef _CSI_REG_H_
  23. #define _CSI_REG_H_
  24. #include<csi_gcc.h>
  25. /**
  26. \brief Enable IRQ Interrupts
  27. \details Enables IRQ interrupts by setting the IE-bit in the PSR.
  28. Can only be executed in Privileged modes.
  29. */
  30. __ALWAYS_INLINE void __enable_irq(void)
  31. {
  32. __ASM volatile("psrset ie");
  33. }
  34. /**
  35. \brief Disable IRQ Interrupts
  36. \details Disables IRQ interrupts by clearing the IE-bit in the PSR.
  37. Can only be executed in Privileged modes.
  38. */
  39. __ALWAYS_INLINE void __disable_irq(void)
  40. {
  41. __ASM volatile("psrclr ie");
  42. }
  43. /**
  44. \brief Get PSR
  45. \details Returns the content of the PSR Register.
  46. \return PSR Register value
  47. */
  48. __ALWAYS_INLINE uint32_t __get_PSR(void)
  49. {
  50. uint32_t result;
  51. __ASM volatile("mfcr %0, psr" : "=r"(result));
  52. return (result);
  53. }
  54. /**
  55. \brief Set PSR
  56. \details Writes the given value to the PSR Register.
  57. \param [in] psr PSR Register value to set
  58. */
  59. __ALWAYS_INLINE void __set_PSR(uint32_t psr)
  60. {
  61. __ASM volatile("mtcr %0, psr" : : "r"(psr));
  62. }
  63. /**
  64. \brief Get SP
  65. \details Returns the content of the SP Register.
  66. \return SP Register value
  67. */
  68. __ALWAYS_INLINE uint32_t __get_SP(void)
  69. {
  70. uint32_t result;
  71. __ASM volatile("mov %0, sp" : "=r"(result));
  72. return (result);
  73. }
  74. /**
  75. \brief Set SP
  76. \details Writes the given value to the SP Register.
  77. \param [in] sp SP Register value to set
  78. */
  79. __ALWAYS_INLINE void __set_SP(uint32_t sp)
  80. {
  81. __ASM volatile("mov sp, %0" : : "r"(sp): "sp");
  82. }
  83. /**
  84. \brief Get VBR Register
  85. \details Returns the content of the VBR Register.
  86. \return VBR Register value
  87. */
  88. __ALWAYS_INLINE uint32_t __get_VBR(void)
  89. {
  90. uint32_t result;
  91. __ASM volatile("mfcr %0, vbr" : "=r"(result));
  92. return (result);
  93. }
  94. /**
  95. \brief Set VBR
  96. \details Writes the given value to the VBR Register.
  97. \param [in] vbr VBR Register value to set
  98. */
  99. __ALWAYS_INLINE void __set_VBR(uint32_t vbr)
  100. {
  101. __ASM volatile("mtcr %0, vbr" : : "r"(vbr));
  102. }
  103. /**
  104. \brief Get EPC Register
  105. \details Returns the content of the EPC Register.
  106. \return EPC Register value
  107. */
  108. __ALWAYS_INLINE uint32_t __get_EPC(void)
  109. {
  110. uint32_t result;
  111. __ASM volatile("mfcr %0, epc" : "=r"(result));
  112. return (result);
  113. }
  114. /**
  115. \brief Set EPC
  116. \details Writes the given value to the EPC Register.
  117. \param [in] epc EPC Register value to set
  118. */
  119. __ALWAYS_INLINE void __set_EPC(uint32_t epc)
  120. {
  121. __ASM volatile("mtcr %0, epc" : : "r"(epc));
  122. }
  123. /**
  124. \brief Get EPSR
  125. \details Returns the content of the EPSR Register.
  126. \return EPSR Register value
  127. */
  128. __ALWAYS_INLINE uint32_t __get_EPSR(void)
  129. {
  130. uint32_t result;
  131. __ASM volatile("mfcr %0, epsr" : "=r"(result));
  132. return (result);
  133. }
  134. /**
  135. \brief Set EPSR
  136. \details Writes the given value to the EPSR Register.
  137. \param [in] epsr EPSR Register value to set
  138. */
  139. __ALWAYS_INLINE void __set_EPSR(uint32_t epsr)
  140. {
  141. __ASM volatile("mtcr %0, epsr" : : "r"(epsr));
  142. }
  143. /**
  144. \brief Get CPUID Register
  145. \details Returns the content of the CPUID Register.
  146. \return CPUID Register value
  147. */
  148. __ALWAYS_INLINE uint32_t __get_CPUID(void)
  149. {
  150. uint32_t result;
  151. __ASM volatile("mfcr %0, cr<13, 0>" : "=r"(result));
  152. return (result);
  153. }
  154. #if (__SOFTRESET_PRESENT == 1U)
  155. /**
  156. \brief Set SRCR
  157. \details Assigns the given value to the SRCR.
  158. \param [in] srcr SRCR value to set
  159. */
  160. __ALWAYS_INLINE void __set_SRCR(uint32_t srcr)
  161. {
  162. __ASM volatile("mtcr %0, cr<31, 0>\n" : : "r"(srcr));
  163. }
  164. #endif /* __SOFTRESET_PRESENT == 1U */
  165. #if (__MGU_PRESENT == 1U)
  166. /**
  167. \brief Get CCR
  168. \details Returns the current value of the CCR.
  169. \return CCR Register value
  170. */
  171. __ALWAYS_INLINE uint32_t __get_CCR(void)
  172. {
  173. register uint32_t result;
  174. __ASM volatile("mfcr %0, cr<18, 0>\n" : "=r"(result));
  175. return (result);
  176. }
  177. /**
  178. \brief Set CCR
  179. \details Assigns the given value to the CCR.
  180. \param [in] ccr CCR value to set
  181. */
  182. __ALWAYS_INLINE void __set_CCR(uint32_t ccr)
  183. {
  184. __ASM volatile("mtcr %0, cr<18, 0>\n" : : "r"(ccr));
  185. }
  186. /**
  187. \brief Get CAPR
  188. \details Returns the current value of the CAPR.
  189. \return CAPR Register value
  190. */
  191. __ALWAYS_INLINE uint32_t __get_CAPR(void)
  192. {
  193. register uint32_t result;
  194. __ASM volatile("mfcr %0, cr<19, 0>\n" : "=r"(result));
  195. return (result);
  196. }
  197. /**
  198. \brief Set CAPR
  199. \details Assigns the given value to the CAPR.
  200. \param [in] capr CAPR value to set
  201. */
  202. __ALWAYS_INLINE void __set_CAPR(uint32_t capr)
  203. {
  204. __ASM volatile("mtcr %0, cr<19, 0>\n" : : "r"(capr));
  205. }
  206. /**
  207. \brief Set PACR
  208. \details Assigns the given value to the PACR.
  209. \param [in] pacr PACR value to set
  210. */
  211. __ALWAYS_INLINE void __set_PACR(uint32_t pacr)
  212. {
  213. __ASM volatile("mtcr %0, cr<20, 0>\n" : : "r"(pacr));
  214. }
  215. /**
  216. \brief Get PACR
  217. \details Returns the current value of PACR.
  218. \return PACR value
  219. */
  220. __ALWAYS_INLINE uint32_t __get_PACR(void)
  221. {
  222. uint32_t result;
  223. __ASM volatile("mfcr %0, cr<20, 0>" : "=r"(result));
  224. return (result);
  225. }
  226. /**
  227. \brief Set PRSR
  228. \details Assigns the given value to the PRSR.
  229. \param [in] prsr PRSR value to set
  230. */
  231. __ALWAYS_INLINE void __set_PRSR(uint32_t prsr)
  232. {
  233. __ASM volatile("mtcr %0, cr<21, 0>\n" : : "r"(prsr));
  234. }
  235. /**
  236. \brief Get PRSR
  237. \details Returns the current value of PRSR.
  238. \return PRSR value
  239. */
  240. __ALWAYS_INLINE uint32_t __get_PRSR(void)
  241. {
  242. uint32_t result;
  243. __ASM volatile("mfcr %0, cr<21, 0>" : "=r"(result));
  244. return (result);
  245. }
  246. #endif /* __MGU_PRESENT == 1U */
  247. /**
  248. \brief Get user sp
  249. \details Returns the current value of user r14.
  250. \return UR14 value
  251. */
  252. __ALWAYS_INLINE uint32_t __get_UR14(void)
  253. {
  254. uint32_t result;
  255. __ASM volatile("mfcr %0, cr<14, 1>" : "=r"(result));
  256. return (result);
  257. }
  258. /**
  259. \brief Enable interrupts and exceptions
  260. \details Enables interrupts and exceptions by setting the IE-bit and EE-bit in the PSR.
  261. Can only be executed in Privileged modes.
  262. */
  263. __ALWAYS_INLINE void __enable_excp_irq(void)
  264. {
  265. __ASM volatile("psrset ee, ie");
  266. }
  267. /**
  268. \brief Disable interrupts and exceptions
  269. \details Disables interrupts and exceptions by clearing the IE-bit and EE-bit in the PSR.
  270. Can only be executed in Privileged modes.
  271. */
  272. __ALWAYS_INLINE void __disable_excp_irq(void)
  273. {
  274. __ASM volatile("psrclr ee, ie");
  275. }
  276. #if (__GSR_GCR_PRESENT == 1U)
  277. /**
  278. \brief Get GSR
  279. \details Returns the content of the GSR Register.
  280. \return GSR Register value
  281. */
  282. __ALWAYS_INLINE uint32_t __get_GSR(void)
  283. {
  284. uint32_t result;
  285. __ASM volatile("mfcr %0, cr<12, 0>" : "=r"(result));
  286. return (result);
  287. }
  288. /**
  289. \brief Get GCR
  290. \details Returns the content of the GCR Register.
  291. \return GCR Register value
  292. */
  293. __ALWAYS_INLINE uint32_t __get_GCR(void)
  294. {
  295. uint32_t result;
  296. __ASM volatile("mfcr %0, cr<11, 0>" : "=r"(result));
  297. return (result);
  298. }
  299. /**
  300. \brief Set GCR
  301. \details Writes the given value to the GCR Register.
  302. \param [in] gcr GCR Register value to set
  303. */
  304. __ALWAYS_INLINE void __set_GCR(uint32_t gcr)
  305. {
  306. __ASM volatile("mtcr %0, cr<11, 0>" : : "r"(gcr));
  307. }
  308. #endif /* (__GSR_GCR_PRESENT == 1U) */
  309. #endif /* _CSI_REG_H_ */