CARME-M4 BSP  V1.5
misc.c
Go to the documentation of this file.
1 
75 /* Includes ------------------------------------------------------------------*/
76 #include "misc.h"
77 
87 /* Private typedef -----------------------------------------------------------*/
88 /* Private define ------------------------------------------------------------*/
89 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
90 
91 /* Private macro -------------------------------------------------------------*/
92 /* Private variables ---------------------------------------------------------*/
93 /* Private function prototypes -----------------------------------------------*/
94 /* Private functions ---------------------------------------------------------*/
95 
118 void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
119 {
120  /* Check the parameters */
121  assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
122 
123  /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
124  SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
125 }
126 
136 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
137 {
138  uint8_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
139 
140  /* Check the parameters */
141  assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
142  assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
143  assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
144 
145  if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
146  {
147  /* Compute the Corresponding IRQ Priority --------------------------------*/
148  tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
149  tmppre = (0x4 - tmppriority);
150  tmpsub = tmpsub >> tmppriority;
151 
152  tmppriority = NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
153  tmppriority |= (uint8_t)(NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub);
154 
155  tmppriority = tmppriority << 0x04;
156 
157  NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
158 
159  /* Enable the Selected IRQ Channels --------------------------------------*/
160  NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
161  (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
162  }
163  else
164  {
165  /* Disable the Selected IRQ Channels -------------------------------------*/
166  NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
167  (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
168  }
169 }
170 
180 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
181 {
182  /* Check the parameters */
183  assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
184  assert_param(IS_NVIC_OFFSET(Offset));
185 
186  SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
187 }
188 
199 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
200 {
201  /* Check the parameters */
202  assert_param(IS_NVIC_LP(LowPowerMode));
203  assert_param(IS_FUNCTIONAL_STATE(NewState));
204 
205  if (NewState != DISABLE)
206  {
207  SCB->SCR |= LowPowerMode;
208  }
209  else
210  {
211  SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
212  }
213 }
214 
223 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
224 {
225  /* Check the parameters */
226  assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
227  if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
228  {
229  SysTick->CTRL |= SysTick_CLKSource_HCLK;
230  }
231  else
232  {
233  SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
234  }
235 }
236 
249 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
This file contains all the functions prototypes for the miscellaneous firmware library functions (add...
void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
Sets the vector table location and Offset.
Definition: misc.c:180
void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
Configures the SysTick clock source.
Definition: misc.c:223
uint8_t NVIC_IRQChannelPreemptionPriority
Definition: misc.h:61
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
Configures the priority grouping: pre-emption priority and subpriority.
Definition: misc.c:118
NVIC Init Structure definition.
Definition: misc.h:54
uint8_t NVIC_IRQChannel
Definition: misc.h:56
FunctionalState NVIC_IRQChannelCmd
Definition: misc.h:71
uint8_t NVIC_IRQChannelSubPriority
Definition: misc.h:66
void NVIC_Init(NVIC_InitTypeDef *NVIC_InitStruct)
Initializes the NVIC peripheral according to the specified parameters in the NVIC_InitStruct.
Definition: misc.c:136
void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
Selects the condition for the system to enter low power mode.
Definition: misc.c:199