Interrupt_INTC.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /* Adapted for use with IAR Embedded Workbench */
  2. /*""FILE COMMENT""*******************************************************
  3. * System Name : Interrupt program for RX62Nxx
  4. * File Name : Interrupt_INTC.c
  5. * Version : 1.02
  6. * Contents : Interrupt handlers for the external interrupts
  7. * Customer :
  8. * Model :
  9. * Order :
  10. * CPU : RX
  11. * Compiler : RXC
  12. * OS : Nothing
  13. * Programmer :
  14. * Note :
  15. ************************************************************************
  16. * Copyright, 2011. Renesas Electronics Corporation
  17. * and Renesas Solutions Corporation
  18. ************************************************************************
  19. * History : 2011.04.08
  20. * : Ver 1.02
  21. * : CS-5 release.
  22. *""FILE COMMENT END""**************************************************/
  23. #include "r_pdl_intc.h"
  24. #include "r_pdl_definitions.h"
  25. #include "r_pdl_user_definitions.h"
  26. /* External functions */
  27. extern void PowerON_Reset_PC(void);
  28. extern void rpdl_ADC_10_Start(void);
  29. /* CMT control register definition */
  30. #define CMSTR_ADDRESS(a) ( (volatile uint16_t *)&CMT.CMSTR0 + ( (0x10u * (a >> 1)) / sizeof(uint16_t)) )
  31. /*""FUNC COMMENT""***************************************************
  32. * Module outline: External interrupt processing
  33. *-------------------------------------------------------------------
  34. * Declaration : void Interrupt_XXXX(void)
  35. *-------------------------------------------------------------------
  36. * Function : Interrupt processing function for External interrupts
  37. *-------------------------------------------------------------------
  38. * Argument : Nothing
  39. *-------------------------------------------------------------------
  40. * Return value : Nothing
  41. *------------------------------------------------------------------
  42. * Input :
  43. * Output :
  44. *-------------------------------------------------------------------
  45. * Use function : rpdl_INTC_callback_func[n]()
  46. *-------------------------------------------------------------------
  47. * Notes :
  48. *-------------------------------------------------------------------
  49. * History : 2011.04.08
  50. * : Ver 1.02
  51. * : CS-5 release.
  52. *""FUNC COMMENT END""**********************************************/
  53. #if FAST_INTC_VECTOR == VECT_ICU_IRQ0
  54. __fast_interrupt void Interrupt_IRQ0(void)
  55. #else
  56. #pragma vector = VECT_ICU_IRQ0
  57. __interrupt void Interrupt_IRQ0(void)
  58. #endif
  59. {
  60. /* Call the user function */
  61. if (rpdl_INTC_callback_func[PDL_INTC_IRQ0] != PDL_NO_FUNC)
  62. {
  63. rpdl_INTC_callback_func[PDL_INTC_IRQ0]();
  64. }
  65. }
  66. #if FAST_INTC_VECTOR == VECT_ICU_IRQ1
  67. __fast_interrupt void Interrupt_IRQ1(void)
  68. #else
  69. #pragma vector = VECT_ICU_IRQ1
  70. __interrupt void Interrupt_IRQ1(void)
  71. #endif
  72. {
  73. /* Call the user function */
  74. if (rpdl_INTC_callback_func[PDL_INTC_IRQ1] != PDL_NO_FUNC)
  75. {
  76. rpdl_INTC_callback_func[PDL_INTC_IRQ1]();
  77. }
  78. }
  79. #if FAST_INTC_VECTOR == VECT_ICU_IRQ2
  80. __fast_interrupt void Interrupt_IRQ2(void)
  81. #else
  82. #pragma vector = VECT_ICU_IRQ2
  83. __interrupt void Interrupt_IRQ2(void)
  84. #endif
  85. {
  86. /* Call the user function */
  87. if (rpdl_INTC_callback_func[PDL_INTC_IRQ2] != PDL_NO_FUNC)
  88. {
  89. rpdl_INTC_callback_func[PDL_INTC_IRQ2]();
  90. }
  91. }
  92. #if FAST_INTC_VECTOR == VECT_ICU_IRQ3
  93. __fast_interrupt void Interrupt_IRQ3(void)
  94. #else
  95. #pragma vector = VECT_ICU_IRQ3
  96. __interrupt void Interrupt_IRQ3(void)
  97. #endif
  98. {
  99. /* Call the user function */
  100. if (rpdl_INTC_callback_func[PDL_INTC_IRQ3] != PDL_NO_FUNC)
  101. {
  102. rpdl_INTC_callback_func[PDL_INTC_IRQ3]();
  103. }
  104. }
  105. #if FAST_INTC_VECTOR == VECT_ICU_IRQ4
  106. __fast_interrupt void Interrupt_IRQ4(void)
  107. #else
  108. #pragma vector = VECT_ICU_IRQ4
  109. __interrupt void Interrupt_IRQ4(void)
  110. #endif
  111. {
  112. /* Call the user function */
  113. if (rpdl_INTC_callback_func[PDL_INTC_IRQ4] != PDL_NO_FUNC)
  114. {
  115. rpdl_INTC_callback_func[PDL_INTC_IRQ4]();
  116. }
  117. }
  118. #if FAST_INTC_VECTOR == VECT_ICU_IRQ5
  119. __fast_interrupt void Interrupt_IRQ5(void)
  120. #else
  121. #pragma vector = VECT_ICU_IRQ5
  122. __interrupt void Interrupt_IRQ5(void)
  123. #endif
  124. {
  125. #ifdef DEVICE_PACKAGE_TFLGA_85
  126. /* This pin is not available on the 85-pin package */
  127. nop();
  128. #else
  129. /* Call the user function */
  130. if (rpdl_INTC_callback_func[PDL_INTC_IRQ5] != PDL_NO_FUNC)
  131. {
  132. rpdl_INTC_callback_func[PDL_INTC_IRQ5]();
  133. }
  134. #endif
  135. }
  136. #if FAST_INTC_VECTOR == VECT_ICU_IRQ6
  137. __fast_interrupt void Interrupt_IRQ6(void)
  138. #else
  139. #pragma vector = VECT_ICU_IRQ6
  140. __interrupt void Interrupt_IRQ6(void)
  141. #endif
  142. {
  143. #ifdef DEVICE_PACKAGE_TFLGA_85
  144. /* This pin is not available on the 85-pin package */
  145. nop();
  146. #else
  147. /* Call the user function */
  148. if (rpdl_INTC_callback_func[PDL_INTC_IRQ6] != PDL_NO_FUNC)
  149. {
  150. rpdl_INTC_callback_func[PDL_INTC_IRQ6]();
  151. }
  152. #endif
  153. }
  154. #if FAST_INTC_VECTOR == VECT_ICU_IRQ7
  155. __fast_interrupt void Interrupt_IRQ7(void)
  156. #else
  157. #pragma vector = VECT_ICU_IRQ7
  158. __interrupt void Interrupt_IRQ7(void)
  159. #endif
  160. {
  161. #ifdef DEVICE_PACKAGE_TFLGA_85
  162. /* This pin is not available on the 85-pin package */
  163. nop();
  164. #else
  165. /* Call the user function */
  166. if (rpdl_INTC_callback_func[PDL_INTC_IRQ7] != PDL_NO_FUNC)
  167. {
  168. rpdl_INTC_callback_func[PDL_INTC_IRQ7]();
  169. }
  170. #endif
  171. }
  172. #if FAST_INTC_VECTOR == VECT_ICU_IRQ8
  173. __fast_interrupt void Interrupt_IRQ8(void)
  174. #else
  175. #pragma vector = VECT_ICU_IRQ8
  176. __interrupt void Interrupt_IRQ8(void)
  177. #endif
  178. {
  179. /* Call the user function */
  180. if (rpdl_INTC_callback_func[PDL_INTC_IRQ8] != PDL_NO_FUNC)
  181. {
  182. rpdl_INTC_callback_func[PDL_INTC_IRQ8]();
  183. }
  184. }
  185. #if FAST_INTC_VECTOR == VECT_ICU_IRQ9
  186. __fast_interrupt void Interrupt_IRQ9(void)
  187. #else
  188. #pragma vector = VECT_ICU_IRQ9
  189. __interrupt void Interrupt_IRQ9(void)
  190. #endif
  191. {
  192. /* Call the user function */
  193. if (rpdl_INTC_callback_func[PDL_INTC_IRQ9] != PDL_NO_FUNC)
  194. {
  195. rpdl_INTC_callback_func[PDL_INTC_IRQ9]();
  196. }
  197. }
  198. #if FAST_INTC_VECTOR == VECT_ICU_IRQ10
  199. __fast_interrupt void Interrupt_IRQ10(void)
  200. #else
  201. #pragma vector = VECT_ICU_IRQ10
  202. __interrupt void Interrupt_IRQ10(void)
  203. #endif
  204. {
  205. /* Call the user function */
  206. if (rpdl_INTC_callback_func[PDL_INTC_IRQ10] != PDL_NO_FUNC)
  207. {
  208. rpdl_INTC_callback_func[PDL_INTC_IRQ10]();
  209. }
  210. }
  211. #if FAST_INTC_VECTOR == VECT_ICU_IRQ11
  212. __fast_interrupt void Interrupt_IRQ11(void)
  213. #else
  214. #pragma vector = VECT_ICU_IRQ11
  215. __interrupt void Interrupt_IRQ11(void)
  216. #endif
  217. {
  218. /* Call the user function */
  219. if (rpdl_INTC_callback_func[PDL_INTC_IRQ11] != PDL_NO_FUNC)
  220. {
  221. rpdl_INTC_callback_func[PDL_INTC_IRQ11]();
  222. }
  223. }
  224. #if FAST_INTC_VECTOR == VECT_ICU_IRQ12
  225. __fast_interrupt void Interrupt_IRQ12(void)
  226. #else
  227. #pragma vector = VECT_ICU_IRQ12
  228. __interrupt void Interrupt_IRQ12(void)
  229. #endif
  230. {
  231. /* Call the user function */
  232. if (rpdl_INTC_callback_func[PDL_INTC_IRQ12] != PDL_NO_FUNC)
  233. {
  234. rpdl_INTC_callback_func[PDL_INTC_IRQ12]();
  235. }
  236. }
  237. #if FAST_INTC_VECTOR == VECT_ICU_IRQ13
  238. __fast_interrupt void Interrupt_IRQ13(void)
  239. #else
  240. #pragma vector = VECT_ICU_IRQ13
  241. __interrupt void Interrupt_IRQ13(void)
  242. #endif
  243. {
  244. /* Call the user function */
  245. if (rpdl_INTC_callback_func[PDL_INTC_IRQ13] != PDL_NO_FUNC)
  246. {
  247. rpdl_INTC_callback_func[PDL_INTC_IRQ13]();
  248. }
  249. }
  250. #if FAST_INTC_VECTOR == VECT_ICU_IRQ14
  251. __fast_interrupt void Interrupt_IRQ14(void)
  252. #else
  253. #pragma vector = VECT_ICU_IRQ14
  254. __interrupt void Interrupt_IRQ14(void)
  255. #endif
  256. {
  257. /* Call the user function */
  258. if (rpdl_INTC_callback_func[PDL_INTC_IRQ14] != PDL_NO_FUNC)
  259. {
  260. rpdl_INTC_callback_func[PDL_INTC_IRQ14]();
  261. }
  262. }
  263. #if FAST_INTC_VECTOR == VECT_ICU_IRQ15
  264. __fast_interrupt void Interrupt_IRQ15(void)
  265. #else
  266. #pragma vector = VECT_ICU_IRQ15
  267. __interrupt void Interrupt_IRQ15(void)
  268. #endif
  269. {
  270. /* Call the user function */
  271. if (rpdl_INTC_callback_func[PDL_INTC_IRQ15] != PDL_NO_FUNC)
  272. {
  273. rpdl_INTC_callback_func[PDL_INTC_IRQ15]();
  274. }
  275. }
  276. /*""FUNC COMMENT""***************************************************
  277. * Module outline: Software interrupt processing
  278. *-------------------------------------------------------------------
  279. * Declaration : void Interrupt_SWINT(void)
  280. *-------------------------------------------------------------------
  281. * Function : Interrupt processing function for the software interrupt
  282. *-------------------------------------------------------------------
  283. * Argument : Nothing
  284. *-------------------------------------------------------------------
  285. * Return value : Nothing
  286. *------------------------------------------------------------------
  287. * Input :
  288. * Output :
  289. *-------------------------------------------------------------------
  290. * Use function : rpdl_INTC_callback_func[PDL_INTC_SWINT]()
  291. *-------------------------------------------------------------------
  292. * Notes :
  293. *-------------------------------------------------------------------
  294. * History : 2011.04.08
  295. * : Ver 1.02
  296. * : CS-5 release.
  297. *""FUNC COMMENT END""**********************************************/
  298. /*""FUNC COMMENT""***************************************************
  299. * Module outline: Break interrupt processing
  300. *-------------------------------------------------------------------
  301. * Declaration : void Interrupt_BRK(void)
  302. *-------------------------------------------------------------------
  303. * Function : Interrupt processing function for the break interrupt
  304. *-------------------------------------------------------------------
  305. * Argument : Nothing
  306. *-------------------------------------------------------------------
  307. * Return value : Nothing
  308. *------------------------------------------------------------------
  309. * Input :
  310. * Output :
  311. *-------------------------------------------------------------------
  312. * Use function :
  313. *-------------------------------------------------------------------
  314. * Notes :
  315. *-------------------------------------------------------------------
  316. * History : 2011.04.08
  317. * : Ver 1.02
  318. * : CS-5 release.
  319. *""FUNC COMMENT END""**********************************************/
  320. #if 0
  321. #pragma vector = 0
  322. __interrupt void Interrupt_BRK(void)
  323. {
  324. uint32_t * vector_location;
  325. volatile uint32_t * stacked_psw_ptr;
  326. uint32_t psw_copy;
  327. switch (rpdl_INTC_brk_command)
  328. {
  329. case BRK_START_ADC_10:
  330. rpdl_ADC_10_Start();
  331. break;
  332. case BRK_START_ADC_10_AND_SLEEP:
  333. rpdl_ADC_10_Start();
  334. /* Prevent all-module clock stop */
  335. SYSTEM.MSTPCRA.BIT.ACSE = 0;
  336. /* Select sleep or all-module clock stop */
  337. SYSTEM.SBYCR.BIT.SSBY = 0;
  338. /* Prevent out-of-order execution */
  339. while (SYSTEM.SBYCR.BIT.SSBY != 0);
  340. wait();
  341. break;
  342. case BRK_SLEEP:
  343. /* Prevent all-module clock stop */
  344. SYSTEM.MSTPCRA.BIT.ACSE = 0;
  345. /* Select sleep or all-module clock stop */
  346. SYSTEM.SBYCR.BIT.SSBY = 0;
  347. /* Prevent out-of-order execution */
  348. while (SYSTEM.SBYCR.BIT.SSBY != 0);
  349. wait();
  350. break;
  351. case BRK_ALL_MODULE_CLOCK_STOP:
  352. /* Select sleep or all-module clock stop */
  353. SYSTEM.SBYCR.BIT.SSBY = 0;
  354. /* Prevent out-of-order execution */
  355. while (SYSTEM.SBYCR.BIT.SSBY != 0);
  356. wait();
  357. break;
  358. case BRK_STANDBY:
  359. /* Prevent deep standby mode */
  360. SYSTEM.DPSBYCR.BIT.DPSBY = 0;
  361. /* Select standby mode */
  362. SYSTEM.SBYCR.BIT.SSBY = 1;
  363. /* Prevent out-of-order execution */
  364. while (SYSTEM.SBYCR.BIT.SSBY != 1);
  365. wait();
  366. break;
  367. case BRK_DEEP_STANDBY:
  368. /* Stop the RAM clock */
  369. SYSTEM.MSTPCRC.BIT.MSTPC0 = 1;
  370. SYSTEM.MSTPCRC.BIT.MSTPC1 = 1;
  371. /* Select deep standby mode */
  372. SYSTEM.DPSBYCR.BIT.DPSBY = 1;
  373. /* Select standby mode */
  374. SYSTEM.SBYCR.BIT.SSBY = 1;
  375. /* Prevent out-of-order execution */
  376. while (SYSTEM.SBYCR.BIT.SSBY != 1);
  377. wait();
  378. break;
  379. case BRK_LOAD_FINTV_REGISTER:
  380. /* Find the start of the maskable interrupt vector table */
  381. vector_location = (uint32_t *)get_intb();
  382. /* Move to the location of the address of the selected interrupt */
  383. vector_location += ICU.FIR.BIT.FVCT;
  384. /* Store the address of this vector in the FINTV register */
  385. set_fintv((__fast_int_f)*vector_location);
  386. break;
  387. case BRK_WRITE_IPL:
  388. /* Find the stacked PSW */
  389. stacked_psw_ptr = (uint32_t *)(rpdl_INTC_saved_isp) - 1;
  390. /* Read the stacked PSW */
  391. psw_copy = *stacked_psw_ptr;
  392. /* Clear the IPL bits */
  393. psw_copy &= (uint32_t)(INV_BIT_27 & INV_BIT_26 & INV_BIT_25 & INV_BIT_24);
  394. /* Modify the IPL bits */
  395. psw_copy |= (uint32_t)(rpdl_INTC_brk_data8 << 24);
  396. /* Modify the saved IPL */
  397. *stacked_psw_ptr = psw_copy;
  398. break;
  399. case BRK_CMT_START:
  400. /* Set STRn to 1 */
  401. *(CMSTR_ADDRESS(rpdl_INTC_brk_data8)) |= (uint16_t)((rpdl_INTC_brk_data8 & 0x01u) + 1);
  402. break;
  403. case BRK_CMT_STOP:
  404. /* Set STRn to 0 */
  405. *(CMSTR_ADDRESS(rpdl_INTC_brk_data8)) &= (uint16_t)(0x2u >> (rpdl_INTC_brk_data8 & 0x01u));
  406. break;
  407. default:
  408. /* This must never occur */
  409. break;
  410. }
  411. rpdl_INTC_brk_command = BRK_NO_COMMAND;
  412. }
  413. #endif
  414. /* Exception (Privileged Instruction) */
  415. __interrupt void __privileged_handler(void)
  416. {
  417. if (rpdl_INTC_callback_func[PDL_INTC_PRIVILEGED] != PDL_NO_FUNC)
  418. {
  419. /* Call the user function */
  420. rpdl_INTC_callback_func[PDL_INTC_PRIVILEGED]();
  421. }
  422. }
  423. /* Exception (Undefined Instruction) */
  424. __interrupt void __undefined_handler(void)
  425. {
  426. if (rpdl_INTC_callback_func[PDL_INTC_UNDEFINED] != PDL_NO_FUNC)
  427. {
  428. /* Call the user function */
  429. rpdl_INTC_callback_func[PDL_INTC_UNDEFINED]();
  430. }
  431. }
  432. /* Exception(Floating Point) */
  433. __interrupt void __floating_point_handler(void)
  434. {
  435. if (rpdl_INTC_callback_func[PDL_INTC_FLOATING_POINT] != PDL_NO_FUNC)
  436. {
  437. /* Call the user function */
  438. rpdl_INTC_callback_func[PDL_INTC_FLOATING_POINT]();
  439. }
  440. }
  441. __interrupt void __NMI_handler(void)
  442. {
  443. if (rpdl_INTC_callback_func[PDL_INTC_NMI] != PDL_NO_FUNC)
  444. {
  445. /* Call the user function */
  446. rpdl_INTC_callback_func[PDL_INTC_NMI]();
  447. }
  448. }
  449. /* End of file */