Commit a4459f10 authored by Christos Gentsos's avatar Christos Gentsos

Main: store fan settings on the flash, making it persistent

parent 962f456a
......@@ -12,8 +12,15 @@
typedef struct {
//! check if we want to enable the remote programming functionality
uint32_t copy_fw;
//! store fan configuration and speeds
uint16_t setfrpms[3];
uint16_t fan_installed[3];
uint16_t fan_cmdrpm[3];
uint16_t fan_ppr[3];
//! provide some (optional) user data storage
uint8_t user_data[252];
uint8_t user_data[228];
} user_flash_t;
extern user_flash_t user_flash;
......
......@@ -271,6 +271,23 @@ void __xMR fan_config()
fan_installed[2] = (fan_config_3_4 >> 7) & 0x1;
fan_cmdrpm[2] = (fan_config_3_4 >> 6) & 0x1;
fan_ppr[2] = (fan_config_3_4 >> 4) & 0x3;
uint32_t *char_user_flash = (uint32_t *)&user_flash;
user_flash_t *tmp_user_flash = (user_flash_t *)&fw_write_buf;
/* backup existing user data */
for (uint8_t i = 0; i < FLASH_ROW_SIZE/4; ++i)
fw_write_buf[i] = char_user_flash[i];
/* set 0xBEC0ABCD copy FW code */
for (uint8_t i = 0; i < 3; ++i) {
tmp_user_flash->fan_installed[i] = fan_installed[i];
tmp_user_flash->fan_cmdrpm[i] = fan_cmdrpm[i];
tmp_user_flash->fan_ppr[i] = fan_ppr[i];
}
/* copy modified block back to the flash */
flash_write_row((uint32_t *)&user_flash, (uint32_t *)fw_write_buf);
}
......@@ -279,6 +296,20 @@ void __xMR set_frpms()
setfrpms[0] = linear_to_float(setfrpms_lin[0]);
setfrpms[1] = linear_to_float(setfrpms_lin[1]);
setfrpms[2] = linear_to_float(setfrpms_lin[2]);
uint32_t *char_user_flash = (uint32_t *)&user_flash;
user_flash_t *tmp_user_flash = (user_flash_t *)&fw_write_buf;
/* backup existing user data */
for (uint8_t i = 0; i < FLASH_ROW_SIZE/4; ++i)
fw_write_buf[i] = char_user_flash[i];
/* set 0xBEC0ABCD copy FW code */
for (uint8_t i = 0; i < 3; ++i)
tmp_user_flash->setfrpms[i] = setfrpms[i];
/* copy modified block back to the flash */
flash_write_row((uint32_t *)&user_flash, (uint32_t *)fw_write_buf);
}
......
......@@ -56,13 +56,15 @@ uint16_t tacho_rpm[3];
// duty cycle (0 to 1000)
#if defined(MMFANT) || defined(MMPROT)
uint16_t fan_installed[3] __xMR = {1, 1, 1};
uint16_t setfrpms[3] __xMR = {600, 600, 600};
#else
uint16_t fan_installed[3] __xMR = {0, 0, 0};
uint16_t setfrpms[3] __xMR = {0, 0, 0};
#endif
uint16_t fan_cmdrpm[3] __xMR = {0, 0, 0};
uint16_t fan_ppr[3] __xMR = {1, 1, 1}; // a 1 here means 2 pulses per revolution
uint16_t setfrpms[3] __xMR = {600, 600, 600};
// static user_flash_t myflash __attribute__((aligned(256))) __attribute__((used)) = {.copy_fw = 0, .setfrpms = {600, 600, 600}, .fan_installed = {1, 1, 1}, .fan_cmdrpm = {0, 0, 0}, .fan_ppr = {1, 1, 1}}; // helper struct to grab user_flash.bin initialization data
pid_cntrl_t PID1 __xMR;
pid_cntrl_t PID2 __xMR;
......@@ -466,6 +468,13 @@ int main(void)
ext_irq_enable(PIN_PA13);
ext_irq_enable(PIN_PB10);
for (uint8_t i = 0; i < 3; ++i) {
fan_installed[i] = user_flash.fan_installed[i];
fan_cmdrpm[i] = user_flash.fan_cmdrpm[i];
fan_ppr[i] = user_flash.fan_ppr[i];
setfrpms[i] = user_flash.setfrpms[i];
}
update_pwm();
pwm_enable(&PWM_0);
pwm_enable(&PWM_1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment