]> git.gag.com Git - fw/stlink/blobdiff - example/libs_stm/src/stm32l1xx/misc.c
Restructure libs source to support multi platform
[fw/stlink] / example / libs_stm / src / stm32l1xx / misc.c
diff --git a/example/libs_stm/src/stm32l1xx/misc.c b/example/libs_stm/src/stm32l1xx/misc.c
new file mode 100644 (file)
index 0000000..3b7a000
--- /dev/null
@@ -0,0 +1,249 @@
+/**\r
+  ******************************************************************************\r
+  * @file    misc.c\r
+  * @author  MCD Application Team\r
+  * @version V1.0.0\r
+  * @date    31-December-2010\r
+  * @brief   This file provides all the miscellaneous firmware functions (add-on\r
+  *          to CMSIS functions).\r
+  ******************************************************************************\r
+  * @attention\r
+  *\r
+  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
+  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
+  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
+  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
+  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
+  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
+  *\r
+  * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>\r
+  ******************************************************************************  \r
+  */ \r
+\r
+/* Includes ------------------------------------------------------------------*/\r
+#include "misc.h"\r
+\r
+/** @addtogroup STM32L1xx_StdPeriph_Driver\r
+  * @{\r
+  */\r
+\r
+/** @defgroup MISC \r
+  * @brief MISC driver modules\r
+  * @{\r
+  */\r
+\r
+/* Private typedef -----------------------------------------------------------*/\r
+/* Private define ------------------------------------------------------------*/\r
+#define AIRCR_VECTKEY_MASK    ((uint32_t)0x05FA0000)\r
+\r
+/* Private macro -------------------------------------------------------------*/\r
+/* Private variables ---------------------------------------------------------*/\r
+/* Private function prototypes -----------------------------------------------*/\r
+/* Private functions ---------------------------------------------------------*/\r
+\r
+/** @defgroup MISC_Private_Functions\r
+  * @{\r
+  */\r
+/**\r
+  *\r
+@verbatim   \r
+ *******************************************************************************\r
+                    Interrupts configuration functions\r
+ *******************************************************************************  \r
+  \r
+  This section provide functions allowing to configure the NVIC interrupts (IRQ).\r
+  The Cortex-M3 exceptions are managed by CMSIS functions.\r
+  \r
+  1. Configure the NVIC Priority Grouping using NVIC_PriorityGroupConfig() function\r
+     according to the following table.\r
\r
+ The table below gives the allowed values of the pre-emption priority and subpriority according\r
+ to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function\r
+  ============================================================================================================================\r
+    NVIC_PriorityGroup   | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority  | Description\r
+  ============================================================================================================================\r
+   NVIC_PriorityGroup_0  |                0                  |            0-15             |   0 bits for pre-emption priority\r
+                         |                                   |                             |   4 bits for subpriority\r
+  ----------------------------------------------------------------------------------------------------------------------------\r
+   NVIC_PriorityGroup_1  |                0-1                |            0-7              |   1 bits for pre-emption priority\r
+                         |                                   |                             |   3 bits for subpriority\r
+  ----------------------------------------------------------------------------------------------------------------------------    \r
+   NVIC_PriorityGroup_2  |                0-3                |            0-3              |   2 bits for pre-emption priority\r
+                         |                                   |                             |   2 bits for subpriority\r
+  ----------------------------------------------------------------------------------------------------------------------------    \r
+   NVIC_PriorityGroup_3  |                0-7                |            0-1              |   3 bits for pre-emption priority\r
+                         |                                   |                             |   1 bits for subpriority\r
+  ----------------------------------------------------------------------------------------------------------------------------    \r
+   NVIC_PriorityGroup_4  |                0-15               |            0                |   4 bits for pre-emption priority\r
+                         |                                   |                             |   0 bits for subpriority                       \r
+  ============================================================================================================================     \r
+\r
+\r
+  2. Enable and Configure the priority of the selected IRQ Channels.  \r
+\r
+@note When the NVIC_PriorityGroup_0 is selected, it will no any nested interrupt,\r
+      the IRQ priority will be managed only by subpriority.\r
+      The sub-priority is only used to sort pending exception priorities, \r
+      and does not affect active exceptions.\r
+\r
+@note Lower priority values gives higher priority.\r
+\r
+@note Priority Order:\r
+       1. Lowest Preemption priority\r
+       2. Lowest Subpriority\r
+       3. Lowest hardware priority (IRQn position)\r
+  \r
+@endverbatim\r
+*/\r
+\r
+/**\r
+  * @brief  Configures the priority grouping: pre-emption priority and subpriority.\r
+  * @param  NVIC_PriorityGroup: specifies the priority grouping bits length. \r
+  *   This parameter can be one of the following values:\r
+  *     @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority\r
+  *                                4 bits for subpriority\r
+  *     @note When NVIC_PriorityGroup_0 is selected, it will no be any nested \r
+  *           interrupt. This interrupts priority is managed only with subpriority.  \r
+  *     @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority\r
+  *                                3 bits for subpriority\r
+  *     @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority\r
+  *                                2 bits for subpriority\r
+  *     @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority\r
+  *                                1 bits for subpriority\r
+  *     @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority\r
+  *                                0 bits for subpriority\r
+  * @retval None\r
+  */\r
+void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));\r
+  \r
+  /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */\r
+  SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;\r
+}\r
+\r
+/**\r
+  * @brief  Initializes the NVIC peripheral according to the specified\r
+  *         parameters in the NVIC_InitStruct.\r
+  * @note   To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()\r
+  *         function should be called before.    \r
+  * @param  NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains\r
+  *         the configuration information for the specified NVIC peripheral.\r
+  * @retval None\r
+  */\r
+void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)\r
+{\r
+  uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;\r
+  \r
+  /* Check the parameters */\r
+  assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));\r
+  assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));  \r
+  assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));\r
+    \r
+  if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)\r
+  {\r
+    /* Compute the Corresponding IRQ Priority --------------------------------*/    \r
+    tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;\r
+    tmppre = (0x4 - tmppriority);\r
+    tmpsub = tmpsub >> tmppriority;\r
+\r
+    tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;\r
+    tmppriority |=  NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;\r
+    tmppriority = tmppriority << 0x04;\r
+        \r
+    NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;\r
+    \r
+    /* Enable the Selected IRQ Channels --------------------------------------*/\r
+    NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =\r
+      (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);\r
+  }\r
+  else\r
+  {\r
+    /* Disable the Selected IRQ Channels -------------------------------------*/\r
+    NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =\r
+      (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);\r
+  }\r
+}\r
+\r
+/**\r
+  * @brief  Sets the vector table location and Offset.\r
+  * @param  NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.\r
+  *   This parameter can be one of the following values:\r
+  *     @arg NVIC_VectTab_RAM\r
+  *     @arg NVIC_VectTab_FLASH\r
+  * @param  Offset: Vector Table base offset field. This value must be a multiple of 0x200.\r
+  * @retval None\r
+  */\r
+void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)\r
+{ \r
+  /* Check the parameters */\r
+  assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));\r
+  assert_param(IS_NVIC_OFFSET(Offset));  \r
+   \r
+  SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);\r
+}\r
+\r
+/**\r
+  * @brief  Selects the condition for the system to enter low power mode.\r
+  * @param  LowPowerMode: Specifies the new mode for the system to enter low power mode.\r
+  *   This parameter can be one of the following values:\r
+  *     @arg NVIC_LP_SEVONPEND\r
+  *     @arg NVIC_LP_SLEEPDEEP\r
+  *     @arg NVIC_LP_SLEEPONEXIT\r
+  * @param  NewState: new state of LP condition. \r
+  *         This parameter can be: ENABLE or DISABLE.\r
+  * @retval None\r
+  */\r
+void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_NVIC_LP(LowPowerMode));\r
+  assert_param(IS_FUNCTIONAL_STATE(NewState));  \r
+  \r
+  if (NewState != DISABLE)\r
+  {\r
+    SCB->SCR |= LowPowerMode;\r
+  }\r
+  else\r
+  {\r
+    SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);\r
+  }\r
+}\r
+\r
+/**\r
+  * @brief  Configures the SysTick clock source.\r
+  * @param  SysTick_CLKSource: specifies the SysTick clock source.\r
+  *   This parameter can be one of the following values:\r
+  *     @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.\r
+  *     @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.\r
+  * @retval None\r
+  */\r
+void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)\r
+{\r
+  /* Check the parameters */\r
+  assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));\r
+  \r
+  if (SysTick_CLKSource == SysTick_CLKSource_HCLK)\r
+  {\r
+    SysTick->CTRL |= SysTick_CLKSource_HCLK;\r
+  }\r
+  else\r
+  {\r
+    SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;\r
+  }\r
+}\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/**\r
+  * @}\r
+  */\r
+\r
+/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/\r