ft32f0xx_misc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. ******************************************************************************
  3. * @file ft32f0xx_misc.c
  4. * @author FMD AE
  5. * @brief This file provides all the miscellaneous firmware functions (add-on
  6. * to CMSIS functions).
  7. * @version V1.0.0
  8. * @data 2021-07-01
  9. ******************************************************************************
  10. */
  11. /* Includes ------------------------------------------------------------------*/
  12. #include "ft32f0xx_misc.h"
  13. /**
  14. * @brief Initializes the NVIC peripheral according to the specified
  15. * parameters in the NVIC_InitStruct.
  16. * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
  17. * the configuration information for the specified NVIC peripheral.
  18. * @retval None
  19. */
  20. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
  21. {
  22. uint32_t tmppriority = 0x00;
  23. /* Check the parameters */
  24. assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
  25. assert_param(IS_NVIC_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPriority));
  26. if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
  27. {
  28. /* Compute the Corresponding IRQ Priority --------------------------------*/
  29. tmppriority = NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02];
  30. tmppriority &= (uint32_t)(~(((uint32_t)0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8)));
  31. tmppriority |= (uint32_t)((((uint32_t)NVIC_InitStruct->NVIC_IRQChannelPriority << 6) & 0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8));
  32. NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02] = tmppriority;
  33. /* Enable the Selected IRQ Channels --------------------------------------*/
  34. NVIC->ISER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  35. }
  36. else
  37. {
  38. /* Disable the Selected IRQ Channels -------------------------------------*/
  39. NVIC->ICER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  40. }
  41. }
  42. /**
  43. * @brief Selects the condition for the system to enter low power mode.
  44. * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
  45. * This parameter can be one of the following values:
  46. * @arg NVIC_LP_SEVONPEND: Low Power SEV on Pend.
  47. * @arg NVIC_LP_SLEEPDEEP: Low Power DEEPSLEEP request.
  48. * @arg NVIC_LP_SLEEPONEXIT: Low Power Sleep on Exit.
  49. * @param NewState: new state of LP condition.
  50. * This parameter can be: ENABLE or DISABLE.
  51. * @retval None
  52. */
  53. void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
  54. {
  55. /* Check the parameters */
  56. assert_param(IS_NVIC_LP(LowPowerMode));
  57. assert_param(IS_FUNCTIONAL_STATE(NewState));
  58. if (NewState != DISABLE)
  59. {
  60. SCB->SCR |= LowPowerMode;
  61. }
  62. else
  63. {
  64. SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
  65. }
  66. }
  67. /**
  68. * @brief Configures the SysTick clock source.
  69. * @param SysTick_CLKSource: specifies the SysTick clock source.
  70. * This parameter can be one of the following values:
  71. * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
  72. * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
  73. * @retval None
  74. */
  75. void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
  76. {
  77. /* Check the parameters */
  78. assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
  79. if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
  80. {
  81. SysTick->CTRL |= SysTick_CLKSource_HCLK;
  82. }
  83. else
  84. {
  85. SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
  86. }
  87. }
  88. /**
  89. * @}
  90. */
  91. /**
  92. * @}
  93. */
  94. /**
  95. * @}
  96. */
  97. /************************ (C) COPYRIGHT FMD *****END OF FILE****/