diff --git a/TinyFrame.c b/TinyFrame.c index be69d8e..36baaa3 100644 --- a/TinyFrame.c +++ b/TinyFrame.c @@ -36,6 +36,7 @@ #elif TF_CKSUM_TYPE == TF_CKSUM_CRC16 +// TODO try to replace with an algorithm /** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */ static const uint16_t crc16_table[256] = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, @@ -83,6 +84,7 @@ static inline uint16_t crc16_byte(uint16_t cksum, const uint8_t byte) #elif TF_CKSUM_TYPE == TF_CKSUM_CRC32 +// TODO try to replace with an algorithm static const uint32_t crc32_table[] = { /* CRC polynomial 0xedb88320 */ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, diff --git a/TinyFrame.h b/TinyFrame.h index 1ab704a..4bb5551 100644 --- a/TinyFrame.h +++ b/TinyFrame.h @@ -91,6 +91,7 @@ typedef enum { TF_MASTER = 1, } TF_Peer; +/** Response from listeners */ typedef enum { TF_NEXT = 0, //!< Not handled, let other listeners handle it TF_STAY = 1, //!< Handled, stay @@ -132,6 +133,8 @@ typedef TF_Result (*TF_Listener)(TinyFrame *tf, TF_Msg *msg); // ------------------------------------------------------------------- +// region Internal + enum TFState_ { TFState_SOF = 0, //!< Wait for SOF TFState_LEN, //!< Wait for Number Of Bytes @@ -207,11 +210,19 @@ struct TinyFrame_ { uint8_t sendbuf[TF_SENDBUF_LEN]; }; +// endregion + // ------------------------------------------------------------------- /** * Initialize the TinyFrame engine. - * This can also be used to completely reset it (removing all listeners etc) + * This can also be used to completely reset it (removing all listeners etc). + * + * The field .userdata (or .usertag) can be used to identify different instances + * in the TF_WriteImpl() function etc. Set this field after the init. + * + * This function is a wrapper around TF_InitStatic that calls malloc() to obtain + * the instance. * * @param peer_bit - peer bit to use for self */ @@ -221,6 +232,8 @@ TinyFrame *TF_Init(TF_Peer peer_bit); /** * Initialize the TinyFrame engine using a statically allocated instance struct. * + * The .userdata / .usertag field is preserved when TF_InitStatic is called. + * * @param peer_bit - peer bit to use for self */ void TF_InitStatic(TinyFrame *tf, TF_Peer peer_bit);