/beta/Code Redesign killagreg/eeprom.c |
---|
76,6 → 76,7 |
paramset_t ParamSet; |
MixerTable_t Mixer; |
uint8_t RequiredMotors = 0; |
BLConfig_t BLConfig[MAX_MOTORS]; |
uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len) |
590,11 → 591,69 |
Mixer.Motor[2][MIX_GAS] = 64; Mixer.Motor[2][MIX_NICK] = 0; Mixer.Motor[2][MIX_ROLL] = -64; Mixer.Motor[2][MIX_YAW] = -64; |
Mixer.Motor[3][MIX_GAS] = 64; Mixer.Motor[3][MIX_NICK] = 0; Mixer.Motor[3][MIX_ROLL] = +64; Mixer.Motor[3][MIX_YAW] = -64; |
memcpy(Mixer.Name, "Quadro\0", 7); |
Mixer.crc = Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
Mixer.crc = RAM_Checksum((uint8_t*)(&Mixer), sizeof(Mixer) - 1); |
} |
/***************************************************/ |
/* Read BL-Config from EEPROM */ |
/***************************************************/ |
uint8_t BLConfig_ReadFromEEProm(uint8_t index) |
{ |
uint8_t crc; |
uint16_t eeadr = EEPROM_ADR_BLCONFIG + (uint16_t)index * sizeof(BLConfig_t); |
// calculate checksum in eeprom |
crc = EEProm_Checksum(eeadr, sizeof(BLConfig_t) - 1); |
// check crc |
if( crc != eeprom_read_byte((uint8_t*)(eeadr + sizeof(BLConfig_t) - 1)) ) return 0; |
// check revision |
if(eeprom_read_byte((uint8_t*)(eeadr)) != EEBLCONFIG_REVISON) return 0; |
// read mixer BLConfig |
eeprom_read_block((void *)&(BLConfig[index]), (void*)(eeadr), sizeof(BLConfig_t)); |
return 1; |
} |
/***************************************************/ |
/* Write BL-Config to EEPROM */ |
/***************************************************/ |
uint8_t BLConfig_WriteToEEProm(uint8_t index) |
{ |
uint16_t eeadr = EEPROM_ADR_BLCONFIG + (uint16_t)index * sizeof(BLConfig_t); |
if(index >= MAX_MOTORS) return 0; |
if(BLConfig[index].Revision == EEBLCONFIG_REVISON) |
{ |
// update crc |
BLConfig[index].crc = RAM_Checksum((uint8_t*)(&(BLConfig[index])), sizeof(BLConfig_t) - 1); |
// write to eeprom |
eeprom_write_block((void *) &(BLConfig[index]), (void*)(eeadr), sizeof(BLConfig_t)); |
return 1; |
} |
else return 0; |
} |
/***************************************************/ |
/* Default BLConfig */ |
/***************************************************/ |
void BLConfig_SetDefault(uint8_t index) |
{ |
if(index < MAX_MOTORS) |
{ |
BLConfig[index].Revision = EEBLCONFIG_REVISON; // set revision |
BLConfig[index].SetMask = MASK_SET_PWM_SCALING|MASK_SET_CURRENT_LIMIT|MASK_SET_TEMP_LIMIT|MASK_SET_CURRENT_SCALING|MASK_SET_BITCONFIG; |
BLConfig[index].PwmScaling = 255; // MaxPWM |
BLConfig[index].CurrentLimit = 30; // Current Limit in A |
BLConfig[index].TempLimit = 99; // Temperature Limit in °C |
BLConfig[index].CurrentScaling = 64; // Current Scaling |
BLConfig[index].BitConfig = 0; // BitConfig |
BLConfig[index].crc = RAM_Checksum((uint8_t*)&(BLConfig[index]), sizeof(BLConfig_t) - 1); // update checksum |
} |
} |
/***************************************************/ |
/* Get active parameter set */ |
/***************************************************/ |
uint8_t GetActiveParamSet(void) |
686,6 → 745,18 |
ParamSet_ReadFromEEProm(i); |
printf("\n\rUsing Parameter Set %d", i); |
// load all BLConfig's |
for(i=0; i<MAX_MOTORS; i++) |
{ |
if(ee_default || !BLConfig_ReadFromEEProm(i)) // could not read BLConfig from eeprom |
{ |
printf("\n\rGenerating default BL-Config for motor %d", i+1); |
BLConfig_SetDefault(i); |
BLConfig_WriteToEEProm(i); |
} |
} |
// load mixer table |
if(ee_default || !MixerTable_ReadFromEEProm() ) |
{ |
/beta/Code Redesign killagreg/eeprom.h |
---|
2,6 → 2,7 |
#define _EEPROM_H |
#include <inttypes.h> |
#include "twimaster.h" |
#define EEPROM_ADR_PARAM_BEGIN 0 |
#define PID_EE_REVISION 1 // byte |
15,9 → 16,10 |
#define PID_FLIGHT_MINUTES_TOTAL 10 // word |
#define PID_FLIGHT_MINUTES 14 // word |
#define EEPROM_ADR_CHANNELS 80 // 12 bytes + 1crc |
#define EEPROM_ADR_PARAMSET 100 |
#define EEPROM_ADR_MIXERTABLE 1000 // 1000 - 1077 |
#define EEPROM_ADR_CHANNELS 80 // 80 - 93, 12 bytes + 1 byte crc |
#define EEPROM_ADR_PARAMSET 100 // 100 - 650, 5 * 110 bytes |
#define EEPROM_ADR_MIXERTABLE 1000 // 1000 - 1078, 78 bytes |
#define EEPROM_ADR_BLCONFIG 1200 // 1200 - 1296, 12 * 8 bytes |
#define MIX_GAS 0 |
36,7 → 38,39 |
extern MixerTable_t Mixer; |
extern uint8_t RequiredMotors; |
#define MASK_SET_PWM_SCALING 0x01 |
#define MASK_SET_CURRENT_LIMIT 0x02 |
#define MASK_SET_TEMP_LIMIT 0x04 |
#define MASK_SET_CURRENT_SCALING 0x08 |
#define MASK_SET_BITCONFIG 0x10 |
#define MASK_RESET_CAPCOUNTER 0x20 |
#define MASK_SET_DEFAULT_PARAMS 0x40 |
#define MASK_SET_SAVE_EEPROM 0x80 |
#define BITCONF_REVERSE_ROTATION 0x01 |
#define BITCONF_RES1 0x02 |
#define BITCONF_RES2 0x04 |
#define BITCONF_RES3 0x08 |
#define BITCONF_RES4 0x10 |
#define BITCONF_RES5 0x20 |
#define BITCONF_RES6 0x40 |
#define BITCONF_RES7 0x80 |
typedef struct |
{ |
uint8_t Revision; // must be BL_REVISION |
uint8_t SetMask; // settings mask |
uint8_t PwmScaling; // maximum value of control pwm, acts like a thrust limit |
uint8_t CurrentLimit; // current limit in A |
uint8_t TempLimit; // in °C |
uint8_t CurrentScaling; // scaling factor for current measurement |
uint8_t BitConfig; // see defines above |
uint8_t crc; // checksum |
} __attribute__((packed)) BLConfig_t; |
extern BLConfig_t BLConfig[MAX_MOTORS]; |
// bit mask for ParamSet.Config0 |
#define CFG0_AIRPRESS_SENSOR 0x01 |
#define CFG0_HEIGHT_SWITCH 0x02 |
92,6 → 126,7 |
#define EEPARAM_REVISION 82 // is count up, if paramater stucture has changed (compatibility) |
#define EEMIXER_REVISION 1 // is count up, if mixer stucture has changed (compatibility) |
#define EEBLCONFIG_REVISON '#' |
// values above 247 representing poti1 to poti8 |
// poti1 = 255 |
205,7 → 240,10 |
extern paramset_t ParamSet; |
extern uint8_t RAM_Checksum(uint8_t* pBuffer, uint16_t len); |
extern void ParamSet_Init(void); |
extern uint8_t ParamSet_ReadFromEEProm(uint8_t setnumber); |
extern uint8_t ParamSet_WriteToEEProm(uint8_t setnumber); |
215,6 → 253,9 |
extern uint8_t MixerTable_ReadFromEEProm(void); |
extern uint8_t MixerTable_WriteToEEProm(void); |
extern uint8_t BLConfig_ReadFromEEProm(uint8_t index); |
extern uint8_t BLConfig_WriteToEEProm(uint8_t index); |
extern void BLConfig_SetDefault(uint8_t index); |
extern uint8_t GetParamByte(uint16_t param_id); |
extern void SetParamByte(uint16_t param_id, uint8_t value); |
/beta/Code Redesign killagreg/libfc1284.a |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/beta/Code Redesign killagreg/main.c |
---|
125,8 → 125,8 |
{ |
timer = SetDelay(500); // wait at least 500 ms to get stable adc readings |
if(print) while(!CheckDelay(timer)); |
// up to 6s LiPo |
for(cells = 1; cells < 7; cells++) |
// up to 6s LiPo, less than 2s is technical impossible |
for(cells = 2; cells < 7; cells++) |
{ |
if(UBat < cells * MAX_CELL_VOLTAGE) break; |
} |
/beta/Code Redesign killagreg/makefile |
---|
6,7 → 6,7 |
#------------------------------------------------------------------- |
VERSION_MAJOR = 0 |
VERSION_MINOR = 79 |
VERSION_PATCH = 0 |
VERSION_PATCH = 2 |
VERSION_SERIAL_MAJOR = 11 # Serial Protocol Major Version |
VERSION_SERIAL_MINOR = 0 # Serial Protocol Minor Version |
/beta/Code Redesign killagreg/twimaster.c |
---|
71,9 → 71,7 |
MotorData_t Motor[MAX_MOTORS]; |
BLConfig_t BLConfig[MAX_MOTORS]; |
#define BL_CONF_SYNC_BYTE '#' |
#define SCL_CLOCK 200000L |
114,12 → 112,6 |
Motor[i].State = 0; |
Motor[i].Current = 0; |
Motor[i].MaxPWM = 0; |
BLConfig[i].SetMask = MASK_SET_PWM_SCALING|MASK_SET_CURRENT_LIMIT|MASK_SET_TEMP_LIMIT|MASK_SET_CURRENT_SCALING|MASK_SET_BITCONFIG; |
BLConfig[i].PwmScaling = 255; // MaxPWM |
BLConfig[i].CurrentLimit = 30; // Current Limit in A |
BLConfig[i].TempLimit = 99; // Temperature Limit in °C |
BLConfig[i].CurrentScaling = 64; // Current Scaling |
BLConfig[i].BitConfig = 0; // BitConfig |
} |
SREG = sreg; |
226,7 → 218,7 |
/****************************************/ |
ISR (TWI_vect) |
{ |
static uint8_t missing_motor = 0, byte_counter = 0, crc = 0, read_more = 0, motor_read_temperature = 0; |
static uint8_t missing_motor = 0, byte_counter = 0, read_more = 0, motor_read_temperature = 0; |
static uint8_t *pTxBuff; |
switch (twi_state++) // First i2c_start from SendMotorData() |
262,7 → 254,6 |
if( (BLFlags & BLFLAG_SEND_CONFIG) && (motor_write == motor_read)) |
{ // prepare sending of configuration |
byte_counter = 0; // reset send byte counter |
crc = 0xAA; // init checksum |
} |
else |
{ // jump to state for end of transmission for that motor |
272,17 → 263,11 |
case 3: // send configuration |
if(!byte_counter) // first byte? |
{ |
I2C_WriteByte(BL_CONF_SYNC_BYTE); |
crc += BL_CONF_SYNC_BYTE; // update crc |
pTxBuff = (uint8_t*)&BLConfig[motor_write]; // select configuration for motor |
I2C_WriteByte(pTxBuff[byte_counter]); |
twi_state = 3; |
} |
else if(byte_counter == sizeof(BLConfig_t) + 1) // last byte? |
{ // send crc byte at the end |
I2C_WriteByte(crc); |
twi_state = 3; |
} |
else if(byte_counter > sizeof(BLConfig_t) + 1) |
else if(byte_counter >= sizeof(BLConfig_t)) |
{ |
I2C_WriteByte(0); |
// continue in state 4 |
289,8 → 274,7 |
} |
else // transmit configuration to BLs |
{ |
I2C_WriteByte(pTxBuff[byte_counter-1]); // submit next byte |
crc += pTxBuff[byte_counter-1]; // update crc |
I2C_WriteByte(pTxBuff[byte_counter]); // submit next byte |
twi_state = 3; // stay in this state |
} |
byte_counter++; // next byte |
/beta/Code Redesign killagreg/twimaster.h |
---|
40,37 → 40,6 |
extern MotorData_t Motor[MAX_MOTORS]; |
#define MASK_SET_PWM_SCALING 0x01 |
#define MASK_SET_CURRENT_LIMIT 0x02 |
#define MASK_SET_TEMP_LIMIT 0x04 |
#define MASK_SET_CURRENT_SCALING 0x08 |
#define MASK_SET_BITCONFIG 0x10 |
#define MASK_RESET_CAPCOUNTER 0x20 |
#define MASK_SET_DEFAULT_PARAMS 0x40 |
#define MASK_SET_SAVE_EEPROM 0x80 |
#define BITCONF_REVERSE_ROTATION 0x01 |
#define BITCONF_RES1 0x02 |
#define BITCONF_RES2 0x04 |
#define BITCONF_RES3 0x08 |
#define BITCONF_RES4 0x10 |
#define BITCONF_RES5 0x20 |
#define BITCONF_RES6 0x40 |
#define BITCONF_RES7 0x80 |
typedef struct |
{ |
uint8_t SetMask; // settings mask |
uint8_t PwmScaling; // maximum value of control pwm, acts like a thrust limit |
uint8_t CurrentLimit; // current limit in A |
uint8_t TempLimit; // in °C |
uint8_t CurrentScaling; // scaling factor for current measurement |
uint8_t BitConfig; // see defines below |
} __attribute__((packed)) BLConfig_t; |
extern BLConfig_t BLConfig[MAX_MOTORS]; |
extern volatile uint16_t I2CTimeout; |
void I2C_Init (void); // Initialize I2C |
/beta/Code Redesign killagreg/uart0.c |
---|
115,6 → 115,28 |
int16_t Heading; |
} __attribute__((packed)) Heading_t; |
#define BLPARAM_REVISION 1 |
#define MASK_SET_PWM_SCALING 0x01 |
#define MASK_SET_CURRENT_LIMIT 0x02 |
#define MASK_SET_TEMP_LIMIT 0x04 |
#define MASK_SET_CURRENT_SCALING 0x08 |
#define MASK_SET_BITCONFIG 0x10 |
#define MASK_RESET_CAPCOUNTER 0x20 |
#define MASK_SET_DEFAULT_PARAMS 0x40 |
#define MASK_SET_SAVE_EEPROM 0x80 |
typedef struct |
{ |
uint8_t Revision; // revision of parameter structure |
uint8_t Address; // target address |
uint8_t PwmScaling; // maximum value of pwm setpoint |
uint8_t CurrentLimit; // current limit in 1A steps |
uint8_t TemperatureLimit; // in °C |
uint8_t CurrentScaling; // scaling factor for current measurement |
uint8_t BitConfig; // see defines above |
uint8_t SetMask; // filter for active paramters |
uint8_t Checksum; // checksum for parameter sturcture |
} __attribute__((packed)) BLParameter_t; |
DebugOut_t DebugOut; |
Data3D_t Data3D; |
ExternControl_t ExternControl; |
667,6 → 689,68 |
AboTimeOut = SetDelay(ABO_TIMEOUT); |
break; |
case 'u': // request BL parameter |
tempchar1 = pRxData[0]; |
Debug("Reading BL-Parameter %d", tempchar1); |
if( (tempchar1 > 0) && (tempchar1 <= MAX_MOTORS) ) |
{ |
BLParameter_t BLParam; |
tempchar1--; |
BLParam.Revision = BLPARAM_REVISION; |
BLParam.Address = tempchar1+1; |
BLParam.PwmScaling = BLConfig[tempchar1].PwmScaling; |
BLParam.CurrentLimit = BLConfig[tempchar1].CurrentLimit; |
BLParam.TemperatureLimit = BLConfig[tempchar1].TempLimit; |
BLParam.CurrentScaling = BLConfig[tempchar1].CurrentScaling; |
BLParam.BitConfig = BLConfig[tempchar1].BitConfig; |
BLParam.SetMask = 0; |
BLParam.Checksum = RAM_Checksum((uint8_t*)&(BLConfig[tempchar1]), sizeof(BLParam)-1); |
SendOutData('U', FC_ADDRESS, 1, &BLParam, sizeof(BLParam)); |
} |
break; |
case 'w': // write BL parameter |
tempchar1 = 0; |
if(!(FCFlags & FCFLAG_MOTOR_RUN)) // save parameter only if motors are off |
{ |
BLParameter_t *pBLParam = (BLParameter_t*)pRxData; |
// version and address check |
if( (pBLParam->Revision == BLPARAM_REVISION) && (pBLParam->Address <= MAX_MOTORS) ) |
{ |
uint8_t i, start, end; |
if(pBLParam->Address == 0) |
{ // all BLs |
start = 0; |
end = MAX_MOTORS - 1; |
} |
else |
{ // only one specific |
start = pBLParam->Address - 1; |
end = start; |
} |
for(i = start; i <= end; i++) |
{ |
if(pBLParam->SetMask & MASK_SET_DEFAULT_PARAMS) BLConfig_SetDefault(i); |
else |
{ |
if(pBLParam->SetMask & MASK_SET_PWM_SCALING) BLConfig[i].PwmScaling = pBLParam->PwmScaling; |
if(pBLParam->SetMask & MASK_SET_CURRENT_LIMIT) BLConfig[i].CurrentLimit = pBLParam->CurrentLimit; |
if(pBLParam->SetMask & MASK_SET_TEMP_LIMIT) BLConfig[i].TempLimit = pBLParam->TemperatureLimit; |
if(pBLParam->SetMask & MASK_SET_CURRENT_SCALING) BLConfig[i].CurrentScaling = pBLParam->CurrentScaling; |
if(pBLParam->SetMask & MASK_SET_BITCONFIG) BLConfig[i].BitConfig = pBLParam->BitConfig; |
BLConfig[i].crc = RAM_Checksum((uint8_t*)&(BLConfig[i]), sizeof(BLConfig_t)-1); // update crc |
} |
if(pBLParam->SetMask & MASK_SET_SAVE_EEPROM) BLConfig_WriteToEEProm(i); |
} |
I2C_SendBLConfig(); |
tempchar1 = 1; |
} |
} |
while(!txd_complete); // wait for previous frame to be sent |
SendOutData('W', FC_ADDRESS,1, &tempchar1, sizeof(tempchar1)); |
break; |
default: |
//unsupported command received |
break; |