25#define GOLIOTH_SYS_WAIT_FOREVER -1
103#ifndef golioth_sys_malloc
104#define golioth_sys_malloc(sz) malloc((sz))
107#ifndef golioth_sys_free
108#define golioth_sys_free(ptr) free((ptr))
116#ifndef golioth_sys_srand
117#define golioth_sys_srand(seed) srand((seed))
120#ifndef golioth_sys_rand
121#define golioth_sys_rand() rand()
137#if defined(CONFIG_GOLIOTH_DEBUG_LOG)
142#define LOG_COLOR_RED "31"
143#define LOG_COLOR_GREEN "32"
144#define LOG_COLOR_BROWN "33"
145#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
146#define LOG_RESET_COLOR "\033[0m"
147#define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
148#define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
149#define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
154#define GLTH_LOGX(COLOR, LEVEL, LEVEL_STR, TAG, ...) \
157 if ((LEVEL) <= golioth_debug_get_log_level()) \
159 uint64_t now_ms = golioth_sys_now_ms(); \
160 printf(COLOR "%s (%" PRIu64 ") %s: ", LEVEL_STR, now_ms, TAG); \
161 printf(__VA_ARGS__); \
162 golioth_debug_printf(now_ms, LEVEL, TAG, __VA_ARGS__); \
163 printf("%s", LOG_RESET_COLOR); \
171#define GLTH_LOGV(TAG, ...) \
172 GLTH_LOGX(LOG_COLOR_V, GOLIOTH_DEBUG_LOG_LEVEL_VERBOSE, "V", TAG, __VA_ARGS__)
176#define GLTH_LOGD(TAG, ...) \
177 GLTH_LOGX(LOG_COLOR_D, GOLIOTH_DEBUG_LOG_LEVEL_DEBUG, "D", TAG, __VA_ARGS__)
181#define GLTH_LOGI(TAG, ...) \
182 GLTH_LOGX(LOG_COLOR_I, GOLIOTH_DEBUG_LOG_LEVEL_INFO, "I", TAG, __VA_ARGS__)
186#define GLTH_LOGW(TAG, ...) \
187 GLTH_LOGX(LOG_COLOR_W, GOLIOTH_DEBUG_LOG_LEVEL_WARN, "W", TAG, __VA_ARGS__)
191#define GLTH_LOGE(TAG, ...) \
192 GLTH_LOGX(LOG_COLOR_E, GOLIOTH_DEBUG_LOG_LEVEL_ERROR, "E", TAG, __VA_ARGS__)
195#ifndef GLTH_LOG_BUFFER_HEXDUMP
196#define GLTH_LOG_BUFFER_HEXDUMP(TAG, payload, size, level) \
199 if ((level) <= golioth_debug_get_log_level()) \
201 golioth_debug_hexdump(TAG, payload, size); \
208#define GLTH_LOGV(TAG, ...)
209#define GLTH_LOGD(TAG, ...)
210#define GLTH_LOGI(TAG, ...)
211#define GLTH_LOGW(TAG, ...)
212#define GLTH_LOGE(TAG, ...)
213#define GLTH_LOG_BUFFER_HEXDUMP(TAG, ...)
golioth_sys_sem_t golioth_sys_sem_create(uint32_t sem_max_count, uint32_t sem_initial_count)
bool golioth_sys_sem_give(golioth_sys_sem_t sem)
bool golioth_sys_timer_reset(golioth_sys_timer_t timer)
void * golioth_sys_thread_t
bool golioth_sys_timer_start(golioth_sys_timer_t timer)
bool golioth_sys_sem_take(golioth_sys_sem_t sem, int32_t ms_to_wait)
void golioth_sys_mutex_destroy(golioth_sys_mutex_t mutex)
void golioth_sys_client_connected(void *client)
void golioth_sys_timer_destroy(golioth_sys_timer_t timer)
golioth_sys_thread_t golioth_sys_thread_create(const struct golioth_thread_config *config)
void(* golioth_sys_thread_fn_t)(void *user_arg)
void golioth_sys_msleep(uint32_t ms)
golioth_sys_mutex_t golioth_sys_mutex_create(void)
bool golioth_sys_mutex_lock(golioth_sys_mutex_t mutex, int32_t ms_to_wait)
void * golioth_sys_timer_t
void * golioth_sys_mutex_t
void(* golioth_sys_timer_fn_t)(golioth_sys_timer_t timer, void *user_arg)
void golioth_sys_client_disconnected(void *client)
void golioth_sys_thread_destroy(golioth_sys_thread_t thread)
int golioth_sys_sem_get_fd(golioth_sys_sem_t sem)
golioth_sys_timer_t golioth_sys_timer_create(const struct golioth_timer_config *config)
uint64_t golioth_sys_now_ms(void)
void golioth_sys_sem_destroy(golioth_sys_sem_t sem)
bool golioth_sys_mutex_unlock(golioth_sys_mutex_t mutex)
golioth_sys_thread_fn_t fn
golioth_sys_timer_fn_t fn