WarEnd 0 Posted February 28, 2013 Share Posted February 28, 2013 arduino crc code: #include <avr/pgmspace.h> static PROGMEM prog_uint32_t crc_table[16] = { 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; unsigned long crc_update(unsigned long crc, byte data) { byte tbl_idx; tbl_idx = crc ^ (data >> (0 * 4)); crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); tbl_idx = crc ^ (data >> (1 * 4)); crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); return crc; } unsigned long crc_string(char *s) { unsigned long crc = ~0L; while (*s) crc = crc_update(crc, *s++); crc = ~crc; return crc; } void setup() { Serial.begin(9600); Serial.println(crc_string("HELLO"), HEX); } void loop() { } Please help to replace avr/pgmspace.h to energia working method. Sorry for my english Quote Link to post Share on other sites
energia 485 Posted February 28, 2013 Share Posted February 28, 2013 Here you go: static uint32_t crc_table[16] = { 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; unsigned long crc_update(unsigned long crc, byte data) { byte tbl_idx; tbl_idx = crc ^ (data >> (0 * 4)); crc = *(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); tbl_idx = crc ^ (data >> (1 * 4)); crc = *(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); return crc; } unsigned long crc_string(const char *s) { unsigned long crc = ~0L; while (*s) crc = crc_update(crc, *s++); crc = ~crc; return crc; } void setup() { Serial.begin(9600); Serial.println(crc_string("HELLO"), HEX); } void loop() { } WarEnd, bluehash and xv4y 3 Quote Link to post Share on other sites
energia 485 Posted February 28, 2013 Share Posted February 28, 2013 And this is the diff: @@ -1,6 +1,5 @@ -#include <avr/pgmspace.h> -static PROGMEM prog_uint32_t crc_table[16] = { +static uint32_t crc_table[16] = { 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, @@ -11,13 +10,13 @@ { byte tbl_idx; tbl_idx = crc ^ (data >> (0 * 4)); - crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); + crc = *(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); tbl_idx = crc ^ (data >> (1 * 4)); - crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); + crc = *(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4); return crc; } -unsigned long crc_string(char *s) +unsigned long crc_string(const char *s) { unsigned long crc = ~0L; while (*s) WarEnd 1 Quote Link to post Share on other sites
WarEnd 0 Posted February 28, 2013 Author Share Posted February 28, 2013 Thank you working :) Quote Link to post Share on other sites
Edward Chen 0 Posted March 7, 2013 Share Posted March 7, 2013 Excuse me, what is this code for? i'm just curious Quote Link to post Share on other sites
WarEnd 0 Posted March 12, 2013 Author Share Posted March 12, 2013 A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data. Blocks of data entering these systems get a short check value attached, based on the remainder of a polynomial division of their contents; on retrieval the calculation is repeated, and corrective action can be taken against presumed data corruption if the check values do not match. Quote Link to post Share on other sites
roadrunner84 466 Posted March 13, 2013 Share Posted March 13, 2013 Yes, but why do you need it in your msp430? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.