Skip to content

file /Users/ios_developer/workspace/coldwave-os/build/_deps/flake-src/portable/portable.h

Types

Name
structflakeThreadAttr_t
Attributes structure for thread.
structflakeMutexAttr_t
Attributes structure for mutex.
enumflakePriority_t
enumflakeTimerType_t
typedef void *flakeThreadId_t
typedef void(*)(void *argument)flakeThreadFunc_t
typedef void *flakeSemaphoreId_t
typedef void *flakeMutexId_t
typedef void *flakeMessageQueueId_t
typedef void *flakeTimerId_t
typedef void(*)(void *argument)flakeTimerFunc_t
typedef void *flakeTLSContext_t

Functions Overview

Name
int8_tflakeThreadNew(flakeThreadId_t * thread_id, flakeThreadFunc_t func, void * argument, const flakeThreadAttr_t * attr)
int8_tflakeThreadTerminate(flakeThreadId_t thread_id)
voidflakeSocketThreadSemaphoreCleanup(void )
voidflakeSocketThreadSemaphoreInit(void )
voidflakeThreadExit(void )
int8_tflakeSemaphoreNew(flakeSemaphoreId_t * semaphore_id, uint32_t max_count, uint32_t initial_count)
int8_tflakeSemaphoreAcquire(flakeSemaphoreId_t semaphore_id, int timeout)
int8_tflakeSemaphoreRelease(flakeSemaphoreId_t semaphore_id)
int8_tflakeSemaphoreDelete(flakeSemaphoreId_t semaphore_id)
int8_tflakeMutexNew(flakeMutexId_t * mutex_id, const flakeMutexAttr_t * attr)
int8_tflakeMutexRelease(flakeMutexId_t mutex_id)
int8_tflakeMutexAcquire(flakeMutexId_t mutex_id)
int8_tflakeMutexDelete(flakeMutexId_t mutex_id)
int8_tflakeMessageQueueNew(flakeMessageQueueId_t * mq_id, uint32_t msg_count, uint32_t msg_size)
int8_tflakeMessageQueueDelete(flakeMessageQueueId_t mq_id)
uint32_tflakeMessageQueueGetCount(flakeMessageQueueId_t mq_id)
int8_tflakeMessageQueueReset(flakeMessageQueueId_t mq_id)
int8_tflakeMessageQueuePut(flakeMessageQueueId_t mq_id, const void * msg_ptr, uint8_t msg_prio, uint32_t timeout)
int8_tflakeMessageQueueGet(flakeMessageQueueId_t mq_id, void * msg_ptr, uint8_t * msg_prio, uint32_t timeout)
flakeTimerId_tflakeTimerNew(flakeTimerFunc_t func, flakeTimerType_t type, void * argument)
int8_tflakeTimerStart(flakeTimerId_t timer_id, uint32_t ticks)
voidflakePortableLog(const char * format, va_list args)
unsignedflakeThreadId()
voidflakeUSleep(uint32_t us)
intflakeTLSSetCACert(flakeTLSContext_t * ctx, unsigned char * x509_ca_cert, unsigned int x509_ca_cert_len)
intflakeTLSSetOwnCert(flakeTLSContext_t * ctx, unsigned char * x509_cert, unsigned int x509_cert_len, unsigned char * pk_key, unsigned int pk_key_len)
intflakeTLSContextCreate(flakeTLSContext_t * ctx, int server_context)
intflakeTLSConnectionBind(flakeTLSContext_t * ctx, const char * ip, const char * port)
intflakeTLSConnectionAccept(flakeTLSContext_t * ctx, flakeTLSContext_t * client)
intflakeTLSConnectionOpen(flakeTLSContext_t * ctx, const char * host, const char * port)
size_tflakeTLSConnectionWrite(flakeTLSContext_t * ctx, const unsigned char * buf, size_t len)
size_tflakeTLSConnectionRead(flakeTLSContext_t * ctx, unsigned char * buf, size_t len)
voidflakeTLSConnectionClose(flakeTLSContext_t * ctx)
voidflakeTLSContextFree(flakeTLSContext_t * ctx)
intflakeDTLSConnectionInit(flakeTLSContext_t * ctx)
intflakeDTLSConnectionOpen(flakeTLSContext_t * ctx, const char * host, const char * port)
size_tflakeDTLSConnectionWrite(flakeTLSContext_t * ctx, const unsigned char * buf, size_t len)
size_tflakeDTLSConnectionRead(flakeTLSContext_t * ctx, unsigned char * buf, size_t len)
voidflakeDTLSConnectionClose(flakeTLSContext_t * ctx)
uint32_tflakeMSTickCount()
unsignedflakeRandom()

