Rev 2158 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2158 | Rev 2164 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | #include "printf_P.h" |
6 | #include "printf_P.h" |
7 | #include "output.h" |
7 | #include "output.h" |
8 | #include "configuration.h" |
8 | #include "configuration.h" |
9 | #include <avr/wdt.h> |
9 | #include <avr/wdt.h> |
10 | #include <avr/eeprom.h> |
10 | #include <avr/eeprom.h> |
- | 11 | #include <avr/interrupt.h> |
|
Line 11... | Line 12... | ||
11 | 12 | ||
12 | // byte array in eeprom |
13 | // byte array in eeprom |
Line 13... | Line 14... | ||
13 | uint8_t EEPromArray[E2END + 1] EEMEM; |
14 | uint8_t EEPromArray[E2END + 1] EEMEM; |
Line 59... | Line 60... | ||
59 | 60 | ||
60 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
61 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
61 | // length is the length of the pure data not including checksum and revision number. |
62 | // length is the length of the pure data not including checksum and revision number. |
62 | void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t offset, uint16_t length) { |
63 | void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t offset, uint16_t length) { |
- | 64 | uint16_t CRC = CRC16(data, length); |
|
- | 65 | uint8_t sreg = SREG; |
|
63 | uint16_t CRC = CRC16(data, length); |
66 | cli(); |
64 | eeprom_write_byte(&EEPromArray[offset], CRC&0xff); |
67 | eeprom_write_byte(&EEPromArray[offset], CRC&0xff); |
65 | eeprom_write_byte(&EEPromArray[offset+1], CRC>>8); |
68 | eeprom_write_byte(&EEPromArray[offset+1], CRC>>8); |
66 | eeprom_write_byte(&EEPromArray[offset+2], revisionNumber); |
69 | eeprom_write_byte(&EEPromArray[offset+2], revisionNumber); |
- | 70 | eeprom_write_block(data, &EEPromArray[offset+3], length); |
|
67 | eeprom_write_block(data, &EEPromArray[offset+3], length); |
71 | SREG = sreg; |
Line 68... | Line 72... | ||
68 | } |
72 | } |
69 | 73 | ||
70 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
74 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
Line 99... | Line 103... | ||
99 | /* Write Parameter Set to EEPROM */ |
103 | /* Write Parameter Set to EEPROM */ |
100 | /***************************************************/ |
104 | /***************************************************/ |
101 | void paramSet_writeToEEProm(uint8_t setnumber) { |
105 | void paramSet_writeToEEProm(uint8_t setnumber) { |
102 | uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(ParamSet_t)+EEPROM_CHECKSUMMED_BLOCK_OVERHEAD); |
106 | uint16_t offset = EEPROM_ADR_PARAMSET_BEGIN + (setnumber-1)*(sizeof(ParamSet_t)+EEPROM_CHECKSUMMED_BLOCK_OVERHEAD); |
103 | writeChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(ParamSet_t)); |
107 | writeChecksummedBlock(EEPARAM_REVISION, (uint8_t*)&staticParams, offset, sizeof(ParamSet_t)); |
104 | // set this parameter set to active set |
- | |
105 | } |
108 | } |
Line 106... | Line 109... | ||
106 | 109 | ||
107 | void paramSet_readOrDefault() { |
110 | void paramSet_readOrDefault() { |
108 | uint8_t setnumber = getActiveParamSet(); |
111 | uint8_t setnumber = getActiveParamSet(); |