TM STM32Fxxx HAL Libraries  v1.0.0
Libraries for STM32Fxxx (F0, F4 and F7 series) devices based on HAL drivers from ST from Tilen Majerle
tm_stm32_delay.h
1 
37 #ifndef TM_DELAY_H
38 #define TM_DELAY_H 100
39 
40 /* C++ detection */
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
92 #include "stm32fxxx_hal.h"
93 #include "defines.h"
94 #include "stdlib.h"
95 
106 #ifndef DELAY_MAX_CUSTOM_TIMERS
107 #define DELAY_MAX_CUSTOM_TIMERS 5
108 #endif
109 
110 /* Memory allocation function */
111 #ifndef LIB_ALLOC_FUNC
112 #define LIB_ALLOC_FUNC malloc
113 #endif
114 
115 /* Memory free function */
116 #ifndef LIB_FREE_FUNC
117 #define LIB_FREE_FUNC free
118 #endif
119 
133 typedef struct _TM_DELAY_Timer_t {
134  union {
135  struct {
136  uint8_t AREN:1;
137  uint8_t CNTEN:1;
138  } F;
139  uint8_t FlagsVal;
140  } Flags;
141  uint32_t ARR;
142  uint32_t CNT;
143  void (*Callback)(struct _TM_DELAY_Timer_t*, void *);
146 
157 extern __IO uint32_t TM_Time;
158 extern __IO uint32_t TM_Time2;
159 
177 uint32_t TM_DELAY_Init(void);
178 
184 __STATIC_INLINE void Delay(__IO uint32_t micros) {
185 #if !defined(STM32F0xx)
186  uint32_t start = DWT->CYCCNT;
187 
188  /* Go to number of cycles for system */
189  micros *= (HAL_RCC_GetHCLKFreq() / 1000000);
190 
191  /* Delay till end */
192  while ((DWT->CYCCNT - start) < micros);
193 #else
194  /* Go to clock cycles */
195  micros *= (SystemCoreClock / 1000000) / 5;
196 
197  /* Wait till done */
198  while (micros--);
199 #endif
200 }
201 
207 __STATIC_INLINE void Delayms(uint32_t millis) {
208  /* Use HAL library for delay ms purpose */
209  HAL_Delay(millis);
210 }
211 
217 #define TM_DELAY_Time() (TM_Time)
218 
224 #define TM_DELAY_SetTime(time) (TM_Time = (time))
225 
232 #define TM_DELAY_Time2() (TM_Time2)
233 
240 #define TM_DELAY_SetTime2(time) (TM_Time2 = (time))
241 
258 TM_DELAY_Timer_t* TM_DELAY_TimerCreate(uint32_t ReloadValue, uint8_t AutoReloadCmd, uint8_t StartTimer, void (*TM_DELAY_CustomTimerCallback)(struct _TM_DELAY_Timer_t*, void *), void* UserParameters);
259 
266 
273 
280 
287 
296 
304 TM_DELAY_Timer_t* TM_DELAY_TimerAutoReloadValue(TM_DELAY_Timer_t* Timer, uint32_t AutoReloadValue);
305 
317 void TM_DELAY_1msHandler(void);
318 
331 /* C++ detection */
332 #ifdef __cplusplus
333 }
334 #endif
335 
336 #endif
__STATIC_INLINE void Delay(__IO uint32_t micros)
Delays for amount of micro seconds.
Definition: tm_stm32_delay.h:184
Custom timer structure.
Definition: tm_stm32_delay.h:133
TM_DELAY_Timer_t * TM_DELAY_TimerAutoReloadCommand(TM_DELAY_Timer_t *Timer, uint8_t AutoReloadCmd)
Sets auto reload feature for timer.
TM_DELAY_Timer_t * TM_DELAY_TimerStop(TM_DELAY_Timer_t *Timer)
Stops custom timer from counting.
uint8_t CNTEN
Definition: tm_stm32_delay.h:137
TM_DELAY_Timer_t * TM_DELAY_TimerCreate(uint32_t ReloadValue, uint8_t AutoReloadCmd, uint8_t StartTimer, void(*TM_DELAY_CustomTimerCallback)(struct _TM_DELAY_Timer_t *, void *), void *UserParameters)
Creates a new custom timer which has 1ms resolution.
void(* Callback)(struct _TM_DELAY_Timer_t *, void *)
Definition: tm_stm32_delay.h:143
void TM_DELAY_TimerDelete(TM_DELAY_Timer_t *Timer)
Deletes already allocated timer.
struct _TM_DELAY_Timer_t TM_DELAY_Timer_t
Custom timer structure.
TM_DELAY_Timer_t * TM_DELAY_TimerAutoReloadValue(TM_DELAY_Timer_t *Timer, uint32_t AutoReloadValue)
Sets auto reload value for timer.
TM_DELAY_Timer_t * TM_DELAY_TimerReset(TM_DELAY_Timer_t *Timer)
Resets custom timer counter value.
uint32_t CNT
Definition: tm_stm32_delay.h:142
TM_DELAY_Timer_t * TM_DELAY_TimerStart(TM_DELAY_Timer_t *Timer)
Starts custom timer counting.
uint32_t ARR
Definition: tm_stm32_delay.h:141
__STATIC_INLINE void Delayms(uint32_t millis)
Delays for amount of milli seconds.
Definition: tm_stm32_delay.h:207
void TM_DELAY_1msHandler(void)
User function, called each 1ms when interrupt from timer happen.
uint32_t TM_DELAY_Init(void)
Initializes delay functions.
void * UserParameters
Definition: tm_stm32_delay.h:144
uint8_t AREN
Definition: tm_stm32_delay.h:136