Defines

Name
flakeMutexRecursiveRecursive mutex.
flakeWaitForeverWait forever timeout value.

Types Documentation

enum flakePriority_t

EnumeratorDescription
flakeThreadPriorityNoneNo priority (not initialized).
flakeThreadPriorityIdleReserved for Idle thread.
flakeThreadPriorityLowPriority: low.
flakeThreadPriorityBelowNormalPriority: below normal.
flakeThreadPriorityNormalPriority: normal.
flakeThreadPriorityAboveNormalPriority: above normal.
flakeThreadPriorityHighPriority: high.
flakeThreadPriorityISRReserved for ISR deferred thread.
flakeThreadPriorityErrorSystem cannot determine priority or illegal priority.

enum flakeTimerType_t

EnumeratorDescription
flakeTimerOnceOne-shot timer.
flakeTimerPeriodicRepeating timer.

typedef flakeThreadId_t

cpp
typedef void* flakeThreadId_t;

Thread ID identifies the thread.

typedef flakeThreadFunc_t

cpp
typedef void(* flakeThreadFunc_t) (void *argument);

typedef flakeSemaphoreId_t

cpp
typedef void* flakeSemaphoreId_t;

Semaphore ID identifies the semaphore.

typedef flakeMutexId_t

cpp
typedef void* flakeMutexId_t;

Mutex ID identifies the mutex.

typedef flakeMessageQueueId_t

cpp
typedef void* flakeMessageQueueId_t;

Message Queue ID identifies the message queue.

typedef flakeTimerId_t

cpp
typedef void* flakeTimerId_t;

typedef flakeTimerFunc_t

cpp
typedef void(* flakeTimerFunc_t) (void *argument);

typedef flakeTLSContext_t

cpp
typedef void* flakeTLSContext_t;

Function Details

function flakeThreadNew

cpp
int8_t flakeThreadNew(
    flakeThreadId_t * thread_id,
    flakeThreadFunc_t func,
    void * argument,
    const flakeThreadAttr_t * attr
)

function flakeThreadTerminate

cpp
int8_t flakeThreadTerminate(
    flakeThreadId_t thread_id
)

function flakeSocketThreadSemaphoreCleanup

cpp
void flakeSocketThreadSemaphoreCleanup(
    void 
)

function flakeSocketThreadSemaphoreInit

cpp
void flakeSocketThreadSemaphoreInit(
    void 
)

function flakeThreadExit

cpp
void flakeThreadExit(
    void 
)

function flakeSemaphoreNew

cpp
int8_t flakeSemaphoreNew(
    flakeSemaphoreId_t * semaphore_id,
    uint32_t max_count,
    uint32_t initial_count
)

function flakeSemaphoreAcquire

cpp
int8_t flakeSemaphoreAcquire(
    flakeSemaphoreId_t semaphore_id,
    int timeout
)

function flakeSemaphoreRelease

cpp
int8_t flakeSemaphoreRelease(
    flakeSemaphoreId_t semaphore_id
)

function flakeSemaphoreDelete

cpp
int8_t flakeSemaphoreDelete(
    flakeSemaphoreId_t semaphore_id
)

function flakeMutexNew

