Rev 1657 | Rev 1664 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1657 | Rev 1662 | ||
---|---|---|---|
Line 74... | Line 74... | ||
74 | #include "twimaster.h" |
74 | #include "twimaster.h" |
Line 75... | Line 75... | ||
75 | 75 | ||
76 | paramset_t EE_Parameter; |
76 | paramset_t EE_Parameter; |
77 | MixerTable_t Mixer; |
77 | MixerTable_t Mixer; |
78 | uint8_t RequiredMotors; |
- | |
Line 79... | Line 78... | ||
79 | BLConfig_t BLConfig[MAX_MOTORS]; |
78 | uint8_t RequiredMotors; |
80 | 79 | ||
81 | 80 | ||
Line 594... | Line 593... | ||
594 | Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] = 0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
593 | Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] = 0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
595 | memcpy(Mixer.Name, "Quadro\0", 7); |
594 | memcpy(Mixer.Name, "Quadro\0", 7); |
596 | Mixer.crc = Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
595 | Mixer.crc = Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
597 | } |
596 | } |
Line 598... | Line -... | ||
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 | - | ||
658 | 597 | ||
659 | /***************************************************/ |
598 | /***************************************************/ |
660 | /* Get active parameter set */ |
599 | /* Get active parameter set */ |
661 | /***************************************************/ |
600 | /***************************************************/ |
662 | uint8_t GetActiveParamSet(void) |
601 | uint8_t GetActiveParamSet(void) |
Line 746... | Line 685... | ||
746 | // read active parameter set to ParamSet stucture |
685 | // read active parameter set to ParamSet stucture |
747 | i = GetActiveParamSet(); |
686 | i = GetActiveParamSet(); |
748 | ParamSet_ReadFromEEProm(i); |
687 | ParamSet_ReadFromEEProm(i); |
749 | printf("\n\rUsing Parameter Set %d", i); |
688 | printf("\n\rUsing Parameter Set %d", i); |
Line 750... | Line -... | ||
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 | } |
- | |
761 | 689 | ||
762 | // load mixer table |
690 | // load mixer table |
763 | if(ee_default || !MixerTable_ReadFromEEProm() ) |
691 | if(ee_default || !MixerTable_ReadFromEEProm() ) |
764 | { |
692 | { |
765 | printf("\n\rGenerating default Mixer Table"); |
693 | printf("\n\rGenerating default Mixer Table"); |