Browse Source

snapshot for reform 2.0d-2

master
mntmn 11 months ago
parent
commit
0b9ddf4bfe
1 changed files with 38 additions and 27 deletions
  1. +38
    -27
      src/boards/reform2/board_reform2.c

+ 38
- 27
src/boards/reform2/board_reform2.c View File

@@ -128,7 +128,7 @@ enum state_t {
// charging state machine
int state = ST_CHARGE;
int cycles_in_state = 0;
int charge_current = 2;
int charge_current = 1;
uint32_t cur_second = 0;
uint32_t last_second = 0;

@@ -289,6 +289,11 @@ void measure_and_accumulate_current() {
uint16_t charger_state;
uint16_t charge_status;
uint16_t system_status;
uint16_t limit_alerts;
uint16_t charger_alerts;
uint16_t status_alerts;
float chg_vin;
float chg_vbat;

void configure_charger(int charge_current) {
// disable jeita
@@ -297,8 +302,13 @@ void configure_charger(int charge_current) {
// set charge current
i2c_write16_be(LTC4162F_ADDRESS, 0x1a, charge_current);
// disable max_cv_time
i2c_write16_be(LTC4162F_ADDRESS, 0x1d, 0);
// set charge voltage
i2c_write16_be(LTC4162F_ADDRESS, 0x1b, 31); // default
// 27 = 30V
// default 31 = 28.8V
i2c_write16_be(LTC4162F_ADDRESS, 0x1b, 31);

if (charge_current > 0) {
// config_bits_reg: unsuspend charger
@@ -309,16 +319,19 @@ void configure_charger(int charge_current) {
}
// set recharge threshold
i2c_write16_be(LTC4162F_ADDRESS, 0x2e, 40000);
// signed 16-bit number, max 32767! default 17424
i2c_write16_be(LTC4162F_ADDRESS, 0x2e, 30000);
// read some charger regs
//uint16_t vcharge_setting = i2c_read16_be(LTC4162F_ADDRESS, 0x1b) & 0x1f; // [4:0]
charger_state = i2c_read16_be(LTC4162F_ADDRESS, 0x34);
charge_status = i2c_read16_be(LTC4162F_ADDRESS, 0x35);
limit_alerts = i2c_read16_be(LTC4162F_ADDRESS, 0x36);
charger_alerts = i2c_read16_be(LTC4162F_ADDRESS, 0x37);
status_alerts = i2c_read16_be(LTC4162F_ADDRESS, 0x38);
system_status = i2c_read16_be(LTC4162F_ADDRESS, 0x39);
//uint16_t charger_config = i2c_read16_be(LTC4162F_ADDRESS, 0x29);
float chg_vbat = i2c_read16_be(LTC4162F_ADDRESS, 0x3a);
float chg_vin = i2c_read16_be(LTC4162F_ADDRESS, 0x3b);
chg_vbat = i2c_read16_be(LTC4162F_ADDRESS, 0x3a);
chg_vin = i2c_read16_be(LTC4162F_ADDRESS, 0x3b);
float chg_vout = i2c_read16_be(LTC4162F_ADDRESS, 0x3c);
//float chg_ibat = i2c_read16_be(LTC4162F_ADDRESS, 0x3d);
//float chg_iin = i2c_read16_be(LTC4162F_ADDRESS, 0x3e);
@@ -352,15 +365,18 @@ void configure_charger(int charge_current) {
}

void turn_som_power_on(void) {
LPC_GPIO->SET[1] = (1 << 15); // 5v, high = on
LPC_GPIO->CLR[0] = (1 << 20); // PCIe, low = on
LPC_GPIO->CLR[1] = (1 << 16); // 3v3, low = on
LPC_GPIO->CLR[0] = (1 << 20); // PCIe, low = on
LPC_GPIO->SET[1] = (1 << 15); // 5v, high = on
}

void turn_som_power_off(void) {
LPC_GPIO->CLR[1] = (1 << 15); // 5v, high = on
LPC_GPIO->SET[0] = (1 << 20); // PCIe, low = on
LPC_GPIO->SET[1] = (1 << 16); // 3v3, low = on

// FIXME experiment: temp. disable charger to reset its timers
configure_charger(0);
}

void brownout_setup(void) {
@@ -388,7 +404,7 @@ void watchdog_setup(void) {
LPC_WWDT->CLKSEL = 1; // WDOSC

LPC_WWDT->TC = 0xffff; // timeout counter
LPC_WWDT->TC = 0xffff/5; // timeout counter, ~5 seconds

LPC_WWDT->MOD = 0;
LPC_WWDT->MOD |= WWDT_WDMOD_WDRESET; // enable WDRESET (watchdog resets system)
@@ -400,9 +416,18 @@ void watchdog_setup(void) {
void boardInit(void)
{
SystemCoreClockUpdate();
delayInit();
GPIOInit();
delayInit();

// 5V regulator on/off
LPC_GPIO->DIR[1] |= (1 << 15);
// 3V3 rail transistor on/off
LPC_GPIO->DIR[1] |= (1 << 16);
// PCIe 1 power supply transistor
LPC_GPIO->DIR[0] |= (1 << 20);

turn_som_power_off();
uartInit(CFG_UART_BAUDRATE);
i2cInit(I2CMASTER);
ssp1Init();
@@ -415,20 +440,6 @@ void boardInit(void)
LPC_GPIO->DIR[1] |= (1 << 23);
LPC_GPIO->SET[1] = (1 << 23); // active low

// 5V regulator on/off
LPC_GPIO->DIR[1] |= (1 << 15);
//LPC_GPIO->SET[1] = (1 << 15); // high = on

// FIXME
// 3V3 rail transistor on/off
LPC_GPIO->DIR[1] |= (1 << 16);

// PCIe 1 power supply transistor
LPC_GPIO->DIR[0] |= (1 << 20);
//LPC_GPIO->CLR[0] = (1 << 20); // low = on

turn_som_power_off(); // FIXME

//sprintf(uartBuffer, "\r\nMNT Reform 2.0 MCU initialized.\r\n");
//uartSend((uint8_t*)uartBuffer, strlen(uartBuffer));
}
@@ -541,7 +552,7 @@ void handle_commands() {
else if (remote_cmd == 's') {
// get charger system state
if (state == ST_CHARGE) {
sprintf(uartBuffer,"idle: %x st: %x sy: %x [%d]\r",charger_state,charge_status,system_status,cycles_in_state);
sprintf(uartBuffer,"idle:%x st:%x sy:%x i:%d b:%d l!%x c!%x s!%x [%d]\r",charger_state,charge_status,system_status,(int)chg_vin,(int)chg_vbat,limit_alerts,charger_alerts,status_alerts,cycles_in_state);
} else if (state == ST_OVERVOLTED) {
sprintf(uartBuffer,"overvolt [%d]\r",cycles_in_state);
} else if (state == ST_UNDERVOLTED) {