CRC example to compute 32-bit CRC .

Revision:
1:6f792125397a
Parent:
0:4ea3a9a52bb6
Child:
2:a9d9b5c4a32b
--- a/main.cpp	Mon Dec 18 22:53:07 2017 +0000
+++ b/main.cpp	Fri Dec 29 23:13:37 2017 +0000
@@ -1,58 +1,36 @@
 #include "mbed.h"
-#include "mbed_crc.h"
-#include "SlowCRC.h"
+#include "BitwiseCRC.h"
 #include "FastCRC.h"
 
 #define FAST_COMPUTE        1
 
 #if defined(FAST_COMPUTE)
-#define CRC_TYPE    FastCRC
+#define CRC_ALGO    FastCRC
 #else
-#define CRC_TYPE    SlowCRC
+#define CRC_ALGO    BitwiseCRC
 #endif
 
 char  test[] = "123456789";
 uint32_t crc;
 
-int crc_ibm_16bit() {
-    CRC_TYPE<uint16_t> ct(CRC_16BIT_IBM);
-    
-    ct.init();
-    ct.compute((void *)test, strlen((const char*)test), &crc);    
-    
-    printf("The CRC of 0x%x \"123456789\" is \"0xBB3D\" Result: 0x%x\n", 
-                            ct.get_polynomial(), crc);
-    ct.deinit();
-    return 0;
-}
+int crc_calculate(crc_polynomial_type_t crc_type) {
+    CRC_ALGO ct(crc_type);
 
-int crc_ccitt_16bit() {
-    CRC_TYPE<uint16_t> ct(CRC_16BIT_CCITT);
-    
     ct.init();
-    ct.compute((void *)test, strlen((const char*)test), &crc);    
-    
-    printf("The CRC of 0x%x \"123456789\" is \"0x29B1\" Result: 0x%x\n", 
-                            ct.get_polynomial(), crc);
-    ct.deinit();
-    return 0;
-}
+    ct.compute((void *)test, strlen((const char*)test), &crc);
 
-int crc_32_bit() {
-    CRC_TYPE<uint32_t> ct(CRC_32BIT);
-    
-    ct.init();
-    ct.compute((void *)test, strlen((const char*)test), &crc);    
-    
-    printf("The CRC of 0x%x \"123456789\" is \"0xCBF43926\" Result: 0x%x\n", 
+    printf("The CRC of 0x%x data \"123456789\" is : 0x%lx\n",
                             ct.get_polynomial(), crc);
     ct.deinit();
     return 0;
 }
 
 int main() {
-    crc_ibm_16bit();
-    crc_ccitt_16bit();
-    crc_32_bit();
+
+    crc_calculate(CRC_32BIT);
+    crc_calculate(CRC_16BIT_IBM);
+    crc_calculate(CRC_16BIT_CCITT);
+
+    printf("End\n");
     return 0;
 }