IBNOS
Macros | Functions
util.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <hardware/context.h>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define UNUSED   __attribute__((unused))
 
#define _STRINGIZE_DETAIL(x)   #x
 
#define _STRINGIZE(x)   _STRINGIZE_DETAIL(x)
 
#define assert(ex)
 
#define SYSTEM_FAILURE(lines, ...)
 
#define NOTIMPLEMENTED()
 

Functions

uint32_t stringLength (const char *str)
 Returns the length of a nullterminated string. More...
 
bool stringIsEqual (const char *str, const char *buf, uint32_t len)
 Checks if the string is equal to the memory region. More...
 
uint32_t stringParseOctal (const char *str, uint32_t len)
 Converts an octal string to a integer number. More...
 
void * memset (void *ptr, int value, size_t num)
 Fills a memory region with some specific byte value. More...
 
void * memcpy (void *destination, const void *source, size_t num)
 Copies a block of memory from source to destination. More...
 
void * memmove (void *destination, const void *source, size_t num)
 Moves a block of memory from source to destination. More...
 
void debugCaptureCpuContext (struct taskContext *context)
 
void debugAssertFailed (const char *assertion, const char *file, const char *function, const char *line, struct taskContext *context)
 Used internally to implement assert() More...
 
void debugNotImplemented (const char *file, const char *function, const char *line, struct taskContext *context)
 Used internally to implement NOTIMPLEMENTED() More...
 
void debugHalt ()
 

Macro Definition Documentation

◆ _STRINGIZE

#define _STRINGIZE (   x)    _STRINGIZE_DETAIL(x)

Definition at line 59 of file util.h.

◆ _STRINGIZE_DETAIL

#define _STRINGIZE_DETAIL (   x)    #x

Definition at line 58 of file util.h.

◆ assert

#define assert (   ex)
Value:
do \
{ \
struct taskContext __context; \
if ((ex)) break; \
debugCaptureCpuContext(&__context); \
debugAssertFailed(#ex, __FILE__, __FUNCTION__, _STRINGIZE(__LINE__), &__context); \
} \
while(1)
#define _STRINGIZE(x)
Definition: util.h:59

Definition at line 61 of file util.h.

◆ NOTIMPLEMENTED

#define NOTIMPLEMENTED ( )
Value:
do \
{ \
struct taskContext __context; \
debugCaptureCpuContext(&__context); \
debugNotImplemented(__FILE__, __FUNCTION__, _STRINGIZE(__LINE__), &__context); \
} \
while(1)
#define _STRINGIZE(x)
Definition: util.h:59

Definition at line 82 of file util.h.

◆ SYSTEM_FAILURE

#define SYSTEM_FAILURE (   lines,
  ... 
)
Value:
do \
{ \
struct taskContext __context; \
uint32_t __args[] = {__VA_ARGS__}; \
memset(&__context, 0xFF, sizeof(__context)); \
debugCaptureCpuContext(&__context); \
consoleSystemFailure((lines), sizeof(__args)/sizeof(__args[0]), __args, &__context); \
} \
while(1)

Definition at line 71 of file util.h.

◆ UNUSED

#define UNUSED   __attribute__((unused))

Definition at line 39 of file util.h.

Function Documentation

◆ debugAssertFailed()

void debugAssertFailed ( const char *  assertion,
const char *  file,
const char *  function,
const char *  line,
struct taskContext context 
)

Used internally to implement assert()

This function shows an assertion message. Normally it shouldn't be necessary to call this function manually, all values will automatically be filled out by using the assert() macro from util.h.

Parameters
assertionString containing the condition which failed
fileFile in which the assertion occured
functionFunction in which the assertion occured
lineString representing the line number, where the assertion occured
contextTask context structure containing the CPU registers after the error occured

Definition at line 228 of file util.c.

◆ debugCaptureCpuContext()

void debugCaptureCpuContext ( struct taskContext context)

◆ debugHalt()

void debugHalt ( )
inline

Definition at line 53 of file util.h.

◆ debugNotImplemented()

void debugNotImplemented ( const char *  file,
const char *  function,
const char *  line,
struct taskContext context 
)

Used internally to implement NOTIMPLEMENTED()

Parameters
fileFile in which the feature is missing
functionFunction in which the assertion occured
lineString representing the line number, where the assertion occured
contextTask context structure containing the CPU registers

Definition at line 251 of file util.c.

◆ memcpy()

void* memcpy ( void *  destination,
const void *  source,
size_t  num 
)

Copies a block of memory from source to destination.

The source and destination blocks shouldn't be overlapping, otherwise it is not safe to call this function. If the regions could be overlapping please use memmove() instead.

Parameters
destinationPointer to the destination memory region
sourcePointer to the source memory region
numLength of the memory region to copy, in bytes
Returns
destination

Definition at line 141 of file util.c.

◆ memmove()

void* memmove ( void *  destination,
const void *  source,
size_t  num 
)

Moves a block of memory from source to destination.

Similar to memcpy(), but will also work safely if both source and destination regions are overlapping.

Parameters
destinationPointer to the destination memory region
sourcePointer to the source memory region
numLength of the memory region to copy, in bytes
Returns
destination

Definition at line 159 of file util.c.

◆ memset()

void* memset ( void *  ptr,
int  value,
size_t  num 
)

Fills a memory region with some specific byte value.

Parameters
ptrPointer to the start of the memory region
valueValue used to fill the memory region
numLength of the memory region in bytes
Returns
ptr

Definition at line 123 of file util.c.

◆ stringIsEqual()

bool stringIsEqual ( const char *  str,
const char *  buf,
uint32_t  len 
)

Checks if the string is equal to the memory region.

Parameters
strPointer to the nullterminated string
bufPointer to a buffer
lenLength of the buffer
Returns
True if both strings are equal, otherwise false

Definition at line 57 of file util.c.

◆ stringLength()

uint32_t stringLength ( const char *  str)

Returns the length of a nullterminated string.

Parameters
strPointer to the nullterminated string
Returns
Length in characters (not including the terminating null character)

Definition at line 37 of file util.c.

◆ stringParseOctal()

uint32_t stringParseOctal ( const char *  str,
uint32_t  len 
)

Converts an octal string to a integer number.

Parameters
strPointer to a string
lenLength of the buffer
Returns
Parsed integer number

Definition at line 84 of file util.c.