From d16ecc6129005085926b5aebb3c158c582f42829 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 21 Feb 2020 20:30:10 -0700 Subject: [PATCH] Fix test for when to update battery and fan state, hold SCI_N for longer --- src/board/system76/darp5/main.c | 6 +++++- src/board/system76/darp5/pmc.c | 5 ++++- src/board/system76/galp3-c/main.c | 6 +++++- src/board/system76/galp3-c/pmc.c | 5 ++++- src/board/system76/lemp9/main.c | 6 +++++- src/board/system76/lemp9/pmc.c | 5 ++++- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/board/system76/darp5/main.c b/src/board/system76/darp5/main.c index ab3aaf7..863e302 100644 --- a/src/board/system76/darp5/main.c +++ b/src/board/system76/darp5/main.c @@ -97,7 +97,10 @@ void main(void) { INFO("System76 EC board '%s', version '%s'\n", board(), version()); + uint32_t last_time = 0; for(main_cycle = 0; ; main_cycle++) { + uint32_t time = time_get(); + // Handle power states power_event(); // Scans keyboard and sends keyboard packets @@ -109,7 +112,8 @@ void main(void) { // Checks for keyboard/mouse packets from host kbc_event(&KBC); // Only run the following once a second - if (time_get() % 1000 == 0) { + if (last_time > time || (time - last_time) >= 1000) { + last_time = time; // Updates fan status and temps peci_event(); // Updates battery status diff --git a/src/board/system76/darp5/pmc.c b/src/board/system76/darp5/pmc.c index d104c6f..9ab446b 100644 --- a/src/board/system76/darp5/pmc.c +++ b/src/board/system76/darp5/pmc.c @@ -26,11 +26,14 @@ void pmc_sci_interrupt(void) { *(SCI_N.control) = GPIO_OUT; // Delay T_HOLD (value assumed) - delay_us(1); + delay_us(65); // Stop SCI interrupt *(SCI_N.control) = GPIO_IN; gpio_set(&SCI_N, true); + + // Delay T_HOLD (value assumed) + delay_us(65); } bool pmc_sci(struct Pmc * pmc, uint8_t sci) { diff --git a/src/board/system76/galp3-c/main.c b/src/board/system76/galp3-c/main.c index ab3aaf7..863e302 100644 --- a/src/board/system76/galp3-c/main.c +++ b/src/board/system76/galp3-c/main.c @@ -97,7 +97,10 @@ void main(void) { INFO("System76 EC board '%s', version '%s'\n", board(), version()); + uint32_t last_time = 0; for(main_cycle = 0; ; main_cycle++) { + uint32_t time = time_get(); + // Handle power states power_event(); // Scans keyboard and sends keyboard packets @@ -109,7 +112,8 @@ void main(void) { // Checks for keyboard/mouse packets from host kbc_event(&KBC); // Only run the following once a second - if (time_get() % 1000 == 0) { + if (last_time > time || (time - last_time) >= 1000) { + last_time = time; // Updates fan status and temps peci_event(); // Updates battery status diff --git a/src/board/system76/galp3-c/pmc.c b/src/board/system76/galp3-c/pmc.c index d104c6f..9ab446b 100644 --- a/src/board/system76/galp3-c/pmc.c +++ b/src/board/system76/galp3-c/pmc.c @@ -26,11 +26,14 @@ void pmc_sci_interrupt(void) { *(SCI_N.control) = GPIO_OUT; // Delay T_HOLD (value assumed) - delay_us(1); + delay_us(65); // Stop SCI interrupt *(SCI_N.control) = GPIO_IN; gpio_set(&SCI_N, true); + + // Delay T_HOLD (value assumed) + delay_us(65); } bool pmc_sci(struct Pmc * pmc, uint8_t sci) { diff --git a/src/board/system76/lemp9/main.c b/src/board/system76/lemp9/main.c index 5faa370..326dc7f 100644 --- a/src/board/system76/lemp9/main.c +++ b/src/board/system76/lemp9/main.c @@ -99,7 +99,10 @@ void main(void) { INFO("System76 EC board '%s', version '%s'\n", board(), version()); + uint32_t last_time = 0; for(main_cycle = 0; ; main_cycle++) { + uint32_t time = time_get(); + // Handle power states power_event(); // Scans keyboard and sends keyboard packets @@ -111,7 +114,8 @@ void main(void) { // Checks for keyboard/mouse packets from host kbc_event(&KBC); // Only run the following once a second - if (time_get() % 1000 == 0) { + if (last_time > time || (time - last_time) >= 1000) { + last_time = time; // Updates fan status and temps peci_event(); // Updates battery status diff --git a/src/board/system76/lemp9/pmc.c b/src/board/system76/lemp9/pmc.c index d104c6f..9ab446b 100644 --- a/src/board/system76/lemp9/pmc.c +++ b/src/board/system76/lemp9/pmc.c @@ -26,11 +26,14 @@ void pmc_sci_interrupt(void) { *(SCI_N.control) = GPIO_OUT; // Delay T_HOLD (value assumed) - delay_us(1); + delay_us(65); // Stop SCI interrupt *(SCI_N.control) = GPIO_IN; gpio_set(&SCI_N, true); + + // Delay T_HOLD (value assumed) + delay_us(65); } bool pmc_sci(struct Pmc * pmc, uint8_t sci) {