#ifndef SW_DEVICE_LIB_UTIL_H_ | |
#define SW_DEVICE_LIB_UTIL_H_ | |
#include <stdbool.h> | |
#include <stdint.h> | |
#ifndef MIN | |
#define MIN(X, Y) (X < Y ? X : Y) | |
#endif | |
inline void cycle_count_enable(bool enable) { | |
unsigned int val = enable ? 0x0 : 0xFFFFFFFF; | |
asm volatile("csrw 0x320, %0" : : "r"(val)); | |
} | |
inline uint32_t cycle_count_read(void) { | |
uint32_t ret; | |
asm volatile("csrr %0, mcycle" : "=r"(ret)); | |
return ret; | |
} | |
#endif // SW_DEVICE_LIB_UTIL_H_ |