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