cpp
int8_t flakeMutexNew(
    flakeMutexId_t * mutex_id,
    const flakeMutexAttr_t * attr
)

function flakeMutexRelease

cpp
int8_t flakeMutexRelease(
    flakeMutexId_t mutex_id
)

function flakeMutexAcquire

cpp
int8_t flakeMutexAcquire(
    flakeMutexId_t mutex_id
)

function flakeMutexDelete

cpp
int8_t flakeMutexDelete(
    flakeMutexId_t mutex_id
)

function flakeMessageQueueNew

cpp
int8_t flakeMessageQueueNew(
    flakeMessageQueueId_t * mq_id,
    uint32_t msg_count,
    uint32_t msg_size
)

function flakeMessageQueueDelete

cpp
int8_t flakeMessageQueueDelete(
    flakeMessageQueueId_t mq_id
)

function flakeMessageQueueGetCount

cpp
uint32_t flakeMessageQueueGetCount(
    flakeMessageQueueId_t mq_id
)

function flakeMessageQueueReset

cpp
int8_t flakeMessageQueueReset(
    flakeMessageQueueId_t mq_id
)

function flakeMessageQueuePut

cpp
int8_t flakeMessageQueuePut(
    flakeMessageQueueId_t mq_id,
    const void * msg_ptr,
    uint8_t msg_prio,
    uint32_t timeout
)

function flakeMessageQueueGet

cpp
int8_t flakeMessageQueueGet(
    flakeMessageQueueId_t mq_id,
    void * msg_ptr,
    uint8_t * msg_prio,
    uint32_t timeout
)

function flakeTimerNew

cpp
flakeTimerId_t flakeTimerNew(
    flakeTimerFunc_t func,
    flakeTimerType_t type,
    void * argument
)

function flakeTimerStart

cpp
int8_t flakeTimerStart(
    flakeTimerId_t timer_id,
    uint32_t ticks
)

function flakePortableLog

cpp
void flakePortableLog(
    const char * format,
    va_list args
)

function flakeThreadId

cpp
unsigned flakeThreadId()

function flakeUSleep

cpp
void flakeUSleep(
    uint32_t us
)

function flakeTLSSetCACert

cpp
int flakeTLSSetCACert(
    flakeTLSContext_t * ctx,
    unsigned char * x509_ca_cert,
    unsigned int x509_ca_cert_len
)

function flakeTLSSetOwnCert

cpp
int flakeTLSSetOwnCert(
    flakeTLSContext_t * ctx,
    unsigned char * x509_cert,
    unsigned int x509_cert_len,
    unsigned char * pk_key,
    unsigned int pk_key_len
)

function flakeTLSContextCreate

cpp
int flakeTLSContextCreate(
    flakeTLSContext_t * ctx,
    int server_context
)

function flakeTLSConnectionBind

cpp
int flakeTLSConnectionBind(
    flakeTLSContext_t * ctx,
    const char * ip,
    const char * port
)

function flakeTLSConnectionAccept

cpp
int flakeTLSConnectionAccept(
    flakeTLSContext_t * ctx,
    flakeTLSContext_t * client
)

function flakeTLSConnectionOpen

cpp
int flakeTLSConnectionOpen(
    flakeTLSContext_t * ctx,
    const char * host,
    const char * port
)

function flakeTLSConnectionWrite

cpp
size_t flakeTLSConnectionWrite(
    flakeTLSContext_t * ctx,
    const unsigned char * buf,
    size_t len
)

function flakeTLSConnectionRead

cpp
size_t flakeTLSConnectionRead(
    flakeTLSContext_t * ctx,
    unsigned char * buf,
    size_t len
)

function flakeTLSConnectionClose

cpp
void flakeTLSConnectionClose(
    flakeTLSContext_t * ctx
)

function flakeTLSContextFree

cpp
void flakeTLSContextFree(
    flakeTLSContext_t * ctx
)

function flakeDTLSConnectionInit

