Interrupt_SPI.c 15 KB

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