Rev 1654 | Rev 1662 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1654 | Rev 1657 | ||
---|---|---|---|
Line 69... | Line 69... | ||
69 | #include "eeprom.h" |
69 | #include "eeprom.h" |
70 | #include "uart.h" |
70 | #include "uart.h" |
71 | #include "led.h" |
71 | #include "led.h" |
72 | #include "main.h" |
72 | #include "main.h" |
73 | #include "fc.h" |
73 | #include "fc.h" |
- | 74 | #include "twimaster.h" |
|
Line 74... | Line 75... | ||
74 | 75 | ||
75 | paramset_t EE_Parameter; |
76 | paramset_t EE_Parameter; |
76 | MixerTable_t Mixer; |
77 | MixerTable_t Mixer; |
- | 78 | uint8_t RequiredMotors; |
|
Line 77... | Line 79... | ||
77 | uint8_t RequiredMotors; |
79 | BLConfig_t BLConfig[MAX_MOTORS]; |
78 | 80 | ||
79 | 81 | ||
Line 594... | Line 596... | ||
594 | Mixer.crc = Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
596 | Mixer.crc = Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
595 | } |
597 | } |
Line 596... | Line 598... | ||
596 | 598 | ||
- | 599 | ||
- | 600 | /***************************************************/ |
|
- | 601 | /* Read BL-Config from EEPROM */ |
|
- | 602 | /***************************************************/ |
|
- | 603 | uint8_t BLConfig_ReadFromEEProm(uint8_t index) |
|
- | 604 | { |
|
- | 605 | uint8_t crc; |
|
- | 606 | uint16_t eeadr = EEPROM_ADR_BLCONFIG + (uint16_t)index * sizeof(BLConfig_t); |
|
- | 607 | // calculate checksum in eeprom |
|
- | 608 | crc = EEProm_Checksum(eeadr, sizeof(BLConfig_t) - 1); |
|
- | 609 | ||
- | 610 | // check crc |
|
- | 611 | if( crc != eeprom_read_byte((uint8_t*)(eeadr + sizeof(BLConfig_t) - 1)) ) return 0; |
|
- | 612 | ||
- | 613 | // check revision |
|
- | 614 | if(eeprom_read_byte((uint8_t*)(eeadr)) != EEBLCONFIG_REVISON) return 0; |
|
- | 615 | ||
- | 616 | // read mixer BLConfig |
|
- | 617 | eeprom_read_block((void *)&(BLConfig[index]), (void*)(eeadr), sizeof(BLConfig_t)); |
|
- | 618 | return 1; |
|
- | 619 | } |
|
- | 620 | ||
- | 621 | /***************************************************/ |
|
- | 622 | /* Write BL-Config to EEPROM */ |
|
- | 623 | /***************************************************/ |
|
- | 624 | uint8_t BLConfig_WriteToEEProm(uint8_t index) |
|
- | 625 | { |
|
- | 626 | uint16_t eeadr = EEPROM_ADR_BLCONFIG + (uint16_t)index * sizeof(BLConfig_t); |
|
- | 627 | if(index >= MAX_MOTORS) return 0; |
|
- | 628 | if(BLConfig[index].Revision == EEBLCONFIG_REVISON) |
|
- | 629 | { |
|
- | 630 | // update crc |
|
- | 631 | BLConfig[index].crc = RAM_Checksum((uint8_t*)(&(BLConfig[index])), sizeof(BLConfig_t) - 1); |
|
- | 632 | ||
- | 633 | // write to eeprom |
|
- | 634 | eeprom_write_block((void *) &(BLConfig[index]), (void*)(eeadr), sizeof(BLConfig_t)); |
|
- | 635 | return 1; |
|
- | 636 | } |
|
- | 637 | else return 0; |
|
- | 638 | } |
|
- | 639 | ||
- | 640 | /***************************************************/ |
|
- | 641 | /* Default BLConfig */ |
|
- | 642 | /***************************************************/ |
|
- | 643 | void BLConfig_SetDefault(uint8_t index) |
|
- | 644 | { |
|
- | 645 | if(index < MAX_MOTORS) |
|
- | 646 | { |
|
- | 647 | BLConfig[index].Revision = EEBLCONFIG_REVISON; // set revision |
|
- | 648 | BLConfig[index].SetMask = MASK_SET_PWM_SCALING|MASK_SET_CURRENT_LIMIT|MASK_SET_TEMP_LIMIT|MASK_SET_CURRENT_SCALING|MASK_SET_BITCONFIG; |
|
- | 649 | BLConfig[index].PwmScaling = 255; // MaxPWM |
|
- | 650 | BLConfig[index].CurrentLimit = 30; // Current Limit in A |
|
- | 651 | BLConfig[index].TempLimit = 99; // Temperature Limit in °C |
|
- | 652 | BLConfig[index].CurrentScaling = 64; // Current Scaling |
|
- | 653 | BLConfig[index].BitConfig = 0; // BitConfig |
|
- | 654 | BLConfig[index].crc = RAM_Checksum((uint8_t*)&(BLConfig[index]), sizeof(BLConfig_t) - 1); // update checksum |
|
- | 655 | } |
|
- | 656 | } |
|
- | 657 | ||
597 | 658 | ||
598 | /***************************************************/ |
659 | /***************************************************/ |
599 | /* Get active parameter set */ |
660 | /* Get active parameter set */ |
600 | /***************************************************/ |
661 | /***************************************************/ |
601 | uint8_t GetActiveParamSet(void) |
662 | uint8_t GetActiveParamSet(void) |
Line 685... | Line 746... | ||
685 | // read active parameter set to ParamSet stucture |
746 | // read active parameter set to ParamSet stucture |
686 | i = GetActiveParamSet(); |
747 | i = GetActiveParamSet(); |
687 | ParamSet_ReadFromEEProm(i); |
748 | ParamSet_ReadFromEEProm(i); |
688 | printf("\n\rUsing Parameter Set %d", i); |
749 | printf("\n\rUsing Parameter Set %d", i); |
Line -... | Line 750... | ||
- | 750 | ||
- | 751 | // load all BLConfig's |
|
- | 752 | for(i=0; i<MAX_MOTORS; i++) |
|
- | 753 | { |
|
- | 754 | if(ee_default || !BLConfig_ReadFromEEProm(i)) // could not read BLConfig from eeprom |
|
- | 755 | { |
|
- | 756 | printf("\n\rGenerating default BL-Config for motor %d", i+1); |
|
- | 757 | BLConfig_SetDefault(i); |
|
- | 758 | BLConfig_WriteToEEProm(i); |
|
- | 759 | } |
|
- | 760 | } |
|
689 | 761 | ||
690 | // load mixer table |
762 | // load mixer table |
691 | if(ee_default || !MixerTable_ReadFromEEProm() ) |
763 | if(ee_default || !MixerTable_ReadFromEEProm() ) |
692 | { |
764 | { |
693 | printf("\n\rGenerating default Mixer Table"); |
765 | printf("\n\rGenerating default Mixer Table"); |