core_802.h 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562
  1. /*
  2. * Copyright (C) 2017-2019 Alibaba Group Holding Limited
  3. */
  4. /******************************************************************************
  5. * @file core_802.h
  6. * @brief CSI 802 Core Peripheral Access Layer Header File
  7. * @version V1.0
  8. * @date 02. June 2017
  9. ******************************************************************************/
  10. #ifndef __CORE_802_H_GENERIC
  11. #define __CORE_802_H_GENERIC
  12. #include <stdint.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /*******************************************************************************
  17. * CSI definitions
  18. ******************************************************************************/
  19. /**
  20. \ingroup Ck802
  21. @{
  22. */
  23. /* CSI CK802 definitions */
  24. #define __CK802_CSI_VERSION_MAIN (0x04U) /*!< [31:16] CSI HAL main version */
  25. #define __CK802_CSI_VERSION_SUB (0x1EU) /*!< [15:0] CSI HAL sub version */
  26. #define __CK802_CSI_VERSION ((__CK802_CSI_VERSION_MAIN << 16U) | \
  27. __CK802_CSI_VERSION_SUB ) /*!< CSI HAL version number */
  28. #ifndef __CK80X
  29. #define __CK80X (0x02U) /*!< CK80X Core */
  30. #endif
  31. /** __FPU_USED indicates whether an FPU is used or not.
  32. This core does not support an FPU at all
  33. */
  34. #define __FPU_USED 0U
  35. #if defined ( __GNUC__ )
  36. #if defined (__VFP_FP__) && !defined(__SOFTFP__)
  37. #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  38. #endif
  39. #endif
  40. #ifdef __cplusplus
  41. }
  42. #endif
  43. #endif /* __CORE_CK802_H_GENERIC */
  44. #ifndef __CSI_GENERIC
  45. #ifndef __CORE_CK802_H_DEPENDANT
  46. #define __CORE_CK802_H_DEPENDANT
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /* check device defines and use defaults */
  51. #ifndef __CK802_REV
  52. #define __CK802_REV 0x0000U
  53. #endif
  54. #ifndef __VIC_PRIO_BITS
  55. #define __VIC_PRIO_BITS 2U
  56. #endif
  57. #ifndef __Vendor_SysTickConfig
  58. #define __Vendor_SysTickConfig 1U
  59. #endif
  60. #ifndef __GSR_GCR_PRESENT
  61. #define __GSR_GCR_PRESENT 0U
  62. #endif
  63. #ifndef __MPU_PRESENT
  64. #define __MPU_PRESENT 1U
  65. #endif
  66. #ifndef __ICACHE_PRESENT
  67. #define __ICACHE_PRESENT 1U
  68. #endif
  69. #ifndef __DCACHE_PRESENT
  70. #define __DCACHE_PRESENT 1U
  71. #endif
  72. #include <core/csi_gcc.h>
  73. /* IO definitions (access restrictions to peripheral registers) */
  74. /**
  75. \defgroup CSI_glob_defs CSI Global Defines
  76. <strong>IO Type Qualifiers</strong> are used
  77. \li to specify the access to peripheral variables.
  78. \li for automatic generation of peripheral register debug information.
  79. */
  80. #ifdef __cplusplus
  81. #define __I volatile /*!< Defines 'read only' permissions */
  82. #else
  83. #define __I volatile const /*!< Defines 'read only' permissions */
  84. #endif
  85. #define __O volatile /*!< Defines 'write only' permissions */
  86. #define __IO volatile /*!< Defines 'read / write' permissions */
  87. /* following defines should be used for structure members */
  88. #define __IM volatile const /*! Defines 'read only' structure member permissions */
  89. #define __OM volatile /*! Defines 'write only' structure member permissions */
  90. #define __IOM volatile /*! Defines 'read / write' structure member permissions */
  91. /*@} end of group CK802 */
  92. /*******************************************************************************
  93. * Register Abstraction
  94. Core Register contain:
  95. - Core Register
  96. - Core VIC Register
  97. - Core Cache Register
  98. - Core CoreTIM Register
  99. ******************************************************************************/
  100. /**
  101. \defgroup CSI_core_register Defines and Type Definitions
  102. \brief Type definitions and defines for CK80X processor based devices.
  103. */
  104. /**
  105. \ingroup CSI_core_register
  106. \defgroup CSI_CORE Status and Control Registers
  107. \brief Core Register type definitions.
  108. @{
  109. */
  110. /**
  111. \brief Access Processor Status Register(PSR)struct definition.
  112. */
  113. typedef union {
  114. struct {
  115. uint32_t C: 1; /*!< bit: 0 Conditional code/Carry flag */
  116. uint32_t _reserved0: 5; /*!< bit: 2.. 5 Reserved */
  117. uint32_t IE: 1; /*!< bit: 6 Interrupt effective control bit */
  118. uint32_t IC: 1; /*!< bit: 7 Interrupt control bit */
  119. uint32_t EE: 1; /*!< bit: 8 Abnormally effective control bit */
  120. uint32_t MM: 1; /*!< bit: 9 Unsymmetrical masking bit */
  121. uint32_t _reserved1: 6; /*!< bit: 10..15 Reserved */
  122. uint32_t VEC: 8; /*!< bit: 16..23 Abnormal event vector value */
  123. uint32_t _reserved2: 3; /*!< bit: 24..26 Reserved */
  124. uint32_t SC: 1; /*!< bit: 27 Secure call bit */
  125. uint32_t HS: 1; /*!< bit: 28 Hardware stacked bit */
  126. uint32_t SP: 1; /*!< bit: 29 Secure pending bit */
  127. uint32_t T: 1; /*!< bit: 30 TEE mode bit */
  128. uint32_t S: 1; /*!< bit: 31 Superuser mode set bit */
  129. } b; /*!< Structure Access by bit */
  130. uint32_t w; /*!< Type Access by whole register */
  131. } PSR_Type;
  132. /* PSR Register Definitions */
  133. #define PSR_S_Pos 31U /*!< PSR: S Position */
  134. #define PSR_S_Msk (1UL << PSR_S_Pos) /*!< PSR: S Mask */
  135. #define PSR_T_Pos 30U /*!< PSR: T Position */
  136. #define PSR_T_Msk (1UL << PSR_T_Pos) /*!< PSR: T Mask */
  137. #define PSR_VEC_Pos 16U /*!< PSR: VEC Position */
  138. #define PSR_VEC_Msk (0x7FUL << PSR_VEC_Pos) /*!< PSR: VEC Mask */
  139. #define PSR_MM_Pos 9U /*!< PSR: MM Position */
  140. #define PSR_MM_Msk (1UL << PSR_MM_Pos) /*!< PSR: MM Mask */
  141. #define PSR_EE_Pos 8U /*!< PSR: EE Position */
  142. #define PSR_EE_Msk (1UL << PSR_EE_Pos) /*!< PSR: EE Mask */
  143. #define PSR_IC_Pos 7U /*!< PSR: IC Position */
  144. #define PSR_IC_Msk (1UL << PSR_IC_Pos) /*!< PSR: IC Mask */
  145. #define PSR_IE_Pos 6U /*!< PSR: IE Position */
  146. #define PSR_IE_Msk (1UL << PSR_IE_Pos) /*!< PSR: IE Mask */
  147. #define PSR_C_Pos 0U /*!< PSR: C Position */
  148. #define PSR_C_Msk (1UL << PSR_C_Pos) /*!< PSR: C Mask */
  149. /**
  150. \brief Consortium definition for accessing Cache Configuration Registers(CCR, CR<18, 0>).
  151. */
  152. typedef union {
  153. struct {
  154. uint32_t MP: 2; /*!< bit: 0.. 1 memory protection settings */
  155. uint32_t _reserved0: 5; /*!< bit: 2.. 6 Reserved */
  156. uint32_t BE: 1; /*!< bit: 7 Endian mode */
  157. uint32_t SCK: 3; /*!< bit: 8..10 the clock ratio of the system and the processor */
  158. uint32_t _reserved1: 2; /*!< bit: 11..12 Reserved */
  159. uint32_t BE_V2: 1; /*!< bit: 13 V2 Endian mode */
  160. uint32_t _reserved2: 18; /*!< bit: 14..31 Reserved */
  161. } b; /*!< Structure Access by bit */
  162. uint32_t w; /*!< Type Access by whole register */
  163. } CCR_Type;
  164. /* CCR Register Definitions */
  165. #define CCR_BE_V2_Pos 13U /*!< CCR: BE_V2 Position */
  166. #define CCR_BE_V2_Msk (0x1UL << CCR_BE_V2_Pos) /*!< CCR: BE_V2 Mask */
  167. #define CCR_SCK_Pos 8U /*!< CCR: SCK Position */
  168. #define CCR_SCK_Msk (0x3UL << CCR_SCK_Pos) /*!< CCR: SCK Mask */
  169. #define CCR_BE_Pos 7U /*!< CCR: BE Position */
  170. #define CCR_BE_Msk (0x1UL << CCR_BE_Pos) /*!< CCR: BE Mask */
  171. #define CCR_MP_Pos 0U /*!< CCR: MP Position */
  172. #define CCR_MP_Msk (0x3UL << CCR_MP_Pos) /*!< CCR: MP Mask */
  173. /**
  174. \brief Consortium definition for accessing high ease access permission configutation registers(CAPR, CR<19,0>)
  175. */
  176. typedef union {
  177. struct {
  178. uint32_t X0: 1; /*!< bit: 0 Non executable attribute setting */
  179. uint32_t X1: 1; /*!< bit: 1 Non executable attribute setting */
  180. uint32_t X2: 1; /*!< bit: 2 Non executable attribute setting */
  181. uint32_t X3: 1; /*!< bit: 3 Non executable attribute setting */
  182. uint32_t X4: 1; /*!< bit: 4 Non executable attribute setting */
  183. uint32_t X5: 1; /*!< bit: 5 Non executable attribute setting */
  184. uint32_t X6: 1; /*!< bit: 6 Non executable attribute setting */
  185. uint32_t X7: 1; /*!< bit: 7 Non executable attribute setting */
  186. uint32_t AP0: 2; /*!< bit: 8.. 9 access permissions settings bit */
  187. uint32_t AP1: 2; /*!< bit: 10..11 access permissions settings bit */
  188. uint32_t AP2: 2; /*!< bit: 12..13 access permissions settings bit */
  189. uint32_t AP3: 2; /*!< bit: 14..15 access permissions settings bit */
  190. uint32_t AP4: 2; /*!< bit: 16..17 access permissions settings bit */
  191. uint32_t AP5: 2; /*!< bit: 18..19 access permissions settings bit */
  192. uint32_t AP6: 2; /*!< bit: 20..21 access permissions settings bit */
  193. uint32_t AP7: 2; /*!< bit: 22..23 access permissions settings bit */
  194. uint32_t S0: 1; /*!< bit: 24 Security property settings */
  195. uint32_t S1: 1; /*!< bit: 25 Security property settings */
  196. uint32_t S2: 1; /*!< bit: 26 Security property settings */
  197. uint32_t S3: 1; /*!< bit: 27 Security property settings */
  198. uint32_t S4: 1; /*!< bit: 28 Security property settings */
  199. uint32_t S5: 1; /*!< bit: 29 Security property settings */
  200. uint32_t S6: 1; /*!< bit: 30 Security property settings */
  201. uint32_t S7: 1; /*!< bit: 31 Security property settings */
  202. } b; /*!< Structure Access by bit */
  203. uint32_t w; /*!< Type Access by whole register */
  204. } CAPR_Type;
  205. /* CAPR Register Definitions */
  206. #define CAPR_S7_Pos 31U /*!< CAPR: S7 Position */
  207. #define CAPR_S7_Msk (1UL << CAPR_S7_Pos) /*!< CAPR: S7 Mask */
  208. #define CAPR_S6_Pos 30U /*!< CAPR: S6 Position */
  209. #define CAPR_S6_Msk (1UL << CAPR_S6_Pos) /*!< CAPR: S6 Mask */
  210. #define CAPR_S5_Pos 29U /*!< CAPR: S5 Position */
  211. #define CAPR_S5_Msk (1UL << CAPR_S5_Pos) /*!< CAPR: S5 Mask */
  212. #define CAPR_S4_Pos 28U /*!< CAPR: S4 Position */
  213. #define CAPR_S4_Msk (1UL << CAPR_S4_Pos) /*!< CAPR: S4 Mask */
  214. #define CAPR_S3_Pos 27U /*!< CAPR: S3 Position */
  215. #define CAPR_S3_Msk (1UL << CAPR_S3_Pos) /*!< CAPR: S3 Mask */
  216. #define CAPR_S2_Pos 26U /*!< CAPR: S2 Position */
  217. #define CAPR_S2_Msk (1UL << CAPR_S2_Pos) /*!< CAPR: S2 Mask */
  218. #define CAPR_S1_Pos 25U /*!< CAPR: S1 Position */
  219. #define CAPR_S1_Msk (1UL << CAPR_S1_Pos) /*!< CAPR: S1 Mask */
  220. #define CAPR_S0_Pos 24U /*!< CAPR: S0 Position */
  221. #define CAPR_S0_Msk (1UL << CAPR_S0_Pos) /*!< CAPR: S0 Mask */
  222. #define CAPR_AP7_Pos 22U /*!< CAPR: AP7 Position */
  223. #define CAPR_AP7_Msk (0x3UL << CAPR_AP7_Pos) /*!< CAPR: AP7 Mask */
  224. #define CAPR_AP6_Pos 20U /*!< CAPR: AP6 Position */
  225. #define CAPR_AP6_Msk (0x3UL << CAPR_AP6_Pos) /*!< CAPR: AP6 Mask */
  226. #define CAPR_AP5_Pos 18U /*!< CAPR: AP5 Position */
  227. #define CAPR_AP5_Msk (0x3UL << CAPR_AP5_Pos) /*!< CAPR: AP5 Mask */
  228. #define CAPR_AP4_Pos 16U /*!< CAPR: AP4 Position */
  229. #define CAPR_AP4_Msk (0x3UL << CAPR_AP4_Pos) /*!< CAPR: AP4 Mask */
  230. #define CAPR_AP3_Pos 14U /*!< CAPR: AP3 Position */
  231. #define CAPR_AP3_Msk (0x3UL << CAPR_AP3_Pos) /*!< CAPR: AP3 Mask */
  232. #define CAPR_AP2_Pos 12U /*!< CAPR: AP2 Position */
  233. #define CAPR_AP2_Msk (0x3UL << CAPR_AP2_Pos) /*!< CAPR: AP2 Mask */
  234. #define CAPR_AP1_Pos 10U /*!< CAPR: AP1 Position */
  235. #define CAPR_AP1_Msk (0x3UL << CAPR_AP1_Pos) /*!< CAPR: AP1 Mask */
  236. #define CAPR_AP0_Pos 8U /*!< CAPR: AP0 Position */
  237. #define CAPR_AP0_Msk (0x3UL << CAPR_AP0_Pos) /*!< CAPR: AP0 Mask */
  238. #define CAPR_X7_Pos 7U /*!< CAPR: X7 Position */
  239. #define CAPR_X7_Msk (0x1UL << CAPR_X7_Pos) /*!< CAPR: X7 Mask */
  240. #define CAPR_X6_Pos 6U /*!< CAPR: X6 Position */
  241. #define CAPR_X6_Msk (0x1UL << CAPR_X6_Pos) /*!< CAPR: X6 Mask */
  242. #define CAPR_X5_Pos 5U /*!< CAPR: X5 Position */
  243. #define CAPR_X5_Msk (0x1UL << CAPR_X5_Pos) /*!< CAPR: X5 Mask */
  244. #define CAPR_X4_Pos 4U /*!< CAPR: X4 Position */
  245. #define CAPR_X4_Msk (0x1UL << CAPR_X4_Pos) /*!< CAPR: X4 Mask */
  246. #define CAPR_X3_Pos 3U /*!< CAPR: X3 Position */
  247. #define CAPR_X3_Msk (0x1UL << CAPR_X3_Pos) /*!< CAPR: X3 Mask */
  248. #define CAPR_X2_Pos 2U /*!< CAPR: X2 Position */
  249. #define CAPR_X2_Msk (0x1UL << CAPR_X2_Pos) /*!< CAPR: X2 Mask */
  250. #define CAPR_X1_Pos 1U /*!< CAPR: X1 Position */
  251. #define CAPR_X1_Msk (0x1UL << CAPR_X1_Pos) /*!< CAPR: X1 Mask */
  252. #define CAPR_X0_Pos 0U /*!< CAPR: X0 Position */
  253. #define CAPR_X0_Msk (0x1UL << CAPR_X0_Pos) /*!< CAPR: X0 Mask */
  254. /**
  255. \brief Consortium definition for accessing control register(PACR, CR<20,0>).
  256. */
  257. typedef union {
  258. struct {
  259. uint32_t E: 1; /*!< bit: 0 Effective setting of protected area */
  260. uint32_t size: 5; /*!< bit: 1.. 5 Size of protected area */
  261. uint32_t _reserved0: 1; /*!< bit: 6 Reserved */
  262. uint32_t base_addr: 25; /*!< bit: 7..31 The high position of the address of a protected area */
  263. } b; /*!< Structure Access by bit */
  264. uint32_t w; /*!< Type Access by whole register */
  265. } PACR_Type;
  266. /* PACR Register Definitions */
  267. #define PACR_BASE_ADDR_Pos 7U /*!< PACR: base_addr Position */
  268. #define PACR_BASE_ADDR_Msk (0x1FFFFFFUL << PACR_BASE_ADDR_Pos) /*!< PACR: base_addr Mask */
  269. #define PACR_SIZE_Pos 1U /*!< PACR: Size Position */
  270. #define PACR_SIZE_Msk (0x1FUL << PACR_SIZE_Pos) /*!< PACR: Size Mask */
  271. #define PACR_E_Pos 0U /*!< PACR: E Position */
  272. #define PACR_E_Msk (0x1UL << PACR_E_Pos) /*!< PACR: E Mask */
  273. /**
  274. \brief Consortium definition for accessing protection area selection register(PRSR,CR<21,0>).
  275. */
  276. typedef union {
  277. struct {
  278. uint32_t RID: 3; /*!< bit: 0.. 2 Protected area index value */
  279. uint32_t _reserved0: 29; /*!< bit: 3..31 Reserved */
  280. } b; /*!< Structure Access by bit */
  281. uint32_t w; /*!< Type Access by whole register */
  282. } PRSR_Type;
  283. /* PRSR Register Definitions */
  284. #define PRSR_RID_Pos 0U /*!< PRSR: RID Position */
  285. #define PRSR_RID_Msk (0x7UL << PRSR_RID_Pos) /*!< PRSR: RID Mask */
  286. /**
  287. \brief Consortium definition for CPU Hint Register(CHR, CR<31,0>).
  288. */
  289. typedef union {
  290. struct {
  291. uint32_t _reserved0: 4; /*!< bit: 0.. 3 Reserved */
  292. uint32_t IAE: 1; /*!< bit: 4 Interrupt response acceleration enable */
  293. uint32_t _reserved1: 9; /*!< bit: 5..13 Reserved */
  294. uint32_t ISE: 1; /*!< bit: 14 Interrupt SP enable */
  295. uint32_t HS_EXP: 1; /*!< bit: 15 Exception bit for TEE world switch */
  296. uint32_t SRST_VAL: 16; /*!< bit: 16..31 Software reset decision value */
  297. } b;
  298. uint32_t w;
  299. } CHR_Type;
  300. /* CHR Register Definitions */
  301. #define CHR_IAE_Pos 4U /*!< CHR: IAE Position */
  302. #define CHR_IAE_Msk (0x1UL << CHR_IAE_Pos) /*!< CHR: IAE Mask */
  303. #define CHR_ISE_Pos 14U /*!< CHR: ISE Position */
  304. #define CHR_ISE_Msk (0x1UL << CHR_ISE_Pos) /*!< CHR: ISE Mask */
  305. #define CHR_HS_EXP_Pos 15U /*!< CHR: HS_EXP Position */
  306. #define CHR_HS_EXP_Msk (0x1UL << CHR_HS_EXP_Pos) /*!< CHR: HS_EXP Mask */
  307. #define CHR_SRST_VAL_Pos 16U /*!< CHR: SRST_VAL Position */
  308. #define CHR_SRST_VAL_Mask (0xFFFFUL << CHR_SRST_VAL_Pos) /*!< CHR: SRST_VAL Mask */
  309. /*@} end of group CSI_CORE */
  310. /**
  311. \ingroup CSI_core_register
  312. \defgroup CSI_VIC Vectored Interrupt Controller (VIC)
  313. \brief Type definitions for the VIC Registers
  314. @{
  315. */
  316. /**
  317. \brief Access to the structure of a vector interrupt controller.
  318. */
  319. typedef struct {
  320. __IOM uint32_t ISER[4U]; /*!< Offset: 0x000 (R/W) Interrupt set enable register */
  321. uint32_t RESERVED0[12U];
  322. __IOM uint32_t IWER[4U]; /*!< Offset: 0x040 (R/W) Interrupt wake-up set register */
  323. uint32_t RESERVED1[12U];
  324. __IOM uint32_t ICER[4U]; /*!< Offset: 0x080 (R/W) Interrupt clear enable register */
  325. uint32_t RESERVED2[12U];
  326. __IOM uint32_t IWDR[4U]; /*!< Offset: 0x0c0 (R/W) Interrupt wake-up clear register */
  327. uint32_t RESERVED3[12U];
  328. __IOM uint32_t ISPR[4U]; /*!< Offset: 0x100 (R/W) Interrupt set pend register */
  329. uint32_t RESERVED4[12U];
  330. __IOM uint32_t ISSR[4U]; /*!< Offset: 0x140 (R/W) Security interrupt set register */
  331. uint32_t RESERVED5[12U];
  332. __IOM uint32_t ICPR[4U]; /*!< Offset: 0x180 (R/W) Interrupt clear pend register */
  333. uint32_t RESERVED6[12U];
  334. __IOM uint32_t ICSR[4U]; /*!< Offset: 0x1c0 (R/W) Security interrupt clear register */
  335. uint32_t RESERVED7[12U];
  336. __IOM uint32_t IABR[4U]; /*!< Offset: 0x200 (R/W) Interrupt answer stateregister */
  337. uint32_t RESERVED8[60U];
  338. __IOM uint32_t IPR[32U]; /*!< Offset: 0x300 (R/W) Interrupt priority register */
  339. uint32_t RESERVED9[480U];
  340. __IM uint32_t ISR; /*!< Offset: 0xB00 (R/ ) Interrupt state register */
  341. __IOM uint32_t IPTR; /*!< Offset: 0xB04 (R/W) Interrupt priority thershold register */
  342. __IOM uint32_t TSPEND; /*!< Offset: 0xB08 (R/W) Task pending register */
  343. __IOM uint32_t TSABR; /*!< Offset: 0xB0c (R/W) Tspend acknowledge register */
  344. __IOM uint32_t TSPR; /*!< Offset: 0xB10 (R/W) Tspend priority register */
  345. } VIC_Type;
  346. /*@} end of group CSI_VIC */
  347. /**
  348. \ingroup CSI_core_register
  349. \defgroup CSI_CACHE
  350. \brief Type definitions for the cache Registers
  351. @{
  352. */
  353. /**
  354. \brief On chip cache structure.
  355. */
  356. typedef struct
  357. {
  358. __IOM uint32_t CER; /*!< Offset: 0x000 (R/W) Cache enable register */
  359. __IOM uint32_t CIR; /*!< Offset: 0x004 (R/W) Cache invalid register */
  360. __IOM uint32_t CRCR[4U]; /*!< Offset: 0x008 (R/W) Cache Configuration register */
  361. uint32_t RSERVED0[1015U];
  362. __IOM uint32_t CPFCR; /*!< Offset: 0xFF4 (R/W) Cache performance analisis control register */
  363. __IOM uint32_t CPFATR; /*!< Offset: 0xFF8 (R/W) Cache access times register */
  364. __IOM uint32_t CPFMTR; /*!< Offset: 0xFFC (R/W) Cache missing times register */
  365. } CACHE_Type;
  366. /* CACHE Register Definitions */
  367. #define CACHE_CER_EN_Pos 0U /*!< CACHE CER: EN Position */
  368. #define CACHE_CER_EN_Msk (0x1UL << CACHE_CER_EN_Pos) /*!< CACHE CER: EN Mask */
  369. #define CACHE_CER_CFIG_Pos 1U /*!< CACHE CER: CFIG Position */
  370. #define CACHE_CER_CFIG_Msk (0x1UL << CACHE_CER_CFIG_Pos) /*!< CACHE CER: CFIG Mask */
  371. #define CACHE_CIR_INV_ALL_Pos 0U /*!< CACHE CIR: INV_ALL Position */
  372. #define CACHE_CIR_INV_ALL_Msk (0x1UL << CACHE_CIR_INV_ALL_Pos) /*!< CACHE CIR: INV_ALL Mask */
  373. #define CACHE_CIR_INV_ONE_Pos 1U /*!< CACHE CIR: INV_ONE Position */
  374. #define CACHE_CIR_INV_ONE_Msk (0x1UL << CACHE_CIR_INV_ONE_Pos) /*!< CACHE CIR: INV_ONE Mask */
  375. #define CACHE_CIR_CLR_ALL_Pos 2U /*!< CACHE CIR: CLR_ALL Position */
  376. #define CACHE_CIR_CLR_ALL_Msk (0x1UL << CACHE_CIR_CLR_ALL_Pos) /*!< CACHE CIR: CLR_ALL Mask */
  377. #define CACHE_CIR_CLR_ONE_Pos 3U /*!< CACHE CIR: CLR_ONE Position */
  378. #define CACHE_CIR_CLR_ONE_Msk (0x1UL << CACHE_CIR_CLR_ONE_Pos) /*!< CACHE CIR: CLR_ONE Mask */
  379. #define CACHE_CIR_INV_ADDR_Pos 4U /*!< CACHE CIR: INV_ADDR Position */
  380. #define CACHE_CIR_INV_ADDR_Msk (0xFFFFFFFUL << CACHE_CIR_INV_ADDR_Pos) /*!< CACHE CIR: INV_ADDR Mask */
  381. #define CACHE_CRCR_EN_Pos 0U /*!< CACHE CRCR: EN Position */
  382. #define CACHE_CRCR_EN_Msk (0x1UL << CACHE_CRCR_EN_Pos) /*!< CACHE CRCR: EN Mask */
  383. #define CACHE_CRCR_SIZE_Pos 1U /*!< CACHE CRCR: Size Position */
  384. #define CACHE_CRCR_SIZE_Msk (0x1FUL << CACHE_CRCR_SIZE_Pos) /*!< CACHE CRCR: Size Mask */
  385. #define CACHE_CRCR_BASE_ADDR_Pos 10U /*!< CACHE CRCR: base addr Position */
  386. #define CACHE_CRCR_BASE_ADDR_Msk (0x3FFFFFUL << CACHE_CRCR_BASE_ADDR_Pos) /*!< CACHE CRCR: base addr Mask */
  387. #define CACHE_CPFCR_PFEN_Pos 0U /*!< CACHE CPFCR: PFEN Position */
  388. #define CACHE_CPFCR_PFEN_Msk (0x1UL << CACHE_CPFCR_PFEN_Pos) /*!< CACHE CPFCR: PFEN Mask */
  389. #define CACHE_CPFCR_PFRST_Pos 1U /*!< CACHE CPFCR: PFRST Position */
  390. #define CACHE_CPFCR_PFRST_Msk (0x1UL << CACHE_CPFCR_PFRST_Pos) /*!< CACHE CPFCR: PFRST Mask */
  391. #define CACHE_CRCR_4K 0xB /* 01011 */
  392. #define CACHE_CRCR_8K 0xC /* 01100 */
  393. #define CACHE_CRCR_16K 0xD /* 01101 */
  394. #define CACHE_CRCR_32K 0xE /* 01110 */
  395. #define CACHE_CRCR_64K 0xF /* 01111 */
  396. #define CACHE_CRCR_128K 0x10 /* 10000 */
  397. #define CACHE_CRCR_256K 0x11 /* 10001 */
  398. #define CACHE_CRCR_512K 0x12 /* 10010 */
  399. #define CACHE_CRCR_1M 0x13 /* 10011 */
  400. #define CACHE_CRCR_2M 0x14 /* 10100 */
  401. #define CACHE_CRCR_4M 0x15 /* 10101 */
  402. #define CACHE_CRCR_8M 0x16 /* 10110 */
  403. #define CACHE_CRCR_16M 0x17 /* 10111 */
  404. #define CACHE_CRCR_32M 0x18 /* 11000 */
  405. #define CACHE_CRCR_64M 0x19 /* 11001 */
  406. #define CACHE_CRCR_128M 0x1A /* 11010 */
  407. #define CACHE_CRCR_256M 0x1B /* 11011 */
  408. #define CACHE_CRCR_512M 0x1C /* 11100 */
  409. #define CACHE_CRCR_1G 0x1D /* 11101 */
  410. #define CACHE_CRCR_2G 0x1E /* 11110 */
  411. #define CACHE_CRCR_4G 0x1F /* 11111 */
  412. /*@} end of group CSI_CACHE */
  413. /**
  414. \ingroup CSI_core_register
  415. \defgroup CSI_SysTick System Tick Timer (CORET)
  416. \brief Type definitions for the System Timer Registers.
  417. @{
  418. */
  419. /**
  420. \brief The data structure of the access system timer.
  421. */
  422. typedef struct {
  423. __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control register */
  424. __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) Backfill register */
  425. __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) Current register */
  426. __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) Calibration register */
  427. } CORET_Type;
  428. /* CORET Control / Status Register Definitions */
  429. #define CORET_CTRL_COUNTFLAG_Pos 16U /*!< CORET CTRL: COUNTFLAG Position */
  430. #define CORET_CTRL_COUNTFLAG_Msk (1UL << CORET_CTRL_COUNTFLAG_Pos) /*!< CORET CTRL: COUNTFLAG Mask */
  431. #define CORET_CTRL_CLKSOURCE_Pos 2U /*!< CORET CTRL: CLKSOURCE Position */
  432. #define CORET_CTRL_CLKSOURCE_Msk (1UL << CORET_CTRL_CLKSOURCE_Pos) /*!< CORET CTRL: CLKSOURCE Mask */
  433. #define CORET_CTRL_TICKINT_Pos 1U /*!< CORET CTRL: TICKINT Position */
  434. #define CORET_CTRL_TICKINT_Msk (1UL << CORET_CTRL_TICKINT_Pos) /*!< CORET CTRL: TICKINT Mask */
  435. #define CORET_CTRL_ENABLE_Pos 0U /*!< CORET CTRL: ENABLE Position */
  436. #define CORET_CTRL_ENABLE_Msk (1UL /*<< CORET_CTRL_ENABLE_Pos*/) /*!< CORET CTRL: ENABLE Mask */
  437. /* CORET Reload Register Definitions */
  438. #define CORET_LOAD_RELOAD_Pos 0U /*!< CORET LOAD: RELOAD Position */
  439. #define CORET_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< CORET_LOAD_RELOAD_Pos*/) /*!< CORET LOAD: RELOAD Mask */
  440. /* CORET Current Register Definitions */
  441. #define CORET_VAL_CURRENT_Pos 0U /*!< CORET VAL: CURRENT Position */
  442. #define CORET_VAL_CURRENT_Msk (0xFFFFFFUL /*<< CORET_VAL_CURRENT_Pos*/) /*!< CORET VAL: CURRENT Mask */
  443. /* CORET Calibration Register Definitions */
  444. #define CORET_CALIB_NOREF_Pos 31U /*!< CORET CALIB: NOREF Position */
  445. #define CORET_CALIB_NOREF_Msk (1UL << CORET_CALIB_NOREF_Pos) /*!< CORET CALIB: NOREF Mask */
  446. #define CORET_CALIB_SKEW_Pos 30U /*!< CORET CALIB: SKEW Position */
  447. #define CORET_CALIB_SKEW_Msk (1UL << CORET_CALIB_SKEW_Pos) /*!< CORET CALIB: SKEW Mask */
  448. #define CORET_CALIB_TENMS_Pos 0U /*!< CORET CALIB: TENMS Position */
  449. #define CORET_CALIB_TENMS_Msk (0xFFFFFFUL /*<< CORET_CALIB_TENMS_Pos*/) /*!< CORET CALIB: TENMS Mask */
  450. /*@} end of group CSI_SysTick */
  451. /**
  452. \ingroup CSI_core_register
  453. \defgroup CSI_DCC
  454. \brief Type definitions for the DCC.
  455. @{
  456. */
  457. /**
  458. \brief Access to the data structure of DCC.
  459. */
  460. typedef struct {
  461. uint32_t RESERVED0[13U];
  462. __IOM uint32_t HCR; /*!< Offset: 0x034 (R/W) */
  463. __IM uint32_t EHSR; /*!< Offset: 0x03C (R/ ) */
  464. uint32_t RESERVED1[6U];
  465. union {
  466. __IM uint32_t DERJW; /*!< Offset: 0x058 (R/ ) Data exchange register CPU read*/
  467. __OM uint32_t DERJR; /*!< Offset: 0x058 ( /W) Data exchange register CPU writer*/
  468. };
  469. } DCC_Type;
  470. #define DCC_HCR_JW_Pos 18U /*!< DCC HCR: jw_int_en Position */
  471. #define DCC_HCR_JW_Msk (1UL << DCC_HCR_JW_Pos) /*!< DCC HCR: jw_int_en Mask */
  472. #define DCC_HCR_JR_Pos 19U /*!< DCC HCR: jr_int_en Position */
  473. #define DCC_HCR_JR_Msk (1UL << DCC_HCR_JR_Pos) /*!< DCC HCR: jr_int_en Mask */
  474. #define DCC_EHSR_JW_Pos 1U /*!< DCC EHSR: jw_vld Position */
  475. #define DCC_EHSR_JW_Msk (1UL << DCC_EHSR_JW_Pos) /*!< DCC EHSR: jw_vld Mask */
  476. #define DCC_EHSR_JR_Pos 2U /*!< DCC EHSR: jr_vld Position */
  477. #define DCC_EHSR_JR_Msk (1UL << DCC_EHSR_JR_Pos) /*!< DCC EHSR: jr_vld Mask */
  478. /*@} end of group CSI_DCC */
  479. /**
  480. \ingroup CSI_core_register
  481. \defgroup CSI_core_bitfield Core register bit field macros
  482. \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
  483. @{
  484. */
  485. /**
  486. \brief Mask and shift a bit field value for use in a register bit range.
  487. \param[in] field Name of the register bit field.
  488. \param[in] value Value of the bit field.
  489. \return Masked and shifted value.
  490. */
  491. #define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
  492. /**
  493. \brief Mask and shift a register value to extract a bit filed value.
  494. \param[in] field Name of the register bit field.
  495. \param[in] value Value of register.
  496. \return Masked and shifted bit field value.
  497. */
  498. #define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
  499. /*@} end of group CSI_core_bitfield */
  500. /**
  501. \ingroup CSI_core_register
  502. \defgroup CSI_core_base Core Definitions
  503. \brief Definitions for base addresses, unions, and structures.
  504. @{
  505. */
  506. /* Memory mapping of CK802 Hardware */
  507. #define TCIP_BASE (0xE000E000UL) /*!< Titly Coupled IP Base Address */
  508. #define CORET_BASE (TCIP_BASE + 0x0010UL) /*!< CORET Base Address */
  509. #define VIC_BASE (TCIP_BASE + 0x0100UL) /*!< VIC Base Address */
  510. #define DCC_BASE (0xE0011000UL) /*!< DCC Base Address */
  511. #define CACHE_BASE (TCIP_BASE + 0x1000UL) /*!< CACHE Base Address */
  512. #define CORET ((CORET_Type *) CORET_BASE ) /*!< SysTick configuration struct */
  513. #define VIC ((VIC_Type *) VIC_BASE ) /*!< VIC configuration struct */
  514. #define DCC ((DCC_Type *) DCC_BASE ) /*!< DCC configuration struct */
  515. #define CACHE ((CACHE_Type *) CACHE_BASE ) /*!< cache configuration struct */
  516. /*@} */
  517. /*******************************************************************************
  518. * Hardware Abstraction Layer
  519. Core Function Interface contains:
  520. - Core VIC Functions
  521. - Core CORET Functions
  522. - Core Register Access Functions
  523. ******************************************************************************/
  524. /**
  525. \defgroup CSI_Core_FunctionInterface Functions and Instructions Reference
  526. */
  527. /* ########################## VIC functions #################################### */
  528. /**
  529. \ingroup CSI_Core_FunctionInterface
  530. \defgroup CSI_Core_VICFunctions VIC Functions
  531. \brief Functions that manage interrupts and exceptions via the VIC.
  532. @{
  533. */
  534. /* The following MACROS handle generation of the register offset and byte masks */
  535. #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
  536. #define _IR_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 5UL) )
  537. #define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
  538. /**
  539. \brief Enable External Interrupt
  540. \details Enable a device-specific interrupt in the VIC interrupt controller.
  541. \param [in] IRQn External interrupt number. Value cannot be negative.
  542. */
  543. __STATIC_INLINE void csi_vic_enable_irq(int32_t IRQn)
  544. {
  545. IRQn &= 0x7FUL;
  546. VIC->ISER[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  547. }
  548. /**
  549. \brief Disable External Interrupt
  550. \details Disable a device-specific interrupt in the VIC interrupt controller.
  551. \param [in] IRQn External interrupt number. Value cannot be negative.
  552. */
  553. __STATIC_INLINE void csi_vic_disable_irq(int32_t IRQn)
  554. {
  555. IRQn &= 0x7FUL;
  556. VIC->ICER[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  557. }
  558. /**
  559. \brief Enable External Secure Interrupt
  560. \details Enable a secure device-specific interrupt in the VIC interrupt controller.
  561. \param [in] IRQn External interrupt number. Value cannot be negative.
  562. */
  563. __STATIC_INLINE void csi_vic_enable_sirq(int32_t IRQn)
  564. {
  565. IRQn &= 0x7FUL;
  566. VIC->ISER[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  567. VIC->ISSR[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  568. }
  569. /**
  570. \brief Disable External Secure Interrupt
  571. \details Disable a secure device-specific interrupt in the VIC interrupt controller.
  572. \param [in] IRQn External interrupt number. Value cannot be negative.
  573. */
  574. __STATIC_INLINE void csi_vic_disable_sirq(int32_t IRQn)
  575. {
  576. IRQn &= 0x7FUL;
  577. VIC->ICER[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  578. VIC->ICSR[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  579. }
  580. /**
  581. \brief Check Interrupt is Enabled or not
  582. \details Read the enabled register in the VIC and returns the pending bit for the specified interrupt.
  583. \param [in] IRQn Interrupt number.
  584. \return 0 Interrupt status is not enabled.
  585. \return 1 Interrupt status is enabled.
  586. */
  587. __STATIC_INLINE uint32_t csi_vic_get_enabled_irq(int32_t IRQn)
  588. {
  589. IRQn &= 0x7FUL;
  590. return ((uint32_t)(((VIC->ISER[_IR_IDX(IRQn)] & (1UL << (((uint32_t)(int32_t)IRQn % 32) & 0x7FUL))) != 0UL) ? 1UL : 0UL));
  591. }
  592. /**
  593. \brief Check Interrupt is Pending or not
  594. \details Read the pending register in the VIC and returns the pending bit for the specified interrupt.
  595. \param [in] IRQn Interrupt number.
  596. \return 0 Interrupt status is not pending.
  597. \return 1 Interrupt status is pending.
  598. */
  599. __STATIC_INLINE uint32_t csi_vic_get_pending_irq(int32_t IRQn)
  600. {
  601. IRQn &= 0x7FUL;
  602. return ((uint32_t)(((VIC->ISPR[_IR_IDX(IRQn)] & (1UL << (((uint32_t)(int32_t)IRQn % 32) & 0x7FUL))) != 0UL) ? 1UL : 0UL));
  603. }
  604. /**
  605. \brief Set Pending Interrupt
  606. \details Set the pending bit of an external interrupt.
  607. \param [in] IRQn Interrupt number. Value cannot be negative.
  608. */
  609. __STATIC_INLINE void csi_vic_set_pending_irq(int32_t IRQn)
  610. {
  611. IRQn &= 0x7FUL;
  612. VIC->ISPR[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  613. }
  614. /**
  615. \brief Clear Pending Interrupt
  616. \details Clear the pending bit of an external interrupt.
  617. \param [in] IRQn External interrupt number. Value cannot be negative.
  618. */
  619. __STATIC_INLINE void csi_vic_clear_pending_irq(int32_t IRQn)
  620. {
  621. IRQn &= 0x7FUL;
  622. VIC->ICPR[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  623. }
  624. /**
  625. \brief Check Interrupt is Wakeup or not
  626. \details Read the wake up register in the VIC and returns the pending bit for the specified interrupt.
  627. \param [in] IRQn Interrupt number.
  628. \return 0 Interrupt is not set as wake up interrupt.
  629. \return 1 Interrupt is set as wake up interrupt.
  630. */
  631. __STATIC_INLINE uint32_t csi_vic_get_wakeup_irq(int32_t IRQn)
  632. {
  633. IRQn &= 0x7FUL;
  634. return ((uint32_t)(((VIC->IWER[_IR_IDX(IRQn)] & (1UL << (((uint32_t)(int32_t)IRQn % 32) & 0x7FUL))) != 0UL) ? 1UL : 0UL));
  635. }
  636. /**
  637. \brief Set Wake up Interrupt
  638. \details Set the wake up bit of an external interrupt.
  639. \param [in] IRQn Interrupt number. Value cannot be negative.
  640. */
  641. __STATIC_INLINE void csi_vic_set_wakeup_irq(int32_t IRQn)
  642. {
  643. IRQn &= 0x7FUL;
  644. VIC->IWER[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  645. }
  646. /**
  647. \brief Clear Wake up Interrupt
  648. \details Clear the wake up bit of an external interrupt.
  649. \param [in] IRQn External interrupt number. Value cannot be negative.
  650. */
  651. __STATIC_INLINE void csi_vic_clear_wakeup_irq(int32_t IRQn)
  652. {
  653. IRQn &= 0x7FUL;
  654. VIC->IWDR[_IR_IDX(IRQn)] = (uint32_t)(1UL << ((uint32_t)(int32_t)IRQn % 32));
  655. }
  656. /**
  657. \brief Get Interrupt is Active or not
  658. \details Read the active register in the VIC and returns the active bit for the device specific interrupt.
  659. \param [in] IRQn Device specific interrupt number.
  660. \return 0 Interrupt status is not active.
  661. \return 1 Interrupt status is active.
  662. \note IRQn must not be negative.
  663. */
  664. __STATIC_INLINE uint32_t csi_vic_get_active(int32_t IRQn)
  665. {
  666. IRQn &= 0x7FUL;
  667. return ((uint32_t)(((VIC->IABR[_IR_IDX(IRQn)] & (1UL << (((uint32_t)(int32_t)IRQn % 32) & 0x7FUL))) != 0UL) ? 1UL : 0UL));
  668. }
  669. /**
  670. \brief Set Threshold register
  671. \details set the threshold register in the VIC.
  672. \param [in] VectThreshold specific vector threshold.
  673. \param [in] PrioThreshold specific priority threshold.
  674. */
  675. __STATIC_INLINE void csi_vic_set_threshold(uint32_t VectThreshold, uint32_t PrioThreshold)
  676. {
  677. VectThreshold &= 0x7FUL;
  678. if (VectThreshold <= 31) {
  679. VIC->IPTR = 0x80000000 | (((VectThreshold + 32) & 0xFF) << 8) | ((PrioThreshold & 0x3) << 6);
  680. }
  681. if (VectThreshold > 31 && VectThreshold < 96) {
  682. VIC->IPTR = 0x80000000 | (((VectThreshold + 32) & 0xFF) << 8) | ((PrioThreshold & 0x7) << 5);
  683. }
  684. if (VectThreshold > 95) {
  685. VIC->IPTR = 0x80000000 | (((VectThreshold + 32) & 0xFF) << 8) | ((PrioThreshold & 0xF) << 4);
  686. }
  687. }
  688. /**
  689. \brief Set Interrupt Priority
  690. \details Set the priority of an interrupt.
  691. \note The priority cannot be set for every core interrupt.
  692. \param [in] IRQn Interrupt number.
  693. \param [in] priority Priority to set.
  694. */
  695. __STATIC_INLINE void csi_vic_set_prio(int32_t IRQn, uint32_t priority)
  696. {
  697. VIC->IPR[_IP_IDX(IRQn)] = ((uint32_t)(VIC->IPR[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
  698. (((priority << (8U - __VIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
  699. }
  700. /**
  701. \brief Get Interrupt Priority
  702. \details Read the priority of an interrupt.
  703. The interrupt number can be positive to specify an external (device specific) interrupt,
  704. or negative to specify an internal (core) interrupt.
  705. \param [in] IRQn Interrupt number.
  706. \return Interrupt Priority.
  707. Value is aligned automatically to the implemented priority bits of the microcontroller.
  708. */
  709. __STATIC_INLINE uint32_t csi_vic_get_prio(int32_t IRQn)
  710. {
  711. return ((uint32_t)(((VIC->IPR[_IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn)) & (uint32_t)0xFFUL) >> (8U - __VIC_PRIO_BITS)));
  712. }
  713. /**
  714. \brief Set interrupt handler
  715. \details Set the interrupt handler according to the interrupt num, the handler will be filled in irq vectors.
  716. \param [in] IRQn Interrupt number.
  717. \param [in] handler Interrupt handler.
  718. */
  719. __STATIC_INLINE void csi_vic_set_vector(int32_t IRQn, uint32_t handler)
  720. {
  721. if (IRQn >= 0 && IRQn < 128) {
  722. uint32_t *vectors = (uint32_t *)__get_VBR();
  723. vectors[32 + IRQn] = handler;
  724. }
  725. }
  726. /**
  727. \brief Get interrupt handler
  728. \details Get the address of interrupt handler function.
  729. \param [in] IRQn Interrupt number.
  730. */
  731. __STATIC_INLINE uint32_t csi_vic_get_vector(int32_t IRQn)
  732. {
  733. if (IRQn >= 0 && IRQn < 128) {
  734. uint32_t *vectors = (uint32_t *)__get_VBR();
  735. return (uint32_t)vectors[32 + IRQn];
  736. }
  737. return 0;
  738. }
  739. /*@} end of CSI_Core_VICFunctions */
  740. /* ################################## SysTick function ############################################ */
  741. /**
  742. \ingroup CSI_Core_FunctionInterface
  743. \defgroup CSI_Core_SysTickFunctions SysTick Functions
  744. \brief Functions that configure the System.
  745. @{
  746. */
  747. /**
  748. \brief CORE timer Configuration
  749. \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
  750. Counter is in free running mode to generate periodic interrupts.
  751. \param [in] ticks Number of ticks between two interrupts.
  752. \param [in] IRQn core timer Interrupt number.
  753. \return 0 Function succeeded.
  754. \return 1 Function failed.
  755. \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
  756. function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
  757. must contain a vendor-specific implementation of this function.
  758. */
  759. __STATIC_INLINE uint32_t csi_coret_config(uint32_t ticks, int32_t IRQn)
  760. {
  761. if ((ticks - 1UL) > CORET_LOAD_RELOAD_Msk) {
  762. return (1UL); /* Reload value impossible */
  763. }
  764. CORET->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
  765. CORET->VAL = 0UL; /* Load the CORET Counter Value */
  766. CORET->CTRL = CORET_CTRL_CLKSOURCE_Msk |
  767. CORET_CTRL_TICKINT_Msk |
  768. CORET_CTRL_ENABLE_Msk; /* Enable CORET IRQ and CORET Timer */
  769. return (0UL); /* Function successful */
  770. }
  771. /**
  772. \brief get CORE timer reload value
  773. \return CORE timer counter value.
  774. */
  775. __STATIC_INLINE uint32_t csi_coret_get_load(void)
  776. {
  777. return CORET->LOAD;
  778. }
  779. /**
  780. \brief get CORE timer counter value
  781. \return CORE timer counter value.
  782. */
  783. __STATIC_INLINE uint32_t csi_coret_get_value(void)
  784. {
  785. return CORET->VAL;
  786. }
  787. /**
  788. \brief clean CORE timer interrupt flag
  789. */
  790. __STATIC_INLINE void csi_coret_clear_irq(void)
  791. {
  792. CORET->CTRL;
  793. }
  794. /*@} end of CSI_Core_SysTickFunctions */
  795. /* ##################################### DCC function ########################################### */
  796. /**
  797. \ingroup CSI_Core_FunctionInterface
  798. \defgroup CSI_core_DebugFunctions HAD Functions
  799. \brief Functions that access the HAD debug interface.
  800. @{
  801. */
  802. /**
  803. \brief HAD Send Character
  804. \details Transmits a character via the HAD channel 0, and
  805. \li Just returns when no debugger is connected that has booked the output.
  806. \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted.
  807. \param [in] ch Character to transmit.
  808. \returns Character to transmit.
  809. */
  810. __STATIC_INLINE uint32_t csi_had_send_char(uint32_t ch)
  811. {
  812. DCC->DERJR = (uint8_t)ch;
  813. return (ch);
  814. }
  815. /**
  816. \brief HAD Receive Character
  817. \details Inputs a character via the external variable \ref HAD_RxBuffer.
  818. \return Received character.
  819. \return -1 No character pending.
  820. */
  821. __STATIC_INLINE int32_t csi_had_receive_char(void)
  822. {
  823. int32_t ch = -1; /* no character available */
  824. if (_FLD2VAL(DCC_EHSR_JW, DCC->EHSR)) {
  825. ch = DCC->DERJW;
  826. }
  827. return (ch);
  828. }
  829. /**
  830. \brief HAD Check Character
  831. \details Check whether a character is pending for reading in the variable \ref HAD_RxBuffer.
  832. \return 0 No character available.
  833. \return 1 Character available.
  834. */
  835. __STATIC_INLINE int32_t csi_had_check_char(void)
  836. {
  837. return _FLD2VAL(DCC_EHSR_JW, DCC->EHSR); /* no character available */
  838. }
  839. /*@} end of CSI_core_DebugFunctions */
  840. /* ########################## Cache functions #################################### */
  841. /**
  842. \ingroup CSI_Core_FunctionInterface
  843. \defgroup CSI_Core_CacheFunctions Cache Functions
  844. \brief Functions that configure Instruction and Data cache.
  845. @{
  846. */
  847. /**
  848. \brief Enable I-Cache
  849. \details Turns on I-Cache
  850. */
  851. __STATIC_INLINE void csi_icache_enable (void)
  852. {
  853. #if (__ICACHE_PRESENT == 1U)
  854. CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
  855. CACHE->CER |= (uint32_t)(CACHE_CER_EN_Msk | CACHE_CER_CFIG_Msk); /* enable all Cache */
  856. #endif
  857. }
  858. /**
  859. \brief Disable I-Cache
  860. \details Turns off I-Cache
  861. */
  862. __STATIC_INLINE void csi_icache_disable (void)
  863. {
  864. #if (__ICACHE_PRESENT == 1U)
  865. CACHE->CER &= ~(uint32_t)(CACHE_CER_EN_Msk | CACHE_CER_CFIG_Msk); /* disable all Cache */
  866. CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
  867. #endif
  868. }
  869. /**
  870. \brief Invalidate I-Cache
  871. \details Invalidates I-Cache
  872. */
  873. __STATIC_INLINE void csi_icache_invalid (void)
  874. {
  875. #if (__ICACHE_PRESENT == 1U)
  876. CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
  877. #endif
  878. }
  879. /**
  880. \brief Enable D-Cache
  881. \details Turns on D-Cache
  882. \note I-Cache also turns on.
  883. */
  884. __STATIC_INLINE void csi_dcache_enable (void)
  885. {
  886. #if (__DCACHE_PRESENT == 1U)
  887. CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
  888. CACHE->CER = (uint32_t)(CACHE_CER_EN_Msk & (~CACHE_CER_CFIG_Msk)); /* enable all Cache */
  889. #endif
  890. }
  891. /**
  892. \brief Disable D-Cache
  893. \details Turns off D-Cache
  894. \note I-Cache also turns off.
  895. */
  896. __STATIC_INLINE void csi_dcache_disable (void)
  897. {
  898. #if (__DCACHE_PRESENT == 1U)
  899. CACHE->CER &= ~(uint32_t)CACHE_CER_EN_Msk; /* disable all Cache */
  900. CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
  901. #endif
  902. }
  903. /**
  904. \brief Invalidate D-Cache
  905. \details Invalidates D-Cache
  906. \note I-Cache also invalid
  907. */
  908. __STATIC_INLINE void csi_dcache_invalid (void)
  909. {
  910. #if (__DCACHE_PRESENT == 1U)
  911. CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
  912. #endif
  913. }
  914. /**
  915. \brief Clean D-Cache
  916. \details Cleans D-Cache
  917. \note I-Cache also cleans
  918. */
  919. __STATIC_INLINE void csi_dcache_clean (void)
  920. {
  921. #if (__DCACHE_PRESENT == 1U)
  922. CACHE->CIR = _VAL2FLD(CACHE_CIR_CLR_ALL, 1); /* clean all Cache */
  923. #endif
  924. }
  925. /**
  926. \brief Clean & Invalidate D-Cache
  927. \details Cleans and Invalidates D-Cache
  928. \note I-Cache also flush.
  929. */
  930. __STATIC_INLINE void csi_dcache_clean_invalid (void)
  931. {
  932. #if (__DCACHE_PRESENT == 1U)
  933. CACHE->CIR = _VAL2FLD(CACHE_CIR_INV_ALL, 1) | _VAL2FLD(CACHE_CIR_CLR_ALL, 1); /* clean and inv all Cache */
  934. #endif
  935. }
  936. /**
  937. \brief D-Cache Invalidate by address
  938. \details Invalidates D-Cache for the given address
  939. \param[in] addr address (aligned to 16-byte boundary)
  940. \param[in] dsize size of memory block (aligned to 16-byte boundary)
  941. */
  942. __STATIC_INLINE void csi_dcache_invalid_range (uint32_t *addr, int32_t dsize)
  943. {
  944. #if (__DCACHE_PRESENT == 1U)
  945. int32_t op_size = dsize + (uint32_t)addr % 16;
  946. uint32_t op_addr = (uint32_t)addr & CACHE_CIR_INV_ADDR_Msk;
  947. int32_t linesize = 16;
  948. op_addr |= _VAL2FLD(CACHE_CIR_INV_ONE, 1);
  949. while (op_size >= 128) {
  950. CACHE->CIR = op_addr;
  951. op_addr += linesize;
  952. CACHE->CIR = op_addr;
  953. op_addr += linesize;
  954. CACHE->CIR = op_addr;
  955. op_addr += linesize;
  956. CACHE->CIR = op_addr;
  957. op_addr += linesize;
  958. CACHE->CIR = op_addr;
  959. op_addr += linesize;
  960. CACHE->CIR = op_addr;
  961. op_addr += linesize;
  962. CACHE->CIR = op_addr;
  963. op_addr += linesize;
  964. CACHE->CIR = op_addr;
  965. op_addr += linesize;
  966. op_size -= 128;
  967. }
  968. while (op_size > 0) {
  969. CACHE->CIR = op_addr;
  970. op_addr += linesize;
  971. op_size -= linesize;
  972. }
  973. #endif
  974. }
  975. /**
  976. \brief D-Cache Clean by address
  977. \details Cleans D-Cache for the given address
  978. \param[in] addr address (aligned to 16-byte boundary)
  979. \param[in] dsize size of memory block (aligned to 16-byte boundary)
  980. */
  981. __STATIC_INLINE void csi_dcache_clean_range (uint32_t *addr, int32_t dsize)
  982. {
  983. #if (__DCACHE_PRESENT == 1)
  984. int32_t op_size = dsize + (uint32_t)addr % 16;
  985. uint32_t op_addr = (uint32_t)addr & CACHE_CIR_INV_ADDR_Msk;
  986. int32_t linesize = 16;
  987. op_addr |= _VAL2FLD(CACHE_CIR_CLR_ONE, 1);
  988. while (op_size >= 128) {
  989. CACHE->CIR = op_addr;
  990. op_addr += linesize;
  991. CACHE->CIR = op_addr;
  992. op_addr += linesize;
  993. CACHE->CIR = op_addr;
  994. op_addr += linesize;
  995. CACHE->CIR = op_addr;
  996. op_addr += linesize;
  997. CACHE->CIR = op_addr;
  998. op_addr += linesize;
  999. CACHE->CIR = op_addr;
  1000. op_addr += linesize;
  1001. CACHE->CIR = op_addr;
  1002. op_addr += linesize;
  1003. CACHE->CIR = op_addr;
  1004. op_addr += linesize;
  1005. op_size -= 128;
  1006. }
  1007. while (op_size > 0) {
  1008. CACHE->CIR = op_addr;
  1009. op_addr += linesize;
  1010. op_size -= linesize;
  1011. }
  1012. #endif
  1013. }
  1014. /**
  1015. \brief D-Cache Clean and Invalidate by address
  1016. \details Cleans and invalidates D_Cache for the given address
  1017. \param[in] addr address (aligned to 16-byte boundary)
  1018. \param[in] dsize size of memory block (aligned to 16-byte boundary)
  1019. */
  1020. __STATIC_INLINE void csi_dcache_clean_invalid_range (uint32_t *addr, int32_t dsize)
  1021. {
  1022. #if (__DCACHE_PRESENT == 1U)
  1023. int32_t op_size = dsize + (uint32_t)addr % 16;
  1024. uint32_t op_addr = (uint32_t)addr & CACHE_CIR_INV_ADDR_Msk;
  1025. int32_t linesize = 16;
  1026. op_addr |= _VAL2FLD(CACHE_CIR_CLR_ONE, 1) | _VAL2FLD(CACHE_CIR_INV_ONE, 1);
  1027. while (op_size >= 128) {
  1028. CACHE->CIR = op_addr;
  1029. op_addr += linesize;
  1030. CACHE->CIR = op_addr;
  1031. op_addr += linesize;
  1032. CACHE->CIR = op_addr;
  1033. op_addr += linesize;
  1034. CACHE->CIR = op_addr;
  1035. op_addr += linesize;
  1036. CACHE->CIR = op_addr;
  1037. op_addr += linesize;
  1038. CACHE->CIR = op_addr;
  1039. op_addr += linesize;
  1040. CACHE->CIR = op_addr;
  1041. op_addr += linesize;
  1042. CACHE->CIR = op_addr;
  1043. op_addr += linesize;
  1044. op_size -= 128;
  1045. }
  1046. while (op_size > 0) {
  1047. CACHE->CIR = op_addr;
  1048. op_addr += linesize;
  1049. op_size -= linesize;
  1050. }
  1051. #endif
  1052. }
  1053. /**
  1054. \brief setup cacheable range Cache
  1055. \details setup Cache range
  1056. */
  1057. __STATIC_INLINE void csi_cache_set_range (uint32_t index, uint32_t baseAddr, uint32_t size, uint32_t enable)
  1058. {
  1059. CACHE->CRCR[index] = ((baseAddr & CACHE_CRCR_BASE_ADDR_Msk) |
  1060. (_VAL2FLD(CACHE_CRCR_SIZE, size)) |
  1061. (_VAL2FLD(CACHE_CRCR_EN, enable)));
  1062. }
  1063. /**
  1064. \brief Enable cache profile
  1065. \details Turns on Cache profile
  1066. */
  1067. __STATIC_INLINE void csi_cache_enable_profile (void)
  1068. {
  1069. CACHE->CPFCR |= (uint32_t)CACHE_CPFCR_PFEN_Msk;
  1070. }
  1071. /**
  1072. \brief Disable cache profile
  1073. \details Turns off Cache profile
  1074. */
  1075. __STATIC_INLINE void csi_cache_disable_profile (void)
  1076. {
  1077. CACHE->CPFCR &= ~(uint32_t)CACHE_CPFCR_PFEN_Msk;
  1078. }
  1079. /**
  1080. \brief Reset cache profile
  1081. \details Reset Cache profile
  1082. */
  1083. __STATIC_INLINE void csi_cache_reset_profile (void)
  1084. {
  1085. CACHE->CPFCR |= (uint32_t)CACHE_CPFCR_PFRST_Msk;
  1086. }
  1087. /**
  1088. \brief cache access times
  1089. \details Cache access times
  1090. \note every 256 access add 1.
  1091. \return cache access times, actual times should be multiplied by 256
  1092. */
  1093. __STATIC_INLINE uint32_t csi_cache_get_access_time (void)
  1094. {
  1095. return CACHE->CPFATR;
  1096. }
  1097. /**
  1098. \brief cache miss times
  1099. \details Cache miss times
  1100. \note every 256 miss add 1.
  1101. \return cache miss times, actual times should be multiplied by 256
  1102. */
  1103. __STATIC_INLINE uint32_t csi_cache_get_miss_time (void)
  1104. {
  1105. return CACHE->CPFMTR;
  1106. }
  1107. /*@} end of CSI_Core_CacheFunctions */
  1108. /*@} end of CSI_core_DebugFunctions */
  1109. /* ########################## MPU functions #################################### */
  1110. /**
  1111. \ingroup CSI_Core_FunctionInterface
  1112. \defgroup CSI_Core_MPUFunctions MPU Functions
  1113. \brief Functions that configure MPU.
  1114. @{
  1115. */
  1116. typedef enum {
  1117. REGION_SIZE_128B = 0x6,
  1118. REGION_SIZE_256B = 0x7,
  1119. REGION_SIZE_512B = 0x8,
  1120. REGION_SIZE_1KB = 0x9,
  1121. REGION_SIZE_2KB = 0xA,
  1122. REGION_SIZE_4KB = 0xB,
  1123. REGION_SIZE_8KB = 0xC,
  1124. REGION_SIZE_16KB = 0xD,
  1125. REGION_SIZE_32KB = 0xE,
  1126. REGION_SIZE_64KB = 0xF,
  1127. REGION_SIZE_128KB = 0x10,
  1128. REGION_SIZE_256KB = 0x11,
  1129. REGION_SIZE_512KB = 0x12,
  1130. REGION_SIZE_1MB = 0x13,
  1131. REGION_SIZE_2MB = 0x14,
  1132. REGION_SIZE_4MB = 0x15,
  1133. REGION_SIZE_8MB = 0x16,
  1134. REGION_SIZE_16MB = 0x17,
  1135. REGION_SIZE_32MB = 0x18,
  1136. REGION_SIZE_64MB = 0x19,
  1137. REGION_SIZE_128MB = 0x1A,
  1138. REGION_SIZE_256MB = 0x1B,
  1139. REGION_SIZE_512MB = 0x1C,
  1140. REGION_SIZE_1GB = 0x1D,
  1141. REGION_SIZE_2GB = 0x1E,
  1142. REGION_SIZE_4GB = 0x1F
  1143. } region_size_e;
  1144. typedef enum {
  1145. AP_BOTH_INACCESSIBLE = 0,
  1146. AP_SUPER_RW_USER_INACCESSIBLE,
  1147. AP_SUPER_RW_USER_RDONLY,
  1148. AP_BOTH_RW
  1149. } access_permission_e;
  1150. typedef struct {
  1151. uint32_t nx: 1; /* instruction fetched excution */
  1152. access_permission_e ap: 2; /* super user and normal user access.*/
  1153. uint32_t s: 1; /* security */
  1154. } mpu_region_attr_t;
  1155. /**
  1156. \brief enable mpu
  1157. \details
  1158. */
  1159. __STATIC_INLINE void csi_mpu_enable(void)
  1160. {
  1161. __set_CCR(__get_CCR() | CCR_MP_Msk);
  1162. }
  1163. /**
  1164. \brief disable mpu
  1165. \details
  1166. */
  1167. __STATIC_INLINE void csi_mpu_disable(void)
  1168. {
  1169. __set_CCR(__get_CCR() & (~CCR_MP_Msk));
  1170. }
  1171. /**
  1172. \brief configure memory protected region.
  1173. \details
  1174. \param [in] idx memory protected region (0, 1, 2, ..., 7).
  1175. \param [in] base_addr base address must be aligned with page size.
  1176. \param [in] size \ref region_size_e. memory protected region size.
  1177. \param [in] attr \ref region_size_t. memory protected region attribute.
  1178. \param [in] enable enable or disable memory protected region.
  1179. */
  1180. __STATIC_INLINE void csi_mpu_config_region(uint32_t idx, uint32_t base_addr, region_size_e size,
  1181. mpu_region_attr_t attr, uint32_t enable)
  1182. {
  1183. CAPR_Type capr;
  1184. PACR_Type pacr;
  1185. PRSR_Type prsr;
  1186. if (idx > 7) {
  1187. return;
  1188. }
  1189. capr.w = __get_CAPR();
  1190. pacr.w = __get_PACR();
  1191. prsr.w = __get_PRSR();
  1192. pacr.b.base_addr = (base_addr >> PACR_BASE_ADDR_Pos) & (0x3FFFFFF);
  1193. prsr.b.RID = idx;
  1194. __set_PRSR(prsr.w);
  1195. if (size != REGION_SIZE_128B) {
  1196. pacr.w &= ~(((1u << (size -6)) - 1) << 7);
  1197. }
  1198. pacr.b.size = size;
  1199. capr.w &= ~((0x1 << idx) | (0x3 << (idx * 2 + 8)) | (0x1 << (idx + 24)));
  1200. capr.w = (capr.w | (attr.nx << idx) | (attr.ap << (idx * 2 + 8)) | (attr.s << (idx + 24)));
  1201. __set_CAPR(capr.w);
  1202. pacr.b.E = enable;
  1203. __set_PACR(pacr.w);
  1204. }
  1205. /**
  1206. \brief enable mpu region by idx.
  1207. \details
  1208. \param [in] idx memory protected region (0, 1, 2, ..., 7).
  1209. */
  1210. __STATIC_INLINE void csi_mpu_enable_region(uint32_t idx)
  1211. {
  1212. if (idx > 7) {
  1213. return;
  1214. }
  1215. __set_PRSR((__get_PRSR() & (~PRSR_RID_Msk)) | idx);
  1216. __set_PACR(__get_PACR() | PACR_E_Msk);
  1217. }
  1218. /**
  1219. \brief disable mpu region by idx.
  1220. \details
  1221. \param [in] idx memory protected region (0, 1, 2, ..., 7).
  1222. */
  1223. __STATIC_INLINE void csi_mpu_disable_region(uint32_t idx)
  1224. {
  1225. if (idx > 7) {
  1226. return;
  1227. }
  1228. __set_PRSR((__get_PRSR() & (~PRSR_RID_Msk)) | idx);
  1229. __set_PACR(__get_PACR() & (~PACR_E_Msk));
  1230. }
  1231. /*@} end of CSI_Core_MMUFunctions */
  1232. /* ################################## IRQ Functions ############################################ */
  1233. /**
  1234. \brief Save the Irq context
  1235. \details save the psr result before disable irq.
  1236. */
  1237. __STATIC_INLINE uint32_t csi_irq_save(void)
  1238. {
  1239. uint32_t result;
  1240. result = __get_PSR();
  1241. __disable_irq();
  1242. return(result);
  1243. }
  1244. /**
  1245. \brief Restore the Irq context
  1246. \details restore saved primask state.
  1247. \param [in] irq_state psr irq state.
  1248. */
  1249. __STATIC_INLINE void csi_irq_restore(uint32_t irq_state)
  1250. {
  1251. __set_PSR(irq_state);
  1252. }
  1253. /*@} end of IRQ Functions */
  1254. /**
  1255. \brief System Reset
  1256. \details Initiates a system reset request to reset the MCU.
  1257. */
  1258. __STATIC_INLINE void csi_system_reset(void)
  1259. {
  1260. CHR_Type chr;
  1261. chr.w = __get_CHR();
  1262. #ifdef __RESET_CONST
  1263. chr.b.SRST_VAL = __RESET_CONST;
  1264. #else
  1265. chr.b.SRST_VAL = 0xABCD;
  1266. #endif
  1267. __DSB(); /* Ensure all outstanding memory accesses included
  1268. buffered write are completed before reset */
  1269. __set_CHR(chr.w);
  1270. __DSB(); /* Ensure completion of memory access */
  1271. for(;;) /* wait until reset */
  1272. {
  1273. __NOP();
  1274. }
  1275. }
  1276. /* ################################## Old Interfaces ############################################ */
  1277. /* These interfaces are deprecated */
  1278. #define NVIC_EnableIRQ(IRQn) csi_vic_enable_irq(IRQn)
  1279. #define NVIC_DisableIRQ(IRQn) csi_vic_disable_irq(IRQn)
  1280. #define NVIC_GetPendingIRQ(IRQn) csi_vic_get_pending_irq(IRQn)
  1281. #define NVIC_SetPendingIRQ(IRQn) csi_vic_set_pending_irq(IRQn)
  1282. #define NVIC_ClearPendingIRQ(IRQn) csi_vic_clear_pending_irq(IRQn)
  1283. #define NVIC_GetWakeupIRQ(IRQn) csi_vic_get_wakeup_irq(IRQn)
  1284. #define NVIC_SetWakeupIRQ(IRQn) csi_vic_set_wakeup_irq(IRQn)
  1285. #define NVIC_ClearWakeupIRQ(IRQn) csi_vic_clear_wakeup_irq(IRQn)
  1286. #define NVIC_GetActive(IRQn) csi_vic_get_active(IRQn)
  1287. #define NVIC_SetThreshold(VectThreshold, PrioThreshold) csi_vic_set_threshold(VectThreshold, PrioThreshold)
  1288. #define NVIC_SetPriority(IRQn, priority) csi_vic_set_prio(IRQn, priority)
  1289. #define NVIC_GetPriority(IRQn) csi_vic_get_prio(IRQn)
  1290. #define NVIC_SystemReset() csi_system_reset()
  1291. #define SysTick_Config(ticks) csi_coret_config(ticks, CORET_IRQn)
  1292. #define CORET_Config(ticks) csi_coret_config(ticks, CORET_IRQn)
  1293. #define HAD_SendChar(ch) csi_had_send_char(ch)
  1294. #define HAD_ReceiveChar() csi_had_receive_char()
  1295. #define HAD_CheckChar() csi_had_check_char()
  1296. /*@} end of Old Interfaces */
  1297. #ifdef __cplusplus
  1298. }
  1299. #endif
  1300. #endif /* __CORE_802_H_DEPENDANT */
  1301. #endif /* __CSI_GENERIC */