FormazioneSitael / Mbed 2 deprecated I2C_PASSED

Dependencies:   mbed

Committer:
jjantoine
Date:
Fri Dec 21 15:38:58 2018 +0000
Revision:
0:8447350292ab
I2C

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jjantoine 0:8447350292ab 1 /* =======================================================================================
jjantoine 0:8447350292ab 2 * (c)
jjantoine 0:8447350292ab 3 * (c) MEL SYSTEM S.r.l.
jjantoine 0:8447350292ab 4 * (c)
jjantoine 0:8447350292ab 5 * (c) Libreria VB32_Lib (Vital Board 32 Bit)
jjantoine 0:8447350292ab 6 * (c)
jjantoine 0:8447350292ab 7 * (c) La libreria VB32_Lib implementa le tutte le funzionalit� necessarie per l'utilizzo
jjantoine 0:8447350292ab 8 * (c) dei due processori AT91SAM9 della scheda VB32. La libreria permette di gestire
jjantoine 0:8447350292ab 9 * (c) tutte le periferiche interne (DBGU, USART, SPI, ecc..) e tutte le periferiche
jjantoine 0:8447350292ab 10 * (c) esterne (HILSCHER COM-C DPM, ecc..) del processore AT91SAM9.
jjantoine 0:8447350292ab 11 * (c)
jjantoine 0:8447350292ab 12 * (c) ===================================================================================
jjantoine 0:8447350292ab 13 * (c)
jjantoine 0:8447350292ab 14 * (c) Copyright (C) MEL SYSTEM S.r.l.
jjantoine 0:8447350292ab 15 * (c)
jjantoine 0:8447350292ab 16 * (c) Tutti i diritti riservati.
jjantoine 0:8447350292ab 17 * (c)
jjantoine 0:8447350292ab 18 * (c) Questo programma e' tutelato dalle leggi sul copyright, dalle leggi sui diritti
jjantoine 0:8447350292ab 19 * (c) d'autore e dai trattati internazionali. La riproduzione o distribuzione non
jjantoine 0:8447350292ab 20 * (c) autorizzata di questo programma, o di parte di esso, sara' perseguibile civilmente
jjantoine 0:8447350292ab 21 * (c) e penalmente.
jjantoine 0:8447350292ab 22 * (c)
jjantoine 0:8447350292ab 23 * =======================================================================================
jjantoine 0:8447350292ab 24 */
jjantoine 0:8447350292ab 25
jjantoine 0:8447350292ab 26 /* =======================================================================================
jjantoine 0:8447350292ab 27 * Elenco delle modifiche (data - autore - descrizione)
jjantoine 0:8447350292ab 28 * =======================================================================================
jjantoine 0:8447350292ab 29 *
jjantoine 0:8447350292ab 30 * Ultima:
jjantoine 0:8447350292ab 31 *
jjantoine 0:8447350292ab 32 * 23/04/2013 - M. Giannese - creazione del modulo
jjantoine 0:8447350292ab 33 * =======================================================================================
jjantoine 0:8447350292ab 34 */
jjantoine 0:8447350292ab 35
jjantoine 0:8447350292ab 36 /* =======================================================================================
jjantoine 0:8447350292ab 37 * File inclusi
jjantoine 0:8447350292ab 38 * =======================================================================================
jjantoine 0:8447350292ab 39 */
jjantoine 0:8447350292ab 40 #include "CRC32BIT_LOOKUP_Int.h"
jjantoine 0:8447350292ab 41
jjantoine 0:8447350292ab 42 /* =======================================================================================
jjantoine 0:8447350292ab 43 * Funzioni
jjantoine 0:8447350292ab 44 * =======================================================================================
jjantoine 0:8447350292ab 45 */
jjantoine 0:8447350292ab 46
jjantoine 0:8447350292ab 47 /* =======================================================================================
jjantoine 0:8447350292ab 48 * \fun Inizializza la struttura _CrcLUTable con i valori di CRC calcolati in funzione
jjantoine 0:8447350292ab 49 * dei valori di crcSettings
jjantoine 0:8447350292ab 50 *
jjantoine 0:8447350292ab 51
jjantoine 0:8447350292ab 52 * \par [in] crcSettings: struttura delle impostazioni per il calcolo del CRC
jjantoine 0:8447350292ab 53 * \val -
jjantoine 0:8447350292ab 54 *
jjantoine 0:8447350292ab 55 * \par [out] _CrcLUTable : la struttura che contiene la look up table
jjantoine 0:8447350292ab 56 * \val -
jjantoine 0:8447350292ab 57 *
jjantoine 0:8447350292ab 58
jjantoine 0:8447350292ab 59 * =======================================================================================
jjantoine 0:8447350292ab 60 */
jjantoine 0:8447350292ab 61
jjantoine 0:8447350292ab 62 ERROR_T CRC32BIT_LOOKUP_Init(CRC32BIT_LOOKUP_TS *pCRCLUTable)
jjantoine 0:8447350292ab 63 {
jjantoine 0:8447350292ab 64 ERROR_T ERROR_Value = E_NULL;
jjantoine 0:8447350292ab 65 UINT32_T UINT32_elementInBytes = 0;
jjantoine 0:8447350292ab 66 UINT32_T UINT32_bitInBytes = 0;
jjantoine 0:8447350292ab 67 UINT32_T UINT32_value = 0;
jjantoine 0:8447350292ab 68
jjantoine 0:8447350292ab 69 /* Viene calcolata la look-up table */
jjantoine 0:8447350292ab 70 if (pCRCLUTable->UINT32_Poly != 0)
jjantoine 0:8447350292ab 71 {
jjantoine 0:8447350292ab 72 for (UINT32_elementInBytes = 0; UINT32_elementInBytes < CRC32BIT_LOOKUP_NUMELEMENTS_IN_BYTE; ++UINT32_elementInBytes)
jjantoine 0:8447350292ab 73 {
jjantoine 0:8447350292ab 74 UINT32_value = UINT32_elementInBytes << 24;
jjantoine 0:8447350292ab 75
jjantoine 0:8447350292ab 76 for (UINT32_bitInBytes = CRC32BIT_LOOKUP_NUMBITS_IN_BYTE; UINT32_bitInBytes > 0; --UINT32_bitInBytes)
jjantoine 0:8447350292ab 77 {
jjantoine 0:8447350292ab 78 if (UINT32_value & TOPBIT)
jjantoine 0:8447350292ab 79 {
jjantoine 0:8447350292ab 80 UINT32_value = (UINT32_value << 1) ^ pCRCLUTable->UINT32_Poly;
jjantoine 0:8447350292ab 81 }
jjantoine 0:8447350292ab 82 else
jjantoine 0:8447350292ab 83 {
jjantoine 0:8447350292ab 84 UINT32_value = (UINT32_value << 1);
jjantoine 0:8447350292ab 85 }
jjantoine 0:8447350292ab 86 }
jjantoine 0:8447350292ab 87
jjantoine 0:8447350292ab 88 pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_elementInBytes] = UINT32_value;
jjantoine 0:8447350292ab 89 }
jjantoine 0:8447350292ab 90
jjantoine 0:8447350292ab 91 ERROR_Value = E_OK;
jjantoine 0:8447350292ab 92 }
jjantoine 0:8447350292ab 93 else
jjantoine 0:8447350292ab 94 {
jjantoine 0:8447350292ab 95 ERROR_Value = E_STD_INVALID_PARAM;
jjantoine 0:8447350292ab 96 }
jjantoine 0:8447350292ab 97 return ERROR_Value;
jjantoine 0:8447350292ab 98 }
jjantoine 0:8447350292ab 99
jjantoine 0:8447350292ab 100 /* =======================================================================================
jjantoine 0:8447350292ab 101 * \fun Restituisce il CRC PROPER a 32 bit calcolato su un vettore di byte
jjantoine 0:8447350292ab 102 *
jjantoine 0:8447350292ab 103 * \par [in] vBYTE_Data: Puntatore al primo byte del vettore di cui calcolare il CRC
jjantoine 0:8447350292ab 104 * \val 0x00..0xFF (1) [-]
jjantoine 0:8447350292ab 105 *
jjantoine 0:8447350292ab 106 * \par [in] UINT32_DataSize: Numero di byte del vettore:
jjantoine 0:8447350292ab 107 * \val -
jjantoine 0:8447350292ab 108 *
jjantoine 0:8447350292ab 109 * \par [in] pCRCLUTable: look-up table
jjantoine 0:8447350292ab 110 * \val - [-]
jjantoine 0:8447350292ab 111 *
jjantoine 0:8447350292ab 112 * \ret il crc calcolato
jjantoine 0:8447350292ab 113 * =======================================================================================
jjantoine 0:8447350292ab 114 */
jjantoine 0:8447350292ab 115 UINT32_T CRC32BIT_LOOKUP_Compute(const BYTE_T vBYTE_Data[],
jjantoine 0:8447350292ab 116 const UINT32_T UINT32_DataSize,
jjantoine 0:8447350292ab 117 const CRC32BIT_LOOKUP_TS *pCRCLUTable)
jjantoine 0:8447350292ab 118 {
jjantoine 0:8447350292ab 119 UINT32_T UINT32_Crc = 0;
jjantoine 0:8447350292ab 120
jjantoine 0:8447350292ab 121 /* si esegue il calcolo del CRC32 proper */
jjantoine 0:8447350292ab 122 UINT32_Crc = CRC32BIT_LOOKUP_Update(0, vBYTE_Data, UINT32_DataSize, TRUE, pCRCLUTable);
jjantoine 0:8447350292ab 123
jjantoine 0:8447350292ab 124 return UINT32_Crc;
jjantoine 0:8447350292ab 125 }
jjantoine 0:8447350292ab 126
jjantoine 0:8447350292ab 127 /* =======================================================================================
jjantoine 0:8447350292ab 128 * \fun Aggiorna e restituisce il CRC PROPER a 32 bit calcolato su un vettore di byte
jjantoine 0:8447350292ab 129 *
jjantoine 0:8447350292ab 130 * \par [in] pSettings: Puntatore alla struttura delle impostazioni per il calcolo del CRC
jjantoine 0:8447350292ab 131 * \val -
jjantoine 0:8447350292ab 132 *
jjantoine 0:8447350292ab 133 * \par [in] UINT32_PartialCrc : Il crc da cui partire
jjantoine 0:8447350292ab 134 * \val -
jjantoine 0:8447350292ab 135 *
jjantoine 0:8447350292ab 136 * \par [in] vBYTE_Data: Puntatore al primo byte del vettore di cui calcolare il CRC
jjantoine 0:8447350292ab 137 * \val -
jjantoine 0:8447350292ab 138 *
jjantoine 0:8447350292ab 139 * \par [in] UINT32_DataSize: Numero di byte del vettore:
jjantoine 0:8447350292ab 140 * \val -
jjantoine 0:8447350292ab 141 *
jjantoine 0:8447350292ab 142 * \par [in] BOOL_FirstData: Indica che � il primo pacchetto di dati per cui si deve
jjantoine 0:8447350292ab 143 * utilizzare il valore di inizializzazione del CRC
jjantoine 0:8447350292ab 144 * \val -
jjantoine 0:8447350292ab 145 *
jjantoine 0:8447350292ab 146 * \par [in] BOOL_LastData: Indica che � l'ultimo pacchetto di dati per cui si deve
jjantoine 0:8447350292ab 147 * effetture la riflessione in uscita o l'XOR finale
jjantoine 0:8447350292ab 148 * \val -
jjantoine 0:8447350292ab 149 *
jjantoine 0:8447350292ab 150 * \par [in] pCRCLUTable: look-up table
jjantoine 0:8447350292ab 151 * \val -
jjantoine 0:8447350292ab 152 *
jjantoine 0:8447350292ab 153 * \ret il crc calcolato
jjantoine 0:8447350292ab 154 * =======================================================================================
jjantoine 0:8447350292ab 155 */
jjantoine 0:8447350292ab 156
jjantoine 0:8447350292ab 157 UINT32_T CRC32BIT_LOOKUP_Update(const UINT32_T UINT32_PartialCrc,
jjantoine 0:8447350292ab 158 const BYTE_T vBYTE_Data[],
jjantoine 0:8447350292ab 159 const UINT32_T UINT32_DataSize,
jjantoine 0:8447350292ab 160 const BOOL_T BOOL_FirstData,
jjantoine 0:8447350292ab 161 const CRC32BIT_LOOKUP_TS *pCRCLUTable)
jjantoine 0:8447350292ab 162 {
jjantoine 0:8447350292ab 163 UINT32_T UINT32_Crc = 0;
jjantoine 0:8447350292ab 164 UINT32_T UINT32_Idx = 0;
jjantoine 0:8447350292ab 165 UINT32_T UINT32_TableIdx = 0;
jjantoine 0:8447350292ab 166 BYTE_T BYTE_Value = 0;
jjantoine 0:8447350292ab 167
jjantoine 0:8447350292ab 168 /* se si tratta del primo pacchetto dati il valore iniziale del CRC � 0xFFFFFFFF, altrimenti
jjantoine 0:8447350292ab 169 � quello parziale ricevuto in input */
jjantoine 0:8447350292ab 170 if (BOOL_FirstData == TRUE)
jjantoine 0:8447350292ab 171 {
jjantoine 0:8447350292ab 172 UINT32_Crc = pCRCLUTable->UINT32_Init;
jjantoine 0:8447350292ab 173 }
jjantoine 0:8447350292ab 174 else
jjantoine 0:8447350292ab 175 {
jjantoine 0:8447350292ab 176 UINT32_Crc = UINT32_PartialCrc;
jjantoine 0:8447350292ab 177 }/* Fine IF */
jjantoine 0:8447350292ab 178
jjantoine 0:8447350292ab 179 UINT32_Idx = 0;
jjantoine 0:8447350292ab 180
jjantoine 0:8447350292ab 181
jjantoine 0:8447350292ab 182 /* per migliorare le performance si riducono il numero di confronti nel while
jjantoine 0:8447350292ab 183 effettuando i calcoli su blocchi di 8 byte */
jjantoine 0:8447350292ab 184 while ((UINT32_DataSize - UINT32_Idx) >= CRC32BIT_LOOKUP_BLOCK_SIZE)
jjantoine 0:8447350292ab 185 {
jjantoine 0:8447350292ab 186 /* verifica se nei parametri di inizializzazione � stata attivata la riflessione dei byte */
jjantoine 0:8447350292ab 187 if (pCRCLUTable->BOOL_RefIn == TRUE)
jjantoine 0:8447350292ab 188 {
jjantoine 0:8447350292ab 189 /* step 1 */
jjantoine 0:8447350292ab 190 BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
jjantoine 0:8447350292ab 191 UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 192 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 193 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 194
jjantoine 0:8447350292ab 195 /* step 2 */
jjantoine 0:8447350292ab 196 BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
jjantoine 0:8447350292ab 197 UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 198 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 199 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 200
jjantoine 0:8447350292ab 201 /* step 3 */
jjantoine 0:8447350292ab 202 BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
jjantoine 0:8447350292ab 203 UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 204 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 205 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 206
jjantoine 0:8447350292ab 207 /* step 4 */
jjantoine 0:8447350292ab 208 BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
jjantoine 0:8447350292ab 209 UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 210 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 211 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 212
jjantoine 0:8447350292ab 213 /* step 5 */
jjantoine 0:8447350292ab 214 BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
jjantoine 0:8447350292ab 215 UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 216 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 217 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 218
jjantoine 0:8447350292ab 219 /* step 6 */
jjantoine 0:8447350292ab 220 BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
jjantoine 0:8447350292ab 221 UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 222 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 223 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 224
jjantoine 0:8447350292ab 225 /* step 7 */
jjantoine 0:8447350292ab 226 BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
jjantoine 0:8447350292ab 227 UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 228 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 229 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 230
jjantoine 0:8447350292ab 231 /* step 8 */
jjantoine 0:8447350292ab 232 BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
jjantoine 0:8447350292ab 233 UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 234 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 235 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 236 }
jjantoine 0:8447350292ab 237 else
jjantoine 0:8447350292ab 238 {
jjantoine 0:8447350292ab 239 /* step 1 */
jjantoine 0:8447350292ab 240 UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 241 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 242 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 243
jjantoine 0:8447350292ab 244 /* step 2 */
jjantoine 0:8447350292ab 245 UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 246 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 247 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 248
jjantoine 0:8447350292ab 249 /* step 3 */
jjantoine 0:8447350292ab 250 UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 251 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 252 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 253
jjantoine 0:8447350292ab 254 /* step 4 */
jjantoine 0:8447350292ab 255 UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 256 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 257 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 258
jjantoine 0:8447350292ab 259 /* step 5 */
jjantoine 0:8447350292ab 260 UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 261 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 262 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 263
jjantoine 0:8447350292ab 264 /* step 6 */
jjantoine 0:8447350292ab 265 UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 266 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 267 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 268
jjantoine 0:8447350292ab 269 /* step 7 */
jjantoine 0:8447350292ab 270 UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 271 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 272 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 273
jjantoine 0:8447350292ab 274 /* step 8 */
jjantoine 0:8447350292ab 275 UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 276 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 277 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 278 }/* Fine IF */
jjantoine 0:8447350292ab 279 }/* Fine WHILE */
jjantoine 0:8447350292ab 280
jjantoine 0:8447350292ab 281 /* si continua con i byte rimanenti */
jjantoine 0:8447350292ab 282 while (UINT32_Idx < UINT32_DataSize)
jjantoine 0:8447350292ab 283 {
jjantoine 0:8447350292ab 284 /* verifica se nei parametri di inizializzazione � stata attivata la riflessione dei byte */
jjantoine 0:8447350292ab 285 if (pCRCLUTable->BOOL_RefIn == TRUE)
jjantoine 0:8447350292ab 286 {
jjantoine 0:8447350292ab 287 BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
jjantoine 0:8447350292ab 288 UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 289 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 290 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 291 }
jjantoine 0:8447350292ab 292 else
jjantoine 0:8447350292ab 293 {
jjantoine 0:8447350292ab 294 UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
jjantoine 0:8447350292ab 295 UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
jjantoine 0:8447350292ab 296 UINT32_Idx = UINT32_Idx + 1;
jjantoine 0:8447350292ab 297 }
jjantoine 0:8447350292ab 298 }/* Fine WHILW */
jjantoine 0:8447350292ab 299
jjantoine 0:8447350292ab 300 /* verifica se nei parametri di inizializzazione � attivata la riflessione in uscita */
jjantoine 0:8447350292ab 301 if (pCRCLUTable->BOOL_RefOut == TRUE)
jjantoine 0:8447350292ab 302 {
jjantoine 0:8447350292ab 303 UINT32_Crc = CRC32BIT_LOOKUP_ReflectUINT32(UINT32_Crc);
jjantoine 0:8447350292ab 304 }/* Fine IF */
jjantoine 0:8447350292ab 305
jjantoine 0:8447350292ab 306 UINT32_Crc = UINT32_Crc ^ pCRCLUTable->UINT32_XorOut;
jjantoine 0:8447350292ab 307
jjantoine 0:8447350292ab 308 return UINT32_Crc;
jjantoine 0:8447350292ab 309 }
jjantoine 0:8447350292ab 310
jjantoine 0:8447350292ab 311 /* =======================================================================================
jjantoine 0:8447350292ab 312 * \fun Riflette i bit di un byte
jjantoine 0:8447350292ab 313 *
jjantoine 0:8447350292ab 314 * \par [in] BYTE_Value : Byte da riflettere
jjantoine 0:8447350292ab 315 * \val -
jjantoine 0:8447350292ab 316 *
jjantoine 0:8447350292ab 317 * \ret il byte riflesso
jjantoine 0:8447350292ab 318 * =======================================================================================
jjantoine 0:8447350292ab 319 */
jjantoine 0:8447350292ab 320 BYTE_T CRC32BIT_LOOKUP_ReflectByte(BYTE_T BYTE_Value)
jjantoine 0:8447350292ab 321 {
jjantoine 0:8447350292ab 322 BYTE_T BYTE_ReflectedValue = 0;
jjantoine 0:8447350292ab 323 BYTE_T BYTE_Temp = 0;
jjantoine 0:8447350292ab 324 UINT16_T UINT16_NumOfShifts = 0;
jjantoine 0:8447350292ab 325 BYTE_T BYTE_Mask = 0;
jjantoine 0:8447350292ab 326 UINT16_T UINT16_Idx = 0;
jjantoine 0:8447350292ab 327
jjantoine 0:8447350292ab 328 BYTE_ReflectedValue = 0;
jjantoine 0:8447350292ab 329
jjantoine 0:8447350292ab 330 /* cicla su tutti i bit del byte per effettuarne la riflessione */
jjantoine 0:8447350292ab 331 UINT16_Idx = 0;
jjantoine 0:8447350292ab 332 while (UINT16_Idx < CRC32BIT_LOOKUP_NUMBITS_IN_BYTE)
jjantoine 0:8447350292ab 333 {
jjantoine 0:8447350292ab 334 BYTE_Temp = (BYTE_T) (BYTE_Value >> UINT16_Idx);
jjantoine 0:8447350292ab 335
jjantoine 0:8447350292ab 336 if (BYTE_Temp & CRC32BIT_LOOKUP_BYTELSB_MASK)
jjantoine 0:8447350292ab 337 {
jjantoine 0:8447350292ab 338 UINT16_NumOfShifts = CRC32BIT_LOOKUP_NUMBITS_IN_BYTE - UINT16_Idx - 1;
jjantoine 0:8447350292ab 339
jjantoine 0:8447350292ab 340 BYTE_Mask = (BYTE_T) (CRC32BIT_LOOKUP_BYTELSB_MASK << UINT16_NumOfShifts);
jjantoine 0:8447350292ab 341
jjantoine 0:8447350292ab 342 BYTE_ReflectedValue = (BYTE_T) (BYTE_ReflectedValue ^ BYTE_Mask);
jjantoine 0:8447350292ab 343 }/* Fine IF */
jjantoine 0:8447350292ab 344
jjantoine 0:8447350292ab 345 UINT16_Idx = UINT16_Idx + 1;
jjantoine 0:8447350292ab 346 }/* Fine WHILE */
jjantoine 0:8447350292ab 347
jjantoine 0:8447350292ab 348 return BYTE_ReflectedValue;
jjantoine 0:8447350292ab 349 }
jjantoine 0:8447350292ab 350
jjantoine 0:8447350292ab 351 /* =======================================================================================
jjantoine 0:8447350292ab 352 * \fun Riflette i bit di una double word
jjantoine 0:8447350292ab 353 *
jjantoine 0:8447350292ab 354 * \par [in] UINT32_Value : Double Word da riflettere
jjantoine 0:8447350292ab 355 * \val -
jjantoine 0:8447350292ab 356 *
jjantoine 0:8447350292ab 357 * \ret la double word riflessa
jjantoine 0:8447350292ab 358 * =======================================================================================
jjantoine 0:8447350292ab 359 */
jjantoine 0:8447350292ab 360 UINT32_T CRC32BIT_LOOKUP_ReflectUINT32(UINT32_T UINT32_Value)
jjantoine 0:8447350292ab 361 {
jjantoine 0:8447350292ab 362 UINT32_T UINT32_ReflectedValue = 0;
jjantoine 0:8447350292ab 363 UINT32_T UINT32_Temp = 0;
jjantoine 0:8447350292ab 364 UINT32_T UINT32_Mask = 0;
jjantoine 0:8447350292ab 365 UINT16_T UINT16_Idx = 0;
jjantoine 0:8447350292ab 366 UINT16_T UINT16_NumOfShifts = 0;
jjantoine 0:8447350292ab 367
jjantoine 0:8447350292ab 368 UINT32_ReflectedValue = 0;
jjantoine 0:8447350292ab 369
jjantoine 0:8447350292ab 370 /* cicla su tutti i bit della DWORD per effettuarne la riflessione */
jjantoine 0:8447350292ab 371 UINT16_Idx = 0;
jjantoine 0:8447350292ab 372 while (UINT16_Idx < CRC32BIT_LOOKUP_NUMBITS_UINT32)
jjantoine 0:8447350292ab 373 {
jjantoine 0:8447350292ab 374 UINT32_Temp = (UINT32_Value >> UINT16_Idx);
jjantoine 0:8447350292ab 375
jjantoine 0:8447350292ab 376 if (UINT32_Temp & CRC32BIT_LOOKUP_UINT32LSB_MASK)
jjantoine 0:8447350292ab 377 {
jjantoine 0:8447350292ab 378 UINT16_NumOfShifts = CRC32BIT_LOOKUP_NUMBITS_UINT32 - UINT16_Idx - 1;
jjantoine 0:8447350292ab 379
jjantoine 0:8447350292ab 380 UINT32_Mask = (UINT32_T) (CRC32BIT_LOOKUP_UINT32LSB_MASK << UINT16_NumOfShifts);
jjantoine 0:8447350292ab 381
jjantoine 0:8447350292ab 382 UINT32_ReflectedValue = (UINT32_ReflectedValue ^ UINT32_Mask);
jjantoine 0:8447350292ab 383 }/* Fine IF */
jjantoine 0:8447350292ab 384
jjantoine 0:8447350292ab 385 UINT16_Idx = UINT16_Idx + 1;
jjantoine 0:8447350292ab 386 }/* Fine WHILE */
jjantoine 0:8447350292ab 387
jjantoine 0:8447350292ab 388 return UINT32_ReflectedValue;
jjantoine 0:8447350292ab 389 }