Rev 1968 | Rev 2055 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1968 | Rev 1969 | ||
---|---|---|---|
Line 109... | Line 109... | ||
109 | 109 | ||
110 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
110 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
111 | // length is the length of the pure data not including checksum and revision number. |
111 | // length is the length of the pure data not including checksum and revision number. |
112 | void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t offset, uint16_t length) { |
112 | void writeChecksummedBlock(uint8_t revisionNumber, uint8_t* data, uint16_t offset, uint16_t length) { |
- | 113 | uint16_t CRC = CRC16(data, length); |
|
113 | uint16_t CRC = CRC16(data, length); |
114 | eeprom_write_byte(&EEPromArray[offset], CRC&0xff); |
114 | eeprom_write_word(&EEPromArray[offset], CRC); |
115 | eeprom_write_byte(&EEPromArray[offset+1], CRC>>8); |
115 | eeprom_write_byte(&EEPromArray[offset+2], revisionNumber); |
116 | eeprom_write_byte(&EEPromArray[offset+2], revisionNumber); |
116 | eeprom_write_block(data, &EEPromArray[offset+3], length); |
117 | eeprom_write_block(data, &EEPromArray[offset+3], length); |
Line 117... | Line 118... | ||
117 | } |
118 | } |
118 | 119 | ||
119 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
120 | // offset is where the checksum is stored, offset+1 is the revision number, and offset+2... are the data. |
120 | // length is the length of the pure data not including checksum and revision number. |
121 | // length is the length of the pure data not including checksum and revision number. |
121 | uint8_t readChecksummedBlock(uint8_t revisionNumber, uint8_t* target, uint16_t offset, uint16_t length) { |
122 | uint8_t readChecksummedBlock(uint8_t revisionNumber, uint8_t* target, uint16_t offset, uint16_t length) { |
122 | uint16_t CRCRead = eeprom_read_word(&EEPromArray[offset]); |
123 | uint16_t CRCRead = eeprom_read_byte(&EEPromArray[offset]) | (eeprom_read_byte(&EEPromArray[offset+1])<<8); |
123 | uint8_t revisionNumberRead = eeprom_read_byte(&EEPromArray[offset+2]); |
124 | uint8_t revisionNumberRead = eeprom_read_byte(&EEPromArray[offset+2]); |
Line 124... | Line 125... | ||
124 | eeprom_read_block(target, &EEPromArray[offset+3], length); |
125 | eeprom_read_block(target, &EEPromArray[offset+3], length); |
125 | uint16_t CRCCalculated = CRC(target, length); |
126 | uint16_t CRCCalculated = CRC16(target, length); |
Line 126... | Line 127... | ||
126 | 127 | ||
127 | uint8_t CRCError = (CRCRead != CRCCalculated); |
128 | uint8_t CRCError = (CRCRead != CRCCalculated); |
128 | uint8_t revisionMismatch = (revisionNumber != revisionNumberRead); |
129 | uint8_t revisionMismatch = (revisionNumber != revisionNumberRead); |
129 | 130 | ||
130 | if (CRCError && revisionMismatch) printf("\n\rEEPROM CRC error and revision mismatch; "); |
131 | if (CRCError && revisionMismatch) printf("\n\rEEPROM CRC error and revision mismatch; "); |
Line 131... | Line 132... | ||
131 | else if (CRCError) printf("\n\rEEPROM CRC error; "); |
132 | else if (CRCError) printf("\n\rEEPROM CRC error; "); |
132 | else if (revisionMismatch) printf("\n\rEEPROM revision mismatch; "); |
133 | else if (revisionMismatch) printf("\n\rEEPROM revision mismatch; "); |
133 | return (checksumError || revisionMismatch); |
134 | return (CRCError || revisionMismatch); |
Line 157... | Line 158... | ||
157 | void paramSet_readOrDefault() { |
158 | void paramSet_readOrDefault() { |
158 | uint8_t setnumber = getActiveParamSet(); |
159 | uint8_t setnumber = getActiveParamSet(); |
159 | // parameter version check |
160 | // parameter version check |
160 | if (setnumber<1 ||setnumber>5 || paramSet_readFromEEProm(setnumber)) { |
161 | if (setnumber<1 ||setnumber>5 || paramSet_readFromEEProm(setnumber)) { |
161 | // if version check faild |
162 | // if version check faild |
162 | printf("writing default parameter sets"); |
163 | printf("\n\rwriting default parameter sets"); |
163 | for (uint8_t i=5; i>0; i--) { |
164 | for (uint8_t i=5; i>0; i--) { |
164 | paramSet_default(i); |
165 | paramSet_default(i); |
165 | paramSet_writeToEEProm(i); |
166 | paramSet_writeToEEProm(i); |
166 | } |
167 | } |
167 | // default-Setting is parameter set 3 |
168 | // default-Setting is parameter set 3 |
Line 172... | Line 173... | ||
172 | } |
173 | } |
Line 173... | Line 174... | ||
173 | 174 | ||
174 | /***************************************************/ |
175 | /***************************************************/ |
175 | /* MixerTable */ |
176 | /* MixerTable */ |
176 | /***************************************************/ |
- | |
177 | uint8_t mixerMatrix_readFromEEProm(void) { |
- | |
178 | return readChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t)); |
- | |
179 | } |
- | |
180 | 177 | /***************************************************/ |
|
181 | void mixerMatrix_writeToEEProm(void) { |
178 | void mixerMatrix_writeToEEProm(void) { |
182 | writeChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t)); |
179 | writeChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t)); |
Line 183... | Line 180... | ||
183 | } |
180 | } |
184 | 181 | ||
185 | void mixerMatrix_readOrDefault(void) { |
182 | void mixerMatrix_readOrDefault(void) { |
186 | // load mixer table |
183 | // load mixer table |
187 | if (mixerMatrix_readFromEEProm()) { |
184 | if (readChecksummedBlock(EEMIXER_REVISION, (uint8_t*)&mixerMatrix, EEPROM_ADR_MIXER_TABLE, sizeof(mixerMatrix_t))) { |
188 | printf("writing default mixerMatrix"); |
185 | printf("writing default mixerMatrix"); |
189 | mixerMatrix_default(); // Quadro |
186 | mixerMatrix_default(); // Quadro |
190 | mixerMatrix_writeToEEProm(); |
187 | mixerMatrix_writeToEEProm(); |
Line 194... | Line 191... | ||
194 | for (uint8_t i=0; i<MAX_MOTORS; i++) { |
191 | for (uint8_t i=0; i<MAX_MOTORS; i++) { |
195 | if (mixerMatrix.motor[i][MIX_THROTTLE]) |
192 | if (mixerMatrix.motor[i][MIX_THROTTLE]) |
196 | requiredMotors++; |
193 | requiredMotors++; |
197 | } |
194 | } |
Line 198... | Line 195... | ||
198 | 195 | ||
199 | printf("\n\r\rMixer-Config: '%s' (%u Motors)",mixerMatrix.name, requiredMotors); |
196 | printf("\n\rMixer-Config: '%s' (%u Motors)",mixerMatrix.name, requiredMotors); |
200 | printf("\n\r\r=============================="); |
197 | printf("\n\r==================================="); |
Line 201... | Line 198... | ||
201 | } |
198 | } |
202 | 199 | ||
203 | /***************************************************/ |
200 | /***************************************************/ |
204 | /* ChannelMap */ |
- | |
205 | /***************************************************/ |
- | |
206 | uint8_t channelMap_readFromEEProm(void) { |
- | |
207 | return readChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t)); |
- | |
208 | } |
201 | /* ChannelMap */ |
209 | 202 | /***************************************************/ |
|
210 | void channelMap_writeToEEProm(void) { |
203 | void channelMap_writeToEEProm(void) { |
Line 211... | Line 204... | ||
211 | writeChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t)); |
204 | writeChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t)); |
212 | } |
205 | } |
213 | 206 | ||
214 | void channelMap_readOrDefault(void) { |
207 | void channelMap_readOrDefault(void) { |
215 | if (channelMap_readFromEEProm()) { |
208 | if (readChecksummedBlock(CHANNELMAP_REVISION, (uint8_t*)&channelMap, EEPROM_ADR_CHANNELMAP, sizeof(channelMap_t))) { |
216 | printf("writing default channel map"); |
209 | printf("writing default channel map"); |
217 | channelMap_default(); |
210 | channelMap_default(); |