Example #1
0
/**-----------------------------------------------------------------------------
 * @brief	Tick watchdog.
 *
 */
void WDG_Tick(){


	WWDG_SetCounter(0x7F);	// Evite de generer une nouvelle IT

	// Decrementation du compteur
	if (WWDG_Cnt >= WWDG_TICK_DELAI_ms) {

		WWDG_Cnt -= WWDG_TICK_DELAI_ms;
	}
	else {
		WWDG_Cnt = 0;
	}

	// Verification Zero atteint
	if (WWDG_Cnt == 0) {

		WWDG_SetCounter(0x40);
		// Attente reboot
		while(1);
	}

	// Relance watchdog
	WWDG_SetCounter(0x7F);

}
Example #2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{

  /* Initialize LED1 and LED2 mounted on STM8L152X-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);

  /* Initialize Key and Joystick down push-buttons mounted on STM8L152X-EVAL board */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
  STM_EVAL_PBInit(BUTTON_DOWN, BUTTON_MODE_EXTI);

  /* enable interrupts */
  enableInterrupts();

  /* Check if the MCU has resumed from WWDG reset */
  if (RST_GetFlagStatus(RST_FLAG_WWDGF) != RESET)
  {
    /* WWDGF flag set */
    /* Toggle LED1 */
    for (Index = 7; Index != 0; Index--)
    {
      STM_EVAL_LEDToggle(LED1);
      Delay(0x7FFF);
    }
    /* Clear WWDGF Flag */
    RST_ClearFlag(RST_FLAG_WWDGF);
  }

  /* WWDG Configuration */
  WWDG_Config();

  while (1)
  {
    /* Check if WWDG counter refresh is allowed in Allowed window */
    if (AllowedRefresh != DISABLE)
    {
      /* get WWDG counter value */
      /* wait until WWDG counter becomes lower than window value */
      while ((WWDG_GetCounter() & 0x7F) > WINDOW_VALUE);
      /* Refresh WWDG counter during allowed window so no MCU reset will occur */
      WWDG_SetCounter(COUNTER_INIT);
    }

    /* Check if WWDG counter refresh is allowed in non Allowed window */
    if (NonAlowedRefresh != DISABLE)
    {
      /* wait until WWDG counter becomes higher than window value */
      while ((WWDG_GetCounter() & 0x7F) < WINDOW_VALUE);
      /* Refresh WWDG counter during non allowed window so MCU reset will occur */
      WWDG_SetCounter(COUNTER_INIT);
    }
    /* Toggle LED2 */
    STM_EVAL_LEDToggle(LED2);
    Delay(0x6FFF);
  }
}
Example #3
0
/*************************************************************
 * WWDT Initialization
**************************************************************/
void WWDG_Init()
{

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
	
    // Deinitializes WWDG peripheral registers 
	#if(STRCMP($ResetEn$, DISABLE) == 0)
	   WWDG_DeInit();
	#endif
	

    // Sets Prescaler value of the WWDG.
    WWDG_SetPrescaler($PreValue$);

    // Sets Window value of the WWDG.
    WWDG_SetWindowValue($WindowValue$);

    // Sets Counter value of the WWDG.
    WWDG_SetCounter($CounterValue$);
	
    // Enable WWDG and set counter value
    WWDG_Enable($CounterValue$);

	   //Enable EW interrupt
	#if((STRCMP($IntEn$,DISABLE)) == 0)
    WWDG_ClearFlag();
    WWDG_EnableIT();
	#endif
    

}
Example #4
0
static void wd_reset(void)
{
	// Init WD
	if(!wd_init_enabled)
	{
		// Start watchdog
		WWDG_Enable(WD_REFRESH_COUNTER);

		// Reset
		wd_init_enabled = 1;
		TimingDelay 	= 0;

		return;
	}

	// 40mS flag for WD reset
	if(TimingDelay > 40)
	{
		TimingDelay = 0;
		//GREEN_LED_PIO->ODR ^= RED_LED;

		// Update WWDG counter
		WWDG_SetCounter(WD_REFRESH_COUNTER);
	}
}
extern hal_result_t hal_watchdog_refresh(hal_watchdog_t id)
{
    hal_watchdog_internal_item_t* intitem = s_hal_watchdog_theinternals.items[HAL_watchdog_id2index(id)];
    hal_result_t res = hal_res_NOK_generic;

    if(hal_false == s_hal_watchdog_initted_is(id))
    {
        return(hal_res_NOK_generic);
    }


    switch(id)
    {
        case hal_watchdog1_normal:
        {
            IWDG_ReloadCounter();
            res = hal_res_OK;
        } break;

        case hal_watchdog2_window:
        {
            WWDG_SetCounter(intitem->reload);
            res = hal_res_OK;
        } break;

        default:
        {
            res = hal_res_NOK_generic;
        } break;
    }

    return(res);

}
Example #6
0
THD_FUNCTION(Thread0, arg)
{
    (void)arg;
    if (RCC->CSR & RCC_CSR_WWDGRSTF)
    {
        /* WWDGRST flag set */
        serDbg("\r\n**WWDG Reset!**\r\n\r\n");

        /* Clear reset flags */
        RCC->CSR |= RCC_CSR_RMVF;
    }

    /* WWDG clock counter = (PCLK1 (48MHz)/4096)/8 = 1464Hz (~683 us)  */
    WWDG_SetPrescaler(WWDG_Prescaler_8);

    /* Set Window value to 126; WWDG counter should be refreshed only when the counter
    is below 126 (and greater than 64) otherwise a reset will be generated */
    WWDG_SetWindowValue(126);

    /* Freeze WWDG while core is stopped */
    DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_WWDG_STOP;

    /* Enable WWDG and set counter value to 127, WWDG timeout = ~683 us * 64 = 43.7 ms
    In this case the refresh window is: ~683 * (127-126)= 0.683ms < refresh window < ~683 * 64 = 43.7ms
    */
    WWDG_Enable(127);
    serDbg("WWDG Started\r\n");
    while (true)
    {
        chThdSleepMilliseconds(25);
        palTogglePad(GPIOC, GPIOC_LED3); /* Watchdog heartbeat */
        WWDG_SetCounter(127);
    }
}
Example #7
0
void WWDG_IRQHandler(void)
{
	u8 i;
	WWDG_SetCounter(WWDG_CNT); //重设窗口看门狗值
	WWDG_ClearFlag();          //清除提前唤醒中断标志	
	for(i=0;i<4;i++);          //此处延时一下,等寄存器稳定
}
Example #8
0
/*}*/
void WWDG_IRQHandler(void)
{
    WWDG_SetCounter(0x7F);
    WWDG_ClearFlag();
    PRINTD ("wdg irq\n\r");
    /* led1_toggle(); */
}
Example #9
0
void WWDG_IRQHandler(void)
{
  /* Update WWDG counter */
  WWDG_SetCounter(0x50);
	
  /* Clear EWI flag */
  WWDG_ClearFlag(); 
}
Example #10
0
void WWDG_IRQHandler(void)
{

    WWDG_SetCounter(0x7F);	  //当禁掉此句后,窗口看门狗将产生复位

    WWDG_ClearFlag();	  //清除提前唤醒中断标志位

    LED1=!LED1;
}
Example #11
0
void WWDG_IRQHandler (void)
{	
	if(WWDG_GetFlagStatus())
	{
		WWDG_ClearFlag();
		WWDG_SetCounter(0x66);
	}
	uart_printf("WWDG interrupt OK!\r\n");	
}
void WWDG_IRQHandler(void)
	{
	// Update WWDG counter
	WWDG_SetCounter(0x7F);	  //当禁掉此句后,窗口看门狗将产生复位
	// Clear EWI flag */
	WWDG_ClearFlag();	  //清除提前唤醒中断标志位
	// Toggle GPIO_Led pin 7 */
	LED1=!LED1;
	}
