AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
crc.h
1 
34 #ifndef _AVRIO_CRC_H_
35 #define _AVRIO_CRC_H_
36 
37 #include <avrio/defs.h>
38 
39 __BEGIN_C_DECLS
40 /* ========================================================================== */
51 /* constants ================================================================ */
55 #define CRC_CCITT_INIT_VAL ((uint16_t)0xFFFF)
56 
60 #define CRC_IBUTTON_INIT_VAL ((uint8_t)0x5A)
61 
62 /* internal public functions ================================================ */
63 
72 uint8_t ucCrcIButton (uint8_t ucCrc, const void * pvBuf, size_t uLen);
73 
82 uint16_t usCrcCcitt (uint16_t usCrc, const void *pvBuf, size_t uLen);
83 
84 
85 # if defined(__DOXYGEN__)
86 /*
87  * __DOXYGEN__ defined
88  * Partie documentation ne devant pas être compilée.
89  * =============================================================================
90  */
97 static inline uint16_t usCrcCcittUpdate (uint8_t ucByte, uint16_t usCrc);
98 
104 # else
105 /*
106  * __DOXYGEN__ not defined
107  * Partie ne devant pas être documentée.
108  * =============================================================================
109  */
110 
111 #include <avr/pgmspace.h>
112 
113 /* CRC table */
114 extern const uint16_t usCrcCcittTab[256];
115 
116 /* inline public functions ================================================ */
117 INLINE uint16_t
118 usCrcCcittUpdate (uint8_t c, uint16_t oldcrc) {
119 
120  return (oldcrc >> 8) ^ pgm_read_word (&usCrcCcittTab[ (oldcrc ^ c) & 0xff]);
121 }
122 
123 #endif /* __DOXYGEN__ not defined */
124 /* ========================================================================== */
125 __END_C_DECLS
126 #endif /* _AVRIO_CRC_H_ */
uint8_t ucCrcIButton(uint8_t ucCrc, const void *pvBuf, size_t uLen)
Calcul du CRC iButton (8-bits)
uint16_t usCrcCcitt(uint16_t usCrc, const void *pvBuf, size_t uLen)
Calcul du CRC CCITT (16-bits)
static uint16_t usCrcCcittUpdate(uint8_t ucByte, uint16_t usCrc)
Mise à jour du CRC CCITT avec un octet.