Skip to content

Commit db0ae30

Browse files
authored
Add re-entrancy support / multiple instances (#9)
* done with changes but now segfaulting * fixed the bug * fix some bad indents * some cleanings * updated readme
1 parent 77f60e1 commit db0ae30

File tree

14 files changed

+1332
-1229
lines changed

14 files changed

+1332
-1229
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ The library lets you register listeners (callback functions) to wait for (1) any
1919
a particular frame Type, or (3) a specific message ID. This high-level API lets you
2020
easily implement various async communication patterns.
2121

22+
TinyFrame is re-entrant and supports creating multiple instances with the limitation
23+
that their structure (field sizes and checksum type) must be the same. There is a support
24+
for adding multi-threaded access to a shared instance using a mutex (via a callback stub).
25+
2226
## Frame structure
2327

2428
All fields in the message frame have a configurable size (see the top of the header file).
@@ -49,7 +53,9 @@ DATA_CKSUM .. checksum, implemented as XOR of all preceding bytes in the message
4953

5054
- All TinyFrame functions, typedefs and macros start with the `TF_` prefix.
5155
- Both peers must include the library with the same parameters (configured at the top of the header file)
52-
- Start by calling `TF_Init()` with `TF_MASTER` or `TF_SLAVE` as the argument
56+
- Start by calling `TF_Init()` with `TF_MASTER` or `TF_SLAVE` as the argument. This creates a handle.
57+
Use `TF_InitStatic()` to avoid the use of malloc(). If multiple instances are used, you can tag them
58+
using the `tf.userdata` / `tf.usertag` field.
5359
- Implement `TF_WriteImpl()` - declared at the bottom of the header file as `extern`.
5460
This function is used by `TF_Send()` and others to write bytes to your UART (or other physical layer).
5561
A frame can be sent in it's entirety, or in multiple parts, depending on its size.

TF_Integration.example.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
* listener timeout feature.
1111
*/
1212

13-
void TF_WriteImpl(const uint8_t *buff, size_t len)
13+
void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, size_t len)
1414
{
1515
// send to UART
1616
}
1717

1818
/** Claim the TX interface before composing and sending a frame */
19-
void TF_ClaimTx(void)
19+
void TF_ClaimTx(TinyFrame *tf)
2020
{
2121
// take mutex
2222
}
2323

2424
/** Free the TX interface after composing and sending a frame */
25-
void TF_ReleaseTx(void)
25+
void TF_ReleaseTx(TinyFrame *tf)
2626
{
2727
// release mutex
2828
}

TinyFrame.c

Lines changed: 643 additions & 657 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)