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
Diff: main.cpp
- Revision:
- 5:851e7afdc4fe
- Parent:
- 4:a5b5809ee14f
--- 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