CDMS_CODE_samp_23SEP_DMA_flag

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA by iitm sat

Committer:
ee12b079
Date:
Sat Apr 02 11:54:50 2016 +0000
Revision:
145:fb800fecf128
Parent:
6:79d422d1ed42
worked for PL

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shreeshas95 0:f016e9e8d48b 1 //EDITS
shreeshas95 0:f016e9e8d48b 2 //changed the initial remainder from 0x0000 to 0xffff according to the standards
shreeshas95 0:f016e9e8d48b 3 //made two seperate functions crc16_gen and crc8_gen
shreeshas95 0:f016e9e8d48b 4
shreeshas95 0:f016e9e8d48b 5 #define TOPBIT16 (1 << 15)
shreeshas95 0:f016e9e8d48b 6 #define TOPBIT8 (1 << 7)
shreeshas95 0:f016e9e8d48b 7 #define POLYNOMIAL16 0x1021
shreeshas95 6:79d422d1ed42 8 #define POLYNOMIAL8 0x07
shreeshas95 0:f016e9e8d48b 9
shreeshas95 0:f016e9e8d48b 10 typedef uint16_t crctype16;
shreeshas95 0:f016e9e8d48b 11 crctype16 crc16_gen(const unsigned char message[], unsigned int nBytes){
shreeshas95 0:f016e9e8d48b 12 crctype16 remainder = 0xffff;
shreeshas95 0:f016e9e8d48b 13 int byte;
shreeshas95 0:f016e9e8d48b 14 char bit;
shreeshas95 0:f016e9e8d48b 15
shreeshas95 0:f016e9e8d48b 16 for( byte = 0 ; byte < nBytes ; byte++ ){
shreeshas95 0:f016e9e8d48b 17 /*
shreeshas95 0:f016e9e8d48b 18 Bring the data byte by byte
shreeshas95 0:f016e9e8d48b 19 each time only one byte is brought
shreeshas95 0:f016e9e8d48b 20 0 xor x = x
shreeshas95 0:f016e9e8d48b 21 */
shreeshas95 0:f016e9e8d48b 22 remainder = remainder ^ ( message[byte] << 8 );
shreeshas95 0:f016e9e8d48b 23
shreeshas95 0:f016e9e8d48b 24 for( bit = 8 ; bit > 0 ; bit--){
shreeshas95 0:f016e9e8d48b 25 /*
shreeshas95 0:f016e9e8d48b 26 for each bit, xor the remainder with polynomial
shreeshas95 0:f016e9e8d48b 27 if the MSB is 1
shreeshas95 0:f016e9e8d48b 28 */
shreeshas95 0:f016e9e8d48b 29 if(remainder & TOPBIT16){
shreeshas95 0:f016e9e8d48b 30 remainder = (remainder << 1) ^ POLYNOMIAL16;
shreeshas95 0:f016e9e8d48b 31 /*
shreeshas95 0:f016e9e8d48b 32 each time the remainder is xor-ed with polynomial, the MSB is made zero
shreeshas95 0:f016e9e8d48b 33 hence the first digit of the remainder is ignored in the loop
shreeshas95 0:f016e9e8d48b 34 */
shreeshas95 0:f016e9e8d48b 35 }
shreeshas95 0:f016e9e8d48b 36 else{
shreeshas95 0:f016e9e8d48b 37 remainder = (remainder << 1);
shreeshas95 0:f016e9e8d48b 38 }
shreeshas95 0:f016e9e8d48b 39 }
shreeshas95 0:f016e9e8d48b 40 }
shreeshas95 0:f016e9e8d48b 41
shreeshas95 0:f016e9e8d48b 42 return remainder;
shreeshas95 0:f016e9e8d48b 43 }
shreeshas95 0:f016e9e8d48b 44
shreeshas95 0:f016e9e8d48b 45 typedef uint8_t crctype8;
shreeshas95 0:f016e9e8d48b 46 crctype8 crc8_gen(const unsigned char message[], unsigned int nBytes){
shreeshas95 0:f016e9e8d48b 47
shreeshas95 0:f016e9e8d48b 48 crctype8 remainder = 0xff;
shreeshas95 0:f016e9e8d48b 49
shreeshas95 0:f016e9e8d48b 50 for(int byte = 0 ; byte < nBytes ; byte++ ){
shreeshas95 0:f016e9e8d48b 51 /*
shreeshas95 0:f016e9e8d48b 52 Bring the data byte by byte
shreeshas95 0:f016e9e8d48b 53 each time only one byte is brought
shreeshas95 0:f016e9e8d48b 54 0 xor x = x
shreeshas95 0:f016e9e8d48b 55 */
shreeshas95 0:f016e9e8d48b 56 remainder = remainder ^ ( message[byte] );
shreeshas95 0:f016e9e8d48b 57
shreeshas95 0:f016e9e8d48b 58 for(int bit = 8 ; bit > 0 ; bit--){
shreeshas95 0:f016e9e8d48b 59 /*
shreeshas95 0:f016e9e8d48b 60 for each bit, xor the remainder with polynomial
shreeshas95 0:f016e9e8d48b 61 if the MSB is 1
shreeshas95 0:f016e9e8d48b 62 */
shreeshas95 0:f016e9e8d48b 63 if(remainder & TOPBIT8){
shreeshas95 0:f016e9e8d48b 64 remainder = (remainder << 1) ^ POLYNOMIAL8;
shreeshas95 0:f016e9e8d48b 65 /*
shreeshas95 0:f016e9e8d48b 66 each time the remainder is xor-ed with polynomial, the MSB is made zero
shreeshas95 0:f016e9e8d48b 67 hence the first digit of the remainder is ignored in the loop
shreeshas95 0:f016e9e8d48b 68 */
shreeshas95 0:f016e9e8d48b 69 }
shreeshas95 0:f016e9e8d48b 70 else{
shreeshas95 0:f016e9e8d48b 71 remainder = (remainder << 1);
shreeshas95 0:f016e9e8d48b 72 }
shreeshas95 0:f016e9e8d48b 73 }
shreeshas95 0:f016e9e8d48b 74 }
shreeshas95 0:f016e9e8d48b 75
shreeshas95 0:f016e9e8d48b 76 return remainder;
ee12b079 145:fb800fecf128 77 }
ee12b079 145:fb800fecf128 78
ee12b079 145:fb800fecf128 79 uint16_t crc16_gen1( char message[], unsigned int nBytes){
ee12b079 145:fb800fecf128 80 crctype16 remainder = 0xffff;
ee12b079 145:fb800fecf128 81 int byte;
ee12b079 145:fb800fecf128 82 char bit;
ee12b079 145:fb800fecf128 83
ee12b079 145:fb800fecf128 84 for( byte = 0 ; byte < nBytes ; byte++ ){
ee12b079 145:fb800fecf128 85 /*
ee12b079 145:fb800fecf128 86 Bring the data byte by byte
ee12b079 145:fb800fecf128 87 each time only one byte is brought
ee12b079 145:fb800fecf128 88 0 xor x = x
ee12b079 145:fb800fecf128 89 */
ee12b079 145:fb800fecf128 90 remainder = remainder ^ ( message[byte] << 8 );
ee12b079 145:fb800fecf128 91
ee12b079 145:fb800fecf128 92 for( bit = 8 ; bit > 0 ; bit--){
ee12b079 145:fb800fecf128 93 /*
ee12b079 145:fb800fecf128 94 for each bit, xor the remainder with polynomial
ee12b079 145:fb800fecf128 95 if the MSB is 1
ee12b079 145:fb800fecf128 96 */
ee12b079 145:fb800fecf128 97 if(remainder & TOPBIT16){
ee12b079 145:fb800fecf128 98 remainder = (remainder << 1) ^ POLYNOMIAL16;
ee12b079 145:fb800fecf128 99 /*
ee12b079 145:fb800fecf128 100 each time the remainder is xor-ed with polynomial, the MSB is made zero
ee12b079 145:fb800fecf128 101 hence the first digit of the remainder is ignored in the loop
ee12b079 145:fb800fecf128 102 */
ee12b079 145:fb800fecf128 103 }
ee12b079 145:fb800fecf128 104 else{
ee12b079 145:fb800fecf128 105 remainder = (remainder << 1);
ee12b079 145:fb800fecf128 106 }
ee12b079 145:fb800fecf128 107 }
ee12b079 145:fb800fecf128 108 }
ee12b079 145:fb800fecf128 109
ee12b079 145:fb800fecf128 110 return remainder;
ee12b079 145:fb800fecf128 111 }
ee12b079 145:fb800fecf128 112