io.h 723 B

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