cpp
int flakeDTLSConnectionInit(
    flakeTLSContext_t * ctx
)

function flakeDTLSConnectionOpen

cpp
int flakeDTLSConnectionOpen(
    flakeTLSContext_t * ctx,
    const char * host,
    const char * port
)

function flakeDTLSConnectionWrite

cpp
size_t flakeDTLSConnectionWrite(
    flakeTLSContext_t * ctx,
    const unsigned char * buf,
    size_t len
)

function flakeDTLSConnectionRead

cpp
size_t flakeDTLSConnectionRead(
    flakeTLSContext_t * ctx,
    unsigned char * buf,
    size_t len
)

function flakeDTLSConnectionClose

cpp
void flakeDTLSConnectionClose(
    flakeTLSContext_t * ctx
)

function flakeMSTickCount

cpp
uint32_t flakeMSTickCount()

function flakeRandom

cpp
unsigned flakeRandom()

Macros Documentation

define flakeMutexRecursive

cpp
#define flakeMutexRecursive 0x00000001U

Recursive mutex.

define flakeWaitForever

cpp
#define flakeWaitForever 0xFFFFFFFFU

Wait forever timeout value.

Source code

cpp
//
// Created by Sebastian Floss on 28.12.18.
// Copyright (c) 2018 ImagineOn GmbH. All rights reserved.
//

#ifndef XOS_PORTABLE_H
#define XOS_PORTABLE_H

#include <inttypes.h>
#include <wchar.h>
#include <stdarg.h>

#define flakeMutexRecursive      0x00000001U 
#define flakeWaitForever         0xFFFFFFFFU 

