/** * @brief Delay x sec * @param Seconds : number of seconds to delay * @retval None. * Note : TIM4 is configured for a system clock = 2MHz */ void Delay_Seconds(uint8_t Seconds) { uint8_t i = 0; /* Enable TIM4 Clock */ CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE); /* Configure TIM4 to generate an update event each 1 s */ TIM4_TimeBaseInit(TIM4_Prescaler_16384, 123); /* Enable TIM4 */ TIM4_Cmd(ENABLE); /* Clear the Flag */ TIM4_ClearFlag(TIM4_FLAG_Update); for (i = 0; i < Seconds; i++) { /* Wait 1 sec */ while ( TIM4_GetFlagStatus(TIM4_FLAG_Update) == RESET ) {} /* Clear the Flag */ TIM4_ClearFlag(TIM4_FLAG_Update); } /* Disable TIM4 */ TIM4_Cmd(DISABLE); /* Disable TIM4 Clock */ CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, DISABLE); }
bool CAN_Node_Clock_check_pending(void) { if (TIM4_GetFlagStatus(TIM4_FLAG_UPDATE) == RESET) return FALSE; TIM4_ClearFlag(TIM4_FLAG_UPDATE); if (--clock_counter == 0) { clock_counter = ClockPostscaler; return TRUE; } //bool result = clock_pending; //clock_pending = FALSE; //return result; return FALSE; }
/** * @brief Wait 1 sec for LSE stabilisation . * @param None. * @retval None. * Note : TIM4 is configured for a system clock = 2MHz */ void LSE_StabTime(void) { CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, ENABLE); /* Configure TIM4 to generate an update event each 1 s */ TIM4_TimeBaseInit(TIM4_Prescaler_16384, 123); /* Enable TIM4 */ TIM4_Cmd(ENABLE); /* Wait 1 sec */ while ( TIM4_GetFlagStatus(TIM4_FLAG_Update) == RESET ); TIM4_ClearFlag(TIM4_FLAG_Update); /* Disable TIM4 */ TIM4_Cmd(DISABLE); CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, DISABLE); }