Skip to content

Commit

Permalink
Added CRC calculation command
Browse files Browse the repository at this point in the history
  • Loading branch information
alexforencich committed Jan 8, 2012
1 parent 32e35e6 commit a1ca747
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions conf/akafuino32a4.conf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ ENABLE_EEPROM_BYTE_SUPPORT = yes
ENABLE_LOCK_BITS = yes
ENABLE_FUSE_BITS = yes
ENABLE_FLASH_ERASE_WRITE = yes
ENABLE_CRC_SUPPORT = yes

# API
ENABLE_API = yes
Expand Down
1 change: 1 addition & 0 deletions conf/arduino328p.conf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ENABLE_EEPROM_BYTE_SUPPORT = yes
ENABLE_LOCK_BITS = yes
ENABLE_FUSE_BITS = yes
ENABLE_FLASH_ERASE_WRITE = yes
ENABLE_CRC_SUPPORT = yes

# API
ENABLE_API = yes
Expand Down
1 change: 1 addition & 0 deletions conf/x32a4.conf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ ENABLE_EEPROM_BYTE_SUPPORT = yes
ENABLE_LOCK_BITS = yes
ENABLE_FUSE_BITS = yes
ENABLE_FLASH_ERASE_WRITE = yes
ENABLE_CRC_SUPPORT = yes

# API
ENABLE_API = yes
Expand Down
1 change: 1 addition & 0 deletions conf/x64a3.conf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ ENABLE_EEPROM_BYTE_SUPPORT = yes
ENABLE_LOCK_BITS = yes
ENABLE_FUSE_BITS = yes
ENABLE_FLASH_ERASE_WRITE = yes
ENABLE_CRC_SUPPORT = yes

# API
ENABLE_API = yes
Expand Down
3 changes: 3 additions & 0 deletions config.h.mk
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ ifneq ($(ENABLE_FUSE_BITS), )
endif
ifneq ($(ENABLE_FLASH_ERASE_WRITE), )
@echo "#define ENABLE_FLASH_ERASE_WRITE" >> config.h
endif
ifneq ($(ENABLE_CRC_SUPPORT), )
@echo "#define ENABLE_CRC_SUPPORT" >> config.h
endif
@echo >> config.h
@echo "// API" >> config.h
Expand Down
9 changes: 9 additions & 0 deletions protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
#define CMD_CLEAR_LED 'y'
#define CMD_SET_TYPE 'T'

#define CMD_CRC 'h'

// I2C Address Autonegotiation Commands
#define CMD_AUTONEG_START '@'
#define CMD_AUTONEG_DONE '#'
Expand All @@ -94,6 +96,13 @@
#define MEM_USERSIG 'U'
#define MEM_PRODSIG 'P'

// Sections for CRC checks
#define SECTION_FLASH 'F'
#define SECTION_APPLICATION 'A'
#define SECTION_BOOT 'B'
#define SECTION_APP 'a'
#define SECTION_APP_TEMP 't'

// Command Responses
#define REPLY_ACK '\r'
#define REPLY_YES 'Y'
Expand Down
41 changes: 41 additions & 0 deletions xboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,47 @@ int main(void)
send_char(SIGNATURE_1);
send_char(SIGNATURE_0);
}
#ifdef ENABLE_CRC_SUPPORT
else if (val == CMD_CRC)
{
uint32_t start = 0;
uint32_t length = 0;
uint16_t crc;

val = get_char();

switch (val)
{
case SECTION_FLASH:
length = PROGMEM_SIZE;
break;
case SECTION_APPLICATION:
length = APP_SECTION_SIZE;
break;
case SECTION_BOOT:
start = BOOT_SECTION_START;
length = BOOT_SECTION_SIZE;
break;
#ifdef ENABLE_API
case SECTION_APP:
length = XB_APP_SIZE;
break;
case SECTION_APP_TEMP:
start = XB_APP_TEMP_START;
length = XB_APP_TEMP_SIZE;
break;
#endif // ENABLE_API
default:
send_char(REPLY_ERROR);
continue;
}

crc = crc16_block(start, length);

send_char((crc >> 8) & 0xff);
send_char(crc & 0xff);
}
#endif // ENABLE_CRC_SUPPORT
#ifdef USE_I2C
#ifdef USE_I2C_ADDRESS_NEGOTIATION
// Enter autonegotiate mode
Expand Down
1 change: 1 addition & 0 deletions xboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
#define ENABLE_LOCK_BITS
#define ENABLE_FUSE_BITS
#define ENABLE_FLASH_ERASE_WRITE
#define ENABLE_CRC_SUPPORT

// API
#define ENABLE_API
Expand Down

0 comments on commit a1ca747

Please sign in to comment.