12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #ifndef IO_H
- #define IO_H
- #include <stdint.h>
- #include <stdarg.h>
- #include <stdbool.h>
- #include "ioregs.h"
- #include "picorv32.h"
- static inline void pause(void)
- {
-
- }
- static inline void set_led(uint8_t leds)
- {
- SYS_LED = leds;
- }
- static inline void __attribute__((noreturn)) reset(void)
- {
- p_maskirq(~0, 0);
- for (;;)
- asm volatile("ebreak");
- }
- extern const uint32_t time_zero;
- 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 ((uint64_t)(((int32_t)l < 0) ? h1 : h0) << 32) + l;
- }
- static inline void udelay(uint32_t us)
- {
- uint32_t cycles = us * (CPU_HZ / 1000000);
- uint32_t start = rdtime();
- while (rdtime() - start < cycles)
- pause();
- }
- static inline void i2c_set_speed(unsigned int khz)
- {
- I2C_DIVISOR = ((CPU_HZ/4000)-1)/khz;
- }
- #endif
|