#if defined (__cplusplus)
extern "C" {
#endif


//--------------
//
//  Threads
//

typedef void *flakeThreadId_t;

typedef enum {
    flakeThreadPriorityNone = 0,         
    flakeThreadPriorityIdle = 1,         
    flakeThreadPriorityLow = 8,         
    flakeThreadPriorityBelowNormal = 16,         
    flakeThreadPriorityNormal = 24,         
    flakeThreadPriorityAboveNormal = 32,         
    flakeThreadPriorityHigh = 40,         
    flakeThreadPriorityISR = 56,         
    flakeThreadPriorityError = -1,         
} flakePriority_t;

typedef struct {
    const char *name;   
    uint32_t attr_bits;   
    void *cb_mem;    
    uint32_t cb_size;   
    void *stack_mem;    
    uint32_t stack_size;   
    flakePriority_t priority;   
    uint32_t tz_module;   
    uint32_t reserved;   
} flakeThreadAttr_t;

typedef void (*flakeThreadFunc_t) (void *argument);

int8_t
flakeThreadNew (flakeThreadId_t *thread_id, flakeThreadFunc_t func, void *argument, const flakeThreadAttr_t *attr);

int8_t
flakeThreadTerminate (flakeThreadId_t thread_id);

void
flakeSocketThreadSemaphoreCleanup (void);

void
flakeSocketThreadSemaphoreInit (void);

void
flakeThreadExit (void);

//--------------
//
//  Semaphores
//

typedef void *flakeSemaphoreId_t;

int8_t
flakeSemaphoreNew (flakeSemaphoreId_t *semaphore_id, uint32_t max_count, uint32_t initial_count);

int8_t
flakeSemaphoreAcquire (flakeSemaphoreId_t semaphore_id, int timeout);

int8_t
flakeSemaphoreRelease (flakeSemaphoreId_t semaphore_id);

int8_t
flakeSemaphoreDelete (flakeSemaphoreId_t semaphore_id);

//--------------
//
//  Mutexes
//

typedef void *flakeMutexId_t;

typedef struct {
    const char *name;   
    uint32_t attr_bits;   
    void *cb_mem;    
    uint32_t cb_size;   
} flakeMutexAttr_t;

int8_t
flakeMutexNew (flakeMutexId_t *mutex_id, const flakeMutexAttr_t *attr);

int8_t
flakeMutexRelease (flakeMutexId_t mutex_id);

int8_t
flakeMutexAcquire (flakeMutexId_t mutex_id);

int8_t
flakeMutexDelete (flakeMutexId_t mutex_id);

//--------------
//
//  Queues
//

typedef void *flakeMessageQueueId_t;

int8_t
flakeMessageQueueNew (flakeMessageQueueId_t *mq_id, uint32_t msg_count, uint32_t msg_size);

int8_t
flakeMessageQueueDelete (flakeMessageQueueId_t mq_id);

uint32_t
flakeMessageQueueGetCount (flakeMessageQueueId_t mq_id);

int8_t
flakeMessageQueueReset (flakeMessageQueueId_t mq_id);

int8_t
flakeMessageQueuePut (flakeMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);

int8_t
flakeMessageQueueGet (flakeMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);

//--------------
//
//  Timers
//

typedef void *flakeTimerId_t;

typedef enum {
    flakeTimerOnce = 0,          
    flakeTimerPeriodic = 1           
} flakeTimerType_t;

typedef void (*flakeTimerFunc_t) (void *argument);

flakeTimerId_t
flakeTimerNew (flakeTimerFunc_t func, flakeTimerType_t type, void *argument);

int8_t
flakeTimerStart (flakeTimerId_t timer_id, uint32_t ticks);


//--------------
//
//  Generic
//

void flakePortableLog (const char *format, va_list args);

unsigned flakeThreadId();

void flakeUSleep (uint32_t us);

//--------------
//
//  TLS
//

typedef void *flakeTLSContext_t;

int
flakeTLSSetCACert (flakeTLSContext_t *ctx, unsigned char *x509_ca_cert, unsigned int x509_ca_cert_len);

int
flakeTLSSetOwnCert (flakeTLSContext_t *ctx, unsigned char *x509_cert, unsigned int x509_cert_len,
                        unsigned char *pk_key, unsigned int pk_key_len);

int
flakeTLSContextCreate (flakeTLSContext_t *ctx, int server_context);

int
flakeTLSConnectionBind (flakeTLSContext_t *ctx, const char *ip, const char *port);

int
flakeTLSConnectionAccept (flakeTLSContext_t *ctx, flakeTLSContext_t *client);

int
flakeTLSConnectionOpen (flakeTLSContext_t *ctx, const char *host, const char *port);

size_t
flakeTLSConnectionWrite (flakeTLSContext_t *ctx, const unsigned char *buf, size_t len);

size_t
flakeTLSConnectionRead (flakeTLSContext_t *ctx, unsigned char *buf, size_t len);

void
flakeTLSConnectionClose (flakeTLSContext_t *ctx);

void
flakeTLSContextFree (flakeTLSContext_t *ctx);



//--------------
//
//  DTLS
//

int
flakeDTLSConnectionInit (flakeTLSContext_t *ctx);

int
flakeDTLSConnectionOpen (flakeTLSContext_t *ctx, const char *host, const char *port);

size_t
flakeDTLSConnectionWrite (flakeTLSContext_t *ctx, const unsigned char *buf, size_t len);

size_t
flakeDTLSConnectionRead (flakeTLSContext_t *ctx, unsigned char *buf, size_t len);

void
flakeDTLSConnectionClose (flakeTLSContext_t *ctx);

uint32_t
flakeMSTickCount ();

unsigned
flakeRandom();

#if FLAKE_BLE_ECDH_CRPTO
typedef uint8_t[32] flakeCryptoUINT256_t;

void flakeCryptoECDHGenerateOwnPubkey ( flakeCryptoUINT256_t * client_public_dh_key );

int flakeCryptoECDHGenerateAESKey ( flakeCryptoUINT256_t const * server_public_dh_key, flakeCryptoUINT256_t ** aes_encryption_key) ;
#endif

#if defined (__cplusplus)
}
#endif

#endif //XOS_PORTABLE_H