Example #13
0
/**
  * @brief  This function handles WWDG interrupt request.
  * @param  None
  * @retval None
  */
void WWDG_IRQHandler(void)
{
  /* Update WWDG counter */
  WWDG_SetCounter(0x7F);

  /* Clear EWI flag */
  WWDG_ClearFlag();

  /* Toggle LED2 */
  STM_EVAL_LEDToggle(LED2);
}
/*******************************************************************************
* Function Name  : WWDG_IRQHandler
* Description    : This function handles WWDG interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void WWDG_IRQHandler(void)
{
  /* Update WWDG counter */
  WWDG_SetCounter(0x7F);

  /* Clear EWI flag */
  WWDG_ClearFlag();

  /* Toggle GPIO_Led pin 7 */
  GPIO_WriteBit(GPIO_LED, GPIO_Pin_7, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIO_LED, GPIO_Pin_7)));
}
Example #15
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f0xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f0xx.c file
     */ 
  /* Initialize LEDs and Tamper Button mounted on EVAL board */       
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI);

  /* Check if the system has resumed from WWDG reset */
  if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
  { 
    /* WWDGRST flag set */
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);

    /* Clear reset flags */
    RCC_ClearFlag();
  }
  else
  {
    /* WWDGRST flag is not set */
    /* Turn off LED1 */
    STM_EVAL_LEDOff(LED1);
   }
  
  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(SystemCoreClock / 1000))
  { 
    /* Capture error */ 
    while (1)
    {}
  }
  
  /* Configure WWDG */
  WWDG_Config();
   
  while (1)
  {
    /* Toggle LED2 */
    STM_EVAL_LEDToggle(LED2);

    /* Insert 33 ms delay */
    Delay(33);

    /* Update WWDG counter */
    WWDG_SetCounter(127);
  }
}
void PhotonWdgs::_tickleWDGs()
{
    if(_aliveCount < PhotonWdgs::_timeoutval) {
        if(PhotonWdgs::_wwdgRunning) {
            WWDG_SetCounter(0x7F);
        }
        if(PhotonWdgs::_iwdgRunning) {
            IWDG_ReloadCounter();
        }
        PhotonWdgs::_aliveCount++;
    }
    // deactivate WWDG if OTA updates pending
    if(System.updatesPending()) {
        if(PhotonWdgs::_wwdgRunning) {
            WWDG_DeInit();
        }
        System.enableUpdates();
        PhotonWdgs::_wdgTimer.end();
    }
}
static void WWDG_Feed(void)
{
    WWDG_SetCounter(WWDG_CNT);	  //当禁掉此句后,窗口看门狗将产生复位
    //WWDG_ClearFlag();	  //清除提前唤醒中断标志位
}
Example #18
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void WWDG_Example(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f30x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f30x.c file
     */
     
  /* Initialize LEDs and Key Button mounted on STM32303C-EVAL board */       
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);

  /* Check if the system has resumed from WWDG reset */
  if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
  { 
    /* WWDGRST flag set */
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);

    /* Clear reset flags */
    RCC_ClearFlag();
  }
  else
  {
    /* WWDGRST flag is not set */
    /* Turn off LED1 */
    STM_EVAL_LEDOff(LED1);
   }
  
  /* Setup SysTick Timer for 1 msec interrupts  */
  if (SysTick_Config(SystemCoreClock / 1000))
  { 
    /* Capture error */ 
    while (1)
    {}
  }

