86 lines
2.4 KiB
C++
Executable File
86 lines
2.4 KiB
C++
Executable File
//
|
|
// Created by zong on 11/20/22.
|
|
//
|
|
// only support for max 26 second
|
|
|
|
#ifndef DCMI_DELAY_H
|
|
#define DCMI_DELAY_H
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "stdint.h"
|
|
#include <stdbool.h>
|
|
#include "global_variable.h"
|
|
#include "stm32u5xx.h"
|
|
|
|
void delay_init();
|
|
|
|
void delay_tick(uint32_t tick, bool allow_irq);
|
|
|
|
void delay_us(uint32_t microsecond, bool allow_irq);
|
|
|
|
void delay_ms(uint32_t millisecond, bool allow_irq);
|
|
|
|
void delay_s(uint32_t second, bool allow_irq);
|
|
|
|
void timeout_setup(uint32_t milliseconds);
|
|
|
|
bool timeout_test();
|
|
|
|
bool timeout_ok();
|
|
|
|
bool timeout_ms(uint32_t start, uint32_t timeout);
|
|
|
|
uint32_t dwt_get_current_cycle();
|
|
|
|
bool timeout_us(uint32_t start, uint32_t timeout);
|
|
|
|
extern uint32_t cnt_per_ms;
|
|
|
|
#define wait_for_true(value, timeout_ms) \
|
|
bool timeout = false; \
|
|
{ \
|
|
uint32_t _start = DWT->CYCCNT; \
|
|
uint32_t _timeout = (uint32_t)(cnt_per_ms * (double)(timeout_ms)); \
|
|
while ((value) == 0) { \
|
|
if ((timeout_ms) != 0 && _timeout < (DWT->CYCCNT - _start)){ \
|
|
timeout = true; \
|
|
break; \
|
|
} \
|
|
} \
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
|
|
#ifdef __cplusplus
|
|
class Delay {
|
|
private:
|
|
// 4294967295/160000000 = 26.84s
|
|
uint32_t cnt_per_s = 0;
|
|
uint32_t cnt_per_ms = 0;
|
|
uint32_t cnt_per_us = 0;
|
|
uint32_t max_time_ms = 0;
|
|
uint32_t max_time_us = 0;
|
|
uint32_t max_time_s = 0;
|
|
uint32_t max_time_tick = UINT32_MAX;
|
|
|
|
public:
|
|
Delay();
|
|
|
|
void setup();
|
|
|
|
void us(uint32_t us, bool allow_irq = true) const;
|
|
|
|
void ms(uint32_t ms, bool allow_irq = true) const;
|
|
|
|
void s(uint32_t s, bool allow_irq = true) const;
|
|
|
|
static void tick(uint32_t tick, bool allow_irq = true);
|
|
};
|
|
#endif
|
|
#endif // DCMI_DELAY_H
|