Skip to content

Commit

Permalink
Add re-entrancy support / multiple instances (#9)
Browse files Browse the repository at this point in the history
* done with changes but now segfaulting

* fixed the bug

* fix some bad indents

* some cleanings

* updated readme
  • Loading branch information
MightyPork authored Dec 13, 2017
1 parent 77f60e1 commit db0ae30
Show file tree
Hide file tree
Showing 14 changed files with 1,332 additions and 1,229 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ The library lets you register listeners (callback functions) to wait for (1) any
a particular frame Type, or (3) a specific message ID. This high-level API lets you
easily implement various async communication patterns.

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

## Frame structure

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

- All TinyFrame functions, typedefs and macros start with the `TF_` prefix.
- Both peers must include the library with the same parameters (configured at the top of the header file)
- Start by calling `TF_Init()` with `TF_MASTER` or `TF_SLAVE` as the argument
- Start by calling `TF_Init()` with `TF_MASTER` or `TF_SLAVE` as the argument. This creates a handle.
Use `TF_InitStatic()` to avoid the use of malloc(). If multiple instances are used, you can tag them
using the `tf.userdata` / `tf.usertag` field.
- Implement `TF_WriteImpl()` - declared at the bottom of the header file as `extern`.
This function is used by `TF_Send()` and others to write bytes to your UART (or other physical layer).
A frame can be sent in it's entirety, or in multiple parts, depending on its size.
Expand Down
6 changes: 3 additions & 3 deletions TF_Integration.example.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
* listener timeout feature.
*/

void TF_WriteImpl(const uint8_t *buff, size_t len)
void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, size_t len)
{
// send to UART
}

/** Claim the TX interface before composing and sending a frame */
void TF_ClaimTx(void)
void TF_ClaimTx(TinyFrame *tf)
{
// take mutex
}

/** Free the TX interface after composing and sending a frame */
void TF_ReleaseTx(void)
void TF_ReleaseTx(TinyFrame *tf)
{
// release mutex
}
1,300 changes: 643 additions & 657 deletions TinyFrame.c

Large diffs are not rendered by default.

Loading

0 comments on commit db0ae30

Please # to comment.