stm8s_it.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /**
  2. ******************************************************************************
  3. * @file stm8s_it.c
  4. * @author MCD Application Team
  5. * @version V2.3.0
  6. * @date 16-June-2017
  7. * @brief Main Interrupt Service Routines.
  8. * This file provides template for all peripherals interrupt service
  9. * routine.
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  14. *
  15. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  16. * You may not use this file except in compliance with the License.
  17. * You may obtain a copy of the License at:
  18. *
  19. * http://www.st.com/software_license_agreement_liberty_v2
  20. *
  21. * Unless required by applicable law or agreed to in writing, software
  22. * distributed under the License is distributed on an "AS IS" BASIS,
  23. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. * See the License for the specific language governing permissions and
  25. * limitations under the License.
  26. *
  27. ******************************************************************************
  28. */
  29. /* Includes ------------------------------------------------------------------*/
  30. #include "stm8s_it.h"
  31. #include "led.h"
  32. #include "delay.h"
  33. /** @addtogroup Template_Project
  34. * @{
  35. */
  36. /* Private typedef -----------------------------------------------------------*/
  37. /* Private define ------------------------------------------------------------*/
  38. /* Private macro -------------------------------------------------------------*/
  39. /* Private variables ---------------------------------------------------------*/
  40. extern __IO uint16_t ConversionBuffer[64];
  41. extern __IO uint8_t BufferIndex;
  42. static uint8_t LedCnt = 0;
  43. static __IO uint16_t TimingDelay;
  44. __IO uint8_t I2C_timeout;
  45. /* Private function prototypes -----------------------------------------------*/
  46. /* Private functions ---------------------------------------------------------*/
  47. /* Public functions ----------------------------------------------------------*/
  48. #ifdef _COSMIC_
  49. /**
  50. * @brief Dummy Interrupt routine
  51. * @par Parameters:
  52. * None
  53. * @retval
  54. * None
  55. */
  56. INTERRUPT_HANDLER(NonHandledInterrupt, 25)
  57. {
  58. /* In order to detect unexpected events during development,
  59. it is recommended to set a breakpoint on the following instruction.
  60. */
  61. }
  62. #endif /*_COSMIC_*/
  63. /**
  64. * @brief TRAP Interrupt routine
  65. * @param None
  66. * @retval None
  67. */
  68. INTERRUPT_HANDLER_TRAP(TRAP_IRQHandler)
  69. {
  70. /* In order to detect unexpected events during development,
  71. it is recommended to set a breakpoint on the following instruction.
  72. */
  73. }
  74. /**
  75. * @brief Top Level Interrupt routine.
  76. * @param None
  77. * @retval None
  78. */
  79. INTERRUPT_HANDLER(TLI_IRQHandler, 0)
  80. {
  81. /* In order to detect unexpected events during development,
  82. it is recommended to set a breakpoint on the following instruction.
  83. */
  84. }
  85. /**
  86. * @brief Auto Wake Up Interrupt routine.
  87. * @param None
  88. * @retval None
  89. */
  90. INTERRUPT_HANDLER(AWU_IRQHandler, 1)
  91. {
  92. /* In order to detect unexpected events during development,
  93. it is recommended to set a breakpoint on the following instruction.
  94. */
  95. }
  96. /**
  97. * @brief Clock Controller Interrupt routine.
  98. * @param None
  99. * @retval None
  100. */
  101. INTERRUPT_HANDLER(CLK_IRQHandler, 2)
  102. {
  103. /* In order to detect unexpected events during development,
  104. it is recommended to set a breakpoint on the following instruction.
  105. */
  106. }
  107. /**
  108. * @brief External Interrupt PORTA Interrupt routine.
  109. * @param None
  110. * @retval None
  111. */
  112. INTERRUPT_HANDLER(EXTI_PORTA_IRQHandler, 3)
  113. {
  114. /* In order to detect unexpected events during development,
  115. it is recommended to set a breakpoint on the following instruction.
  116. */
  117. }
  118. /**
  119. * @brief External Interrupt PORTB Interrupt routine.
  120. * @param None
  121. * @retval None
  122. */
  123. INTERRUPT_HANDLER(EXTI_PORTB_IRQHandler, 4)
  124. {
  125. /* In order to detect unexpected events during development,
  126. it is recommended to set a breakpoint on the following instruction.
  127. */
  128. }
  129. /**
  130. * @brief External Interrupt PORTC Interrupt routine.
  131. * @param None
  132. * @retval None
  133. */
  134. INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5)
  135. {
  136. /* In order to detect unexpected events during development,
  137. it is recommended to set a breakpoint on the following instruction.
  138. */
  139. }
  140. /**
  141. * @brief External Interrupt PORTD Interrupt routine.
  142. * @param None
  143. * @retval None
  144. */
  145. INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6)
  146. {
  147. /* In order to detect unexpected events during development,
  148. it is recommended to set a breakpoint on the following instruction.
  149. */
  150. }
  151. /**
  152. * @brief External Interrupt PORTE Interrupt routine.
  153. * @param None
  154. * @retval None
  155. */
  156. INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler, 7)
  157. {
  158. /* In order to detect unexpected events during development,
  159. it is recommended to set a breakpoint on the following instruction.
  160. */
  161. }
  162. #if defined (STM8S903) || defined (STM8AF622x)
  163. /**
  164. * @brief External Interrupt PORTF Interrupt routine.
  165. * @param None
  166. * @retval None
  167. */
  168. INTERRUPT_HANDLER(EXTI_PORTF_IRQHandler, 8)
  169. {
  170. /* In order to detect unexpected events during development,
  171. it is recommended to set a breakpoint on the following instruction.
  172. */
  173. }
  174. #endif /* (STM8S903) || (STM8AF622x) */
  175. #if defined (STM8S208) || defined (STM8AF52Ax)
  176. /**
  177. * @brief CAN RX Interrupt routine.
  178. * @param None
  179. * @retval None
  180. */
  181. INTERRUPT_HANDLER(CAN_RX_IRQHandler, 8)
  182. {
  183. /* In order to detect unexpected events during development,
  184. it is recommended to set a breakpoint on the following instruction.
  185. */
  186. }
  187. /**
  188. * @brief CAN TX Interrupt routine.
  189. * @param None
  190. * @retval None
  191. */
  192. INTERRUPT_HANDLER(CAN_TX_IRQHandler, 9)
  193. {
  194. /* In order to detect unexpected events during development,
  195. it is recommended to set a breakpoint on the following instruction.
  196. */
  197. }
  198. #endif /* (STM8S208) || (STM8AF52Ax) */
  199. /**
  200. * @brief SPI Interrupt routine.
  201. * @param None
  202. * @retval None
  203. */
  204. INTERRUPT_HANDLER(SPI_IRQHandler, 10)
  205. {
  206. /* In order to detect unexpected events during development,
  207. it is recommended to set a breakpoint on the following instruction.
  208. */
  209. }
  210. /**
  211. * @brief Timer1 Update/Overflow/Trigger/Break Interrupt routine.
  212. * @param None
  213. * @retval None
  214. */
  215. INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11)
  216. {
  217. /* In order to detect unexpected events during development,
  218. it is recommended to set a breakpoint on the following instruction.
  219. */
  220. }
  221. /**
  222. * @brief Timer1 Capture/Compare Interrupt routine.
  223. * @param None
  224. * @retval None
  225. */
  226. INTERRUPT_HANDLER(TIM1_CAP_COM_IRQHandler, 12)
  227. {
  228. /* In order to detect unexpected events during development,
  229. it is recommended to set a breakpoint on the following instruction.
  230. */
  231. }
  232. #if defined (STM8S903) || defined (STM8AF622x)
  233. /**
  234. * @brief Timer5 Update/Overflow/Break/Trigger Interrupt routine.
  235. * @param None
  236. * @retval None
  237. */
  238. INTERRUPT_HANDLER(TIM5_UPD_OVF_BRK_TRG_IRQHandler, 13)
  239. {
  240. /* In order to detect unexpected events during development,
  241. it is recommended to set a breakpoint on the following instruction.
  242. */
  243. }
  244. /**
  245. * @brief Timer5 Capture/Compare Interrupt routine.
  246. * @param None
  247. * @retval None
  248. */
  249. INTERRUPT_HANDLER(TIM5_CAP_COM_IRQHandler, 14)
  250. {
  251. /* In order to detect unexpected events during development,
  252. it is recommended to set a breakpoint on the following instruction.
  253. */
  254. }
  255. #else /* (STM8S208) || (STM8S207) || (STM8S105) || (STM8S103) || (STM8AF62Ax) || (STM8AF52Ax) || (STM8AF626x) */
  256. /**
  257. * @brief Timer2 Update/Overflow/Break Interrupt routine.
  258. * @param None
  259. * @retval None
  260. */
  261. INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)
  262. {
  263. /* In order to detect unexpected events during development,
  264. it is recommended to set a breakpoint on the following instruction.
  265. */
  266. }
  267. /**
  268. * @brief Timer2 Capture/Compare Interrupt routine.
  269. * @param None
  270. * @retval None
  271. */
  272. INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14)
  273. {
  274. /* In order to detect unexpected events during development,
  275. it is recommended to set a breakpoint on the following instruction.
  276. */
  277. }
  278. #endif /* (STM8S903) || (STM8AF622x) */
  279. #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \
  280. defined(STM8S005) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8AF626x)
  281. /**
  282. * @brief Timer3 Update/Overflow/Break Interrupt routine.
  283. * @param None
  284. * @retval None
  285. */
  286. INTERRUPT_HANDLER(TIM3_UPD_OVF_BRK_IRQHandler, 15)
  287. {
  288. /* In order to detect unexpected events during development,
  289. it is recommended to set a breakpoint on the following instruction.
  290. */
  291. }
  292. /**
  293. * @brief Timer3 Capture/Compare Interrupt routine.
  294. * @param None
  295. * @retval None
  296. */
  297. INTERRUPT_HANDLER(TIM3_CAP_COM_IRQHandler, 16)
  298. {
  299. /* In order to detect unexpected events during development,
  300. it is recommended to set a breakpoint on the following instruction.
  301. */
  302. }
  303. #endif /* (STM8S208) || (STM8S207) || (STM8S105) || (STM8AF62Ax) || (STM8AF52Ax) || (STM8AF626x) */
  304. #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S103) || \
  305. defined (STM8S003) || defined(STM8S001) || defined (STM8AF62Ax) || defined (STM8AF52Ax) || defined (STM8S903)
  306. /**
  307. * @brief UART1 TX Interrupt routine.
  308. * @param None
  309. * @retval None
  310. */
  311. INTERRUPT_HANDLER(UART1_TX_IRQHandler, 17)
  312. {
  313. /* In order to detect unexpected events during development,
  314. it is recommended to set a breakpoint on the following instruction.
  315. */
  316. }
  317. /**
  318. * @brief UART1 RX Interrupt routine.
  319. * @param None
  320. * @retval None
  321. */
  322. INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18)
  323. {
  324. /* In order to detect unexpected events during development,
  325. it is recommended to set a breakpoint on the following instruction.
  326. */
  327. }
  328. #endif /* (STM8S208) || (STM8S207) || (STM8S103) || (STM8S001) || (STM8S903) || (STM8AF62Ax) || (STM8AF52Ax) */
  329. #if defined(STM8AF622x)
  330. /**
  331. * @brief UART4 TX Interrupt routine.
  332. * @param None
  333. * @retval None
  334. */
  335. INTERRUPT_HANDLER(UART4_TX_IRQHandler, 17)
  336. {
  337. /* In order to detect unexpected events during development,
  338. it is recommended to set a breakpoint on the following instruction.
  339. */
  340. }
  341. /**
  342. * @brief UART4 RX Interrupt routine.
  343. * @param None
  344. * @retval None
  345. */
  346. INTERRUPT_HANDLER(UART4_RX_IRQHandler, 18)
  347. {
  348. /* In order to detect unexpected events during development,
  349. it is recommended to set a breakpoint on the following instruction.
  350. */
  351. }
  352. #endif /* (STM8AF622x) */
  353. /**
  354. * @brief I2C Interrupt routine.
  355. * @param None
  356. * @retval None
  357. */
  358. INTERRUPT_HANDLER(I2C_IRQHandler, 19)
  359. {
  360. /* In order to detect unexpected events during development,
  361. it is recommended to set a breakpoint on the following instruction.
  362. */
  363. }
  364. #if defined(STM8S105) || defined(STM8S005) || defined (STM8AF626x)
  365. /**
  366. * @brief UART2 TX interrupt routine.
  367. * @param None
  368. * @retval None
  369. */
  370. INTERRUPT_HANDLER(UART2_TX_IRQHandler, 20)
  371. {
  372. /* In order to detect unexpected events during development,
  373. it is recommended to set a breakpoint on the following instruction.
  374. */
  375. }
  376. /**
  377. * @brief UART2 RX interrupt routine.
  378. * @param None
  379. * @retval None
  380. */
  381. INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21)
  382. {
  383. /* In order to detect unexpected events during development,
  384. it is recommended to set a breakpoint on the following instruction.
  385. */
  386. }
  387. #endif /* (STM8S105) || (STM8AF626x) */
  388. #if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
  389. /**
  390. * @brief UART3 TX interrupt routine.
  391. * @param None
  392. * @retval None
  393. */
  394. INTERRUPT_HANDLER(UART3_TX_IRQHandler, 20)
  395. {
  396. /* In order to detect unexpected events during development,
  397. it is recommended to set a breakpoint on the following instruction.
  398. */
  399. }
  400. /**
  401. * @brief UART3 RX interrupt routine.
  402. * @param None
  403. * @retval None
  404. */
  405. INTERRUPT_HANDLER(UART3_RX_IRQHandler, 21)
  406. {
  407. /* In order to detect unexpected events during development,
  408. it is recommended to set a breakpoint on the following instruction.
  409. */
  410. }
  411. #endif /* (STM8S208) || (STM8S207) || (STM8AF52Ax) || (STM8AF62Ax) */
  412. #if defined(STM8S207) || defined(STM8S007) || defined(STM8S208) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
  413. /**
  414. * @brief ADC2 interrupt routine.
  415. * @param None
  416. * @retval None
  417. */
  418. INTERRUPT_HANDLER(ADC2_IRQHandler, 22)
  419. {
  420. /* In order to detect unexpected events during development,
  421. it is recommended to set a breakpoint on the following instruction.
  422. */
  423. }
  424. #else /* STM8S105 or STM8S103 or STM8S903 or STM8AF626x or STM8AF622x */
  425. /**
  426. * @brief ADC1 interrupt routine.
  427. * @par Parameters:
  428. * None
  429. * @retval
  430. * None
  431. */
  432. INTERRUPT_HANDLER(ADC1_IRQHandler, 22)
  433. {
  434. /* In order to detect unexpected events during development,
  435. it is recommended to set a breakpoint on the following instruction.
  436. */
  437. uint8_t temph = 0;
  438. uint8_t templ = 0;
  439. /* Read LSB first ? */
  440. templ = ADC1->DRL;
  441. /* Then read MSB */
  442. temph = ADC1->DRH;
  443. ConversionBuffer[BufferIndex] = (uint16_t)(templ | (uint16_t)(temph << (uint8_t)8));
  444. BufferIndex ++;
  445. /* ADC1_ClearITPendingBit */
  446. ADC1->CSR &= (uint8_t)((uint16_t)~(uint16_t)ADC1_IT_EOC);
  447. }
  448. #endif /* (STM8S208) || (STM8S207) || (STM8AF52Ax) || (STM8AF62Ax) */
  449. #if defined (STM8S903) || defined (STM8AF622x)
  450. /**
  451. * @brief Timer6 Update/Overflow/Trigger Interrupt routine.
  452. * @param None
  453. * @retval None
  454. */
  455. INTERRUPT_HANDLER(TIM6_UPD_OVF_TRG_IRQHandler, 23)
  456. {
  457. /* In order to detect unexpected events during development,
  458. it is recommended to set a breakpoint on the following instruction.
  459. */
  460. }
  461. #else /* STM8S208 or STM8S207 or STM8S105 or STM8S103 or STM8AF52Ax or STM8AF62Ax or STM8AF626x */
  462. /**
  463. * @brief Timer4 Update/Overflow Interrupt routine.
  464. * @param None
  465. * @retval None
  466. */
  467. INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
  468. {
  469. /* Cleat Interrupt Pending bit */
  470. TIM4->SR1 = (uint8_t)(~(uint8_t)TIM4_IT_UPDATE);
  471. LedCnt ++;
  472. if (LedCnt >= LED_ONE_PERIOD) {
  473. LedCnt = 0;
  474. led_OutputValue();
  475. }
  476. /* Decrements the TimingDelay variable */
  477. if (TimingDelay > 0) {
  478. TimingDelay --;
  479. }
  480. /* for I2C */
  481. if (I2C_timeout != 0) {
  482. I2C_timeout --;
  483. }
  484. }
  485. #endif /* (STM8S903) || (STM8AF622x)*/
  486. /**
  487. * @brief Eeprom EEC Interrupt routine.
  488. * @param None
  489. * @retval None
  490. */
  491. INTERRUPT_HANDLER(EEPROM_EEC_IRQHandler, 24)
  492. {
  493. /* In order to detect unexpected events during development,
  494. it is recommended to set a breakpoint on the following instruction.
  495. */
  496. }
  497. /**
  498. * @}
  499. */
  500. /**
  501. * @brief Inserts a delay time.
  502. * @param nTime: specifies the delay time length, in milliseconds.
  503. * @retval None
  504. */
  505. void Delay(__IO uint16_t nTime)
  506. {
  507. TimingDelay = nTime;
  508. while (TimingDelay != 0) {
  509. wfi();
  510. }
  511. }
  512. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/