interrupt_iic.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. /*""FILE COMMENT""*******************************************************
  2. * System Name : Interrupt program for RX62Nx
  3. * File Name : Interrupt_IIC.c
  4. * Version : 1.02
  5. * Contents : Interrupt handlers for all IIC 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_iic.h"
  23. #include "r_pdl_definitions.h"
  24. #include "r_pdl_user_definitions.h"
  25. /* For DMAC support */
  26. #define DMCNT_ADDRESS(a) ((volatile uint8_t *)&DMAC0.DMCNT + ((0x40u * a) / sizeof( uint8_t)) )
  27. /* External functions */
  28. extern void Store_detected_address(const uint8_t);
  29. /*""FUNC COMMENT""***************************************************
  30. * Module outline: IICn event interrupt processing
  31. *-------------------------------------------------------------------
  32. * Declaration : void InterruptIIC_ICEEIn(void)
  33. *-------------------------------------------------------------------
  34. * Function :
  35. *-------------------------------------------------------------------
  36. * Argument : Nothing
  37. *-------------------------------------------------------------------
  38. * Return value : Nothing
  39. *-------------------------------------------------------------------
  40. * Output :
  41. *-------------------------------------------------------------------
  42. * Use function :
  43. *-------------------------------------------------------------------
  44. * Notes :
  45. *-------------------------------------------------------------------
  46. * History : 2011.04.08
  47. * : Ver 1.02
  48. * : CS-5 release.
  49. *""FUNC COMMENT END""**********************************************/
  50. #if FAST_INTC_VECTOR == VECT_RIIC0_ICEEI0
  51. __fast_interrupt void Interrupt_IIC_ICEEI0(void)
  52. #else
  53. #pragma vector = VECT_RIIC0_ICEEI0
  54. __interrupt void Interrupt_IIC_ICEEI0(void)
  55. #endif
  56. {
  57. uint8_t valid_flags;
  58. volatile uint8_t unwanted_byte;
  59. /* Read the status register */
  60. valid_flags = RIIC0.ICSR2.BYTE;
  61. /* Remove any that are not enabled */
  62. valid_flags &= RIIC0.ICIER.BYTE;
  63. /* Remove the transmit and receive flags */
  64. valid_flags &= 0x1Fu;
  65. /* Start or Repeated Start detected? */
  66. if ((valid_flags & BIT_2) != 0x0u)
  67. {
  68. /* Decide what to send */
  69. switch(rpdl_IIC_next_state[0])
  70. {
  71. case IIC_MASTER_SEND_SLAVE_ADDRESS_7:
  72. /* Send the slave address */
  73. RIIC0.ICDRT = rpdl_IIC_slave_address_lower[0];
  74. /* Transmit mode? */
  75. if ((rpdl_IIC_slave_address_lower[0] & BIT_0) == 0)
  76. {
  77. rpdl_IIC_current_state[0] = IIC_MASTER_SEND_DATA;
  78. }
  79. else
  80. {
  81. rpdl_IIC_current_state[0] = IIC_MASTER_START_READ;
  82. }
  83. break;
  84. case IIC_MASTER_SEND_SLAVE_ADDRESS_10a:
  85. rpdl_IIC_current_state[0] = IIC_MASTER_SEND_SLAVE_ADDRESS_10b;
  86. /* Send the first part of the slave address */
  87. RIIC0.ICDRT = rpdl_IIC_slave_address_upper[0];
  88. break;
  89. default:
  90. break;
  91. }
  92. /* Were we expecting data? */
  93. if (rpdl_IIC_current_state[0] == IIC_SLAVE_READ_DATA)
  94. {
  95. /* Go back to checking for a device address */
  96. rpdl_IIC_current_state[0] = IIC_SLAVE_MONITOR;
  97. /* Disable Start detection */
  98. RIIC0.ICIER.BIT.STIE = 0;
  99. }
  100. /* Clear the flag */
  101. RIIC0.ICSR2.BIT.START = 0;
  102. }
  103. /* NACK detected? */
  104. else if ((valid_flags & BIT_4) != 0x0u)
  105. {
  106. /* Disable NACK interrupt request generation */
  107. RIIC0.ICIER.BIT.NAKIE = 0;
  108. /* Failed transmission of data? */
  109. if (rpdl_IIC_current_state[0] == IIC_MASTER_SEND_DATA)
  110. {
  111. /* Decrement the counter */
  112. rpdl_IIC_tx_counter[0]--;
  113. /* Call the callback function */
  114. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  115. {
  116. rpdl_IIC_callback_func[0]();
  117. }
  118. }
  119. /* NACK received from the master? */
  120. else
  121. {
  122. /* Do a dummy read to release SCL */
  123. unwanted_byte = RIIC0.ICDRR;
  124. }
  125. }
  126. else
  127. {
  128. /* Disable all interrupt request generation */
  129. RIIC0.ICIER.BYTE = 0x00u;
  130. /* Call the callback function */
  131. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  132. {
  133. rpdl_IIC_callback_func[0]();
  134. }
  135. }
  136. }
  137. #if FAST_INTC_VECTOR == VECT_RIIC1_ICEEI1
  138. __fast_interrupt void Interrupt_IIC_ICEEI1(void)
  139. #else
  140. #pragma vector = VECT_RIIC1_ICEEI1
  141. __interrupt void Interrupt_IIC_ICEEI1(void)
  142. #endif
  143. {
  144. #ifdef DEVICE_PACKAGE_LQFP_100
  145. /* This channel is not available on the 100-pin package */
  146. nop();
  147. #else
  148. uint8_t valid_flags;
  149. volatile uint8_t unwanted_byte;
  150. /* Read the status register */
  151. valid_flags = RIIC1.ICSR2.BYTE;
  152. /* Remove any that are not enabled */
  153. valid_flags &= RIIC1.ICIER.BYTE;
  154. /* Remove the transmit and receive flags */
  155. valid_flags &= 0x1Fu;
  156. /* Start or Repeated Start detected? */
  157. if ((valid_flags & BIT_2) != 0x0u)
  158. {
  159. /* Decide what to send */
  160. switch(rpdl_IIC_next_state[1])
  161. {
  162. case IIC_MASTER_SEND_SLAVE_ADDRESS_7:
  163. /* Send the slave address */
  164. RIIC1.ICDRT = rpdl_IIC_slave_address_lower[1];
  165. /* Transmit mode? */
  166. if ((rpdl_IIC_slave_address_lower[1] & BIT_0) == 0)
  167. {
  168. rpdl_IIC_current_state[1] = IIC_MASTER_SEND_DATA;
  169. }
  170. else
  171. {
  172. rpdl_IIC_current_state[1] = IIC_MASTER_START_READ;
  173. }
  174. break;
  175. case IIC_MASTER_SEND_SLAVE_ADDRESS_10a:
  176. rpdl_IIC_current_state[1] = IIC_MASTER_SEND_SLAVE_ADDRESS_10b;
  177. /* Send the first part of the slave address */
  178. RIIC1.ICDRT = rpdl_IIC_slave_address_upper[1];
  179. break;
  180. default:
  181. break;
  182. }
  183. /* Were we expecting data? */
  184. if (rpdl_IIC_current_state[1] == IIC_SLAVE_READ_DATA)
  185. {
  186. /* Go back to checking for a device address */
  187. rpdl_IIC_current_state[1] = IIC_SLAVE_MONITOR;
  188. /* Disable Start detection */
  189. RIIC1.ICIER.BIT.STIE = 0;
  190. }
  191. /* Clear the flag */
  192. RIIC1.ICSR2.BIT.START = 0;
  193. }
  194. /* NACK detected? */
  195. else if ((valid_flags & BIT_4) != 0x0u)
  196. {
  197. /* Disable NACK interrupt request generation */
  198. RIIC1.ICIER.BIT.NAKIE = 0;
  199. /* Failed transmission of data? */
  200. if (rpdl_IIC_current_state[1] == IIC_MASTER_SEND_DATA)
  201. {
  202. /* Decrement the counter */
  203. rpdl_IIC_tx_counter[1]--;
  204. /* Call the callback function */
  205. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  206. {
  207. rpdl_IIC_callback_func[1]();
  208. }
  209. }
  210. /* NACK received from the master? */
  211. else
  212. {
  213. /* Do a dummy read to release SCL */
  214. unwanted_byte = RIIC1.ICDRR;
  215. }
  216. }
  217. else
  218. {
  219. /* Disable all interrupt request generation */
  220. RIIC1.ICIER.BYTE = 0x00u;
  221. /* Call the callback function */
  222. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  223. {
  224. rpdl_IIC_callback_func[1]();
  225. }
  226. }
  227. #endif
  228. }
  229. /*""FUNC COMMENT""***************************************************
  230. * Module outline: IICn receive data interrupt processing
  231. *-------------------------------------------------------------------
  232. * Declaration : void Interrupt_IIC_ICRXIn(void)
  233. *-------------------------------------------------------------------
  234. * Function :
  235. *-------------------------------------------------------------------
  236. * Argument : Nothing
  237. *-------------------------------------------------------------------
  238. * Return value : Nothing
  239. *-------------------------------------------------------------------
  240. * Output : ICDRR, ICIER
  241. *-------------------------------------------------------------------
  242. * Use function :
  243. *-------------------------------------------------------------------
  244. * Notes :
  245. *-------------------------------------------------------------------
  246. * History : 2011.04.08
  247. * : Ver 1.02
  248. * : CS-5 release.
  249. *""FUNC COMMENT END""**********************************************/
  250. #if FAST_INTC_VECTOR == VECT_RIIC0_ICRXI0
  251. __fast_interrupt void Interrupt_IIC_ICRXI0(void)
  252. #else
  253. #pragma vector = VECT_RIIC0_ICRXI0
  254. __interrupt void Interrupt_IIC_ICRXI0(void)
  255. #endif
  256. {
  257. volatile uint8_t unwanted_byte;
  258. switch (rpdl_IIC_current_state[0])
  259. {
  260. case IIC_MASTER_START_READ:
  261. /* Only one byte to be read? */
  262. if (rpdl_IIC_rx_threshold[0] == 1)
  263. {
  264. /* Prepare to signal a NACK to the slave (ACKBT = 1) */
  265. RIIC0.ICMR3.BIT.ACKBT = 1;
  266. }
  267. rpdl_IIC_current_state[0] = IIC_MASTER_READ_DATA;
  268. /* Do a dummy read */
  269. unwanted_byte = RIIC0.ICDRR;
  270. break;
  271. case IIC_MASTER_READ_DATA:
  272. /* Is the last byte about to be read from the slave? */
  273. if (rpdl_IIC_rx_counter[0] == (rpdl_IIC_rx_threshold[0] - 2))
  274. {
  275. /* Prepare to signal a NACK to the slave (ACKBT = 1) */
  276. RIIC0.ICMR3.BIT.ACKBT = 1;
  277. }
  278. /* All data read from the slave? */
  279. else if (rpdl_IIC_rx_counter[0] == (rpdl_IIC_rx_threshold[0] - 1))
  280. {
  281. rpdl_IIC_current_state[0] = IIC_MASTER_WAIT_FOR_STOP;
  282. /* Enable Stop detection */
  283. RIIC0.ICIER.BIT.SPIE = 1;
  284. /* Issue a stop condition */
  285. RIIC0.ICCR2.BIT.SP = 1;
  286. }
  287. /* Store the data byte */
  288. *rpdl_IIC_rx_data_pointer[0] = RIIC0.ICDRR;
  289. /* Increment the pointer */
  290. rpdl_IIC_rx_data_pointer[0]++;
  291. /* Increment the counter */
  292. rpdl_IIC_rx_counter[0]++;
  293. break;
  294. case IIC_SLAVE_MONITOR:
  295. /* Note the detected address */
  296. Store_detected_address(0);
  297. /* Clear the Start flag */
  298. RIIC0.ICSR2.BIT.START = 0;
  299. /* Enable Start detection (in case a Repeated Start arrives) */
  300. RIIC0.ICIER.BIT.STIE = 1;
  301. /* Will interrupts be used for the transfers? */
  302. if (rpdl_IIC_rx_transfer_method[0] == IIC_TRANSFER_CPU)
  303. {
  304. rpdl_IIC_current_state[0] = IIC_SLAVE_READ_DATA;
  305. }
  306. else
  307. {
  308. /* Disable ACK / NACK decisions (RDRFS = 0) */
  309. RIIC0.ICMR3.BIT.RDRFS = 0;
  310. /* Select DMAC or DTC transfers */
  311. if (rpdl_IIC_rx_transfer_method[0] == IIC_TRANSFER_DTC)
  312. {
  313. ICU.DTCER[DTCE_RIIC0_ICRXI0].BIT.DTCE = 1;
  314. }
  315. else /* DMAC */
  316. {
  317. /* Set DTE = 1 */
  318. *DMCNT_ADDRESS(rpdl_IIC_rx_dmac_channel[0]) = 0x01u;
  319. }
  320. /* Prevent further RX-based interrupts */
  321. ICU.IPR[IPR_RIIC0_ICRXI0].BIT.IPR = 0;
  322. rpdl_IIC_current_state[0] = IIC_EXIT_LOOP;
  323. }
  324. /* Do a dummy read */
  325. unwanted_byte = RIIC0.ICDRR;
  326. break;
  327. case IIC_SLAVE_READ_DATA:
  328. /* All data received? */
  329. if (rpdl_IIC_rx_counter[0] == rpdl_IIC_rx_threshold[0])
  330. {
  331. /* Do a dummy read */
  332. unwanted_byte = RIIC0.ICDRR;
  333. /* Signal a NACK to the master */
  334. RIIC0.ICMR3.BIT.ACKBT = 1;
  335. }
  336. else
  337. {
  338. /* Store the data byte */
  339. *rpdl_IIC_rx_data_pointer[0] = RIIC0.ICDRR;
  340. /* Increment the pointer */
  341. rpdl_IIC_rx_data_pointer[0]++;
  342. /* Increment the counter */
  343. rpdl_IIC_rx_counter[0]++;
  344. /* Signal an ACK to the master */
  345. RIIC0.ICMR3.BIT.ACKBT = 0;
  346. }
  347. break;
  348. case IIC_SLAVE_SEND_DATA:
  349. /* Call the callback function */
  350. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  351. {
  352. rpdl_IIC_callback_func[0]();
  353. }
  354. break;
  355. case IIC_EXIT_LOOP:
  356. /* This will occur if the DMAC/DTC is being used with a callback */
  357. /* Call the callback function */
  358. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  359. {
  360. rpdl_IIC_callback_func[0]();
  361. }
  362. break;
  363. default:
  364. /* Call the callback function */
  365. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  366. {
  367. rpdl_IIC_callback_func[0]();
  368. }
  369. break;
  370. }
  371. }
  372. #if FAST_INTC_VECTOR == VECT_RIIC1_ICRXI1
  373. __fast_interrupt void Interrupt_IIC_ICRXI1(void)
  374. #else
  375. #pragma vector = VECT_RIIC1_ICRXI1
  376. __interrupt void Interrupt_IIC_ICRXI1(void)
  377. #endif
  378. {
  379. #ifdef DEVICE_PACKAGE_LQFP_100
  380. /* This channel is not available on the 100-pin package */
  381. nop();
  382. #else
  383. volatile uint8_t unwanted_byte;
  384. switch (rpdl_IIC_current_state[1])
  385. {
  386. case IIC_MASTER_START_READ:
  387. /* Only one byte to be read? */
  388. if (rpdl_IIC_rx_threshold[1] == 1)
  389. {
  390. /* Prepare to signal a NACK to the slave (ACKBT = 1) */
  391. RIIC1.ICMR3.BIT.ACKBT = 1;
  392. }
  393. rpdl_IIC_current_state[1] = IIC_MASTER_READ_DATA;
  394. /* Do a dummy read */
  395. unwanted_byte = RIIC1.ICDRR;
  396. break;
  397. case IIC_MASTER_READ_DATA:
  398. /* Is the last byte about to be read from the slave? */
  399. if (rpdl_IIC_rx_counter[1] == (rpdl_IIC_rx_threshold[1] - 2))
  400. {
  401. /* Prepare to signal a NACK to the slave (ACKBT = 1) */
  402. RIIC1.ICMR3.BIT.ACKBT = 1;
  403. }
  404. /* All data read from the slave? */
  405. else if (rpdl_IIC_rx_counter[1] == (rpdl_IIC_rx_threshold[1] - 1))
  406. {
  407. rpdl_IIC_current_state[1] = IIC_MASTER_WAIT_FOR_STOP;
  408. /* Enable Stop detection */
  409. RIIC1.ICIER.BIT.SPIE = 1;
  410. /* Issue a stop condition */
  411. RIIC1.ICCR2.BIT.SP = 1;
  412. }
  413. /* Store the data byte */
  414. *rpdl_IIC_rx_data_pointer[1] = RIIC1.ICDRR;
  415. /* Increment the pointer */
  416. rpdl_IIC_rx_data_pointer[1]++;
  417. /* Increment the counter */
  418. rpdl_IIC_rx_counter[1]++;
  419. break;
  420. case IIC_SLAVE_MONITOR:
  421. /* Note the detected address */
  422. Store_detected_address(1);
  423. /* Clear the Start flag */
  424. RIIC1.ICSR2.BIT.START = 0;
  425. /* Enable Start detection (in case a Repeated Start arrives) */
  426. RIIC1.ICIER.BIT.STIE = 1;
  427. /* Will interrupts be used for the transfers? */
  428. if (rpdl_IIC_rx_transfer_method[1] == IIC_TRANSFER_CPU)
  429. {
  430. rpdl_IIC_current_state[1] = IIC_SLAVE_READ_DATA;
  431. }
  432. else
  433. {
  434. /* Disable ACK / NACK decisions (RDRFS = 0) */
  435. RIIC1.ICMR3.BIT.RDRFS = 0;
  436. /* Select DMAC or DTC transfers */
  437. if (rpdl_IIC_rx_transfer_method[1] == IIC_TRANSFER_DTC)
  438. {
  439. ICU.DTCER[DTCE_RIIC1_ICRXI1].BIT.DTCE = 1;
  440. }
  441. else /* DMAC */
  442. {
  443. /* Set DTE = 1 */
  444. *DMCNT_ADDRESS(rpdl_IIC_rx_dmac_channel[1]) = 0x01u;
  445. }
  446. /* Prevent further RX-based interrupts */
  447. ICU.IPR[IPR_RIIC1_ICRXI1].BIT.IPR = 0;
  448. rpdl_IIC_current_state[1] = IIC_EXIT_LOOP;
  449. }
  450. /* Do a dummy read */
  451. unwanted_byte = RIIC1.ICDRR;
  452. break;
  453. case IIC_SLAVE_READ_DATA:
  454. /* All data received? */
  455. if (rpdl_IIC_rx_counter[1] == rpdl_IIC_rx_threshold[1])
  456. {
  457. /* Do a dummy read */
  458. unwanted_byte = RIIC1.ICDRR;
  459. /* Signal a NACK to the master */
  460. RIIC1.ICMR3.BIT.ACKBT = 1;
  461. }
  462. else
  463. {
  464. /* Store the data byte */
  465. *rpdl_IIC_rx_data_pointer[1] = RIIC1.ICDRR;
  466. /* Increment the pointer */
  467. rpdl_IIC_rx_data_pointer[1]++;
  468. /* Increment the counter */
  469. rpdl_IIC_rx_counter[1]++;
  470. /* Signal an ACK to the master */
  471. RIIC1.ICMR3.BIT.ACKBT = 0;
  472. }
  473. break;
  474. case IIC_SLAVE_SEND_DATA:
  475. /* Call the callback function */
  476. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  477. {
  478. rpdl_IIC_callback_func[1]();
  479. }
  480. break;
  481. case IIC_EXIT_LOOP:
  482. /* This will occur if the DMAC/DTC is being used with a callback */
  483. /* Call the callback function */
  484. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  485. {
  486. rpdl_IIC_callback_func[1]();
  487. }
  488. break;
  489. default:
  490. /* Call the callback function */
  491. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  492. {
  493. rpdl_IIC_callback_func[1]();
  494. }
  495. break;
  496. }
  497. #endif
  498. }
  499. /*""FUNC COMMENT""***************************************************
  500. * Module outline: IICn transmit data interrupt processing
  501. *-------------------------------------------------------------------
  502. * Declaration : void Interrupt_IIC_ICTXIn(void)
  503. *-------------------------------------------------------------------
  504. * Function :
  505. *-------------------------------------------------------------------
  506. * Argument : Nothing
  507. *-------------------------------------------------------------------
  508. * Return value : Nothing
  509. *-------------------------------------------------------------------
  510. * Output : ICDRT, ICIER
  511. *-------------------------------------------------------------------
  512. * Use function :
  513. *-------------------------------------------------------------------
  514. * Notes :
  515. *-------------------------------------------------------------------
  516. * History : 2011.04.08
  517. * : Ver 1.02
  518. * : CS-5 release.
  519. *""FUNC COMMENT END""**********************************************/
  520. #if FAST_INTC_VECTOR == VECT_RIIC0_ICTXI0
  521. __fast_interrupt void Interrupt_IIC_ICTXI0(void)
  522. #else
  523. #pragma vector = VECT_RIIC0_ICTXI0
  524. __interrupt void Interrupt_IIC_ICTXI0(void)
  525. #endif
  526. {
  527. switch (rpdl_IIC_current_state[0])
  528. {
  529. case IIC_MASTER_SEND_SLAVE_ADDRESS_10b:
  530. /* Send the second part of the slave address */
  531. RIIC0.ICDRT = rpdl_IIC_slave_address_lower[0];
  532. /* Transmit mode? */
  533. if ((rpdl_IIC_slave_address_upper[0] & BIT_0) == 0)
  534. {
  535. rpdl_IIC_current_state[0] = IIC_MASTER_SEND_DATA;
  536. }
  537. else
  538. {
  539. rpdl_IIC_current_state[0] = IIC_MASTER_START_READ;
  540. /* Enable receive interrupt request generation */
  541. RIIC0.ICIER.BIT.RIE = 1;
  542. }
  543. break;
  544. case IIC_MASTER_SEND_DATA:
  545. /* All data sent? */
  546. if (rpdl_IIC_tx_counter[0] == rpdl_IIC_tx_threshold[0])
  547. {
  548. rpdl_IIC_current_state[0] = IIC_MASTER_WAIT_FOR_TX_COMPLETE;
  549. /* Disable ICTXI interrupt request generation */
  550. RIIC0.ICIER.BIT.TIE = 0;
  551. /* Ensure the ICTEI IR flag is clear */
  552. ICU.IR[IR_RIIC0_ICTEI0].BIT.IR = 0;
  553. /* Enable Transmit End interrupt generation */
  554. RIIC0.ICIER.BIT.TEIE = 1;
  555. }
  556. else
  557. {
  558. /* Load the data to be sent */
  559. RIIC0.ICDRT = *rpdl_IIC_tx_data_pointer[0];
  560. /* Increment the pointer */
  561. rpdl_IIC_tx_data_pointer[0]++;
  562. /* Increment the counter */
  563. rpdl_IIC_tx_counter[0]++;
  564. }
  565. break;
  566. case IIC_SLAVE_MONITOR:
  567. /* Note the detected address */
  568. Store_detected_address(0);
  569. /* Call the callback function */
  570. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  571. {
  572. rpdl_IIC_callback_func[0]();
  573. }
  574. break;
  575. case IIC_SLAVE_SEND_DATA:
  576. /* All data sent? */
  577. if (rpdl_IIC_tx_counter[0] == rpdl_IIC_tx_threshold[0])
  578. {
  579. /* Clear the counter */
  580. rpdl_IIC_tx_counter[0] = 0;
  581. /* Loop back to the start */
  582. rpdl_IIC_tx_data_pointer[0] = rpdl_IIC_tx_data_start[0];
  583. }
  584. /* Load the data to be sent */
  585. RIIC0.ICDRT = *rpdl_IIC_tx_data_pointer[0];
  586. /* Increment the pointer */
  587. rpdl_IIC_tx_data_pointer[0]++;
  588. /* Increment the counter */
  589. rpdl_IIC_tx_counter[0]++;
  590. break;
  591. case IIC_SLAVE_READ_DATA:
  592. /* Call the callback function */
  593. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  594. {
  595. rpdl_IIC_callback_func[0]();
  596. }
  597. break;
  598. case IIC_EXIT_LOOP:
  599. /* This will occur if the DMAC/DTC is being used with a callback */
  600. /* Call the callback function */
  601. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  602. {
  603. rpdl_IIC_callback_func[0]();
  604. }
  605. break;
  606. default:
  607. /* Call the callback function */
  608. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  609. {
  610. rpdl_IIC_callback_func[0]();
  611. }
  612. break;
  613. }
  614. }
  615. #if FAST_INTC_VECTOR == VECT_RIIC1_ICTXI1
  616. __fast_interrupt void Interrupt_IIC_ICTXI1(void)
  617. #else
  618. #pragma vector = VECT_RIIC1_ICTXI1
  619. __interrupt void Interrupt_IIC_ICTXI1(void)
  620. #endif
  621. {
  622. #ifdef DEVICE_PACKAGE_LQFP_100
  623. /* This channel is not available on the 100-pin package */
  624. nop();
  625. #else
  626. switch (rpdl_IIC_current_state[1])
  627. {
  628. case IIC_MASTER_SEND_SLAVE_ADDRESS_10b:
  629. /* Send the second part of the slave address */
  630. RIIC1.ICDRT = rpdl_IIC_slave_address_lower[1];
  631. /* Transmit mode? */
  632. if ((rpdl_IIC_slave_address_upper[1] & BIT_0) == 0)
  633. {
  634. rpdl_IIC_current_state[1] = IIC_MASTER_SEND_DATA;
  635. }
  636. else
  637. {
  638. rpdl_IIC_current_state[1] = IIC_MASTER_START_READ;
  639. /* Enable receive interrupt request generation */
  640. RIIC1.ICIER.BIT.RIE = 1;
  641. }
  642. break;
  643. case IIC_MASTER_SEND_DATA:
  644. /* All data sent? */
  645. if (rpdl_IIC_tx_counter[1] == rpdl_IIC_tx_threshold[1])
  646. {
  647. rpdl_IIC_current_state[1] = IIC_MASTER_WAIT_FOR_TX_COMPLETE;
  648. /* Disable ICTXI interrupt request generation */
  649. RIIC1.ICIER.BIT.TIE = 0;
  650. /* Ensure the ICTEI IR flag is clear */
  651. ICU.IR[IR_RIIC1_ICTEI1].BIT.IR = 0;
  652. /* Enable Transmit End interrupt generation */
  653. RIIC1.ICIER.BIT.TEIE = 1;
  654. }
  655. else
  656. {
  657. /* Load the data to be sent */
  658. RIIC1.ICDRT = *rpdl_IIC_tx_data_pointer[1];
  659. /* Increment the pointer */
  660. rpdl_IIC_tx_data_pointer[1]++;
  661. /* Increment the counter */
  662. rpdl_IIC_tx_counter[1]++;
  663. }
  664. break;
  665. case IIC_SLAVE_MONITOR:
  666. /* Note the detected address */
  667. Store_detected_address(1);
  668. /* Call the callback function */
  669. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  670. {
  671. rpdl_IIC_callback_func[1]();
  672. }
  673. break;
  674. case IIC_SLAVE_SEND_DATA:
  675. /* All data sent? */
  676. if (rpdl_IIC_tx_counter[1] == rpdl_IIC_tx_threshold[1])
  677. {
  678. /* Clear the counter */
  679. rpdl_IIC_tx_counter[1] = 0;
  680. /* Loop back to the start */
  681. rpdl_IIC_tx_data_pointer[1] = rpdl_IIC_tx_data_start[1];
  682. }
  683. /* Load the data to be sent */
  684. RIIC1.ICDRT = *rpdl_IIC_tx_data_pointer[1];
  685. /* Increment the pointer */
  686. rpdl_IIC_tx_data_pointer[1]++;
  687. /* Increment the counter */
  688. rpdl_IIC_tx_counter[1]++;
  689. break;
  690. case IIC_SLAVE_READ_DATA:
  691. /* Call the callback function */
  692. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  693. {
  694. rpdl_IIC_callback_func[1]();
  695. }
  696. break;
  697. case IIC_EXIT_LOOP:
  698. /* This will occur if the DMAC/DTC is being used with a callback */
  699. /* Call the callback function */
  700. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  701. {
  702. rpdl_IIC_callback_func[1]();
  703. }
  704. break;
  705. default:
  706. /* Call the callback function */
  707. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  708. {
  709. rpdl_IIC_callback_func[1]();
  710. }
  711. break;
  712. }
  713. #endif
  714. }
  715. /*""FUNC COMMENT""***************************************************
  716. * Module outline: IICn transmit end interrupt processing
  717. *-------------------------------------------------------------------
  718. * Declaration : void InterruptIIC_ICTEIn(void)
  719. *-------------------------------------------------------------------
  720. * Function :
  721. *-------------------------------------------------------------------
  722. * Argument : Nothing
  723. *-------------------------------------------------------------------
  724. * Return value : Nothing
  725. *-------------------------------------------------------------------
  726. * Output : ICIER, ICSR2
  727. *-------------------------------------------------------------------
  728. * Use function :
  729. *-------------------------------------------------------------------
  730. * Notes :
  731. *-------------------------------------------------------------------
  732. * History : 2011.04.08
  733. * : Ver 1.02
  734. * : CS-5 release.
  735. *""FUNC COMMENT END""**********************************************/
  736. #if FAST_INTC_VECTOR == VECT_RIIC0_ICTEI0
  737. __fast_interrupt void Interrupt_IIC_ICTEI0(void)
  738. #else
  739. #pragma vector = VECT_RIIC0_ICTEI0
  740. __interrupt void Interrupt_IIC_ICTEI0(void)
  741. #endif
  742. {
  743. /* Disable Transmit End interrupt request generation */
  744. RIIC0.ICIER.BIT.TEIE = 0;
  745. /* Clear the flag */
  746. RIIC0.ICSR2.BIT.TEND = 0;
  747. /* Stop condition required? */
  748. if (rpdl_IIC_stop[0] == true)
  749. {
  750. rpdl_IIC_current_state[0] = IIC_MASTER_WAIT_FOR_STOP;
  751. /* Enable Stop detection */
  752. RIIC0.ICIER.BIT.SPIE = 1;
  753. /* Issue a stop condition */
  754. RIIC0.ICCR2.BIT.SP = 1;
  755. }
  756. else
  757. {
  758. /* Disable all interrupt request generation */
  759. RIIC0.ICIER.BYTE = 0x00u;
  760. /* Call the callback function */
  761. if (rpdl_IIC_callback_func[0] != PDL_NO_FUNC)
  762. {
  763. rpdl_IIC_callback_func[0]();
  764. }
  765. }
  766. }
  767. #if FAST_INTC_VECTOR == VECT_RIIC1_ICTEI1
  768. __fast_interrupt void Interrupt_IIC_ICTEI1(void)
  769. #else
  770. #pragma vector = VECT_RIIC1_ICTEI1
  771. __interrupt void Interrupt_IIC_ICTEI1(void)
  772. #endif
  773. {
  774. #ifdef DEVICE_PACKAGE_LQFP_100
  775. /* This channel is not available on the 100-pin package */
  776. nop();
  777. #else
  778. /* Disable Transmit End interrupt request generation */
  779. RIIC1.ICIER.BIT.TEIE = 0;
  780. /* Clear the flag */
  781. RIIC1.ICSR2.BIT.TEND = 0;
  782. /* Stop condition required? */
  783. if (rpdl_IIC_stop[1] == true)
  784. {
  785. rpdl_IIC_current_state[1] = IIC_MASTER_WAIT_FOR_STOP;
  786. /* Enable Stop detection */
  787. RIIC1.ICIER.BIT.SPIE = 1;
  788. /* Issue a stop condition */
  789. RIIC1.ICCR2.BIT.SP = 1;
  790. }
  791. else
  792. {
  793. /* Disable all interrupt request generation */
  794. RIIC1.ICIER.BYTE = 0x00u;
  795. /* Call the callback function */
  796. if (rpdl_IIC_callback_func[1] != PDL_NO_FUNC)
  797. {
  798. rpdl_IIC_callback_func[1]();
  799. }
  800. }
  801. #endif
  802. }
  803. /* End of file */