rokath / trice

🟒 super fast πŸš€ and tiny πŸ₯ embedded device 𝘾 printf-like trace ✍ code, works also inside ⚑ interrupts ⚑ and real-time PC πŸ’» logging (trace ID visualization πŸ‘€)
MIT License
515 stars 46 forks source link

FunctionPointerList Generator #303

Open rokath opened 2 years ago

rokath commented 2 years ago

targetCode.c:

...
trice16F( iD(123), "rpc:fn1( %p, %d )\n", paramBuf1, 5 );
...
trice32F( iD(456), "rpc:fn2( %p, %d )\n", paramBuf2, 3 );
...

With trice insert a til.json exists and a trice generate command creates 2 files from til.json:

File triceRpc.h:

typedef void (*triceRpcHandler_t)(void* buffer, int count);

typedef struct{
    int id;
    triceRpcHandler_t fn;
} triceRpc_t;

extern triceRpc_t triceRpc[];
extern int triceRpcCount;

void fn1( int16_t*, int );
void fn2( int32_t*, int );
...

File triceRpc.c:

#include "triceRpc.h"

triceRpc_t triceRpc[] = {
    { 123, fn1 },
    { 456, fn2 },
    ...
};

int triceRpcCount = sizeof(triceRpc) / sizeof(triceRpc_t);

__weak void fn1( int16_t*, int ){}
__weak void fn2( int32_t*, int ){}
...

When triceRpc.c is compiled into a remote target or a PC application, a target machine can trigger a remote procedure call on a remote target. If a result is needed, the remote target can answer with a triceRpc call.

All targets can get the same triceRpc.c files compiled in. It is up to the user to provide fn1, fn2, ... with target specific functionality. When a target receives an id, it checks the triceRpc list and executes the appropriate function if the id was found.

rokath commented 2 months ago

The function pointer list generator uses simply til.json as input

rokath commented 1 month ago

A CLI command trice generate -fpl could be used. See also #198 and #200 .