Index: Utilities.c =================================================================== diff -u -r66600859e4fb3036f48901aae8c9845f37e3e707 -r5846ff450c26de04b388c2636964a9116ccb6e9d --- Utilities.c (.../Utilities.c) (revision 66600859e4fb3036f48901aae8c9845f37e3e707) +++ Utilities.c (.../Utilities.c) (revision 5846ff450c26de04b388c2636964a9116ccb6e9d) @@ -207,6 +207,41 @@ return crc; } +U08 crc4( U08* buffer ) +{ + U32 count; + U08 nBit; + U32 nRem = 0; + + for ( count = 0; count < 16; count++ ) + { + if ( 1 == ( count % 2 ) ) + { + nRem ^= (U16)( buffer[ count >> 1 ] & MASK_OFF_MSB ); + } + else + { + nRem ^= (U16)( buffer[ count >> 1 ] >> SHIFT_8_BITS_FOR_BYTE_SHIFT ); + } + + for ( nBit = SHIFT_8_BITS_FOR_BYTE_SHIFT; nBit > 0; nBit-- ) + { + if ( nRem & 0x8000 ) + { + nRem = ( nRem << 1 ) ^ 0x3000; + } + else + { + nRem = ( nRem << 1 ); + } + } + } + + nRem = ( 0x000F & ( nRem >> 12 ) ); + + return ( nRem ^ 0x00 ); +} + /*********************************************************************//** * @brief * The u32DiffWithWrap function calculates the difference between two given Index: Utilities.h =================================================================== diff -u -r4f4de3faf2468a13710bace8f2c7174d59396f4a -r5846ff450c26de04b388c2636964a9116ccb6e9d --- Utilities.h (.../Utilities.h) (revision 4f4de3faf2468a13710bace8f2c7174d59396f4a) +++ Utilities.h (.../Utilities.h) (revision 5846ff450c26de04b388c2636964a9116ccb6e9d) @@ -87,6 +87,7 @@ U32 crc32( U32 const initialValue, const U08 *address, U32 len ); U16 crc16( const U08 *address, U32 len ); U08 crc8( const U08 *address, U32 len ); +U08 crc4( U08* buffer ); U32 u32DiffWithWrap( U32 start, U32 end ); S32 u32BiDiffWithWrap( U32 start, U32 end ); U16 u16DiffWithWrap( U16 start, U16 end );