Use a 16-bit system tick
The maximum interval when configured for a 1ms tick: - 16-bit: ~65 seconds - 32-bit: ~49.7 days The value is used for scheduling and timeouts, and not to track the uptime of the system, so the 32-bit value is excessive. Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
committed by
Tim Crawford
parent
9e7f1952fa
commit
0f7642defb
@ -5,7 +5,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint16_t systick_t;
|
||||
|
||||
void time_init(void);
|
||||
uint32_t time_get(void);
|
||||
systick_t time_get(void);
|
||||
|
||||
#endif // _ARCH_TIME_H
|
||||
|
@ -10,7 +10,7 @@
|
||||
// Value to reload into the timer when the overflow interrupt is triggered.
|
||||
#define TIMER_RELOAD (0xFFFF - (TICK_INTERVAL_MS * (CONFIG_CLOCK_FREQ_KHZ / OSC_DIVISOR)))
|
||||
|
||||
static volatile uint32_t time_overflows = 0;
|
||||
static volatile systick_t time_overflows = 0;
|
||||
|
||||
void timer_0(void) __interrupt(1) {
|
||||
// Hardware automatically clears the the interrupt
|
||||
@ -52,6 +52,6 @@ void time_init(void) __critical {
|
||||
TR0 = 1;
|
||||
}
|
||||
|
||||
uint32_t time_get(void) __critical {
|
||||
systick_t time_get(void) __critical {
|
||||
return time_overflows;
|
||||
}
|
||||
|
@ -284,15 +284,15 @@ void kbscan_event(void) {
|
||||
uint8_t matrix_curr[KM_OUT];
|
||||
|
||||
static bool debounce = false;
|
||||
static uint32_t debounce_time = 0;
|
||||
static systick_t debounce_time = 0;
|
||||
|
||||
static bool repeat = false;
|
||||
static uint16_t repeat_key = 0;
|
||||
static uint32_t repeat_key_time = 0;
|
||||
static systick_t repeat_key_time = 0;
|
||||
|
||||
// If debounce complete
|
||||
if (debounce) {
|
||||
uint32_t time = time_get();
|
||||
systick_t time = time_get();
|
||||
if ((time - debounce_time) >= DEBOUNCE_DELAY) {
|
||||
// Debounce time elapsed: Read new state
|
||||
debounce = false;
|
||||
@ -384,8 +384,8 @@ void kbscan_event(void) {
|
||||
kbscan_matrix[i] = new;
|
||||
} else if (new && repeat_key != 0 && key_should_repeat(repeat_key)) {
|
||||
// A key is being pressed
|
||||
uint32_t time = time_get();
|
||||
static uint32_t repeat_start = 0;
|
||||
systick_t time = time_get();
|
||||
static systick_t repeat_start = 0;
|
||||
|
||||
if (!repeat) {
|
||||
if (time < repeat_key_time) {
|
||||
|
@ -98,8 +98,8 @@ void main(void) {
|
||||
|
||||
INFO("System76 EC board '%s', version '%s'\n", board(), version());
|
||||
|
||||
uint32_t last_time_battery = 0;
|
||||
uint32_t last_time_fan = 0;
|
||||
systick_t last_time_battery = 0;
|
||||
systick_t last_time_fan = 0;
|
||||
|
||||
for (main_cycle = 0;; main_cycle++) {
|
||||
// NOTE: Do note use modulo to avoid expensive call to SDCC library
|
||||
@ -128,7 +128,7 @@ void main(void) {
|
||||
}
|
||||
|
||||
if (main_cycle == 0) {
|
||||
uint32_t time = time_get();
|
||||
systick_t time = time_get();
|
||||
// Only run the following once per interval
|
||||
if ((time - last_time_fan) >= fan_interval) {
|
||||
last_time_fan = time;
|
||||
|
@ -32,7 +32,7 @@
|
||||
bool parallel_debug = false;
|
||||
|
||||
static bool parallel_wait_peripheral(uint8_t mask, uint8_t value) {
|
||||
uint32_t start = time_get();
|
||||
systick_t start = time_get();
|
||||
|
||||
while ((time_get() - start) < PARALLEL_TIMEOUT) {
|
||||
if ((KSOHGDMRR & mask) == value) {
|
||||
|
@ -93,7 +93,7 @@ bool peci_get_temp(int16_t *const data) {
|
||||
ESUCTRL0 |= ESUCTRL0_GO;
|
||||
|
||||
// Wait until upstream done
|
||||
uint32_t start = time_get();
|
||||
systick_t start = time_get();
|
||||
while (!(ESUCTRL0 & ESUCTRL0_DONE)) {
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
DEBUG("peci_get_temp: upstream timeout\n");
|
||||
@ -189,7 +189,7 @@ int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
|
||||
ESUCTRL0 |= ESUCTRL0_GO;
|
||||
|
||||
// Wait until upstream done
|
||||
uint32_t start = time_get();
|
||||
systick_t start = time_get();
|
||||
while (!(ESUCTRL0 & ESUCTRL0_DONE)) {
|
||||
DEBUG("peci_wr_pkg_config: wait upstream\n");
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
@ -254,7 +254,7 @@ void peci_init(void) {
|
||||
// Returns true on success, false on error
|
||||
bool peci_get_temp(int16_t *const data) {
|
||||
// Wait for any in-progress transaction to complete
|
||||
uint32_t start = time_get();
|
||||
systick_t start = time_get();
|
||||
while (HOSTAR & BIT(0)) {
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
DEBUG("%s: host timeout\n", __func__);
|
||||
@ -310,7 +310,7 @@ bool peci_get_temp(int16_t *const data) {
|
||||
// negative (0x1000 | status register) on PECI hardware error
|
||||
int16_t peci_wr_pkg_config(uint8_t index, uint16_t param, uint32_t data) {
|
||||
// Wait for any in-progress transaction to complete
|
||||
uint32_t start = time_get();
|
||||
systick_t start = time_get();
|
||||
while (HOSTAR & BIT(0)) {
|
||||
if ((time_get() - start) >= PECI_ESPI_TIMEOUT) {
|
||||
DEBUG("%s: host timeout\n", __func__);
|
||||
|
@ -572,8 +572,8 @@ void power_event(void) {
|
||||
wake_last = wake_new;
|
||||
#endif // HAVE_LAN_WAKEUP_N
|
||||
|
||||
static uint32_t last_time = 0;
|
||||
uint32_t time = time_get();
|
||||
static systick_t last_time = 0;
|
||||
systick_t time = time_get();
|
||||
if (power_state == POWER_STATE_S0) {
|
||||
#if CONFIG_BUS_ESPI
|
||||
// HOST_C10 virtual wire is high when CPU is in C10 sleep state
|
||||
|
Reference in New Issue
Block a user