Configuration according to flowchart included. (UPTO PHY_ON). INclusion of #define functions
Fork of send_tn_intgration_sss by
CRCheader.h@5:9664602e1ceb, 2016-01-13 (annotated)
- Committer:
- dheerajmpai23
- Date:
- Wed Jan 13 11:49:09 2016 +0000
- Revision:
- 5:9664602e1ceb
- Parent:
- 1:743a1d709fe0
Changes Made:; ; inclusion of 1. #define functions 2.config_f() function without PHY_TX; ; file from krishan's a/c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
krishanprajapat | 1:743a1d709fe0 | 1 | //EDITS |
krishanprajapat | 1:743a1d709fe0 | 2 | //changed the initial remainder from 0x0000 to 0xffff according to the standards |
krishanprajapat | 1:743a1d709fe0 | 3 | //made two seperate functions crc16_gen and crc8_gen |
krishanprajapat | 1:743a1d709fe0 | 4 | |
krishanprajapat | 1:743a1d709fe0 | 5 | #define TOPBIT16 (1 << 15) |
krishanprajapat | 1:743a1d709fe0 | 6 | #define TOPBIT8 (1 << 7) |
krishanprajapat | 1:743a1d709fe0 | 7 | #define POLYNOMIAL16 0x1021 |
krishanprajapat | 1:743a1d709fe0 | 8 | #define POLYNOMIAL8 0xEA |
krishanprajapat | 1:743a1d709fe0 | 9 | |
krishanprajapat | 1:743a1d709fe0 | 10 | namespace CRC{ |
krishanprajapat | 1:743a1d709fe0 | 11 | typedef unsigned short int crctype16; |
krishanprajapat | 1:743a1d709fe0 | 12 | crctype16 crc16_gen(const unsigned char message[], unsigned int nBytes){ |
krishanprajapat | 1:743a1d709fe0 | 13 | crctype16 remainder = 0xffff; |
krishanprajapat | 1:743a1d709fe0 | 14 | int byte; |
krishanprajapat | 1:743a1d709fe0 | 15 | char bit; |
krishanprajapat | 1:743a1d709fe0 | 16 | |
krishanprajapat | 1:743a1d709fe0 | 17 | for( byte = 0 ; byte < nBytes ; byte++ ){ |
krishanprajapat | 1:743a1d709fe0 | 18 | /* |
krishanprajapat | 1:743a1d709fe0 | 19 | Bring the data byte by byte |
krishanprajapat | 1:743a1d709fe0 | 20 | each time only one byte is brought |
krishanprajapat | 1:743a1d709fe0 | 21 | 0 xor x = x |
krishanprajapat | 1:743a1d709fe0 | 22 | */ |
krishanprajapat | 1:743a1d709fe0 | 23 | remainder = remainder ^ ( message[byte] << 8 ); |
krishanprajapat | 1:743a1d709fe0 | 24 | |
krishanprajapat | 1:743a1d709fe0 | 25 | for( bit = 8 ; bit > 0 ; bit--){ |
krishanprajapat | 1:743a1d709fe0 | 26 | /* |
krishanprajapat | 1:743a1d709fe0 | 27 | for each bit, xor the remainder with polynomial |
krishanprajapat | 1:743a1d709fe0 | 28 | if the MSB is 1 |
krishanprajapat | 1:743a1d709fe0 | 29 | */ |
krishanprajapat | 1:743a1d709fe0 | 30 | if(remainder & TOPBIT16){ |
krishanprajapat | 1:743a1d709fe0 | 31 | remainder = (remainder << 1) ^ POLYNOMIAL16; |
krishanprajapat | 1:743a1d709fe0 | 32 | /* |
krishanprajapat | 1:743a1d709fe0 | 33 | each time the remainder is xor-ed with polynomial, the MSB is made zero |
krishanprajapat | 1:743a1d709fe0 | 34 | hence the first digit of the remainder is ignored in the loop |
krishanprajapat | 1:743a1d709fe0 | 35 | */ |
krishanprajapat | 1:743a1d709fe0 | 36 | } |
krishanprajapat | 1:743a1d709fe0 | 37 | else{ |
krishanprajapat | 1:743a1d709fe0 | 38 | remainder = (remainder << 1); |
krishanprajapat | 1:743a1d709fe0 | 39 | } |
krishanprajapat | 1:743a1d709fe0 | 40 | } |
krishanprajapat | 1:743a1d709fe0 | 41 | } |
krishanprajapat | 1:743a1d709fe0 | 42 | |
krishanprajapat | 1:743a1d709fe0 | 43 | return remainder; |
krishanprajapat | 1:743a1d709fe0 | 44 | } |
krishanprajapat | 1:743a1d709fe0 | 45 | |
krishanprajapat | 1:743a1d709fe0 | 46 | typedef unsigned char crctype8; |
krishanprajapat | 1:743a1d709fe0 | 47 | crctype8 crc8_gen(const unsigned char message[], unsigned int nBytes){ |
krishanprajapat | 1:743a1d709fe0 | 48 | |
krishanprajapat | 1:743a1d709fe0 | 49 | crctype8 remainder = 0xff; |
krishanprajapat | 1:743a1d709fe0 | 50 | |
krishanprajapat | 1:743a1d709fe0 | 51 | for(int byte = 0 ; byte < nBytes ; byte++ ){ |
krishanprajapat | 1:743a1d709fe0 | 52 | /* |
krishanprajapat | 1:743a1d709fe0 | 53 | Bring the data byte by byte |
krishanprajapat | 1:743a1d709fe0 | 54 | each time only one byte is brought |
krishanprajapat | 1:743a1d709fe0 | 55 | 0 xor x = x |
krishanprajapat | 1:743a1d709fe0 | 56 | */ |
krishanprajapat | 1:743a1d709fe0 | 57 | remainder = remainder ^ ( message[byte] ); |
krishanprajapat | 1:743a1d709fe0 | 58 | |
krishanprajapat | 1:743a1d709fe0 | 59 | for(int bit = 8 ; bit > 0 ; bit--){ |
krishanprajapat | 1:743a1d709fe0 | 60 | /* |
krishanprajapat | 1:743a1d709fe0 | 61 | for each bit, xor the remainder with polynomial |
krishanprajapat | 1:743a1d709fe0 | 62 | if the MSB is 1 |
krishanprajapat | 1:743a1d709fe0 | 63 | */ |
krishanprajapat | 1:743a1d709fe0 | 64 | if(remainder & TOPBIT8){ |
krishanprajapat | 1:743a1d709fe0 | 65 | remainder = (remainder << 1) ^ POLYNOMIAL8; |
krishanprajapat | 1:743a1d709fe0 | 66 | /* |
krishanprajapat | 1:743a1d709fe0 | 67 | each time the remainder is xor-ed with polynomial, the MSB is made zero |
krishanprajapat | 1:743a1d709fe0 | 68 | hence the first digit of the remainder is ignored in the loop |
krishanprajapat | 1:743a1d709fe0 | 69 | */ |
krishanprajapat | 1:743a1d709fe0 | 70 | } |
krishanprajapat | 1:743a1d709fe0 | 71 | else{ |
krishanprajapat | 1:743a1d709fe0 | 72 | remainder = (remainder << 1); |
krishanprajapat | 1:743a1d709fe0 | 73 | } |
krishanprajapat | 1:743a1d709fe0 | 74 | } |
krishanprajapat | 1:743a1d709fe0 | 75 | } |
krishanprajapat | 1:743a1d709fe0 | 76 | |
krishanprajapat | 1:743a1d709fe0 | 77 | return remainder; |
krishanprajapat | 1:743a1d709fe0 | 78 | } |
krishanprajapat | 1:743a1d709fe0 | 79 | } |
krishanprajapat | 1:743a1d709fe0 | 80 |