io.h 618 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef IO_H
  2. #define IO_H
  3. #include "iodev.h"
  4. static inline void set_led(uint8_t leds)
  5. {
  6. LED = leds;
  7. }
  8. static inline uint32_t rdtime(void)
  9. {
  10. uint32_t t;
  11. asm volatile("rdtime %0" : "=r" (t));
  12. return t;
  13. }
  14. static inline uint64_t rdtimeq(void)
  15. {
  16. uint32_t l, h1, h0;
  17. asm volatile("rdtimeh %0; rdtime %1; %rdtimeh %2"
  18. : "=r" (h1), "=r" (l), "=r" (h0));
  19. return ((int32_t)l < 0) ? h1 : h0;
  20. }
  21. static inline void udelay(uint32_t us)
  22. {
  23. uint32_t cycles = us * (CPU_CLK_HZ / 1000000);
  24. uint32_t start = rdtime();
  25. while (rdtime() - start < cycles)
  26. /* wait */;
  27. }
  28. #endif /* IO_H */