stm8s_itc.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /**
  2. ******************************************************************************
  3. * @file stm8s_itc.c
  4. * @author MCD Application Team
  5. * @version V2.3.0
  6. * @date 16-June-2017
  7. * @brief This file contains all the functions for the ITC peripheral.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm8s_itc.h"
  29. /** @addtogroup STM8S_StdPeriph_Driver
  30. * @{
  31. */
  32. /* Private typedef -----------------------------------------------------------*/
  33. /* Private define ------------------------------------------------------------*/
  34. /* Private macro -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private function prototypes -----------------------------------------------*/
  37. /* Private functions ---------------------------------------------------------*/
  38. /** @addtogroup ITC_Private_Functions
  39. * @{
  40. */
  41. /**
  42. * @brief Utility function used to read CC register.
  43. * @param None
  44. * @retval CPU CC register value
  45. */
  46. uint8_t ITC_GetCPUCC(void)
  47. {
  48. #ifdef _COSMIC_
  49. _asm("push cc");
  50. _asm("pop a");
  51. return; /* Ignore compiler warning, the returned value is in A register */
  52. #elif defined _RAISONANCE_ /* _RAISONANCE_ */
  53. return _getCC_();
  54. #else /* _IAR_ */
  55. asm("push cc");
  56. asm("pop a"); /* Ignore compiler warning, the returned value is in A register */
  57. #endif /* _COSMIC_*/
  58. }
  59. /**
  60. * @}
  61. */
  62. /* Public functions ----------------------------------------------------------*/
  63. /** @addtogroup ITC_Public_Functions
  64. * @{
  65. */
  66. /**
  67. * @brief Deinitializes the ITC registers to their default reset value.
  68. * @param None
  69. * @retval None
  70. */
  71. void ITC_DeInit(void)
  72. {
  73. ITC->ISPR1 = ITC_SPRX_RESET_VALUE;
  74. ITC->ISPR2 = ITC_SPRX_RESET_VALUE;
  75. ITC->ISPR3 = ITC_SPRX_RESET_VALUE;
  76. ITC->ISPR4 = ITC_SPRX_RESET_VALUE;
  77. ITC->ISPR5 = ITC_SPRX_RESET_VALUE;
  78. ITC->ISPR6 = ITC_SPRX_RESET_VALUE;
  79. ITC->ISPR7 = ITC_SPRX_RESET_VALUE;
  80. ITC->ISPR8 = ITC_SPRX_RESET_VALUE;
  81. }
  82. /**
  83. * @brief Gets the interrupt software priority bits (I1, I0) value from CPU CC register.
  84. * @param None
  85. * @retval The interrupt software priority bits value.
  86. */
  87. uint8_t ITC_GetSoftIntStatus(void)
  88. {
  89. return (uint8_t)(ITC_GetCPUCC() & CPU_CC_I1I0);
  90. }
  91. /**
  92. * @brief Gets the software priority of the specified interrupt source.
  93. * @param IrqNum : Specifies the peripheral interrupt source.
  94. * @retval ITC_PriorityLevel_TypeDef : Specifies the software priority of the interrupt source.
  95. */
  96. ITC_PriorityLevel_TypeDef ITC_GetSoftwarePriority(ITC_Irq_TypeDef IrqNum)
  97. {
  98. uint8_t Value = 0;
  99. uint8_t Mask = 0;
  100. /* Check function parameters */
  101. assert_param(IS_ITC_IRQ_OK((uint8_t)IrqNum));
  102. /* Define the mask corresponding to the bits position in the SPR register */
  103. Mask = (uint8_t)(0x03U << (((uint8_t)IrqNum % 4U) * 2U));
  104. switch (IrqNum)
  105. {
  106. case ITC_IRQ_TLI: /* TLI software priority can be read but has no meaning */
  107. case ITC_IRQ_AWU:
  108. case ITC_IRQ_CLK:
  109. case ITC_IRQ_PORTA:
  110. Value = (uint8_t)(ITC->ISPR1 & Mask); /* Read software priority */
  111. break;
  112. case ITC_IRQ_PORTB:
  113. case ITC_IRQ_PORTC:
  114. case ITC_IRQ_PORTD:
  115. case ITC_IRQ_PORTE:
  116. Value = (uint8_t)(ITC->ISPR2 & Mask); /* Read software priority */
  117. break;
  118. #if defined(STM8S208) || defined(STM8AF52Ax)
  119. case ITC_IRQ_CAN_RX:
  120. case ITC_IRQ_CAN_TX:
  121. #endif /*STM8S208 or STM8AF52Ax */
  122. #if defined(STM8S903) || defined(STM8AF622x)
  123. case ITC_IRQ_PORTF:
  124. #endif /*STM8S903 or STM8AF622x */
  125. case ITC_IRQ_SPI:
  126. case ITC_IRQ_TIM1_OVF:
  127. Value = (uint8_t)(ITC->ISPR3 & Mask); /* Read software priority */
  128. break;
  129. case ITC_IRQ_TIM1_CAPCOM:
  130. #if defined (STM8S903) || defined (STM8AF622x)
  131. case ITC_IRQ_TIM5_OVFTRI:
  132. case ITC_IRQ_TIM5_CAPCOM:
  133. #else
  134. case ITC_IRQ_TIM2_OVF:
  135. case ITC_IRQ_TIM2_CAPCOM:
  136. #endif /* STM8S903 or STM8AF622x*/
  137. case ITC_IRQ_TIM3_OVF:
  138. Value = (uint8_t)(ITC->ISPR4 & Mask); /* Read software priority */
  139. break;
  140. case ITC_IRQ_TIM3_CAPCOM:
  141. #if defined(STM8S208) ||defined(STM8S207) || defined (STM8S007) || defined(STM8S103) || \
  142. defined(STM8S003) ||defined(STM8S001) || defined (STM8S903) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
  143. case ITC_IRQ_UART1_TX:
  144. case ITC_IRQ_UART1_RX:
  145. #endif /*STM8S208 or STM8S207 or STM8S007 or STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF52Ax or STM8AF62Ax */
  146. #if defined(STM8AF622x)
  147. case ITC_IRQ_UART4_TX:
  148. case ITC_IRQ_UART4_RX:
  149. #endif /*STM8AF622x */
  150. case ITC_IRQ_I2C:
  151. Value = (uint8_t)(ITC->ISPR5 & Mask); /* Read software priority */
  152. break;
  153. #if defined(STM8S105) || defined(STM8S005) || defined(STM8AF626x)
  154. case ITC_IRQ_UART2_TX:
  155. case ITC_IRQ_UART2_RX:
  156. #endif /*STM8S105 or STM8AF626x*/
  157. #if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8AF52Ax) || \
  158. defined(STM8AF62Ax)
  159. case ITC_IRQ_UART3_TX:
  160. case ITC_IRQ_UART3_RX:
  161. case ITC_IRQ_ADC2:
  162. #endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */
  163. #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \
  164. defined(STM8S001) || defined(STM8S903) || defined(STM8AF626x) || defined(STM8AF622x)
  165. case ITC_IRQ_ADC1:
  166. #endif /*STM8S105, STM8S005, STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF626x or STM8AF622x */
  167. #if defined (STM8S903) || defined (STM8AF622x)
  168. case ITC_IRQ_TIM6_OVFTRI:
  169. #else
  170. case ITC_IRQ_TIM4_OVF:
  171. #endif /*STM8S903 or STM8AF622x */
  172. Value = (uint8_t)(ITC->ISPR6 & Mask); /* Read software priority */
  173. break;
  174. case ITC_IRQ_EEPROM_EEC:
  175. Value = (uint8_t)(ITC->ISPR7 & Mask); /* Read software priority */
  176. break;
  177. default:
  178. break;
  179. }
  180. Value >>= (uint8_t)(((uint8_t)IrqNum % 4u) * 2u);
  181. return((ITC_PriorityLevel_TypeDef)Value);
  182. }
  183. /**
  184. * @brief Sets the software priority of the specified interrupt source.
  185. * @note - The modification of the software priority is only possible when
  186. * the interrupts are disabled.
  187. * - The normal behavior is to disable the interrupt before calling
  188. * this function, and re-enable it after.
  189. * - The priority level 0 cannot be set (see product specification
  190. * for more details).
  191. * @param IrqNum : Specifies the peripheral interrupt source.
  192. * @param PriorityValue : Specifies the software priority value to set,
  193. * can be a value of @ref ITC_PriorityLevel_TypeDef .
  194. * @retval None
  195. */
  196. void ITC_SetSoftwarePriority(ITC_Irq_TypeDef IrqNum, ITC_PriorityLevel_TypeDef PriorityValue)
  197. {
  198. uint8_t Mask = 0;
  199. uint8_t NewPriority = 0;
  200. /* Check function parameters */
  201. assert_param(IS_ITC_IRQ_OK((uint8_t)IrqNum));
  202. assert_param(IS_ITC_PRIORITY_OK(PriorityValue));
  203. /* Check if interrupts are disabled */
  204. assert_param(IS_ITC_INTERRUPTS_DISABLED);
  205. /* Define the mask corresponding to the bits position in the SPR register */
  206. /* The mask is reversed in order to clear the 2 bits after more easily */
  207. Mask = (uint8_t)(~(uint8_t)(0x03U << (((uint8_t)IrqNum % 4U) * 2U)));
  208. /* Define the new priority to write */
  209. NewPriority = (uint8_t)((uint8_t)(PriorityValue) << (((uint8_t)IrqNum % 4U) * 2U));
  210. switch (IrqNum)
  211. {
  212. case ITC_IRQ_TLI: /* TLI software priority can be written but has no meaning */
  213. case ITC_IRQ_AWU:
  214. case ITC_IRQ_CLK:
  215. case ITC_IRQ_PORTA:
  216. ITC->ISPR1 &= Mask;
  217. ITC->ISPR1 |= NewPriority;
  218. break;
  219. case ITC_IRQ_PORTB:
  220. case ITC_IRQ_PORTC:
  221. case ITC_IRQ_PORTD:
  222. case ITC_IRQ_PORTE:
  223. ITC->ISPR2 &= Mask;
  224. ITC->ISPR2 |= NewPriority;
  225. break;
  226. #if defined(STM8S208) || defined(STM8AF52Ax)
  227. case ITC_IRQ_CAN_RX:
  228. case ITC_IRQ_CAN_TX:
  229. #endif /*STM8S208 or STM8AF52Ax */
  230. #if defined(STM8S903) || defined(STM8AF622x)
  231. case ITC_IRQ_PORTF:
  232. #endif /*STM8S903 or STM8AF622x */
  233. case ITC_IRQ_SPI:
  234. case ITC_IRQ_TIM1_OVF:
  235. ITC->ISPR3 &= Mask;
  236. ITC->ISPR3 |= NewPriority;
  237. break;
  238. case ITC_IRQ_TIM1_CAPCOM:
  239. #if defined(STM8S903) || defined(STM8AF622x)
  240. case ITC_IRQ_TIM5_OVFTRI:
  241. case ITC_IRQ_TIM5_CAPCOM:
  242. #else
  243. case ITC_IRQ_TIM2_OVF:
  244. case ITC_IRQ_TIM2_CAPCOM:
  245. #endif /*STM8S903 or STM8AF622x */
  246. case ITC_IRQ_TIM3_OVF:
  247. ITC->ISPR4 &= Mask;
  248. ITC->ISPR4 |= NewPriority;
  249. break;
  250. case ITC_IRQ_TIM3_CAPCOM:
  251. #if defined(STM8S208) ||defined(STM8S207) || defined (STM8S007) || defined(STM8S103) || \
  252. defined(STM8S001) ||defined(STM8S003) ||defined(STM8S903) || defined (STM8AF52Ax) || defined (STM8AF62Ax)
  253. case ITC_IRQ_UART1_TX:
  254. case ITC_IRQ_UART1_RX:
  255. #endif /*STM8S208 or STM8S207 or STM8S007 or STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF52Ax or STM8AF62Ax */
  256. #if defined(STM8AF622x)
  257. case ITC_IRQ_UART4_TX:
  258. case ITC_IRQ_UART4_RX:
  259. #endif /*STM8AF622x */
  260. case ITC_IRQ_I2C:
  261. ITC->ISPR5 &= Mask;
  262. ITC->ISPR5 |= NewPriority;
  263. break;
  264. #if defined(STM8S105) || defined(STM8S005) || defined(STM8AF626x)
  265. case ITC_IRQ_UART2_TX:
  266. case ITC_IRQ_UART2_RX:
  267. #endif /*STM8S105 or STM8AF626x */
  268. #if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8AF52Ax) || \
  269. defined(STM8AF62Ax)
  270. case ITC_IRQ_UART3_TX:
  271. case ITC_IRQ_UART3_RX:
  272. case ITC_IRQ_ADC2:
  273. #endif /*STM8S208 or STM8S207 or STM8AF52Ax or STM8AF62Ax */
  274. #if defined(STM8S105) || defined(STM8S005) || defined(STM8S103) || defined(STM8S003) || \
  275. defined(STM8S001) || defined(STM8S903) || defined(STM8AF626x) || defined (STM8AF622x)
  276. case ITC_IRQ_ADC1:
  277. #endif /*STM8S105, STM8S005, STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF626x or STM8AF622x */
  278. #if defined (STM8S903) || defined (STM8AF622x)
  279. case ITC_IRQ_TIM6_OVFTRI:
  280. #else
  281. case ITC_IRQ_TIM4_OVF:
  282. #endif /* STM8S903 or STM8AF622x */
  283. ITC->ISPR6 &= Mask;
  284. ITC->ISPR6 |= NewPriority;
  285. break;
  286. case ITC_IRQ_EEPROM_EEC:
  287. ITC->ISPR7 &= Mask;
  288. ITC->ISPR7 |= NewPriority;
  289. break;
  290. default:
  291. break;
  292. }
  293. }
  294. /**
  295. * @}
  296. */
  297. /**
  298. * @}
  299. */
  300. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/