X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/4c6d990440cdba6c7dd294adb7e435770ffcbcc4..01a605198da7bc5883a3dfa96b38f4f7c04f67f9:/lunaix-os/includes/lunaix/spike.h diff --git a/lunaix-os/includes/lunaix/spike.h b/lunaix-os/includes/lunaix/spike.h index 0764822..cbdadfb 100644 --- a/lunaix-os/includes/lunaix/spike.h +++ b/lunaix-os/includes/lunaix/spike.h @@ -4,36 +4,60 @@ // Some helper functions. As helpful as Spike the Dragon! :) // 除法向上取整 -#define CEIL(v, k) (((v) + (1 << (k)) - 1) >> (k)) +#define CEIL(v, k) (((v) + (1 << (k)) - 1) >> (k)) // 除法向下取整 -#define FLOOR(v, k) ((v) >> (k)) +#define FLOOR(v, k) ((v) >> (k)) // 获取v最近的最大k倍数 -#define ROUNDUP(v, k) (((v) + (k) - 1) & ~((k) - 1)) +#define ROUNDUP(v, k) (((v) + (k)-1) & ~((k)-1)) // 获取v最近的最小k倍数 -#define ROUNDDOWN(v, k) ((v) & ~((k) - 1)) +#define ROUNDDOWN(v, k) ((v) & ~((k)-1)) -inline static void spin() { - while(1); +#define __USER__ __attribute__((section(".usrtext"))) + +inline static void +spin() +{ + while (1) + ; } #ifdef __LUNAIXOS_DEBUG__ -#define assert(cond) \ - if (!(cond)) { \ - __assert_fail(#cond, __FILE__, __LINE__); \ +#define assert(cond) \ + if (!(cond)) { \ + __assert_fail(#cond, __FILE__, __LINE__); \ } -#define assert_msg(cond, msg) \ - if (!(cond)) { \ - __assert_fail(msg, __FILE__, __LINE__); \ +#define assert_msg(cond, msg) \ + if (!(cond)) { \ + __assert_fail(msg, __FILE__, __LINE__); \ } -void __assert_fail(const char* expr, const char* file, unsigned int line) __attribute__((noinline, noreturn)); +void +__assert_fail(const char* expr, const char* file, unsigned int line) + __attribute__((noinline, noreturn)); #else -#define assert(cond) //nothing +#define assert(cond) (void)(cond); // assert nothing +#define assert_msg(cond, msg) (void)(cond); // assert nothing #endif - +void +panick(const char* msg); + +#define wait_until(cond) \ + while (!(cond)) \ + ; +#define loop_until(cond) \ + while (!(cond)) \ + ; + +#define wait_until_expire(cond, max) \ + ({ \ + unsigned int __wcounter__ = (max); \ + while (!(cond) && __wcounter__-- > 0) \ + ; \ + __wcounter__; \ + }) #endif /* __LUNAIX_SPIKE_H */