#ifndef IO_H #define IO_H #include "iodev.h" static inline void con_write(uint8_t c) { CONSOLE = c; } static inline void con_set_baudrate(uint32_t b) { uint32_t bauddiv = (CON_BAUD_BASE + (b >> 1))/b; CON_BAUDDIV = bauddiv ? bauddiv - 1 : 0; } static inline void set_led(uint8_t leds) { LED = leds; } static inline uint32_t rdtime(void) { uint32_t t; asm volatile("rdtime %0" : "=r" (t)); return t; } static inline uint64_t rdtimeq(void) { uint32_t l, h1, h0; asm volatile("rdtimeh %0; rdtime %1; %rdtimeh %2" : "=r" (h1), "=r" (l), "=r" (h0)); return ((int32_t)l < 0) ? h1 : h0; } static inline void udelay(uint32_t us) { uint32_t cycles = us * (CPU_CLK_HZ / 1000000); uint32_t start = rdtime(); while (rdtime() - start < cycles) /* wait */; } #endif /* IO_H */