/* WWDG configuration */
  /* Enable WWDG clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

  /* WWDG clock counter = (PCLK1 (36MHz)/4096)/8 = 1098Hz (~910 us)  */
  WWDG_SetPrescaler(WWDG_Prescaler_8);

  /* Set Window value to 80; WWDG counter should be refreshed only when the counter
    is below 80 (and greater than 64) otherwise a reset will be generated */
  WWDG_SetWindowValue(80);

  /* Enable WWDG and set counter value to 127, WWDG timeout = ~910 us * 64 = 58.24 ms 
    In this case the refresh window is: ~910 * (127-80) = 42.7ms < refresh window < ~910 * 64 = 58.2ms
  */
  WWDG_Enable(127);
   
  while (1)
  {
    /* Toggle LED2 */
    STM_EVAL_LEDToggle(LED2);

    /* Insert 43 ms delay */
    Delay(43);

    /* Update WWDG counter */
    WWDG_SetCounter(127);
  }
}
Example #19
0
/**-----------------------------------------------------------------------------
 * @brief	Rafraichissement du watchdog.
 *
 */
void  WDG_Refresh(){
	IWDG_ReloadCounter();

	WWDG_SetCounter(0x7F);
	WWDG_Cnt = WWDG_Reload;
}
Example #20
0
/*
*********************************************************************************************************
*	函 数 名: Wwdg_Feed
*	功能说明: 窗口看门狗超喂狗函数。
*	形    参:  
*	返 回 值: 无
*********************************************************************************************************
*/
void Wwdg_Feed(void)
{
    WWDG_SetCounter(WWDG_RELOAD_VALUE);
}
Example #21
0
void isr_wdg(InterruptVector vector)
{
	WWDG_SetCounter(0x7F);
}