Skip to content

Instantly share code, notes, and snippets.

View michahoiting's full-sized avatar

Micha Hoiting michahoiting

View GitHub Profile
@michahoiting
michahoiting / sbrk.c
Last active December 17, 2022 16:31
A very naive implementation of the newlib _sbrk dependency function
//! A very naive implementation of the newlib _sbrk dependency function
caddr_t _sbrk(int incr);
caddr_t _sbrk(int incr) {
static uint32_t s_index = 0;
static uint8_t s_newlib_heap[2048] __attribute__((aligned(8)));
if ((s_index + (uint32_t)incr) <= sizeof(s_newlib_heap)) {
EXAMPLE_LOG("Out of Memory!");
return 0;
}
@michahoiting
michahoiting / gist:b3b57e969a14df37fa00085ac6ee44f6
Created June 27, 2017 13:49
zeilen meebrengen (creative commons)
zeilen meebrengen (creative commons)
reddingsvest >=275N
life-line
laag 1 synthetisch ondergoed
laag 2 fleece trui / broek / sokken
laag 3 wind stopper jack
laag 4 zeil pak
zeil schoenen
zeil laarzen
@michahoiting
michahoiting / c-vtable.c
Created April 12, 2016 13:23
vtable example in C
#include <stdio.h>
/* class definitions */
typedef struct Base
{
void (**vtable)();
int _x;
} Base;
typedef struct Child
@michahoiting
michahoiting / gist:5976702
Last active December 19, 2015 15:29
Using function pointers in FFF

Using FFF to stub functions that have function pointer parameter can cause problems when trying to stub them. Presented here is an example how to deal with this situation.

If you need to stub a function that has a function pointer parameter, e.g. something like:

/* timer.h */
typedef int timer_handle;
extern int timer_start(timer_handle handle, long delay, void (*cb_function) (int arg), int arg);

Then creating a fake like below will horribly fail when trying to compile because the FFF macro will internally expand into an illegal variable int (*)(int) arg2_val.

@michahoiting
michahoiting / gist:5976104
Created July 11, 2013 14:48
Resetting a list of fakes
/* List of fakes used by this unit tester */
#define FFF_FAKES_LIST(FAKE) \
FAKE(DISPLAY_init) \
FAKE(DISPLAY_clear) \
FAKE(DISPLAY_output_message) \
FAKE(DISPLAY_get_line_capacity) \
FAKE(DISPLAY_get_line_insert_index)
void setup()
{
@michahoiting
michahoiting / fff.h
Created November 8, 2012 08:22
Concept of using variable arguments operator '...' with limit functionality in the Fake Function Framework
/*******************
*
* fff.h
*
*******************/
#define DECLARE_FAKE_VOID_FUNC3_VARARG(FUNCNAME, ARG0_TYPE, ARG1_TYPE, VARARG2_TYPE) \
EXTERN_C \
typedef struct FUNCNAME##_Fake { \
DECLARE_ARG(ARG0_TYPE, 0, FUNCNAME) \
DECLARE_ARG(ARG1_TYPE, 1, FUNCNAME) \