#ifndef DELAY_H
#define DELAY_H
#include <stdint.h>
// TODO: define system clock well
/* #define SYSTEM_CLOCK ((uint32_t)360000000UL) */
#define SYSTEM_CLOCK ((uint32_t)64000000UL)
/* #define SYSTICK_CALIB 0x3E8 */
// Underflow every 1 us
#define SYSTICK_LOAD (SYSTEM_CLOCK/1000UL-1)
#define SYSTICK_DELAY_CALIB (SYSTICK_LOAD >> 1)
extern uint32_t us_ticks;
#define DELAY_US(us) \
do { \
for (int i = 0; i < 500000; i++); \
/* uint32_t start = us_ticks; \ */ \
/* while((us_ticks - start) < us); \ */ \
} while (0)
#define DELAY_MS(ms) \
do { \
for (int i = 0; i < 500000; i++); \
/* for (uint32_t i = 0; i < ms; ++i) { \ */ \
/* DELAY_US(1000); \ */ \
/* } \ */ \
} while (0)
void systick_configure();
#endif // DELAY_H