Golioth Firmware SDK
Loading...
Searching...
No Matches
golioth_sys.h File Reference
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <golioth/config.h>

Go to the source code of this file.

Data Structures

struct  golioth_timer_config
 
struct  golioth_thread_config
 

Macros

#define GOLIOTH_SYS_WAIT_FOREVER   -1
 
#define golioth_sys_malloc(sz)   malloc((sz))
 
#define golioth_sys_free(ptr)   free((ptr))
 
#define golioth_sys_srand(seed)   srand((seed))
 
#define golioth_sys_rand()   rand()
 
#define GLTH_LOGV(TAG, ...)
 
#define GLTH_LOGD(TAG, ...)
 
#define GLTH_LOGI(TAG, ...)
 
#define GLTH_LOGW(TAG, ...)
 
#define GLTH_LOGE(TAG, ...)
 
#define GLTH_LOG_BUFFER_HEXDUMP(TAG, ...)
 

Typedefs

typedef void * golioth_sys_mutex_t
 
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)
 
typedef void * golioth_sys_sha256_t
 Opaque handle for sha256 context.
 

Functions

void golioth_sys_msleep (uint32_t ms)
 
uint64_t golioth_sys_now_ms (void)
 
golioth_sys_mutex_t golioth_sys_mutex_create (void)
 
bool golioth_sys_mutex_lock (golioth_sys_mutex_t mutex, int32_t ms_to_wait)
 
bool golioth_sys_mutex_unlock (golioth_sys_mutex_t mutex)
 
void golioth_sys_mutex_destroy (golioth_sys_mutex_t mutex)
 
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)
 
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)
 
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 (const struct golioth_thread_config *config)
 
void golioth_sys_thread_destroy (golioth_sys_thread_t thread)
 
golioth_sys_sha256_t golioth_sys_sha256_create (void)
 
void golioth_sys_sha256_destroy (golioth_sys_sha256_t sha_ctx)
 
enum golioth_status golioth_sys_sha256_update (golioth_sys_sha256_t sha_ctx, const uint8_t *input, size_t len)
 
enum golioth_status golioth_sys_sha256_finish (golioth_sys_sha256_t sha_ctx, uint8_t *output)
 
size_t golioth_sys_hex2bin (const char *hex, size_t hexlen, uint8_t *buf, size_t buflen)
 
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,
... )

Definition at line 304 of file golioth_sys.h.

◆ GLTH_LOGD

#define GLTH_LOGD ( TAG,
... )

Definition at line 300 of file golioth_sys.h.

◆ GLTH_LOGE

#define GLTH_LOGE ( TAG,
... )

Definition at line 303 of file golioth_sys.h.

◆ GLTH_LOGI

#define GLTH_LOGI ( TAG,
... )

Definition at line 301 of file golioth_sys.h.

◆ GLTH_LOGV

#define GLTH_LOGV ( TAG,
... )

Definition at line 299 of file golioth_sys.h.

◆ GLTH_LOGW

#define GLTH_LOGW ( TAG,
... )

Definition at line 302 of file golioth_sys.h.

◆ golioth_sys_free

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

Definition at line 108 of file golioth_sys.h.

◆ golioth_sys_malloc

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

Definition at line 104 of file golioth_sys.h.

◆ golioth_sys_rand

#define golioth_sys_rand ( )    rand()

Definition at line 121 of file golioth_sys.h.

◆ golioth_sys_srand

#define golioth_sys_srand ( seed)    srand((seed))

Definition at line 117 of file golioth_sys.h.

◆ GOLIOTH_SYS_WAIT_FOREVER

#define GOLIOTH_SYS_WAIT_FOREVER   -1

Definition at line 25 of file golioth_sys.h.

Typedef Documentation

◆ golioth_sys_mutex_t

typedef void* golioth_sys_mutex_t

Definition at line 35 of file golioth_sys.h.

◆ golioth_sys_sem_t

typedef void* golioth_sys_sem_t

Definition at line 47 of file golioth_sys.h.

◆ golioth_sys_sha256_t

typedef void* golioth_sys_sha256_t

Opaque handle for sha256 context.

Definition at line 131 of file golioth_sys.h.

◆ golioth_sys_thread_fn_t

typedef void(* golioth_sys_thread_fn_t) (void *user_arg)

Definition at line 84 of file golioth_sys.h.

◆ golioth_sys_thread_t

typedef void* golioth_sys_thread_t

Definition at line 82 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 62 of file golioth_sys.h.

◆ golioth_sys_timer_t

typedef void* golioth_sys_timer_t

Definition at line 60 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_hex2bin()

size_t golioth_sys_hex2bin ( const char * hex,
size_t hexlen,
uint8_t * buf,
size_t buflen )

Convert a string of hexadecimal values to an array of bytes

Parameters
hexPointer at a hexadecimal string.
hexlenLength of the hex string.
bufA buffer where binary values will be written.
buflenLength of the binary buffer.
Returns
GOLIOTH_OK On success
GOLIOTH_ERR_FAIL On failure

◆ golioth_sys_msleep()

void golioth_sys_msleep ( uint32_t ms)

◆ golioth_sys_mutex_create()

golioth_sys_mutex_t golioth_sys_mutex_create ( void )

◆ golioth_sys_mutex_destroy()

void golioth_sys_mutex_destroy ( golioth_sys_mutex_t mutex)

◆ golioth_sys_mutex_lock()

bool golioth_sys_mutex_lock ( golioth_sys_mutex_t mutex,
int32_t ms_to_wait )

◆ golioth_sys_mutex_unlock()

bool golioth_sys_mutex_unlock ( golioth_sys_mutex_t mutex)

◆ 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_get_fd()

int golioth_sys_sem_get_fd ( 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_sha256_create()

golioth_sys_sha256_t golioth_sys_sha256_create ( void )

Create a context for generating a sha256 hash.

Dynamically creates and initializes a context, then returns an opaque handle to the context. The handle is a required parameter for all other Golioth sha256 functions.

Returns
Non-NULL The sha256 context handle (success)
NULL There was an error creating the context

◆ golioth_sys_sha256_destroy()

void golioth_sys_sha256_destroy ( golioth_sys_sha256_t sha_ctx)

Destroys a Golioth sha256 context

Frees memory dynamically allocated for golioth_sys_sha256_t context handle by golioth_sys_sha256_create.

Parameters
sha_ctxA sha256 context handle

◆ golioth_sys_sha256_finish()

enum golioth_status golioth_sys_sha256_finish ( golioth_sys_sha256_t sha_ctx,
uint8_t * output )

Finalizes a sha256 hash calculation and outputs to a binary buffer.

Parameters
sha_ctxA sha256 context handle.
outputA buffer of exactly 32 bytes where the sha256 value is written.
Returns
GOLIOTH_OK On success
GOLIOTH_ERR_FAIL On failure

◆ golioth_sys_sha256_update()

enum golioth_status golioth_sys_sha256_update ( golioth_sys_sha256_t sha_ctx,
const uint8_t * input,
size_t len )

Adds an input buffer into a sha256 hash calculation.

Call on an existing context to add data to the sha256 calculation. May be called repeatedly (eg: each block in a block download) or once for a large data set (eg: calculate the hash after writing all bytes to memory).

Parameters
sha_ctxA sha256 context handle
inputInput buffer to be added to the sha256 calculation
lenLength of the input buffer, in bytes.
Returns
GOLIOTH_OK On success
GOLIOTH_ERR_FAIL On failure

◆ golioth_sys_thread_create()

golioth_sys_thread_t golioth_sys_thread_create ( const struct golioth_thread_config * 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 ( const struct golioth_timer_config * 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)