Golioth Firmware SDK
golioth_sys.h File Reference
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include "golioth_config.h"
#include <stdio.h>
#include "golioth_debug.h"

Go to the source code of this file.

Data Structures

struct  golioth_sys_timer_config_t
 
struct  golioth_sys_thread_config_t
 

Macros

#define GOLIOTH_SYS_WAIT_FOREVER   -1
 
#define golioth_sys_malloc(sz)   malloc((sz))
 
#define golioth_sys_free(ptr)   free((ptr))
 
#define LOG_COLOR_RED   "31"
 
#define LOG_COLOR_GREEN   "32"
 
#define LOG_COLOR_BROWN   "33"
 
#define LOG_COLOR(COLOR)   "\033[0;" COLOR "m"
 
#define LOG_RESET_COLOR   "\033[0m"
 
#define LOG_COLOR_E   LOG_COLOR(LOG_COLOR_RED)
 
#define LOG_COLOR_W   LOG_COLOR(LOG_COLOR_BROWN)
 
#define LOG_COLOR_I   LOG_COLOR(LOG_COLOR_GREEN)
 
#define LOG_COLOR_D
 
#define LOG_COLOR_V
 
#define GLTH_LOGX(COLOR, LEVEL, LEVEL_STR, TAG, ...)
 
#define GLTH_LOGV(TAG, ...)    GLTH_LOGX(LOG_COLOR_V, GOLIOTH_DEBUG_LOG_LEVEL_VERBOSE, "V", TAG, __VA_ARGS__)
 
#define GLTH_LOGD(TAG, ...)    GLTH_LOGX(LOG_COLOR_D, GOLIOTH_DEBUG_LOG_LEVEL_DEBUG, "D", TAG, __VA_ARGS__)
 
#define GLTH_LOGI(TAG, ...)    GLTH_LOGX(LOG_COLOR_I, GOLIOTH_DEBUG_LOG_LEVEL_INFO, "I", TAG, __VA_ARGS__)
 
#define GLTH_LOGW(TAG, ...)    GLTH_LOGX(LOG_COLOR_W, GOLIOTH_DEBUG_LOG_LEVEL_WARN, "W", TAG, __VA_ARGS__)
 
#define GLTH_LOGE(TAG, ...)    GLTH_LOGX(LOG_COLOR_E, GOLIOTH_DEBUG_LOG_LEVEL_ERROR, "E", TAG, __VA_ARGS__)
 
#define GLTH_LOG_BUFFER_HEXDUMP(TAG, payload, size, level)
 

Typedefs

typedef void * golioth_sys_sem_t
 
typedef void * golioth_sys_timer_t
 
typedef void(* golioth_sys_timer_fn_t) (golioth_sys_timer_t timer, void *user_arg)
 
typedef void * golioth_sys_thread_t
 
typedef void(* golioth_sys_thread_fn_t) (void *user_arg)
 

Functions

void golioth_sys_msleep (uint32_t ms)
 
uint64_t golioth_sys_now_ms (void)
 
golioth_sys_sem_t golioth_sys_sem_create (uint32_t sem_max_count, uint32_t sem_initial_count)
 
bool golioth_sys_sem_take (golioth_sys_sem_t sem, int32_t ms_to_wait)
 
bool golioth_sys_sem_give (golioth_sys_sem_t sem)
 
void golioth_sys_sem_destroy (golioth_sys_sem_t sem)
 
golioth_sys_timer_t golioth_sys_timer_create (golioth_sys_timer_config_t config)
 
bool golioth_sys_timer_start (golioth_sys_timer_t timer)
 
bool golioth_sys_timer_reset (golioth_sys_timer_t timer)
 
void golioth_sys_timer_destroy (golioth_sys_timer_t timer)
 
golioth_sys_thread_t golioth_sys_thread_create (golioth_sys_thread_config_t config)
 
void golioth_sys_thread_destroy (golioth_sys_thread_t thread)
 
void golioth_sys_client_connected (void *client)
 
void golioth_sys_client_disconnected (void *client)
 

Macro Definition Documentation

◆ GLTH_LOG_BUFFER_HEXDUMP

#define GLTH_LOG_BUFFER_HEXDUMP (   TAG,
  payload,
  size,
  level 
)
Value:
do { \
if ((level) <= golioth_debug_get_log_level()) { \
golioth_debug_hexdump(TAG, payload, size); \
} \
} while (0);
golioth_debug_log_level_t golioth_debug_get_log_level(void)

Definition at line 155 of file golioth_sys.h.

◆ GLTH_LOGD

#define GLTH_LOGD (   TAG,
  ... 
)     GLTH_LOGX(LOG_COLOR_D, GOLIOTH_DEBUG_LOG_LEVEL_DEBUG, "D", TAG, __VA_ARGS__)

Definition at line 135 of file golioth_sys.h.

◆ GLTH_LOGE

#define GLTH_LOGE (   TAG,
  ... 
)     GLTH_LOGX(LOG_COLOR_E, GOLIOTH_DEBUG_LOG_LEVEL_ERROR, "E", TAG, __VA_ARGS__)

Definition at line 150 of file golioth_sys.h.

◆ GLTH_LOGI

#define GLTH_LOGI (   TAG,
  ... 
)     GLTH_LOGX(LOG_COLOR_I, GOLIOTH_DEBUG_LOG_LEVEL_INFO, "I", TAG, __VA_ARGS__)

Definition at line 140 of file golioth_sys.h.

◆ GLTH_LOGV

#define GLTH_LOGV (   TAG,
  ... 
)     GLTH_LOGX(LOG_COLOR_V, GOLIOTH_DEBUG_LOG_LEVEL_VERBOSE, "V", TAG, __VA_ARGS__)

