diff --git a/README.md b/README.md index 74ba657..687eb93 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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. diff --git a/TinyFrame.c b/TinyFrame.c index 36baaa3..42c05d1 100644 --- a/TinyFrame.c +++ b/TinyFrame.c @@ -151,8 +151,12 @@ void _TF_FN TF_InitStatic(TinyFrame *tf, TF_Peer peer_bit) // Zero it out, keeping user config uint32_t usertag = tf->usertag; + void * userdata = tf->userdata; + memset(tf, 0, sizeof(struct TinyFrame_)); + tf->usertag = usertag; + tf->userdata = userdata; tf->peer_bit = peer_bit; } diff --git a/TinyFrame.h b/TinyFrame.h index 4bb5551..43eb016 100644 --- a/TinyFrame.h +++ b/TinyFrame.h @@ -10,7 +10,7 @@ * Upstream URL: https://github.com/MightyPork/TinyFrame */ -#define TF_VERSION "1.2.0" +#define TF_VERSION "2.0.0" //--------------------------------------------------------------------------- #include // for uint8_t etc @@ -168,11 +168,8 @@ struct TF_GenericListener_ { */ struct TinyFrame_ { /* Public user data */ - union { - // choice between two representations - void *userdata; - uint32_t usertag; - }; + void *userdata; + uint32_t usertag; // --- the rest of the struct is internal, do not access directly ---