mattia griotti / Mbed 2 deprecated HelloWorld_IKS01A1

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 X_NUCLEO_IKS01A1 mbed

Fork of HelloWorld_IKS01A1 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers misc.c Source File

misc.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    misc.c
00004   * @author  MCD Application Team
00005   * @version V1.0.0
00006   * @date    30-September-2011
00007   * @brief   This file provides all the miscellaneous firmware functions (add-on
00008   *          to CMSIS functions).
00009   *          
00010   *  @verbatim   
00011   *                               
00012   *          ===================================================================      
00013   *                        How to configure Interrupts using driver 
00014   *          ===================================================================      
00015   * 
00016   *            This section provide functions allowing to configure the NVIC interrupts (IRQ).
00017   *            The Cortex-M4 exceptions are managed by CMSIS functions.
00018   *
00019   *            1. Configure the NVIC Priority Grouping using NVIC_PriorityGroupConfig()
00020   *                function according to the following table.
00021  
00022   *  The table below gives the allowed values of the pre-emption priority and subpriority according
00023   *  to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function
00024   *    ==========================================================================================================================
00025   *      NVIC_PriorityGroup   | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority  |       Description
00026   *    ==========================================================================================================================
00027   *     NVIC_PriorityGroup_0  |                0                  |            0-15             | 0 bits for pre-emption priority
00028   *                           |                                   |                             | 4 bits for subpriority
00029   *    --------------------------------------------------------------------------------------------------------------------------
00030   *     NVIC_PriorityGroup_1  |                0-1                |            0-7              | 1 bits for pre-emption priority
00031   *                           |                                   |                             | 3 bits for subpriority
00032   *    --------------------------------------------------------------------------------------------------------------------------    
00033   *     NVIC_PriorityGroup_2  |                0-3                |            0-3              | 2 bits for pre-emption priority
00034   *                           |                                   |                             | 2 bits for subpriority
00035   *    --------------------------------------------------------------------------------------------------------------------------    
00036   *     NVIC_PriorityGroup_3  |                0-7                |            0-1              | 3 bits for pre-emption priority
00037   *                           |                                   |                             | 1 bits for subpriority
00038   *    --------------------------------------------------------------------------------------------------------------------------    
00039   *     NVIC_PriorityGroup_4  |                0-15               |            0                | 4 bits for pre-emption priority
00040   *                           |                                   |                             | 0 bits for subpriority                       
00041   *    ==========================================================================================================================     
00042   *
00043   *            2. Enable and Configure the priority of the selected IRQ Channels using NVIC_Init()  
00044   *
00045   * @note  When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible. 
00046   *        The pending IRQ priority will be managed only by the subpriority.
00047   *
00048   * @note  IRQ priority order (sorted by highest to lowest priority):
00049   *         - Lowest pre-emption priority
00050   *         - Lowest subpriority
00051   *         - Lowest hardware priority (IRQ number)
00052   *
00053   *  @endverbatim
00054   *
00055   ******************************************************************************
00056   * @attention
00057   *
00058   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00059   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00060   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00061   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00062   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00063   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00064   *
00065   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
00066   ******************************************************************************
00067   */
00068 
00069 /* Includes ------------------------------------------------------------------*/
00070 #include "misc.h"
00071 
00072 /** @addtogroup STM32F4xx_StdPeriph_Driver
00073   * @{
00074   */
00075 
00076 /** @defgroup MISC 
00077   * @brief MISC driver modules
00078   * @{
00079   */
00080 
00081 /* Private typedef -----------------------------------------------------------*/
00082 /* Private define ------------------------------------------------------------*/
00083 #define AIRCR_VECTKEY_MASK    ((uint32_t)0x05FA0000)
00084 
00085 /* Private macro -------------------------------------------------------------*/
00086 /* Private variables ---------------------------------------------------------*/
00087 /* Private function prototypes -----------------------------------------------*/
00088 /* Private functions ---------------------------------------------------------*/
00089 
00090 /** @defgroup MISC_Private_Functions
00091   * @{
00092   */
00093 
00094 /**
00095   * @brief  Configures the priority grouping: pre-emption priority and subpriority.
00096   * @param  NVIC_PriorityGroup: specifies the priority grouping bits length. 
00097   *   This parameter can be one of the following values:
00098   *     @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
00099   *                                4 bits for subpriority
00100   *     @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
00101   *                                3 bits for subpriority
00102   *     @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
00103   *                                2 bits for subpriority
00104   *     @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
00105   *                                1 bits for subpriority
00106   *     @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
00107   *                                0 bits for subpriority
00108   * @note   When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible. 
00109   *         The pending IRQ priority will be managed only by the subpriority. 
00110   * @retval None
00111   */
00112 void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
00113 {
00114   /* Check the parameters */
00115   assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
00116   
00117   /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
00118   SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
00119 }
00120 
00121 /**
00122   * @brief  Initializes the NVIC peripheral according to the specified
00123   *         parameters in the NVIC_InitStruct.
00124   * @note   To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
00125   *         function should be called before. 
00126   * @param  NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
00127   *         the configuration information for the specified NVIC peripheral.
00128   * @retval None
00129   */
00130 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
00131 {
00132   uint8_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
00133   
00134   /* Check the parameters */
00135   assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
00136   assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));  
00137   assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
00138     
00139   if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
00140   {
00141     /* Compute the Corresponding IRQ Priority --------------------------------*/    
00142     tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
00143     tmppre = (0x4 - tmppriority);
00144     tmpsub = tmpsub >> tmppriority;
00145 
00146     tmppriority = NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
00147     tmppriority |=  (uint8_t)(NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub);
00148         
00149     tmppriority = tmppriority << 0x04;
00150         
00151     NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
00152     
00153     /* Enable the Selected IRQ Channels --------------------------------------*/
00154     NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
00155       (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
00156   }
00157   else
00158   {
00159     /* Disable the Selected IRQ Channels -------------------------------------*/
00160     NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
00161       (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
00162   }
00163 }
00164 
00165 /**
00166   * @brief  Sets the vector table location and Offset.
00167   * @param  NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
00168   *   This parameter can be one of the following values:
00169   *     @arg NVIC_VectTab_RAM: Vector Table in internal SRAM.
00170   *     @arg NVIC_VectTab_FLASH: Vector Table in internal FLASH.
00171   * @param  Offset: Vector Table base offset field. This value must be a multiple of 0x200.
00172   * @retval None
00173   */
00174 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
00175 { 
00176   /* Check the parameters */
00177   assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
00178   assert_param(IS_NVIC_OFFSET(Offset));  
00179    
00180   SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
00181 }
00182 
00183 /**
00184   * @brief  Selects the condition for the system to enter low power mode.
00185   * @param  LowPowerMode: Specifies the new mode for the system to enter low power mode.
00186   *   This parameter can be one of the following values:
00187   *     @arg NVIC_LP_SEVONPEND: Low Power SEV on Pend.
00188   *     @arg NVIC_LP_SLEEPDEEP: Low Power DEEPSLEEP request.
00189   *     @arg NVIC_LP_SLEEPONEXIT: Low Power Sleep on Exit.
00190   * @param  NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
00191   * @retval None
00192   */
00193 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
00194 {
00195   /* Check the parameters */
00196   assert_param(IS_NVIC_LP(LowPowerMode));
00197   assert_param(IS_FUNCTIONAL_STATE(NewState));  
00198   
00199   if (NewState != DISABLE)
00200   {
00201     SCB->SCR |= LowPowerMode;
00202   }
00203   else
00204   {
00205     SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
00206   }
00207 }
00208 
00209 /**
00210   * @brief  Configures the SysTick clock source.
00211   * @param  SysTick_CLKSource: specifies the SysTick clock source.
00212   *   This parameter can be one of the following values:
00213   *     @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
00214   *     @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
00215   * @retval None
00216   */
00217 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
00218 {
00219   /* Check the parameters */
00220   assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
00221   if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
00222   {
00223     SysTick->CTRL |= SysTick_CLKSource_HCLK;
00224   }
00225   else
00226   {
00227     SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
00228   }
00229 }
00230 
00231 /**
00232   * @}
00233   */
00234 
00235 /**
00236   * @}
00237   */
00238 
00239 /**
00240   * @}
00241   */
00242 
00243 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
00244