1 /*""FILE COMMENT""******************************************************* 2 * System Name : Interrupt program for RX62Nxx 3 * File Name : Interrupt_SPI.c 4 * Version : 1.02 5 * Contents : Interrupt handlers for all SPI channels 6 * Customer : 7 * Model : 8 * Order : 9 * CPU : RX 10 * Compiler : RXC 11 * OS : Nothing 12 * Programmer : 13 * Note : 14 ************************************************************************ 15 * Copyright, 2011. Renesas Electronics Corporation 16 * and Renesas Solutions Corporation 17 ************************************************************************ 18 * History : 2011.04.08 19 * : Ver 1.02 20 * : CS-5 release. 21 *""FILE COMMENT END""**************************************************/ 22 23 #include "r_pdl_spi.h" 24 #include "r_pdl_definitions.h" 25 #include "r_pdl_user_definitions.h" 26 27 /*""FUNC COMMENT""*************************************************** 28 * Module outline: SPIn receive data error interrupt processing 29 *------------------------------------------------------------------- 30 * Declaration : void Interrupt_RSPIn_SPEIn(void) 31 *------------------------------------------------------------------- 32 * Function : 33 *------------------------------------------------------------------- 34 * Argument : Nothing 35 *------------------------------------------------------------------- 36 * Return value : Nothing 37 *------------------------------------------------------------------- 38 * Output : None 39 *------------------------------------------------------------------- 40 * Use function : rpdl_SPI_callback_func[n] 41 *------------------------------------------------------------------- 42 * Notes : 43 *------------------------------------------------------------------- 44 * History : 2011.04.08 45 * : Ver 1.02 46 * : CS-5 release. 47 *""FUNC COMMENT END""**********************************************/ 48 49 #if FAST_INTC_VECTOR == VECT_RSPI0_SPEI0 Interrupt_RSPI0_SPEI0(void)50__fast_interrupt void Interrupt_RSPI0_SPEI0(void) 51 #else 52 #pragma vector = VECT_RSPI0_SPEI0 53 __interrupt void Interrupt_RSPI0_SPEI0(void) 54 #endif 55 { 56 /* Will the user handle the errors? */ 57 if (rpdl_SPI_callback_func[0] != PDL_NO_FUNC) 58 { 59 /* Notify the user */ 60 rpdl_SPI_callback_func[0](); 61 } 62 } 63 64 #if FAST_INTC_VECTOR == VECT_RSPI1_SPEI1 Interrupt_RSPI1_SPEI1(void)65__fast_interrupt void Interrupt_RSPI1_SPEI1(void) 66 #else 67 #pragma vector = VECT_RSPI1_SPEI1 68 __interrupt void Interrupt_RSPI1_SPEI1(void) 69 #endif 70 { 71 /* Will the user handle the errors? */ 72 if (rpdl_SPI_callback_func[1] != PDL_NO_FUNC) 73 { 74 /* Notify the user */ 75 rpdl_SPI_callback_func[1](); 76 } 77 } 78 79 /*""FUNC COMMENT""*************************************************** 80 * Module outline: SPIn receive data interrupt processing 81 *------------------------------------------------------------------- 82 * Declaration : void Interrupt_RSPIn_SPRIn(void) 83 *------------------------------------------------------------------- 84 * Function : 85 *------------------------------------------------------------------- 86 * Argument : Nothing 87 *------------------------------------------------------------------- 88 * Return value : Nothing 89 *------------------------------------------------------------------- 90 * Input : (I/ ) : SPDCR, SBDR 91 * Output : (I/O) : SPCR, SPCR2 92 *------------------------------------------------------------------- 93 * Use function : None 94 *------------------------------------------------------------------- 95 * Notes : 96 *------------------------------------------------------------------- 97 * History : 2011.04.08 98 * : Ver 1.02 99 * : CS-5 release. 100 *""FUNC COMMENT END""**********************************************/ 101 102 #if FAST_INTC_VECTOR == VECT_RSPI0_SPRI0 Interrupt_RSPI0_SPRI0(void)103__fast_interrupt void Interrupt_RSPI0_SPRI0(void) 104 #else 105 #pragma vector = VECT_RSPI0_SPRI0 106 __interrupt void Interrupt_RSPI0_SPRI0(void) 107 #endif 108 { 109 uint8_t frame_count; 110 uint32_t received_frame; 111 uint8_t spdcr_copy; 112 uint8_t splw; 113 uint8_t spfc; 114 volatile uint32_t * rx_data_ptr; 115 116 /* Ok to process the data? */ 117 if (rpdl_SPI_method[0] == SPI_USING_IRQ) 118 { 119 spdcr_copy = RSPI0.SPDCR.BYTE; 120 splw = (uint8_t)(spdcr_copy & BIT_5); 121 spfc = (uint8_t)(spdcr_copy & 0x03u); 122 rx_data_ptr = rpdl_SPI_rx_ptr[0]; 123 124 /* Load the data register */ 125 for (frame_count = 0; frame_count <= spfc; frame_count++) 126 { 127 if (splw == 0) 128 { 129 /* Read the data */ 130 received_frame = (uint32_t)RSPI0.SPDR.WORD.H; 131 } 132 else 133 { 134 /* Read the data */ 135 received_frame = RSPI0.SPDR.LONG; 136 } 137 138 /* Store the data? */ 139 if (rx_data_ptr != PDL_NO_PTR) 140 { 141 *rx_data_ptr = received_frame; 142 143 /* Increment the address pointer */ 144 rx_data_ptr ++; 145 } 146 147 /* Increment the frame counter */ 148 rpdl_SPI_rx_frame_counter[0] ++; 149 } 150 151 /* Store the updated pointer */ 152 rpdl_SPI_rx_ptr[0] = rx_data_ptr; 153 154 /* All data read? */ 155 if (rpdl_SPI_rx_frame_counter[0] == rpdl_SPI_frame_total[0]) 156 { 157 /* Increment the loop counter */ 158 rpdl_SPI_rx_sequence_counter[0]++; 159 160 /* All loops completed? */ 161 if (rpdl_SPI_rx_sequence_counter[0] == rpdl_SPI_sequence_count[0]) 162 { 163 /* Disable receive interrupts */ 164 RSPI0.SPCR.BIT.SPRIE = 0; 165 166 /* Master mode? */ 167 if (RSPI0.SPCR.BIT.MSTR == 1) 168 { 169 /* Enable idle interrupts */ 170 RSPI0.SPCR2.BIT.SPIIE = 1; 171 } 172 else 173 { 174 /* Notify the user */ 175 if (rpdl_SPI_callback_func[0] != PDL_NO_FUNC) 176 { 177 rpdl_SPI_callback_func[0](); 178 } 179 } 180 } 181 else 182 { 183 /* Reset the frame counter */ 184 rpdl_SPI_rx_frame_counter[0] = 0; 185 } 186 } 187 } 188 else 189 { 190 /* Notify the user */ 191 if (rpdl_SPI_callback_func[0] != PDL_NO_FUNC) 192 { 193 rpdl_SPI_callback_func[0](); 194 } 195 } 196 } 197 198 #if FAST_INTC_VECTOR == VECT_RSPI1_SPRI1 Interrupt_RSPI1_SPRI1(void)199__fast_interrupt void Interrupt_RSPI1_SPRI1(void) 200 #else 201 #pragma vector = VECT_RSPI1_SPRI1 202 __interrupt void Interrupt_RSPI1_SPRI1(void) 203 #endif 204 { 205 uint8_t frame_count; 206 uint32_t received_frame; 207 uint8_t spdcr_copy; 208 uint8_t splw; 209 uint8_t spfc; 210 volatile uint32_t * rx_data_ptr; 211 212 /* Ok to process the data? */ 213 if (rpdl_SPI_method[1] == SPI_USING_IRQ) 214 { 215 spdcr_copy = RSPI1.SPDCR.BYTE; 216 splw = (uint8_t)(spdcr_copy & BIT_5); 217 spfc = (uint8_t)(spdcr_copy & 0x03u); 218 rx_data_ptr = rpdl_SPI_rx_ptr[1]; 219 220 /* Load the data register */ 221 for (frame_count = 0; frame_count <= spfc; frame_count++) 222 { 223 if (splw == 0) 224 { 225 /* Read the data */ 226 received_frame = (uint32_t)RSPI1.SPDR.WORD.H; 227 } 228 else 229 { 230 /* Read the data */ 231 received_frame = RSPI1.SPDR.LONG; 232 } 233 234 /* Store the data? */ 235 if (rx_data_ptr != PDL_NO_PTR) 236 { 237 *rx_data_ptr = received_frame; 238 239 /* Increment the address pointer */ 240 rx_data_ptr ++; 241 } 242 243 /* Increment the frame counter */ 244 rpdl_SPI_rx_frame_counter[1] ++; 245 } 246 247 /* Store the updated pointer */ 248 rpdl_SPI_rx_ptr[1] = rx_data_ptr; 249 250 /* All data read? */ 251 if (rpdl_SPI_rx_frame_counter[1] == rpdl_SPI_frame_total[1]) 252 { 253 /* Increment the loop counter */ 254 rpdl_SPI_rx_sequence_counter[1]++; 255 256 /* All loops completed? */ 257 if (rpdl_SPI_rx_sequence_counter[1] == rpdl_SPI_sequence_count[1]) 258 { 259 /* Disable receive interrupts */ 260 RSPI1.SPCR.BIT.SPRIE = 0; 261 262 /* Master mode? */ 263 if (RSPI1.SPCR.BIT.MSTR == 1) 264 { 265 /* Enable idle interrupts */ 266 RSPI1.SPCR2.BIT.SPIIE = 1; 267 } 268 else 269 { 270 /* Notify the user */ 271 if (rpdl_SPI_callback_func[1] != PDL_NO_FUNC) 272 { 273 rpdl_SPI_callback_func[1](); 274 } 275 } 276 } 277 else 278 { 279 /* Reset the frame counter */ 280 rpdl_SPI_rx_frame_counter[1] = 0; 281 } 282 } 283 } 284 else 285 { 286 /* Notify the user */ 287 if (rpdl_SPI_callback_func[1] != PDL_NO_FUNC) 288 { 289 rpdl_SPI_callback_func[1](); 290 } 291 } 292 } 293 294 /*""FUNC COMMENT""*************************************************** 295 * Module outline: SPIn transmit data interrupt processing 296 *------------------------------------------------------------------- 297 * Declaration : void Interrupt_RSPIn_SPTIn(void) 298 *------------------------------------------------------------------- 299 * Function : 300 *------------------------------------------------------------------- 301 * Argument : Nothing 302 *------------------------------------------------------------------- 303 * Return value : Nothing 304 *------------------------------------------------------------------- 305 * Input : (I/ ) : SPDCR 306 * Output : ( /O) : SBDR 307 * : (I/O) : SPCR, SPCR2 308 *------------------------------------------------------------------- 309 * Use function : 310 *------------------------------------------------------------------- 311 * Notes : 312 *------------------------------------------------------------------- 313 * History : 2011.04.08 314 * : Ver 1.02 315 * : CS-5 release. 316 *""FUNC COMMENT END""**********************************************/ 317 318 #if FAST_INTC_VECTOR == VECT_RSPI0_SPTI0 Interrupt_RSPI0_SPTI0(void)319__fast_interrupt void Interrupt_RSPI0_SPTI0(void) 320 #else 321 #pragma vector = VECT_RSPI0_SPTI0 322 __interrupt void Interrupt_RSPI0_SPTI0(void) 323 #endif 324 { 325 uint8_t frame_count; 326 uint8_t spdcr_copy; 327 uint8_t splw; 328 uint8_t spfc; 329 volatile const uint32_t * tx_data_ptr; 330 331 /* Ok to process the string? */ 332 if (rpdl_SPI_method[0] == SPI_USING_IRQ) 333 { 334 spdcr_copy = RSPI0.SPDCR.BYTE; 335 splw = (uint8_t)(spdcr_copy & BIT_5); 336 spfc = (uint8_t)(spdcr_copy & 0x03u); 337 tx_data_ptr = rpdl_SPI_tx_ptr[0]; 338 339 /* Load the data register */ 340 for (frame_count = 0; frame_count <= spfc; frame_count++) 341 { 342 if (splw == 0) 343 { 344 RSPI0.SPDR.WORD.H = (uint16_t)*tx_data_ptr; 345 } 346 else 347 { 348 RSPI0.SPDR.LONG = *tx_data_ptr; 349 } 350 351 /* Increment the address pointer? */ 352 if (tx_data_ptr != PDL_NO_PTR) 353 { 354 tx_data_ptr ++; 355 } 356 357 /* Increment the frame counter */ 358 rpdl_SPI_tx_frame_counter[0] ++; 359 } 360 361 /* Store the updated pointer */ 362 rpdl_SPI_tx_ptr[0] = tx_data_ptr; 363 364 /* All data written? */ 365 if (rpdl_SPI_tx_frame_counter[0] == rpdl_SPI_frame_total[0]) 366 { 367 /* Increment the loop counter */ 368 rpdl_SPI_tx_sequence_counter[0]++; 369 370 /* All loops completed? */ 371 if (rpdl_SPI_tx_sequence_counter[0] == rpdl_SPI_sequence_count[0]) 372 { 373 /* Disable transmit interrupts */ 374 RSPI0.SPCR.BIT.SPTIE = 0; 375 376 /* Transmit only? */ 377 if (RSPI0.SPCR.BIT.TXMD == 1) 378 { 379 /* Master mode? */ 380 if (RSPI0.SPCR.BIT.MSTR == 1) 381 { 382 /* Enable idle interrupts */ 383 RSPI0.SPCR2.BIT.SPIIE = 1; 384 } 385 else 386 { 387 /* Notify the user */ 388 if (rpdl_SPI_callback_func[0] != PDL_NO_FUNC) 389 { 390 rpdl_SPI_callback_func[0](); 391 } 392 } 393 } 394 } 395 else 396 { 397 /* Reset the frame counter */ 398 rpdl_SPI_tx_frame_counter[0] = 0; 399 } 400 } 401 } 402 else 403 { 404 /* Notify the user */ 405 if (rpdl_SPI_callback_func[0] != PDL_NO_FUNC) 406 { 407 rpdl_SPI_callback_func[0](); 408 } 409 } 410 } 411 412 #if FAST_INTC_VECTOR == VECT_RSPI1_SPTI1 Interrupt_RSPI1_SPTI1(void)413__fast_interrupt void Interrupt_RSPI1_SPTI1(void) 414 #else 415 #pragma vector = VECT_RSPI1_SPTI1 416 __interrupt void Interrupt_RSPI1_SPTI1(void) 417 #endif 418 { 419 uint8_t frame_count; 420 uint8_t spdcr_copy; 421 uint8_t splw; 422 uint8_t spfc; 423 volatile const uint32_t * tx_data_ptr; 424 425 /* Ok to process the string? */ 426 if (rpdl_SPI_method[1] == SPI_USING_IRQ) 427 { 428 spdcr_copy = RSPI1.SPDCR.BYTE; 429 splw = (uint8_t)(spdcr_copy & BIT_5); 430 spfc = (uint8_t)(spdcr_copy & 0x03u); 431 tx_data_ptr = rpdl_SPI_tx_ptr[1]; 432 433 /* Load the data register */ 434 for (frame_count = 0; frame_count <= spfc; frame_count++) 435 { 436 if (splw == 0) 437 { 438 RSPI1.SPDR.WORD.H = (uint16_t)*tx_data_ptr; 439 } 440 else 441 { 442 RSPI1.SPDR.LONG = *tx_data_ptr; 443 } 444 445 /* Increment the address pointer? */ 446 if (tx_data_ptr != PDL_NO_PTR) 447 { 448 tx_data_ptr ++; 449 } 450 451 /* Increment the frame counter */ 452 rpdl_SPI_tx_frame_counter[1] ++; 453 } 454 455 /* Store the updated pointer */ 456 rpdl_SPI_tx_ptr[1] = tx_data_ptr; 457 458 /* All data written? */ 459 if (rpdl_SPI_tx_frame_counter[1] == rpdl_SPI_frame_total[1]) 460 { 461 /* Increment the loop counter */ 462 rpdl_SPI_tx_sequence_counter[1]++; 463 464 /* All loops completed? */ 465 if (rpdl_SPI_tx_sequence_counter[1] == rpdl_SPI_sequence_count[1]) 466 { 467 /* Disable transmit interrupts */ 468 RSPI1.SPCR.BIT.SPTIE = 0; 469 470 /* Transmit only? */ 471 if (RSPI1.SPCR.BIT.TXMD == 1) 472 { 473 /* Master mode? */ 474 if (RSPI1.SPCR.BIT.MSTR == 1) 475 { 476 /* Enable idle interrupts */ 477 RSPI1.SPCR2.BIT.SPIIE = 1; 478 } 479 else 480 { 481 /* Notify the user */ 482 if (rpdl_SPI_callback_func[1] != PDL_NO_FUNC) 483 { 484 rpdl_SPI_callback_func[1](); 485 } 486 } 487 } 488 } 489 else 490 { 491 /* Reset the frame counter */ 492 rpdl_SPI_tx_frame_counter[1] = 0; 493 } 494 } 495 } 496 else 497 { 498 /* Notify the user */ 499 if (rpdl_SPI_callback_func[1] != PDL_NO_FUNC) 500 { 501 rpdl_SPI_callback_func[1](); 502 } 503 } 504 } 505 506 /*""FUNC COMMENT""*************************************************** 507 * Module outline: SPIn idle interrupt processing 508 *------------------------------------------------------------------- 509 * Declaration : void Interrupt_RSPIn_SPIIn(void) 510 *------------------------------------------------------------------- 511 * Function : 512 *------------------------------------------------------------------- 513 * Argument : Nothing 514 *------------------------------------------------------------------- 515 * Return value : Nothing 516 *------------------------------------------------------------------- 517 * Output : SPCR, SPCR2 518 *------------------------------------------------------------------- 519 * Use function : rpdl_SPI_callback_func() 520 *------------------------------------------------------------------- 521 * Notes : 522 *------------------------------------------------------------------- 523 * History : 2011.04.08 524 * : Ver 1.02 525 * : CS-5 release. 526 *""FUNC COMMENT END""**********************************************/ 527 528 #if FAST_INTC_VECTOR == VECT_RSPI0_SPII0 Interrupt_RSPI0_SPII0(void)529__fast_interrupt void Interrupt_RSPI0_SPII0(void) 530 #else 531 #pragma vector = VECT_RSPI0_SPII0 532 __interrupt void Interrupt_RSPI0_SPII0(void) 533 #endif 534 { 535 /* Disable the channel */ 536 RSPI0.SPCR.BIT.SPE = 0; 537 538 /* Disable idle interrupts */ 539 RSPI0.SPCR2.BIT.SPIIE = 0; 540 541 /* Call the callback function */ 542 if (rpdl_SPI_callback_func[0] != PDL_NO_FUNC) 543 { 544 rpdl_SPI_callback_func[0](); 545 } 546 } 547 548 #if FAST_INTC_VECTOR == VECT_RSPI1_SPII1 Interrupt_RSPI1_SPII1(void)549__fast_interrupt void Interrupt_RSPI1_SPII1(void) 550 #else 551 #pragma vector = VECT_RSPI1_SPII1 552 __interrupt void Interrupt_RSPI1_SPII1(void) 553 #endif 554 { 555 /* Disable the channel */ 556 RSPI1.SPCR.BIT.SPE = 0; 557 558 /* Disable idle interrupts */ 559 RSPI1.SPCR2.BIT.SPIIE = 0; 560 561 /* Call the callback function */ 562 if (rpdl_SPI_callback_func[1] != PDL_NO_FUNC) 563 { 564 rpdl_SPI_callback_func[1](); 565 } 566 } 567 568 /* End of file */ 569