Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 5:851e7afdc4fe, committed 2018-12-21
- Comitter:
- jjantoine
- Date:
- Fri Dec 21 15:39:53 2018 +0000
- Parent:
- 4:a5b5809ee14f
- Commit message:
- GPO
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CRC/CRC32BIT_LOOKUP_Ext.h Fri Dec 21 15:39:53 2018 +0000
@@ -0,0 +1,135 @@
+/* =======================================================================================
+ * (c)
+ * (c) MEL SYSTEM S.r.l.
+ * (c)
+ * (c) Libreria VB32_Lib (Vital Board 32 Bit)
+ * (c)
+ * (c) La libreria VB32_Lib implementa le tutte le funzionalità necessarie per l'utilizzo
+ * (c) dei due processori AT91SAM9 della scheda VB32. La libreria permette di gestire
+ * (c) tutte le periferiche interne (DBGU, USART, SPI, ecc..) e tutte le periferiche
+ * (c) esterne (HILSCHER COM-C DPM, ecc..) del processore AT91SAM9.
+ * (c)
+ * (c) ===================================================================================
+ * (c)
+ * (c) Copyright (C) MEL SYSTEM S.r.l.
+ * (c)
+ * (c) Tutti i diritti riservati.
+ * (c)
+ * (c) Questo programma e' tutelato dalle leggi sul copyright, dalle leggi sui diritti
+ * (c) d'autore e dai trattati internazionali. La riproduzione o distribuzione non
+ * (c) autorizzata di questo programma, o di parte di esso, sara' perseguibile civilmente
+ * (c) e penalmente.
+ * (c)
+ * =======================================================================================
+ */
+
+/* =======================================================================================
+ * Informazioni del modulo
+ * =======================================================================================
+ * \brf CRC32BIT_LOOKUP
+ *
+ * \mod Il modulo CRC32BIT_LOOKUP permette di calcolare crc a 32 bit di vettori di BYTE
+ * o di WORD utilizzando una tabella di lookup
+ *
+ * \aut Michele Giannese
+ * =======================================================================================
+ */
+
+/* =======================================================================================
+ * Elenco delle modifiche (data - autore - descrizione)
+ * =======================================================================================
+ *
+ * Ultima:
+ *
+ * 23/04/2013 - M. Giannese - creazione del modulo
+ * =======================================================================================
+ */
+
+#ifndef _CRC32BIT_LOOKUP_EXT_H
+#define _CRC32BIT_LOOKUP_EXT_H
+
+/* =======================================================================================
+ * File inclusi
+ * =======================================================================================
+ */
+#include "TYPE_Def.h"
+
+
+/* =======================================================================================
+ * Macro
+ * =======================================================================================
+ */
+
+/* =======================================================================================
+ * Definizioni
+ * =======================================================================================
+ */
+
+/* \str Struttura contenente la look-up table per il calcolo ottimizzato del CRC a 32 bit */
+typedef struct
+{
+ /* \var polynomial Crc 32 bit
+ * \val 0x00000000..0xFFFFFFFF (1) [-]
+ * \ini 0
+ */
+ UINT32_T UINT32_Poly;
+
+ /* \var Initial value Crc 32 bit
+ * \val 0x00000000..0xFFFFFFFF (1) [-]
+ * \ini 0
+ */
+ UINT32_T UINT32_Init;
+
+ /* \var Input reflection Crc 32 bit
+ * \val 0x00000000..0xFFFFFFFF (1) [-]
+ * \ini 0
+ */
+ BOOL_T BOOL_RefIn;
+ /* \var Output reflection Crc 32 bit
+ * \val 0x00000000..0xFFFFFFFF (1) [-]
+ * \ini 0
+ */
+ BOOL_T BOOL_RefOut;
+ /* \var XOR value Crc 32 bit
+ * \val 0x00000000..0xFFFFFFFF (1) [-]
+ * \ini 0
+ */
+ UINT32_T UINT32_XorOut;
+
+ /* \var Look-up Table Crc 32 bit
+ * \val 0x00000000..0xFFFFFFFF (1) [-]
+ * \ini 0
+ */
+ DWORD_T _vDWORD_CRC32LookUpTable[256];
+} CRC32BIT_LOOKUP_TS;
+
+/* =======================================================================================
+ * Prototipi delle funzioni
+ * =======================================================================================
+ */
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif /* __cplusplus */
+
+/* Restituisce il CRC PROPER a 32 bit calcolato su un vettore di byte */
+UINT32_T CRC32BIT_LOOKUP_Compute(const BYTE_T vBYTE_Data[],
+ const UINT32_T UINT32_DataSize,
+ const CRC32BIT_LOOKUP_TS *pCRCLUTable);
+
+/* Valorizza la look-up table in funzione del valore crcSettings */
+ERROR_T CRC32BIT_LOOKUP_Init(CRC32BIT_LOOKUP_TS *pCRCLUTable);
+
+/* Aggiorna e restituisce il CRC PROPER a 32 bit calcolato su un vettore di byte */
+UINT32_T CRC32BIT_LOOKUP_Update(const UINT32_T UINT32_PartialCrc,
+ const BYTE_T vBYTE_Data[],
+ const UINT32_T UINT32_DataSize,
+ const BOOL_T BOOL_FirstData,
+ const CRC32BIT_LOOKUP_TS *pCRCLUTable);
+
+#if defined(__cplusplus)
+}
+#endif /* __cplusplus */
+
+#endif /* _CRC32BIT_LOOKUP_EXT_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CRC/CRC32BIT_LOOKUP_Int.h Fri Dec 21 15:39:53 2018 +0000 @@ -0,0 +1,88 @@ +/* ======================================================================================= + * (c) + * (c) MEL SYSTEM S.r.l. + * (c) + * (c) Libreria VB32_Lib (Vital Board 32 Bit) + * (c) + * (c) La libreria VB32_Lib implementa le tutte le funzionalità necessarie per l'utilizzo + * (c) dei due processori AT91SAM9 della scheda VB32. La libreria permette di gestire + * (c) tutte le periferiche interne (DBGU, USART, SPI, ecc..) e tutte le periferiche + * (c) esterne (HILSCHER COM-C DPM, ecc..) del processore AT91SAM9. + * (c) + * (c) =================================================================================== + * (c) + * (c) Copyright (C) MEL SYSTEM S.r.l. + * (c) + * (c) Tutti i diritti riservati. + * (c) + * (c) Questo programma e' tutelato dalle leggi sul copyright, dalle leggi sui diritti + * (c) d'autore e dai trattati internazionali. La riproduzione o distribuzione non + * (c) autorizzata di questo programma, o di parte di esso, sara' perseguibile civilmente + * (c) e penalmente. + * (c) + * ======================================================================================= + */ + +/* ======================================================================================= + * Elenco delle modifiche (data - autore - descrizione) + * ======================================================================================= + * + * Ultima: + * + * 23/04/2013 - M. Giannese - creazione del modulo + * ======================================================================================= + */ + +#ifndef _CRC32_LOOKUP_INT_H +#define _CRC32_LOOKUP_INT_H + +/* ======================================================================================= + * File inclusi + * ======================================================================================= + */ + +#include "CRC32BIT_LOOKUP_Ext.h" +#include "ERROR_STD_Def.h" +//#include "WORD_Ext.h" + +/* ======================================================================================= + * Definizioni + * ======================================================================================= + */ + +/* \def Numero di bit in un byte */ +#define CRC32BIT_LOOKUP_NUMBITS_IN_BYTE 8 +/* \def Numero di bit in un byte */ +#define CRC32BIT_LOOKUP_NUMELEMENTS_IN_BYTE 256 +/* \def Numero di bit in una double word */ +#define CRC32BIT_LOOKUP_NUMBITS_UINT32 32 +/* \def Differenza di dimensione tra intero a 32 bit e byte */ +#define CRC32BIT_LOOKUP_AUGMENTATION (CRC32BIT_LOOKUP_NUMBITS_UINT32 - CRC32BIT_LOOKUP_NUMBITS_IN_BYTE) +/* \def Maschera del bit meno significativo di una double word */ +#define CRC32BIT_LOOKUP_UINT32LSB_MASK (UINT32_T)1 + /* \def Maschera del bit meno significativo di un byte */ +#define CRC32BIT_LOOKUP_BYTELSB_MASK (BYTE_T)0x01 +/* \def Maschera del bit più significativo di una double word */ +#define CRC32BIT_LOOKUP_UINT32MSB_MASK (UINT32_T)0x80000000 +/* \def dimensione del blocco per il calcolo veloce del CRC */ +#define CRC32BIT_LOOKUP_BLOCK_SIZE 8 + +#define TOPBIT ((UINT32_T)(1<<(CRC32BIT_LOOKUP_NUMBITS_UINT32-1))) + +/* ======================================================================================= + * Macro + * ======================================================================================= + */ + +/* ======================================================================================= + * Prototipi delle funzioni + * ======================================================================================= + */ + +/* Riflette i bit di un byte */ +BYTE_T CRC32BIT_LOOKUP_ReflectByte(BYTE_T BYTE_Value); + +/* Riflette i bit di una double word */ +UINT32_T CRC32BIT_LOOKUP_ReflectUINT32(UINT32_T UINT32_Value); + +#endif /* _CRC32_LOOKUP_INT_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CRC/CRC32BIT_LOOKUP_Md0.c Fri Dec 21 15:39:53 2018 +0000
@@ -0,0 +1,389 @@
+/* =======================================================================================
+* (c)
+* (c) MEL SYSTEM S.r.l.
+* (c)
+* (c) Libreria VB32_Lib (Vital Board 32 Bit)
+* (c)
+* (c) La libreria VB32_Lib implementa le tutte le funzionalit� necessarie per l'utilizzo
+* (c) dei due processori AT91SAM9 della scheda VB32. La libreria permette di gestire
+* (c) tutte le periferiche interne (DBGU, USART, SPI, ecc..) e tutte le periferiche
+* (c) esterne (HILSCHER COM-C DPM, ecc..) del processore AT91SAM9.
+* (c)
+* (c) ===================================================================================
+* (c)
+* (c) Copyright (C) MEL SYSTEM S.r.l.
+* (c)
+* (c) Tutti i diritti riservati.
+* (c)
+* (c) Questo programma e' tutelato dalle leggi sul copyright, dalle leggi sui diritti
+* (c) d'autore e dai trattati internazionali. La riproduzione o distribuzione non
+* (c) autorizzata di questo programma, o di parte di esso, sara' perseguibile civilmente
+* (c) e penalmente.
+* (c)
+* =======================================================================================
+*/
+
+/* =======================================================================================
+ * Elenco delle modifiche (data - autore - descrizione)
+ * =======================================================================================
+ *
+ * Ultima:
+ *
+ * 23/04/2013 - M. Giannese - creazione del modulo
+ * =======================================================================================
+ */
+
+/* =======================================================================================
+* File inclusi
+* =======================================================================================
+*/
+#include "CRC32BIT_LOOKUP_Int.h"
+
+/* =======================================================================================
+* Funzioni
+* =======================================================================================
+*/
+
+/* =======================================================================================
+* \fun Inizializza la struttura _CrcLUTable con i valori di CRC calcolati in funzione
+* dei valori di crcSettings
+*
+
+* \par [in] crcSettings: struttura delle impostazioni per il calcolo del CRC
+* \val -
+*
+* \par [out] _CrcLUTable : la struttura che contiene la look up table
+* \val -
+*
+
+* =======================================================================================
+*/
+
+ERROR_T CRC32BIT_LOOKUP_Init(CRC32BIT_LOOKUP_TS *pCRCLUTable)
+{
+ERROR_T ERROR_Value = E_NULL;
+UINT32_T UINT32_elementInBytes = 0;
+UINT32_T UINT32_bitInBytes = 0;
+UINT32_T UINT32_value = 0;
+
+ /* Viene calcolata la look-up table */
+ if (pCRCLUTable->UINT32_Poly != 0)
+ {
+ for (UINT32_elementInBytes = 0; UINT32_elementInBytes < CRC32BIT_LOOKUP_NUMELEMENTS_IN_BYTE; ++UINT32_elementInBytes)
+ {
+ UINT32_value = UINT32_elementInBytes << 24;
+
+ for (UINT32_bitInBytes = CRC32BIT_LOOKUP_NUMBITS_IN_BYTE; UINT32_bitInBytes > 0; --UINT32_bitInBytes)
+ {
+ if (UINT32_value & TOPBIT)
+ {
+ UINT32_value = (UINT32_value << 1) ^ pCRCLUTable->UINT32_Poly;
+ }
+ else
+ {
+ UINT32_value = (UINT32_value << 1);
+ }
+ }
+
+ pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_elementInBytes] = UINT32_value;
+ }
+
+ ERROR_Value = E_OK;
+ }
+ else
+ {
+ ERROR_Value = E_STD_INVALID_PARAM;
+ }
+ return ERROR_Value;
+}
+
+/* =======================================================================================
+* \fun Restituisce il CRC PROPER a 32 bit calcolato su un vettore di byte
+*
+* \par [in] vBYTE_Data: Puntatore al primo byte del vettore di cui calcolare il CRC
+* \val 0x00..0xFF (1) [-]
+*
+* \par [in] UINT32_DataSize: Numero di byte del vettore:
+* \val -
+*
+* \par [in] pCRCLUTable: look-up table
+* \val - [-]
+*
+* \ret il crc calcolato
+* =======================================================================================
+*/
+UINT32_T CRC32BIT_LOOKUP_Compute(const BYTE_T vBYTE_Data[],
+ const UINT32_T UINT32_DataSize,
+ const CRC32BIT_LOOKUP_TS *pCRCLUTable)
+{
+UINT32_T UINT32_Crc = 0;
+
+ /* si esegue il calcolo del CRC32 proper */
+ UINT32_Crc = CRC32BIT_LOOKUP_Update(0, vBYTE_Data, UINT32_DataSize, TRUE, pCRCLUTable);
+
+ return UINT32_Crc;
+}
+
+/* =======================================================================================
+* \fun Aggiorna e restituisce il CRC PROPER a 32 bit calcolato su un vettore di byte
+*
+* \par [in] pSettings: Puntatore alla struttura delle impostazioni per il calcolo del CRC
+* \val -
+*
+* \par [in] UINT32_PartialCrc : Il crc da cui partire
+* \val -
+*
+* \par [in] vBYTE_Data: Puntatore al primo byte del vettore di cui calcolare il CRC
+* \val -
+*
+* \par [in] UINT32_DataSize: Numero di byte del vettore:
+* \val -
+*
+* \par [in] BOOL_FirstData: Indica che � il primo pacchetto di dati per cui si deve
+* utilizzare il valore di inizializzazione del CRC
+* \val -
+*
+* \par [in] BOOL_LastData: Indica che � l'ultimo pacchetto di dati per cui si deve
+* effetture la riflessione in uscita o l'XOR finale
+* \val -
+*
+* \par [in] pCRCLUTable: look-up table
+* \val -
+*
+* \ret il crc calcolato
+* =======================================================================================
+*/
+
+UINT32_T CRC32BIT_LOOKUP_Update(const UINT32_T UINT32_PartialCrc,
+ const BYTE_T vBYTE_Data[],
+ const UINT32_T UINT32_DataSize,
+ const BOOL_T BOOL_FirstData,
+ const CRC32BIT_LOOKUP_TS *pCRCLUTable)
+{
+UINT32_T UINT32_Crc = 0;
+UINT32_T UINT32_Idx = 0;
+UINT32_T UINT32_TableIdx = 0;
+BYTE_T BYTE_Value = 0;
+
+ /* se si tratta del primo pacchetto dati il valore iniziale del CRC � 0xFFFFFFFF, altrimenti
+ � quello parziale ricevuto in input */
+ if (BOOL_FirstData == TRUE)
+ {
+ UINT32_Crc = pCRCLUTable->UINT32_Init;
+ }
+ else
+ {
+ UINT32_Crc = UINT32_PartialCrc;
+ }/* Fine IF */
+
+ UINT32_Idx = 0;
+
+
+ /* per migliorare le performance si riducono il numero di confronti nel while
+ effettuando i calcoli su blocchi di 8 byte */
+ while ((UINT32_DataSize - UINT32_Idx) >= CRC32BIT_LOOKUP_BLOCK_SIZE)
+ {
+ /* verifica se nei parametri di inizializzazione � stata attivata la riflessione dei byte */
+ if (pCRCLUTable->BOOL_RefIn == TRUE)
+ {
+ /* step 1 */
+ BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
+ UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 2 */
+ BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
+ UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 3 */
+ BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
+ UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 4 */
+ BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
+ UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 5 */
+ BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
+ UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 6 */
+ BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
+ UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 7 */
+ BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
+ UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 8 */
+ BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
+ UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+ }
+ else
+ {
+ /* step 1 */
+ UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 2 */
+ UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 3 */
+ UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 4 */
+ UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 5 */
+ UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 6 */
+ UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 7 */
+ UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+
+ /* step 8 */
+ UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+ }/* Fine IF */
+ }/* Fine WHILE */
+
+ /* si continua con i byte rimanenti */
+ while (UINT32_Idx < UINT32_DataSize)
+ {
+ /* verifica se nei parametri di inizializzazione � stata attivata la riflessione dei byte */
+ if (pCRCLUTable->BOOL_RefIn == TRUE)
+ {
+ BYTE_Value = CRC32BIT_LOOKUP_ReflectByte(vBYTE_Data[UINT32_Idx]);
+ UINT32_TableIdx = (UINT32_T)(BYTE_Value ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+ }
+ else
+ {
+ UINT32_TableIdx = (UINT32_T)(vBYTE_Data[UINT32_Idx] ^ (UINT32_Crc >> CRC32BIT_LOOKUP_AUGMENTATION));
+ UINT32_Crc = pCRCLUTable->_vDWORD_CRC32LookUpTable[UINT32_TableIdx] ^ (UINT32_Crc << CRC32BIT_LOOKUP_NUMBITS_IN_BYTE);
+ UINT32_Idx = UINT32_Idx + 1;
+ }
+ }/* Fine WHILW */
+
+ /* verifica se nei parametri di inizializzazione � attivata la riflessione in uscita */
+ if (pCRCLUTable->BOOL_RefOut == TRUE)
+ {
+ UINT32_Crc = CRC32BIT_LOOKUP_ReflectUINT32(UINT32_Crc);
+ }/* Fine IF */
+
+ UINT32_Crc = UINT32_Crc ^ pCRCLUTable->UINT32_XorOut;
+
+ return UINT32_Crc;
+}
+
+/* =======================================================================================
+* \fun Riflette i bit di un byte
+*
+* \par [in] BYTE_Value : Byte da riflettere
+* \val -
+*
+* \ret il byte riflesso
+* =======================================================================================
+*/
+BYTE_T CRC32BIT_LOOKUP_ReflectByte(BYTE_T BYTE_Value)
+{
+BYTE_T BYTE_ReflectedValue = 0;
+BYTE_T BYTE_Temp = 0;
+UINT16_T UINT16_NumOfShifts = 0;
+BYTE_T BYTE_Mask = 0;
+UINT16_T UINT16_Idx = 0;
+
+ BYTE_ReflectedValue = 0;
+
+ /* cicla su tutti i bit del byte per effettuarne la riflessione */
+ UINT16_Idx = 0;
+ while (UINT16_Idx < CRC32BIT_LOOKUP_NUMBITS_IN_BYTE)
+ {
+ BYTE_Temp = (BYTE_T) (BYTE_Value >> UINT16_Idx);
+
+ if (BYTE_Temp & CRC32BIT_LOOKUP_BYTELSB_MASK)
+ {
+ UINT16_NumOfShifts = CRC32BIT_LOOKUP_NUMBITS_IN_BYTE - UINT16_Idx - 1;
+
+ BYTE_Mask = (BYTE_T) (CRC32BIT_LOOKUP_BYTELSB_MASK << UINT16_NumOfShifts);
+
+ BYTE_ReflectedValue = (BYTE_T) (BYTE_ReflectedValue ^ BYTE_Mask);
+ }/* Fine IF */
+
+ UINT16_Idx = UINT16_Idx + 1;
+ }/* Fine WHILE */
+
+ return BYTE_ReflectedValue;
+}
+
+/* =======================================================================================
+* \fun Riflette i bit di una double word
+*
+* \par [in] UINT32_Value : Double Word da riflettere
+* \val -
+*
+* \ret la double word riflessa
+* =======================================================================================
+*/
+UINT32_T CRC32BIT_LOOKUP_ReflectUINT32(UINT32_T UINT32_Value)
+{
+UINT32_T UINT32_ReflectedValue = 0;
+UINT32_T UINT32_Temp = 0;
+UINT32_T UINT32_Mask = 0;
+UINT16_T UINT16_Idx = 0;
+UINT16_T UINT16_NumOfShifts = 0;
+
+ UINT32_ReflectedValue = 0;
+
+ /* cicla su tutti i bit della DWORD per effettuarne la riflessione */
+ UINT16_Idx = 0;
+ while (UINT16_Idx < CRC32BIT_LOOKUP_NUMBITS_UINT32)
+ {
+ UINT32_Temp = (UINT32_Value >> UINT16_Idx);
+
+ if (UINT32_Temp & CRC32BIT_LOOKUP_UINT32LSB_MASK)
+ {
+ UINT16_NumOfShifts = CRC32BIT_LOOKUP_NUMBITS_UINT32 - UINT16_Idx - 1;
+
+ UINT32_Mask = (UINT32_T) (CRC32BIT_LOOKUP_UINT32LSB_MASK << UINT16_NumOfShifts);
+
+ UINT32_ReflectedValue = (UINT32_ReflectedValue ^ UINT32_Mask);
+ }/* Fine IF */
+
+ UINT16_Idx = UINT16_Idx + 1;
+ }/* Fine WHILE */
+
+ return UINT32_ReflectedValue;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CRC/ERROR_STD_Def.h Fri Dec 21 15:39:53 2018 +0000
@@ -0,0 +1,114 @@
+/* =======================================================================================
+ * (c)
+ * (c) Sitael S.p.A.
+ * (c)
+ * (c) Componente ERROR_STD
+ * (c)
+ * (c)
+ * (c) ===================================================================================
+ * (c)
+ * (c) Copyright (C) Sitael S.p.A.
+ * (c)
+ * (c) Tutti i diritti riservati.
+ * (c)
+ * (c) Questo programma e' tutelato dalle leggi sul copyright, dalle leggi sui diritti
+ * (c) d'autore e dai trattati internazionali. La riproduzione o distribuzione non
+ * (c) autorizzata di questo programma, o di parte di esso, sara' perseguibile civilmente
+ * (c) e penalmente.
+ * (c)
+ * =======================================================================================
+ */
+/* =======================================================================================
+ * Informazioni del modulo
+ * =======================================================================================
+ */
+ /*! \file ERROR_STD_Def.h
+ * Questo file definisce i codici di errore della libreria
+ *
+ * \details Questo file definisce i codici di errore della libreria
+ *
+ *
+ * \author Orlando Petrone
+ */
+
+/* =======================================================================================
+ * Elenco delle modifiche (data - autore - descrizione)
+ * =======================================================================================
+ * Ultima:
+ *
+ * 03/11/2015 - O. Petrone - creazione del modulo
+ * =======================================================================================
+ */
+#ifndef _ERROR_STD_DEF_H
+#define _ERROR_STD_DEF_H
+
+/* =======================================================================================
+ * File inclusi
+ * =======================================================================================
+ */
+ #include "TYPE_Def.h" /* Contiene la definizione di ERROR_T */
+
+/* =======================================================================================
+ * Definizioni
+ * =======================================================================================
+ */
+
+/*!
+ * Codice identificativo della libreria
+ */
+#define STD_LIB_CODE (0x82)
+
+#define E_STD_INVALID_PARAM (ERROR_T) 0x01 /*!< Parametro non valido */
+#define E_STD_INVALID_STATE (ERROR_T) 0x02 /*!< Stato non ammesso */
+#define E_STD_NULL_POINTER (ERROR_T) 0x03 /*!< Puntatore nullo */
+#define E_STD_CHECKSUM (ERROR_T) 0x04 /*!< Checksum non valida */
+#define E_STD_SEQ_NUMBER (ERROR_T) 0x05 /*!< Errore di sequence counter */
+#define E_STD_MESSAGE_INVALID_SIZE (ERROR_T) 0x06 /*!< Dimensione messaggio non valida */
+#define E_STD_DATA_MAX_SIZE (ERROR_T) 0x08 /*!< Errore sulla massima dimensione */
+#define E_STD_FRAME_INVALID_SIZE (ERROR_T) 0x09 /*!< Dimensione non valida */
+#define E_STD_DECODING_FRAME (ERROR_T) 0x0A /*!< Errore decodifica frame */
+
+
+/*! \def MODULE_STD_ID_TE
+ * Moduli e componenti appartenenti all'applicazione INTLOCK.
+ */
+typedef enum
+{
+ MODULE_STD_ID_IODEB = 0x01 /*!< Modulo IODEB */
+ ,MODULE_STD_ID_NVCP = 0x02 /*!< Modulo NVCP */
+ ,MODULE_STD_ID_NVCPDL = 0x03 /*!< Modulo NVCPDL */
+ ,MODULE_STD_ID_INVALID = 0xFF /*!< Identificativo modulo valido */
+
+
+} MODULE_STD_ID_TE;
+
+
+/* =======================================================================================
+ * Macro
+ * =======================================================================================
+ */
+
+ /*! \def ERROR_FormatAPP(ENUM_ModuleID, ERROR_Value)
+ * Crea una parola da 32 bit con le informazioni sul modulo che ha generato l'errore
+ * ed il tipo d'errore.
+ * Nella formattazione degli errori si usa il seguente formato
+ * Il formato degli errori (32 bit) e'
+ *
+ * | (1° byte) | (2° byte)| (3° byte) | (4° byte) |
+ * | Byte piu' | | | Byte meno |
+ * | significativo| | | significativo |
+ * ----------------------------------------------------------
+ * | Application/ | Modulo | Codice Errore Rilevato |
+ * | Library | | Modulo | Errore |
+ * | | | [0x0000......0xFFFF] |
+ *
+ * Per identificare la libreria di provenienza si aggiorna il
+ * 2° byte piu' significativo
+ */
+#define ERROR_FormatSTD(ENUM_ModuleID, ERROR_Value) \
+ (((ERROR_T)((STD_LIB_CODE << 24) | (ENUM_ModuleID) << 16)) | (ERROR_Value))
+
+
+
+
+#endif /* _ERROR_STD_DEF_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CRC/TYPE_Def.h Fri Dec 21 15:39:53 2018 +0000
@@ -0,0 +1,305 @@
+/* =======================================================================================
+ * (c)
+ * (c) Sitael S.p.A
+ * (c)
+ * (c) Libreria STD_Lib
+ * (c)
+ * (c) Copyright (C) Sitael S.p.A.
+ * (c)
+ * (c) Tutti i diritti riservati.
+ * (c)
+ * (c) Questo programma e' tutelato dalle leggi sul copyright, dalle leggi sui diritti
+ * (c) d'autore e dai trattati internazionali. La riproduzione o distribuzione non
+ * (c) autorizzata di questo programma, o di parte di esso, sara' perseguibile civilmente
+ * (c) e penalmente.
+ * (c)
+ * =======================================================================================
+ */
+
+/* =======================================================================================
+ * Informazioni del modulo
+ * =======================================================================================
+ * \brf Tipi e definizioni della libreria STD_Lib
+ *
+ * \mod Tipi e definizioni della libreria STD_Lib
+ * \aut Luigi Ingravallo
+ * =======================================================================================
+ */
+
+/* =======================================================================================
+ * Elenco delle modifiche (data - autore - descrizione)
+ * =======================================================================================
+ *
+ * Ultima:
+ *
+ * 24/05/2017 - Luigi Ingravallo - Creazione del modulo
+ * =======================================================================================
+ */
+
+#ifndef _TYPE_DEF_H
+#define _TYPE_DEF_H
+
+/* =======================================================================================
+ * File inclusi
+ * =======================================================================================
+ */
+#ifdef _UNICODE
+#include <wchar.h>
+#endif
+/* =======================================================================================
+ * Definizioni
+ * =======================================================================================
+ */
+
+
+#ifndef _64BIT_PLATFORM
+//#error Definire la piattaforma
+#endif
+
+
+/* TIPI SEMPLICI */
+
+#ifndef _CHAR_T
+ /* \typ Carattere (Intero segnato a 8 bit) */
+#ifdef _UNICODE
+ typedef wchar_t CHAR_T;
+#else
+ typedef char CHAR_T;
+#endif
+#define _CHAR_T
+#endif
+
+#ifndef _SMALL_T
+ /* \typ Dato generico (Intero segnato a 8 bit) */
+ typedef signed char SMALL_T;
+#define _SMALL_T
+#endif
+
+#ifndef _INT8_T
+ /* \typ Contatore (Intero segnato a 8 bit) */
+ typedef signed char INT8_T;
+#define _INT8_T
+#endif
+
+#ifndef _BYTE_T
+ /* \typ Dato generico (Intero non segnato a 8 bit) */
+ typedef unsigned char BYTE_T;
+#define _BYTE_T
+#endif
+
+#ifndef _UINT8_T
+ /* \typ Contatore\dimensione (Intero non segnato a 8 bit) */
+ typedef unsigned char UINT8_T;
+#define _UINT8_T
+#endif
+
+#ifndef _BOOL_T
+ /* \typ Booleano (Intero non segnato a 32 bit) */
+ typedef int BOOL_T;
+#define _BOOL_T
+#endif
+
+#ifndef _SHORT_T
+ /* \typ Dato generico (Intero segnato a 16 bit) */
+ typedef signed short SHORT_T;
+#define _SHORT_T
+#endif
+
+#ifndef _INT16_T
+ /* \typ Contatore (Intero segnato a 16 bit) */
+ typedef signed short INT16_T;
+#define _INT16_T
+#endif
+
+#ifndef _WORD_T
+ /* \typ Dato generico (Intero non segnato a 16 bit) */
+ typedef unsigned short WORD_T;
+#define _WORD_T
+#endif
+
+#ifndef _UINT16_T
+ /* \typ Contatore\dimensione (Intero non segnato a 16 bit) */
+ typedef unsigned short UINT16_T;
+#define _UINT16_T
+#endif
+
+#ifndef _LONG_T
+ /* \typ Dato generico (Intero segnato a 32 bit) */
+ typedef signed long LONG_T;
+#define _LONG_T
+#endif
+
+#ifdef _16BIT_PLATFORM
+#ifndef _INT32_T
+ /* \typ Contatore (Intero segnato a 32 bit) */
+ typedef signed long INT32_T;
+#define _INT32_T
+#endif
+
+#ifndef _DWORD_T
+ /* \typ Dato generico (Intero non segnato a 32 bit) */
+ typedef unsigned long DWORD_T;
+#define _DWORD_T
+#endif
+
+#ifndef _UINT32_T
+ /* \typ Contatore\dimensione (Intero non segnato a 32 bit) */
+ typedef unsigned long UINT32_T;
+#define _UINT32_T
+#endif
+#else
+ #ifndef _INT32_T
+ /* \typ Contatore (Intero segnato a 32 bit) */
+ typedef signed int INT32_T;
+#define _INT32_T
+#endif
+
+#ifndef _DWORD_T
+ /* \typ Dato generico (Intero non segnato a 32 bit) */
+ typedef unsigned int DWORD_T;
+#define _DWORD_T
+#endif
+
+#ifndef _QWORD_T
+ /* \typ Dato generico (Intero non segnato a 64 bit) */
+ typedef unsigned long long QWORD_T;
+#define _QWORD_T
+#endif
+
+#ifndef _UINT32_T
+ /* \typ Contatore\dimensione (Intero non segnato a 32 bit) */
+ typedef unsigned int UINT32_T;
+#define _UINT32_T
+#endif
+#endif
+
+
+//#ifndef _MSC_VER
+
+#ifndef _INT64_T
+ /* \typ Contatore (Intero segnato a 64 bit) */
+ typedef signed long long INT64_T;
+#define _INT64_T
+#endif
+
+#ifndef _UINT64_T
+ /* \typ Contatore\dimensione (Intero non segnato a 64 bit) */
+ typedef unsigned long long UINT64_T;
+#define _UINT64_T
+#endif
+
+//#endif
+
+ #ifndef _TIME_T
+ /* \typ Tempo (Intero non segnato a 32 bit) */
+ typedef unsigned long TIME_T;
+ #define _TIME_T
+ #endif
+
+
+#ifndef _ADDR_T
+ /* \typ Indirizzo di memoria (Intero non segnato a 32 bit) */
+ typedef unsigned long ADDR_T;
+#define _ADDR_T
+#endif
+
+#ifndef _ERROR_T
+ /* \typ Codice di errore (Intero non segnato a 32 bit) */
+ typedef unsigned long ERROR_T;
+#define _ERROR_T
+#endif
+
+#ifndef _HANDLE_T
+ /* \typ Handle (Intero non segnato a 16 bit) */
+ typedef unsigned short HANDLE_T;
+#define _HANDLE_T
+#endif
+
+#ifndef _BARRIER_T
+ /* \typ Tag di inzio e fine di una barriera */
+ typedef unsigned char BARRIER_T;
+#define _BARRIER_T
+#endif
+
+#ifndef _FLOAT_T
+ /* \typ Dato generico (Virgola mobile a 32 bit) */
+ typedef float FLOAT_T;
+#define _FLOAT_T
+#endif
+
+#ifndef _DOUBLE_T
+ /* \typ Dato generico (Virgola mobile a 64 bit) */
+ typedef double DOUBLE_T;
+#define _DOUBLE_T
+#endif
+
+
+/* COSTANTI PER IL TIPO BOOL_T */
+#ifndef TRUE
+ /* \def Valore "vero" del tipo booleano BOOL_T */
+ #define TRUE (1)
+#endif
+#ifndef FALSE
+ /* \def Valore "falso" del tipo booleano BOOL_T */
+ #define FALSE (0)
+#endif
+
+/* COSTANTI PER IL TIPO HANDLE_T */
+
+#ifndef NULL_HANDLE
+ /* \def Valore che indica un handle non valido */
+ #define NULL_HANDLE (HANDLE_T)-1
+#endif
+
+/* COSTANTI PER IL TIPO BARRIER_T */
+
+/* \def Tag di inizio barriera */
+#define BARRIER_BEGIN ((BARRIER_T) 0x0F)
+/* \def Tag di fine barriera */
+#define BARRIER_END ((BARRIER_T) 0xF0)
+
+/* COSTANTI PER I PUNTATORI */
+#ifndef NULL
+ /* \def Puntatore nullo */
+ #define NULL (0)
+#endif
+
+/* COSTANTI PER GLI ERRORI */
+#ifndef E_NULL
+ /* \err Valore iniziale delle variabili di tipo ERROR_T */
+ #define E_NULL (ERROR_T) -1
+#endif
+#ifndef E_OK
+ /* \err Operazione completata con successo */
+ #define E_OK (ERROR_T) 0x00
+#endif
+
+
+
+/* =======================================================================================
+ * Macro
+ * =======================================================================================
+ */
+
+/* =======================================================================================
+ * \mac Esegue la funzione ERROR_Function solo se precedentemente non si sono
+ * verificati degli errori
+ *
+ * \par [in] ERROR_Value : Codice di errore di tipo ERROR_T
+ * \val -
+ *
+ * \par [in] ERROR_Function : Funzione che restituisce il tipo ERROR_T
+ * \val -
+ *
+ * \ret -
+ * =======================================================================================
+ */
+#define ERROR_Check(ERROR_Value, ERROR_Function) \
+ if ((ERROR_Value) == E_OK) \
+ { \
+ (ERROR_Value) = (ERROR_Function); \
+ }
+
+
+
+#endif /* _TYPE_DEF_H */
--- a/main.cpp Wed Dec 12 09:26:53 2018 +0000
+++ b/main.cpp Fri Dec 21 15:39:53 2018 +0000
@@ -1,7 +1,22 @@
#include "mbed.h"
+#include "TYPE_Def.h"
+#include "CRC32BIT_LOOKUP_Ext.h"
+
Serial pc(USBTX, USBRX); // tx, rx
+UINT32_T crc;
+ERROR_T ERROR_Value;
+CRC32BIT_LOOKUP_TS _Crc32Table_TGP_DUT;
+BYTE_T vettore[11];
+char crcchar[4];
+unsigned int j;
+
+//char crc[4] = {0xBD ,0x5A , 0x97 , 0xDD};
+char packetsize[4] = {0x00 ,0x00 , 0x00 , 0x0F};
+
+
+
DigitalIn mybutton(USER_BUTTON);
DigitalOut myled(LED2);
@@ -42,7 +57,7 @@
DigitalOut Porta3_1 (PB_12);
DigitalOut Porta3_0 (PC_4);
-
+void crc_cal();
void TGP_SET_GPO_CMD();
void TGP_SET_GPO_ACK(char*, char*, char*, char*, char*);
void GPIO_SET(char*,char*,char*,char*,char*,char*,char*,char*);
@@ -50,9 +65,12 @@
int main()
{
+
+ pc.baud(9600);
+
while(1)
{
- TGP_SET_GPO_CMD();
+ pc.attach(&TGP_SET_GPO_CMD,Serial::RxIrq);
}
@@ -78,55 +96,59 @@
char UINT32_Port3Mask [4];
char UINT32_CRC [4];
+ myled = 0;
+
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_PacketSize[i]);
+ UINT32_PacketSize[i] = pc.getc();
}
- pc.scanf("%c",&ENUM_Packet_ID);
+ ENUM_Packet_ID=pc.getc();
for(i=0; i<2; i++){
- pc.scanf("%c",&UINT16_PacketCounter[i]);
+ UINT16_PacketCounter[i]=pc.getc();
}
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_Timestamp[i]);
+ UINT32_Timestamp[i]=pc.getc();
}
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_Port0Value[i]);
+ UINT32_Port0Value[i]=pc.getc();
}
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_Port0Mask[i]);
+ UINT32_Port0Mask[i]=pc.getc();
}
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_Port1Value[i]);
+ UINT32_Port1Value[i]=pc.getc();
}
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_Port1Mask[i]);
+ UINT32_Port1Mask[i]=pc.getc();
}
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_Port2Value[i]);
+ UINT32_Port2Value[i]=pc.getc();
}
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_Port2Mask[i]);
+ UINT32_Port2Mask[i]=pc.getc();
+ }
+
+ for(i=0; i<4; i++){
+ UINT32_Port3Value[i]=pc.getc();
}
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_Port3Value[i]);
+ UINT32_Port3Mask[i]=pc.getc();
}
for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_Port3Mask[i]);
+ UINT32_CRC[i]=pc.getc();
}
- for(i=0; i<4; i++){
- pc.scanf("%c",&UINT32_CRC[i]);
- }
+ myled = 1;
TGP_SET_GPO_ACK(UINT32_PacketSize,&ENUM_Packet_ID,UINT16_PacketCounter,UINT32_Timestamp,UINT32_CRC);
GPIO_SET(UINT32_Port0Value,UINT32_Port0Mask,UINT32_Port1Value,UINT32_Port1Mask,UINT32_Port2Value,UINT32_Port2Mask,UINT32_Port3Value,UINT32_Port3Mask);
@@ -168,12 +190,36 @@
UINT32_CRC[i] = E[i];
}
+ //def vettore
+ j=0;
+ for(i=0; i<4; i++){
+ vettore[j] = packetsize[i];
+ j++;
+ }
+ vettore[j] = ENUM_Packet_ID+1;
+ j++;
+
+ for(i=0; i<2; i++){
+ vettore[j] = UINT16_PacketCounter[i];
+ j++;
+ }
+
+ for(i=0; i<4; i++){
+ vettore[j] = UINT32_Timestamp[i];
+ j++;
+ }
+
+ /*
for(i=0; i<4; i++){
pc.printf("%c",UINT32_PacketSize[i]);
}
+ */
+ for(i=0; i<4; i++){
+ pc.printf("%c",packetsize[i]);
+ }
- pc.printf("%c",ENUM_Packet_ID);
+ pc.printf("%c",ENUM_Packet_ID+1);
for(i=0; i<2; i++){
pc.printf("%c",UINT16_PacketCounter[i]);
@@ -182,10 +228,20 @@
for(i=0; i<4; i++){
pc.printf("%c",UINT32_Timestamp[i]);
}
-
+
+ /*
for(i=0; i<4; i++){
pc.printf("%c",UINT32_CRC[i]);
}
+ */
+
+ crc_cal();
+
+ for(i=0; i<4; i++){
+ pc.printf("%c",crcchar[i]);
+ }
+
+ myled = 0;
}
@@ -283,12 +339,11 @@
bit3[i]=porta3[i];
}
- while(1)
- {
+ //while(1)
+ //{
- myled = mybutton;
- if(mybutton == 0 & btts ==0)
- {
+ //if(mybutton == 0 & btts ==0)
+ //{
Porta0_7 = bit0[0];
Porta0_6 = bit0[1];
Porta0_5 = bit0[2];
@@ -325,8 +380,9 @@
Porta3_1 = bit3[6];
Porta3_0 = bit3[7];
- btts = 1;
- } else if (mybutton == 1 & btts == 1) {
+ // wait(1);
+ // btts = 1;
+ //} else if (mybutton == 0 & btts == 1) {
Porta0_7 = bit0[8];
Porta0_6 = bit0[9];
@@ -364,8 +420,9 @@
Porta3_1 = bit3[14];
Porta3_0 = bit3[15];
- btts = 2;
- } else if (mybutton == 0 & btts == 2) {
+ // wait(1);
+ // btts = 2;
+ //} else if (mybutton == 0 & btts == 2) {
Porta0_7 = bit0[16];
Porta0_6 = bit0[17];
@@ -403,8 +460,9 @@
Porta3_1 = bit3[22];
Porta3_0 = bit3[23];
- btts = 3;
- } else if (mybutton == 1 & btts == 3) {
+ // wait(1);
+ // btts = 3;
+ //} else if (mybutton == 0 & btts == 3) {
Porta0_7 = bit0[24];
Porta0_6 = bit0[25];
@@ -442,12 +500,13 @@
Porta3_1 = bit3[30];
Porta3_0 = bit3[31];
- btts = 4;
- } else if (mybutton == 0 & btts == 4)
- {
- break;
- }
- }
+ // wait(1);
+ // btts = 4;
+ //} else if (mybutton == 0 & btts == 4)
+ // {
+ // break;
+ // }
+ // }
}
@@ -534,4 +593,28 @@
}
return &msb3[0];
+}
+
+void crc_cal()
+{
+
+
+
+
+ _Crc32Table_TGP_DUT.UINT32_Poly = 0xE7994FEB;
+ _Crc32Table_TGP_DUT.UINT32_Init = 0xFFFFFFFF;
+ _Crc32Table_TGP_DUT.BOOL_RefIn = FALSE;
+ _Crc32Table_TGP_DUT.BOOL_RefOut = FALSE;
+ _Crc32Table_TGP_DUT.UINT32_XorOut = 0x00000000;
+
+ /* Inizializzazione della tabella */
+ ERROR_Value = CRC32BIT_LOOKUP_Init(&_Crc32Table_TGP_DUT);
+
+ crc = CRC32BIT_LOOKUP_Compute(vettore,11,&_Crc32Table_TGP_DUT);
+
+ crcchar[0] = (crc >> 24) & 0xFF;
+ crcchar[1] = (crc >> 16) & 0xFF;
+ crcchar[2] = (crc >> 8) & 0xFF;
+ crcchar[3] = crc & 0xFF;
+
}
\ No newline at end of file