2024-12-20 22:45:12 +00:00
|
|
|
#include <bcm.h> /* for ARM_SYSTIMER_CLO */
|
|
|
|
#include <mem.h> /* for read32() */
|
|
|
|
#include <stdint.h> /* for uint32_t */
|
|
|
|
#include <timer.h> /* for CLOCKHZ */
|
|
|
|
|
|
|
|
void gilbraltar_delay_hot_loop(uint32_t cycle) {
|
|
|
|
volatile uint32_t v;
|
|
|
|
for (v = 0; v < cycle; v++)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gilbraltar_delay_us(uint32_t us) {
|
|
|
|
if (us > 0) {
|
|
|
|
uint32_t ticks = us * (CLOCKHZ / 1000000) + 1;
|
|
|
|
uint32_t s = read32(ARM_SYSTIMER_CLO);
|
|
|
|
|
|
|
|
while (read32(ARM_SYSTIMER_CLO) - s < ticks)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gilbraltar_delay_ms(uint32_t ms) {
|
|
|
|
if (ms > 0)
|
|
|
|
gilbraltar_delay_us(ms * 1000);
|
|
|
|
}
|
2025-01-12 19:06:40 +00:00
|
|
|
|
|
|
|
uint32_t gilbraltar_system_clock(void) {
|
|
|
|
return (read32(ARM_SYSTIMER_CLO)); // TODO(dinosaure): CLOCKHZ?
|
|
|
|
}
|