1 /**
2 ******************************************************************************
3 * @file    HAL_misc.c
4 * @author  AE Team
5 * @version  V2.0.0
6 * @date  22/08/2017
7 * @brief   This file provides all the miscellaneous firmware functions (add-on
8 *          to CMSIS functions).
9 ******************************************************************************
10 * @attention
11 *
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 *
19 * <h2><center>&copy; COPYRIGHT 2017 MindMotion</center></h2>
20 ******************************************************************************
21 */
22 
23 /* Includes ------------------------------------------------------------------*/
24 #include "HAL_misc.h"
25 
26 /** @addtogroup StdPeriph_Driver
27 * @{
28 */
29 
30 /** @defgroup MISC
31 * @brief MISC driver modules
32 * @{
33 */
34 
35 /** @defgroup MISC_Private_TypesDefinitions
36 * @{
37 */
38 
39 /**
40 * @}
41 */
42 
43 /** @defgroup MISC_Private_Defines
44 * @{
45 */
46 
47 #define AIRCR_VECTKEY_MASK    ((uint32_t)0x05FA0000)
48 /**
49 * @}
50 */
51 
52 
53 /**
54 * @brief  Initializes the NVIC peripheral according to the specified
55 *         parameters in the NVIC_InitStruct.
56 * @param  NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
57 *         the configuration information for the specified NVIC peripheral.
58 * @retval None
59 */
NVIC_Init(NVIC_InitTypeDef * NVIC_InitStruct)60 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
61 {
62   uint32_t tmppriority = 0x00;
63 
64   /* Check the parameters */
65   assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
66   assert_param(IS_NVIC_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPriority));
67 
68   if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
69   {
70     /* Compute the Corresponding IRQ Priority --------------------------------*/
71     tmppriority = NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02];
72     tmppriority &= (uint32_t)(~(((uint32_t)0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8)));
73     tmppriority |= (uint32_t)((((uint32_t)NVIC_InitStruct->NVIC_IRQChannelPriority << 6) & 0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8));
74 
75     NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02] = tmppriority;
76 
77     /* Enable the Selected IRQ Channels --------------------------------------*/
78     NVIC->ISER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
79   }
80   else
81   {
82     /* Disable the Selected IRQ Channels -------------------------------------*/
83     NVIC->ICER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
84   }
85 }
86 
87 /**
88 * @brief  Sets the vector table location and Offset.
89 * @param  NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
90 *   This parameter can be one of the following values:
91 *     @arg NVIC_VectTab_RAM
92 *     @arg NVIC_VectTab_FLASH
93 * @param  Offset: Vector Table base offset field. This value must be a multiple
94 *         of 0x200.
95 * @retval None
96 */
NVIC_SetVectorTable(uint32_t NVIC_VectTab,uint32_t Offset)97 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
98 {
99 //    SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
100 }
101 
102 /**
103 * @brief  Selects the condition for the system to enter low power mode.
104 * @param  LowPowerMode: Specifies the new mode for the system to enter low power mode.
105 *   This parameter can be one of the following values:
106 *     @arg NVIC_LP_SEVONPEND
107 *     @arg NVIC_LP_SLEEPDEEP
108 *     @arg NVIC_LP_SLEEPONEXIT
109 * @param  NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
110 * @retval None
111 */
NVIC_SystemLPConfig(uint8_t LowPowerMode,FunctionalState NewState)112 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
113 {
114   /* Check the parameters */
115   assert_param(IS_NVIC_LP(LowPowerMode));
116 
117   assert_param(IS_FUNCTIONAL_STATE(NewState));
118     if (NewState != DISABLE)
119     {
120         SCB->SCR |= LowPowerMode;
121     }
122     else
123     {
124         SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
125     }
126 }
127 
128 /**
129 * @brief  Configures the SysTick clock source.
130 * @param  SysTick_CLKSource: specifies the SysTick clock source.
131 *   This parameter can be one of the following values:
132 *     @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
133 *     @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
134 * @retval None
135 */
SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)136 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
137 {
138     /* Check the parameters */
139 assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
140 
141     if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
142     {
143         SysTick->CTRL |= SysTick_CLKSource_HCLK;
144     }
145     else
146     {
147         SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
148     }
149 }
150 
151 /**
152 * @}
153 */
154 
155 /**
156 * @}
157 */
158 
159 /**
160 * @}
161 */
162 
163 /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/
164