Definition at line 130 of file golioth_sys.h.

◆ GLTH_LOGW

#define GLTH_LOGW (   TAG,
  ... 
)     GLTH_LOGX(LOG_COLOR_W, GOLIOTH_DEBUG_LOG_LEVEL_WARN, "W", TAG, __VA_ARGS__)

Definition at line 145 of file golioth_sys.h.

◆ GLTH_LOGX

#define GLTH_LOGX (   COLOR,
  LEVEL,
  LEVEL_STR,
  TAG,
  ... 
)
Value:
do { \
if ((LEVEL) <= golioth_debug_get_log_level()) { \
uint64_t now_ms = golioth_time_millis(); \
printf(COLOR "%s (%" PRIu64 ") %s: ", LEVEL_STR, now_ms, TAG); \
printf(__VA_ARGS__); \
golioth_debug_printf(now_ms, LEVEL, TAG, __VA_ARGS__); \
printf("%s", LOG_RESET_COLOR); \
puts(""); \
} \
} while (0)
#define LOG_RESET_COLOR
Definition: golioth_sys.h:107
uint64_t golioth_time_millis(void)
Time since boot, in milliseconds.

Definition at line 115 of file golioth_sys.h.

◆ golioth_sys_free

#define golioth_sys_free (   ptr)    free((ptr))

Definition at line 82 of file golioth_sys.h.

◆ golioth_sys_malloc

#define golioth_sys_malloc (   sz)    malloc((sz))

Definition at line 78 of file golioth_sys.h.

◆ GOLIOTH_SYS_WAIT_FOREVER

#define GOLIOTH_SYS_WAIT_FOREVER   -1

Definition at line 14 of file golioth_sys.h.

◆ LOG_COLOR

#define LOG_COLOR (   COLOR)    "\033[0;" COLOR "m"

Definition at line 106 of file golioth_sys.h.

◆ LOG_COLOR_BROWN

#define LOG_COLOR_BROWN   "33"

Definition at line 105 of file golioth_sys.h.

◆ LOG_COLOR_D

#define LOG_COLOR_D

Definition at line 111 of file golioth_sys.h.

◆ LOG_COLOR_E

#define LOG_COLOR_E   LOG_COLOR(LOG_COLOR_RED)

Definition at line 108 of file golioth_sys.h.

◆ LOG_COLOR_GREEN

#define LOG_COLOR_GREEN   "32"

Definition at line 104 of file golioth_sys.h.

◆ LOG_COLOR_I

#define LOG_COLOR_I   LOG_COLOR(LOG_COLOR_GREEN)

Definition at line 110 of file golioth_sys.h.

◆ LOG_COLOR_RED

#define LOG_COLOR_RED   "31"

Definition at line 103 of file golioth_sys.h.

◆ LOG_COLOR_V

#define LOG_COLOR_V

Definition at line 112 of file golioth_sys.h.

◆ LOG_COLOR_W

#define LOG_COLOR_W   LOG_COLOR(LOG_COLOR_BROWN)

Definition at line 109 of file golioth_sys.h.

◆ LOG_RESET_COLOR

#define LOG_RESET_COLOR   "\033[0m"

Definition at line 107 of file golioth_sys.h.

Typedef Documentation

◆ golioth_sys_sem_t

typedef void* golioth_sys_sem_t

Definition at line 24 of file golioth_sys.h.

◆ golioth_sys_thread_fn_t

typedef void(* golioth_sys_thread_fn_t) (void *user_arg)

Definition at line 59 of file golioth_sys.h.

◆ golioth_sys_thread_t

typedef void* golioth_sys_thread_t

Definition at line 57 of file golioth_sys.h.

◆ golioth_sys_timer_fn_t

typedef void(* golioth_sys_timer_fn_t) (golioth_sys_timer_t timer, void *user_arg)

Definition at line 38 of file golioth_sys.h.

◆ golioth_sys_timer_t

typedef void* golioth_sys_timer_t

Definition at line 36 of file golioth_sys.h.

Function Documentation

◆ golioth_sys_client_connected()

void golioth_sys_client_connected ( void *  client)

◆ golioth_sys_client_disconnected()

void golioth_sys_client_disconnected ( void *  client)

◆ golioth_sys_msleep()

void golioth_sys_msleep ( uint32_t  ms)

◆ golioth_sys_now_ms()

uint64_t golioth_sys_now_ms ( void  )

◆ golioth_sys_sem_create()

golioth_sys_sem_t golioth_sys_sem_create ( uint32_t  sem_max_count,
uint32_t  sem_initial_count 
)

◆ golioth_sys_sem_destroy()

void golioth_sys_sem_destroy ( golioth_sys_sem_t  sem)

◆ golioth_sys_sem_give()

bool golioth_sys_sem_give ( golioth_sys_sem_t  sem)

◆ golioth_sys_sem_take()

bool golioth_sys_sem_take ( golioth_sys_sem_t  sem,
int32_t  ms_to_wait 
)

◆ golioth_sys_thread_create()

golioth_sys_thread_t golioth_sys_thread_create ( golioth_sys_thread_config_t  config)

◆ golioth_sys_thread_destroy()

void golioth_sys_thread_destroy ( golioth_sys_thread_t  thread)

◆ golioth_sys_timer_create()

golioth_sys_timer_t golioth_sys_timer_create ( golioth_sys_timer_config_t  config)

◆ golioth_sys_timer_destroy()

void golioth_sys_timer_destroy ( golioth_sys_timer_t  timer)

◆ golioth_sys_timer_reset()

bool golioth_sys_timer_reset ( golioth_sys_timer_t  timer)

◆ golioth_sys_timer_start()

bool golioth_sys_timer_start ( golioth_sys_timer_t  timer)