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