Rev 1543 | Rev 1546 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1543 | Rev 1545 | ||
|---|---|---|---|
| Line 269... | Line 269... | ||
| 269 | /* The CRC of the EEPROM is not correct, store default values and update CRC */ |
269 | /* The CRC of the EEPROM is not correct, store default values and update CRC */ |
| 270 | for (uint8_t i=0; i<sns_inputAnalog_NUM_SUPPORTED; i++) |
270 | for (uint8_t i=0; i<sns_inputAnalog_NUM_SUPPORTED; i++) |
| 271 | { |
271 | { |
| 272 | sns_inputAnalog_Config[i].LowTh=50; //Config, low level threshold voltage |
272 | sns_inputAnalog_Config[i].LowTh=50; //Config, low level threshold voltage |
| 273 | sns_inputAnalog_Config[i].HighTh=100; //Config, high level threshold voltage |
273 | sns_inputAnalog_Config[i].HighTh=100; //Config, high level threshold voltage |
| 274 | sns_inputAnalog_Config[i].Periodicity=5000; //Config, periodicity |
274 | sns_inputAnalog_Config[i].Periodicity=5000+i*100; //Config, periodicity |
| 275 | sns_inputAnalog_Config[i].Type=CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_SETTING_PERIODICMEASURE; //Config, if sensor is of type periodic or digital input |
275 | sns_inputAnalog_Config[i].Type=CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_SETTING_PERIODICMEASURE; //Config, if sensor is of type periodic or digital input |
| 276 | sns_inputAnalog_Config[i].PullupEnable=CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_PULLUP_DISABLE; //Config, if the pullup should be enabled |
276 | sns_inputAnalog_Config[i].PullupEnable=CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_PULLUP_DISABLE; //Config, if the pullup should be enabled |
| 277 | sns_inputAnalog_Config[i].RefEnable=CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_REFERENCE_DISABLE; //Config, if the reference to GND should be enabled |
277 | sns_inputAnalog_Config[i].RefEnable=CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_REFERENCE_DISABLE; //Config, if the reference to GND should be enabled |
| 278 | 278 | ||
| 279 | #if ((__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ == 6 && __AVR_LIBC_REVISION__ >= 7)||(__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ > 6)||__AVR_LIBC_MAJOR__ > 1) |
279 | #if ((__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ == 6 && __AVR_LIBC_REVISION__ >= 7)||(__AVR_LIBC_MAJOR__ == 1 && __AVR_LIBC_MINOR__ > 6)||__AVR_LIBC_MAJOR__ > 1) |
| Line 424... | Line 424... | ||
| 424 | uint8_t index=0; |
424 | uint8_t index=0; |
| 425 | switch (rxMsg->Header.Command) |
425 | switch (rxMsg->Header.Command) |
| 426 | { |
426 | { |
| 427 | case CAN_MODULE_CMD_INPUTANALOG_ANALOGCONFIG: |
427 | case CAN_MODULE_CMD_INPUTANALOG_ANALOGCONFIG: |
| 428 | /* Find sensor id from incoming data */ |
428 | /* Find sensor id from incoming data */ |
| 429 | index=rxMsg |
429 | index=(rxMsg->Data[0]>>4)&0x0f; |
| 430 | /* Check if sensor id is in range */ |
430 | /* Check if sensor id is in range */ |
| 431 | if (index < sns_inputAnalog_NUM_SUPPORTED) |
431 | if (index < sns_inputAnalog_NUM_SUPPORTED) |
| 432 | { |
432 | { |
| 433 | /* Save all config values */ |
433 | /* Save all config values */ |
| 434 | sns_inputAnalog_Config[index].Type=(rxMsg->Data[0]>> |
434 | sns_inputAnalog_Config[index].Type=(rxMsg->Data[0]>>2)&0x03; |
| 435 | sns_inputAnalog_Config[index].PullupEnable=(rxMsg->Data[0]>> |
435 | sns_inputAnalog_Config[index].PullupEnable=(rxMsg->Data[0]>>1)&0x01; |
| 436 | sns_inputAnalog_Config[index].RefEnable=(rxMsg->Data[0]>> |
436 | sns_inputAnalog_Config[index].RefEnable=(rxMsg->Data[0]>>0)&0x01; |
| 437 | sns_inputAnalog_Config[index].LowTh=(rxMsg->Data[2])|(rxMsg->Data[1]<<8); |
437 | sns_inputAnalog_Config[index].LowTh=(rxMsg->Data[2])|(rxMsg->Data[1]<<8); |
| 438 | sns_inputAnalog_Config[index].HighTh=(rxMsg->Data[4])|(rxMsg->Data[3]<<8); |
438 | sns_inputAnalog_Config[index].HighTh=(rxMsg->Data[4])|(rxMsg->Data[3]<<8); |
| 439 | sns_inputAnalog_Config[index].Periodicity=(rxMsg->Data[6])|(rxMsg->Data[5]<<8); |
439 | sns_inputAnalog_Config[index].Periodicity=(rxMsg->Data[6])|(rxMsg->Data[5]<<8); |
| 440 | 440 | ||
| 441 | /* Convert voltage to AD value (0-1023) acording static config parameters */ |
441 | /* Convert voltage to AD value (0-1023) acording static config parameters */ |
| Line 472... | Line 472... | ||
| 472 | eeprom_update_block( &sns_inputAnalog_Config[index], &eeprom_sns_inputAnalog+sizeof(sns_inputAnalog_Config)*index, sizeof(sns_inputAnalog_Config) ); |
472 | eeprom_update_block( &sns_inputAnalog_Config[index], &eeprom_sns_inputAnalog+sizeof(sns_inputAnalog_Config)*index, sizeof(sns_inputAnalog_Config) ); |
| 473 | #else |
473 | #else |
| 474 | eeprom_write_block( &sns_inputAnalog_Config[index], &eeprom_sns_inputAnalog+sizeof(sns_inputAnalog_Config)*index, sizeof(sns_inputAnalog_Config) ); |
474 | eeprom_write_block( &sns_inputAnalog_Config[index], &eeprom_sns_inputAnalog+sizeof(sns_inputAnalog_Config)*index, sizeof(sns_inputAnalog_Config) ); |
| 475 | #warning Using old version of AVRlibc, does not support eeprom_update-functions |
475 | #warning Using old version of AVRlibc, does not support eeprom_update-functions |
| 476 | #endif |
476 | #endif |
| - | 477 | EEDATA_UPDATE_CRC; |
|
| 477 | } |
478 | } |
| 478 | break; |
479 | break; |
| 479 | } |
480 | } |
| 480 | /* Set pullups according config */ |
481 | /* Set pullups according config */ |
| 481 | setPullups(); |
482 | setPullups(); |