Contiki 2.6

stm32w_systick.c

00001 /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
00002 * File Name          : stm32w108_systick.c
00003 * Author             : MCD Application Team
00004 * Version            : V2.0.3
00005 * Date               : 09/22/2008
00006 * Description        : This file provides all the SysTick firmware functions.
00007 ********************************************************************************
00008 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00009 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
00010 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
00011 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
00012 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
00013 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00014 *******************************************************************************/
00015 
00016 /* Includes ------------------------------------------------------------------*/
00017 #include "stm32w_systick.h"
00018 
00019 /* Private typedef -----------------------------------------------------------*/
00020 /* Private define ------------------------------------------------------------*/
00021 /* ---------------------- SysTick registers bit mask -------------------- */
00022 /* CTRL TICKINT Mask */
00023 #define CTRL_TICKINT_Set      ((u32)0x00000002)
00024 #define CTRL_TICKINT_Reset    ((u32)0xFFFFFFFD)
00025 
00026 /* Private macro -------------------------------------------------------------*/
00027 /* Private variables ---------------------------------------------------------*/
00028 /* Private function prototypes -----------------------------------------------*/
00029 /* Private functions ---------------------------------------------------------*/
00030 
00031 /*******************************************************************************
00032 * Function Name  : SysTick_CLKSourceConfig
00033 * Description    : Configures the SysTick clock source.
00034 * Input          : - SysTick_CLKSource: specifies the SysTick clock source.
00035 *                    This parameter can be one of the following values:
00036 *                       - SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8
00037 *                         selected as SysTick clock source.
00038 *                       - SysTick_CLKSource_HCLK: AHB clock selected as
00039 *                         SysTick clock source.
00040 * Output         : None
00041 * Return         : None
00042 *******************************************************************************/
00043 void SysTick_CLKSourceConfig(u32 SysTick_CLKSource)
00044 {
00045   /* Check the parameters */
00046   assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
00047 
00048   if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
00049   {
00050     SysTick->CTRL |= SysTick_CLKSource_HCLK;
00051   }
00052   else
00053   {
00054     SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
00055   }
00056 }
00057 
00058 /*******************************************************************************
00059 * Function Name  : SysTick_SetReload
00060 * Description    : Sets SysTick Reload value.
00061 * Input          : - Reload: SysTick Reload new value.
00062 *                    This parameter must be a number between 1 and 0xFFFFFF.
00063 * Output         : None
00064 * Return         : None
00065 *******************************************************************************/
00066 void SysTick_SetReload(u32 Reload)
00067 {
00068   /* Check the parameters */
00069   assert_param(IS_SYSTICK_RELOAD(Reload));
00070 
00071   SysTick->LOAD = Reload;
00072 }
00073 
00074 /*******************************************************************************
00075 * Function Name  : SysTick_CounterCmd
00076 * Description    : Enables or disables the SysTick counter.
00077 * Input          : - SysTick_Counter: new state of the SysTick counter.
00078 *                    This parameter can be one of the following values:
00079 *                       - SysTick_Counter_Disable: Disable counter
00080 *                       - SysTick_Counter_Enable: Enable counter
00081 *                       - SysTick_Counter_Clear: Clear counter value to 0
00082 * Output         : None
00083 * Return         : None
00084 *******************************************************************************/
00085 void SysTick_CounterCmd(u32 SysTick_Counter)
00086 {
00087   /* Check the parameters */
00088   assert_param(IS_SYSTICK_COUNTER(SysTick_Counter));
00089 
00090   if (SysTick_Counter == SysTick_Counter_Enable)
00091   {
00092     SysTick->CTRL |= SysTick_Counter_Enable;
00093   }
00094   else if (SysTick_Counter == SysTick_Counter_Disable) 
00095   {
00096     SysTick->CTRL &= SysTick_Counter_Disable;
00097   }
00098   else /* SysTick_Counter == SysTick_Counter_Clear */
00099   {
00100     SysTick->VAL = SysTick_Counter_Clear;
00101   }    
00102 }
00103 
00104 /*******************************************************************************
00105 * Function Name  : SysTick_ITConfig
00106 * Description    : Enables or disables the SysTick Interrupt.
00107 * Input          : - NewState: new state of the SysTick Interrupt.
00108 *                    This parameter can be: ENABLE or DISABLE.
00109 * Output         : None
00110 * Return         : None
00111 *******************************************************************************/
00112 void SysTick_ITConfig(FunctionalState NewState)
00113 {
00114   /* Check the parameters */
00115   assert_param(IS_FUNCTIONAL_STATE(NewState));
00116 
00117   if (NewState != DISABLE)
00118   {
00119     SysTick->CTRL |= CTRL_TICKINT_Set;
00120   }
00121   else
00122   {
00123     SysTick->CTRL &= CTRL_TICKINT_Reset;
00124   }
00125 }
00126 
00127 /*******************************************************************************
00128 * Function Name  : SysTick_GetCounter
00129 * Description    : Gets SysTick counter value.
00130 * Input          : None
00131 * Output         : None
00132 * Return         : SysTick current value
00133 *******************************************************************************/
00134 u32 SysTick_GetCounter(void)
00135 {
00136   return(SysTick->VAL);
00137 }
00138 
00139 /*******************************************************************************
00140 * Function Name  : SysTick_GetFlagStatus
00141 * Description    : Checks whether the specified SysTick flag is set or not.
00142 * Input          : - SysTick_FLAG: specifies the flag to check.
00143 *                    This parameter can be one of the following values:
00144 *                       - SysTick_FLAG_COUNT
00145 *                       - SysTick_FLAG_SKEW
00146 *                       - SysTick_FLAG_NOREF
00147 * Output         : None
00148 * Return         : None
00149 *******************************************************************************/
00150 FlagStatus SysTick_GetFlagStatus(u8 SysTick_FLAG)
00151 {
00152   u32 statusreg = 0, tmp = 0 ;
00153   FlagStatus bitstatus = RESET;
00154 
00155   /* Check the parameters */
00156   assert_param(IS_SYSTICK_FLAG(SysTick_FLAG));
00157 
00158   /* Get the SysTick register index */
00159   tmp = SysTick_FLAG >> 3;
00160 
00161   if (tmp == 2) /* The flag to check is in CTRL register */
00162   {
00163     statusreg = SysTick->CTRL;
00164   }
00165   else          /* The flag to check is in CALIB register */
00166   {
00167     statusreg = SysTick->CALIB;
00168   }
00169 
00170   if ((statusreg & ((u32)1 << SysTick_FLAG)) != (u32)RESET)
00171   {
00172     bitstatus = SET;
00173   }
00174   else
00175   {
00176     bitstatus = RESET;
00177   }
00178   return bitstatus;
00179 }
00180 
00181 /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/