|
30 | 30 | void readUserSettings() { |
31 | 31 | //--------------------------------------------------------------------------------- |
32 | 32 |
|
33 | | - PERSONAL_DATA slot1; |
34 | | - PERSONAL_DATA slot2; |
| 33 | + PERSONAL_DATA slots[2]; |
35 | 34 |
|
36 | 35 | short slot1count, slot2count; |
37 | 36 | short slot1CRC, slot2CRC; |
38 | 37 |
|
39 | 38 | uint32 userSettingsBase; |
40 | 39 | readFirmware( 0x20, &userSettingsBase,2); |
41 | | - |
| 40 | + |
42 | 41 | uint32 slot1Address = userSettingsBase * 8; |
43 | 42 | uint32 slot2Address = userSettingsBase * 8 + 0x100; |
44 | | - |
45 | | - readFirmware( slot1Address , &slot1, sizeof(PERSONAL_DATA)); |
46 | | - readFirmware( slot2Address , &slot2, sizeof(PERSONAL_DATA)); |
| 43 | + |
| 44 | + readFirmware( slot1Address , &slots[0], sizeof(PERSONAL_DATA)); |
| 45 | + readFirmware( slot2Address , &slots[1], sizeof(PERSONAL_DATA)); |
47 | 46 | readFirmware( slot1Address + 0x70, &slot1count, 2); |
48 | 47 | readFirmware( slot2Address + 0x70, &slot2count, 2); |
49 | 48 | readFirmware( slot1Address + 0x72, &slot1CRC, 2); |
50 | 49 | readFirmware( slot2Address + 0x72, &slot2CRC, 2); |
51 | 50 |
|
52 | 51 | // default to slot 1 user Settings |
53 | | - void *currentSettings = &slot1; |
54 | | - |
55 | | - short calc1CRC = swiCRC16( 0xffff, &slot1, sizeof(PERSONAL_DATA)); |
56 | | - short calc2CRC = swiCRC16( 0xffff, &slot2, sizeof(PERSONAL_DATA)); |
| 52 | + int currentSettingsSlot = 0; |
| 53 | + |
| 54 | + short calc1CRC = swiCRC16( 0xffff, &slots[0], sizeof(PERSONAL_DATA)); |
| 55 | + short calc2CRC = swiCRC16( 0xffff, &slots[1], sizeof(PERSONAL_DATA)); |
57 | 56 |
|
58 | 57 | // bail out if neither slot is valid |
59 | 58 | if ( calc1CRC != slot1CRC && calc2CRC != slot2CRC) return; |
60 | | - |
| 59 | + |
61 | 60 | // if both slots are valid pick the most recent |
62 | | - if ( calc1CRC == slot1CRC && calc2CRC == slot2CRC ) { |
63 | | - currentSettings = (slot2count == (( slot1count + 1 ) & 0x7f) ? &slot2 : &slot1); |
| 61 | + if ( calc1CRC == slot1CRC && calc2CRC == slot2CRC ) { |
| 62 | + currentSettingsSlot = (slot2count == (( slot1count + 1 ) & 0x7f) ? 1 : 0); |
64 | 63 | } else { |
65 | 64 | if ( calc2CRC == slot2CRC ) |
66 | | - currentSettings = &slot2; |
| 65 | + currentSettingsSlot = 1; |
67 | 66 | } |
68 | | - memcpy ( PersonalData, currentSettings, sizeof(PERSONAL_DATA)); |
69 | | - |
| 67 | + *PersonalData = slots[currentSettingsSlot]; |
| 68 | + |
70 | 69 | } |
0 commit comments