mcu_interrupts.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /***********************************************************************************************************************
  2. * DISCLAIMER
  3. * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. No
  4. * other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
  5. * applicable laws, including copyright laws.
  6. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
  7. * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
  8. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. TO THE MAXIMUM
  9. * EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES
  10. * SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS
  11. * SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  12. * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability of
  13. * this software. By using this software, you agree to the additional terms and conditions found by accessing the
  14. * following link:
  15. * http://www.renesas.com/disclaimer
  16. *
  17. * Copyright (C) 2016 Renesas Electronics Corporation. All rights reserved.
  18. ***********************************************************************************************************************/
  19. /***********************************************************************************************************************
  20. * File Name : mcu_interrupts.h
  21. * Description : This module allows for callbacks to be registered for certain interrupts.
  22. ***********************************************************************************************************************/
  23. /**********************************************************************************************************************
  24. * History : DD.MM.YYYY Version Description
  25. * : 01.10.2016 1.00 First Release
  26. * : 15.05.2017 2.00 Added the following enumeration constant.
  27. * - BSP_INT_SRC_EXRAM
  28. * - BSP_INT_SRC_BL1_RIIC1_TEI1
  29. * - BSP_INT_SRC_BL1_RIIC1_EEI1
  30. * - BSP_INT_SRC_AL1_GLCDC_VPOS
  31. * - BSP_INT_SRC_AL1_GLCDC_GR1UF
  32. * - BSP_INT_SRC_AL1_GLCDC_GR2UF
  33. * - BSP_INT_SRC_AL1_DRW2D_DRW_IRQ
  34. ***********************************************************************************************************************/
  35. /***********************************************************************************************************************
  36. Macro definitions
  37. ***********************************************************************************************************************/
  38. /***********************************************************************************************************************
  39. Typedef definitions
  40. ***********************************************************************************************************************/
  41. /* Available return codes. */
  42. typedef enum
  43. {
  44. BSP_INT_SUCCESS = 0,
  45. BSP_INT_ERR_NO_REGISTERED_CALLBACK, //There is not a registered callback for this interrupt source
  46. BSP_INT_ERR_INVALID_ARG, //Illegal argument input
  47. BSP_INT_ERR_UNSUPPORTED, //Operation is not supported by this API
  48. BSP_INT_ERR_GROUP_STILL_ENABLED //Not all group interrupts were disabled so group interrupt was not disabled
  49. } bsp_int_err_t;
  50. /* Available interrupts to register a callback for. */
  51. typedef enum
  52. {
  53. BSP_INT_SRC_EXC_SUPERVISOR_INSTR = 0, //Occurs when privileged instruction is executed in User Mode
  54. BSP_INT_SRC_EXC_UNDEFINED_INSTR, //Occurs when MCU encounters an unknown instruction
  55. BSP_INT_SRC_EXC_NMI_PIN, //NMI Pin interrupt
  56. BSP_INT_SRC_EXC_FPU, //FPU exception
  57. BSP_INT_SRC_EXC_ACCESS, //Access exception
  58. BSP_INT_SRC_OSC_STOP_DETECT, //Oscillation stop is detected
  59. BSP_INT_SRC_WDT_ERROR, //WDT underflow/refresh error has occurred
  60. BSP_INT_SRC_IWDT_ERROR, //IWDT underflow/refresh error has occurred
  61. BSP_INT_SRC_LVD1, //Voltage monitoring 1 interrupt
  62. BSP_INT_SRC_LVD2, //Voltage monitoring 2 interrupt
  63. BSP_INT_SRC_UNDEFINED_INTERRUPT, //Interrupt has triggered for a vector that user did not write a handler for
  64. BSP_INT_SRC_BUS_ERROR, //Bus error: illegal address access or timeout
  65. BSP_INT_SRC_RAM, //RAM error interrupt
  66. BSP_INT_SRC_EXRAM, //EXRAM error interrupt
  67. /* BE0 Group Interrupts are all CAN and therefore will be taken care of by the CAN module. */
  68. /* BL0 Group Interrupts. */
  69. BSP_INT_SRC_BL0_SCI0_TEI0,
  70. BSP_INT_SRC_BL0_SCI0_ERI0,
  71. BSP_INT_SRC_BL0_SCI1_TEI1,
  72. BSP_INT_SRC_BL0_SCI1_ERI1,
  73. BSP_INT_SRC_BL0_SCI2_TEI2,
  74. BSP_INT_SRC_BL0_SCI2_ERI2,
  75. BSP_INT_SRC_BL0_SCI3_TEI3,
  76. BSP_INT_SRC_BL0_SCI3_ERI3,
  77. BSP_INT_SRC_BL0_SCI4_TEI4,
  78. BSP_INT_SRC_BL0_SCI4_ERI4,
  79. BSP_INT_SRC_BL0_SCI5_TEI5,
  80. BSP_INT_SRC_BL0_SCI5_ERI5,
  81. BSP_INT_SRC_BL0_SCI6_TEI6,
  82. BSP_INT_SRC_BL0_SCI6_ERI6,
  83. BSP_INT_SRC_BL0_SCI7_TEI7,
  84. BSP_INT_SRC_BL0_SCI7_ERI7,
  85. BSP_INT_SRC_BL0_SCI12_TEI12,
  86. BSP_INT_SRC_BL0_SCI12_ERI12,
  87. BSP_INT_SRC_BL0_SCI12_SCIX0,
  88. BSP_INT_SRC_BL0_SCI12_SCIX1,
  89. BSP_INT_SRC_BL0_SCI12_SCIX2,
  90. BSP_INT_SRC_BL0_SCI12_SCIX3,
  91. BSP_INT_SRC_BL0_QSPI_QSPSSLI,
  92. BSP_INT_SRC_BL0_CAC_FERRI,
  93. BSP_INT_SRC_BL0_CAC_MENDI,
  94. BSP_INT_SRC_BL0_CAC_OVFI,
  95. BSP_INT_SRC_BL0_DOC_DOPCI,
  96. BSP_INT_SRC_BL0_PDC_PCFEI,
  97. BSP_INT_SRC_BL0_PDC_PCERI,
  98. /* BL1 Group Interrupts. */
  99. BSP_INT_SRC_BL1_SDHI_CDETI,
  100. BSP_INT_SRC_BL1_SDHI_CACI,
  101. BSP_INT_SRC_BL1_SDHI_SDACI,
  102. BSP_INT_SRC_BL1_MMCIF_CDETIO,
  103. BSP_INT_SRC_BL1_MMCIF_ERRIO,
  104. BSP_INT_SRC_BL1_MMCIF_ACCIO,
  105. BSP_INT_SRC_BL1_POE3_OEI1,
  106. BSP_INT_SRC_BL1_POE3_OEI2,
  107. BSP_INT_SRC_BL1_POE3_OEI3,
  108. BSP_INT_SRC_BL1_POE3_OEI4,
  109. BSP_INT_SRC_BL1_RIIC0_TEI0,
  110. BSP_INT_SRC_BL1_RIIC0_EEI0,
  111. BSP_INT_SRC_BL1_RIIC2_TEI2,
  112. BSP_INT_SRC_BL1_RIIC2_EEI2,
  113. BSP_INT_SRC_BL1_S12AD0_S12CMPAI,
  114. BSP_INT_SRC_BL1_S12AD0_S12CMPBI,
  115. BSP_INT_SRC_BL1_S12AD1_S12CMPAI1,
  116. BSP_INT_SRC_BL1_S12AD1_S12CMPBI1,
  117. BSP_INT_SRC_BL1_SCI8_TEI8,
  118. BSP_INT_SRC_BL1_SCI8_ERI8,
  119. BSP_INT_SRC_BL1_SCI9_TEI9,
  120. BSP_INT_SRC_BL1_SCI9_ERI9,
  121. BSP_INT_SRC_BL1_RIIC1_TEI1,
  122. BSP_INT_SRC_BL1_RIIC1_EEI1,
  123. /* BL2 Group Interrupts. */
  124. BSP_INT_SRC_BL2_SDSI_SDIOI,
  125. /* AL0 Group Interrupts. */
  126. BSP_INT_SRC_AL0_SCI10_TEI10,
  127. BSP_INT_SRC_AL0_SCI10_ERI10,
  128. BSP_INT_SRC_AL0_SCI11_TEI11,
  129. BSP_INT_SRC_AL0_SCI11_ERI11,
  130. BSP_INT_SRC_AL0_RSPI0_SPII0,
  131. BSP_INT_SRC_AL0_RSPI0_SPEI0,
  132. BSP_INT_SRC_AL0_RSPI1_SPII1,
  133. BSP_INT_SRC_AL0_RSPI1_SPEI1,
  134. BSP_INT_SRC_AL0_RSPI2_SPII2,
  135. BSP_INT_SRC_AL0_RSPI2_SPEI2,
  136. /* AL1 Group Interrupts. */
  137. BSP_INT_SRC_AL1_EDMAC0_EINT0,
  138. BSP_INT_SRC_AL1_GLCDC_VPOS,
  139. BSP_INT_SRC_AL1_GLCDC_GR1UF,
  140. BSP_INT_SRC_AL1_GLCDC_GR2UF,
  141. BSP_INT_SRC_AL1_DRW2D_DRW_IRQ,
  142. BSP_INT_SRC_TOTAL_ITEMS //DO NOT MODIFY! This is used for sizing the interrupt callback array.
  143. } bsp_int_src_t;
  144. /* Available commands for R_BSP_InterruptControl() function. */
  145. typedef enum
  146. {
  147. BSP_INT_CMD_CALL_CALLBACK = 0, //Calls registered callback function if one exists
  148. BSP_INT_CMD_INTERRUPT_ENABLE, //Enables a given interrupt (Available for NMI pin, FPU, and Bus Error)
  149. BSP_INT_CMD_INTERRUPT_DISABLE, //Disables a given interrupt (Available for FPU, and Bus Error)
  150. BSP_INT_CMD_GROUP_INTERRUPT_ENABLE, //Enables a group interrupt when a group interrupt source is given. The
  151. //pdata argument should give the IPL to be used using the bsp_int_ctrl_t
  152. //type. If a group interrupt is enabled multiple times with different IPL
  153. //levels it will use the highest given IPL.
  154. BSP_INT_CMD_GROUP_INTERRUPT_DISABLE, //Disables a group interrupt when a group interrupt source is given.
  155. //This will only disable a group interrupt when all interrupt
  156. //sources for that group are already disabled.
  157. } bsp_int_cmd_t;
  158. /* Type to be used for pdata argument in Control function. */
  159. typedef union
  160. {
  161. uint32_t ipl; //Used when enabling an interrupt to set that interrupt's priority level
  162. } bsp_int_ctrl_t;
  163. /* Easy to use typedef for callback functions. */
  164. typedef void (*bsp_int_cb_t)(void *);
  165. /* This structure is the common one that is passed as the 'void *' argument to callback functions when an
  166. * exception occurs.
  167. */
  168. typedef struct
  169. {
  170. bsp_int_src_t vector; //Which vector caused this interrupt
  171. } bsp_int_cb_args_t;
  172. /***********************************************************************************************************************
  173. Exported global variables
  174. ***********************************************************************************************************************/
  175. /***********************************************************************************************************************
  176. Exported global functions (to be accessed by other files)
  177. ***********************************************************************************************************************/
  178. bsp_int_err_t R_BSP_InterruptWrite(bsp_int_src_t vector, bsp_int_cb_t callback);
  179. bsp_int_err_t R_BSP_InterruptRead(bsp_int_src_t vector, bsp_int_cb_t * callback);
  180. bsp_int_err_t R_BSP_InterruptControl(bsp_int_src_t vector, bsp_int_cmd_t cmd, void * pdata);
  181. void bsp_interrupt_open(void); //r_bsp internal function. DO NOT CALL.