add openbeacon-compatible crc (CCITT-16)
This commit is contained in:
parent
fc7b630902
commit
b0f5c3e9b6
|
@ -8,7 +8,7 @@ OBJS = main.o
|
||||||
VPATH +=
|
VPATH +=
|
||||||
OBJS +=
|
OBJS +=
|
||||||
OBJS += basic/basic.o basic/reinvoke_isp.o basic/delayms.o basic/voltage.o
|
OBJS += basic/basic.o basic/reinvoke_isp.o basic/delayms.o basic/voltage.o
|
||||||
OBJS += basic/keyin.o basic/uuid.o
|
OBJS += basic/keyin.o basic/uuid.o basic/crc.o
|
||||||
LIBS += core/libcore.a lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a funk/libfunk.a
|
LIBS += core/libcore.a lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a funk/libfunk.a
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -106,3 +106,4 @@ $(OUTFILE).elf: $(OBJS) $(SYS_OBJS) $(LIBS) $(LPCFIX) $(LD_TEMP)
|
||||||
|
|
||||||
.PHONY: $(LD_TEMP) lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a
|
.PHONY: $(LD_TEMP) lcd/liblcd.a applications/libapp.a filesystem/libfat.a usb/libusb.a
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -152,4 +152,8 @@ uint16_t GetUUID16(void);
|
||||||
// for core/iap/iap.c (no official definition)
|
// for core/iap/iap.c (no official definition)
|
||||||
void iap_entry(uint32_t param_tab[], uint32_t result_tab[]);
|
void iap_entry(uint32_t param_tab[], uint32_t result_tab[]);
|
||||||
|
|
||||||
|
// crc.c
|
||||||
|
uint16_t crc16(char * buf, int len);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include "basic.h"
|
||||||
|
|
||||||
|
// Calculate the CRC for transmitted and received data using
|
||||||
|
// the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1).
|
||||||
|
|
||||||
|
uint16_t crc16(char * buf, int len){
|
||||||
|
unsigned int crc=0xffff;
|
||||||
|
|
||||||
|
for(int i=0;i<len;i++){
|
||||||
|
crc = (unsigned char)(crc >> 8) | (crc << 8);
|
||||||
|
crc ^= buf[i];
|
||||||
|
crc ^= (unsigned char)(crc & 0xff) >> 4;
|
||||||
|
crc ^= (crc << 8) << 4;
|
||||||
|
crc ^= ((crc & 0xff) << 4) << 1;
|
||||||
|
};
|
||||||
|
return crc;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Note:
|
||||||
|
It is best not to alter this code. For example, (crc<<8)<<4 does
|
||||||
|
not generate the same code as crc<<12. Although the result of the
|
||||||
|
computation is the same, the latter generates much more code and
|
||||||
|
executes slower.
|
||||||
|
*/
|
Loading…
Reference in New Issue