diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-10-26 14:31:47 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-10-29 16:52:49 -0700 |
commit | 1d916d7c6b25de10c870cf7f35a44d3654d9f099 (patch) | |
tree | 5d7337654d86766324103217ab61ae0b71d65e0f /common | |
parent | 67aadcf614513353d7c9a0216fc70f7af18d8d05 (diff) | |
download | chrome-ec-1d916d7c6b25de10c870cf7f35a44d3654d9f099.tar.gz |
Use SECOND and MSEC constants
We'd defined them in a number of different files. This moves
definitions to timer.h, and uses them everywhere we have large delays
(since 10*SECOND is less typo-prone than 10000000).
Also add msleep() and sleep() inline functions. No need for mdelay()
or delay(), since any delays that long should use sleep funcs instead
of spin-waiting.
BUG=chrome-os-partner:15579
BRANCH=none
TEST=boot system; taskinfo displays similar numbers to before
Change-Id: I2a92a9f10f46b6b7b6571759b1f8ab4ecfbf8259
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/36726
Diffstat (limited to 'common')
-rw-r--r-- | common/battery_precharge.c | 10 | ||||
-rw-r--r-- | common/charge_state.c | 2 | ||||
-rw-r--r-- | common/gaia_power.c | 20 | ||||
-rw-r--r-- | common/lightbar.c | 11 | ||||
-rw-r--r-- | common/mock_i8042.c | 2 | ||||
-rw-r--r-- | common/mock_temp_sensor.c | 7 | ||||
-rw-r--r-- | common/mock_x86_power.c | 2 | ||||
-rw-r--r-- | common/pmu_tps65090_charger.c | 15 | ||||
-rw-r--r-- | common/smart_battery.c | 2 | ||||
-rw-r--r-- | common/temp_sensor.c | 2 | ||||
-rw-r--r-- | common/thermal.c | 2 | ||||
-rw-r--r-- | common/x86_power.c | 12 |
12 files changed, 41 insertions, 46 deletions
diff --git a/common/battery_precharge.c b/common/battery_precharge.c index 1f8d732f46..10cae97269 100644 --- a/common/battery_precharge.c +++ b/common/battery_precharge.c @@ -86,7 +86,7 @@ static enum power_state go_next_level(struct power_state_context *ctx) * Battery chemical reaction lags behind the charging voltage * change. Delay the charging state machine 2 seconds. */ - usleep(SECOND * 2); + sleep(2); charger_get_voltage(&baseline_voltage); return PWR_STATE_UNCHANGE; @@ -165,7 +165,7 @@ enum power_state trickle_charge(struct power_state_context *ctx) batt->voltage > (binfo->voltage_min * 105 / 100)) { kicking_count++; charger_set_voltage(batt->desired_voltage); - usleep(5 * SECOND); + sleep(5); desired_curr = 0; battery_desired_current(&desired_curr); if (desired_curr >= cinfo->current_min) { @@ -189,7 +189,7 @@ enum power_state trickle_charge(struct power_state_context *ctx) dec_voltage(ctx); if (baseline_voltage > ctx->curr.charging_voltage) baseline_voltage = ctx->curr.charging_voltage; - usleep(SECOND); + sleep(1); reset_data_log(); return PWR_STATE_UNCHANGE; } @@ -225,14 +225,14 @@ enum power_state trickle_charge(struct power_state_context *ctx) if (desired_volt > baseline_voltage) { if (desired_volt > curr->charging_voltage) { inc_voltage(ctx); - usleep(SECOND); + sleep(1); return PWR_STATE_UNCHANGE; } if (desired_volt < (curr->charging_voltage - cinfo->voltage_step)) { dec_voltage(ctx); - usleep(SECOND); + sleep(1); return PWR_STATE_UNCHANGE; } } diff --git a/common/charge_state.c b/common/charge_state.c index 8f82656b7e..09efefffe1 100644 --- a/common/charge_state.c +++ b/common/charge_state.c @@ -194,7 +194,7 @@ static int state_common(struct power_state_context *ctx) charger_set_voltage(ctx->battery->voltage_max); charger_set_current(ctx->charger->current_min); for (d = 0; d < 30; d++) { - usleep(SECOND); + sleep(1); rv = battery_temperature(&batt->temperature); if (rv == 0) { ctx->battery_present = 1; diff --git a/common/gaia_power.c b/common/gaia_power.c index 922b07afbb..20875cb0ce 100644 --- a/common/gaia_power.c +++ b/common/gaia_power.c @@ -42,13 +42,13 @@ #define CPRINTF(format, args...) cprintf(CC_CHIPSET, format, ## args) /* Time necessary for the 5v regulator output to stabilize */ -#define DELAY_5V_SETUP 1000 /* 1ms */ +#define DELAY_5V_SETUP MSEC /* 1ms */ /* Delay between 1.35v and 3.3v rails startup */ #define DELAY_RAIL_STAGGERING 100 /* 100us */ /* Long power key press to force shutdown */ -#define DELAY_FORCE_SHUTDOWN 8000000 /* 8s */ +#define DELAY_FORCE_SHUTDOWN (8 * SECOND) /* * If the power key is pressed to turn on, then held for this long, we @@ -68,11 +68,11 @@ * see XPSHOLD, it waits up to 16sec for an event. If no event occurs * within 16sec, EC powers off AP. */ -#define DELAY_SHUTDOWN_ON_POWER_HOLD (8 * 1000000) -#define DELAY_SHUTDOWN_ON_USB_BOOT (16 * 1000000) +#define DELAY_SHUTDOWN_ON_POWER_HOLD (8 * SECOND) +#define DELAY_SHUTDOWN_ON_USB_BOOT (16 * SECOND) /* Maximum delay after power button press before we release GPIO_PMIC_PWRON_L */ -#define DELAY_RELEASE_PWRON 1000000 /* 1s */ +#define DELAY_RELEASE_PWRON SECOND /* 1s */ /* debounce time to prevent accidental power-on after keyboard power off */ #define KB_PWR_ON_DEBOUNCE 250 /* 250us */ @@ -81,10 +81,10 @@ #define LID_SWITCH_DEBOUNCE 250 /* 250us */ /* PMIC fails to set the LDO2 output */ -#define PMIC_TIMEOUT 100000 /* 100ms */ +#define PMIC_TIMEOUT (100 * MSEC) /* 100ms */ /* Default timeout for input transition */ -#define FAIL_TIMEOUT 500000 /* 500ms */ +#define FAIL_TIMEOUT (500 * MSEC) /* 500ms */ /* Application processor power state */ @@ -538,9 +538,9 @@ static int command_force_power(int argc, char **argv) force_value = 1; /* Wake up the task */ task_wake(TASK_ID_GAIAPOWER); - /* wait 100 ms */ - usleep(100000); - /* release power button */ + /* Wait 100 ms */ + msleep(100); + /* Release power button */ force_signal = -1; force_value = 0; diff --git a/common/lightbar.c b/common/lightbar.c index e2d1b50162..dad881e18e 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -183,7 +183,7 @@ static const struct lightbar_params default_params = { .s0_tick_delay = { 45000, 30000 }, /* battery, AC */ .s0a_tick_delay = { 5000, 3000 }, /* battery, AC */ .s0s3_ramp_down = 2000, - .s3_sleep_for = 5000000, /* between checks */ + .s3_sleep_for = 5 * SECOND, /* between checks */ .s3_ramp_up = 2500, .s3_ramp_down = 10000, @@ -464,11 +464,6 @@ static uint32_t pending_msg; if (TASK_EVENT_CUSTOM(msg) == PENDING_MSG) \ return PENDING_MSG; } while (0) -/* Handy conversions */ -#define MSECS(a) ((a) * 1000) -#define SEC(a) ((a) * 1000000) - - /******************************************************************************/ /* Here are the preprogrammed sequences. */ /******************************************************************************/ @@ -569,7 +564,7 @@ static uint32_t sequence_S0(void) /* Only check the battery state every few seconds. The battery * charging task doesn't update as quickly as we do, and isn't * always valid for a bit after jumping from RO->RW. */ - tick = (now.le.lo - start.le.lo) / SEC(1); + tick = (now.le.lo - start.le.lo) / SECOND; if (tick % 4 == 3 && tick != last_tick) { get_battery_level(); last_tick = tick; @@ -845,7 +840,7 @@ static uint32_t sequence_ERROR(void) lightbar_setrgb(2, 0, 255, 255); lightbar_setrgb(3, 255, 255, 255); - WAIT_OR_RET(SEC(10)); + WAIT_OR_RET(10 * SECOND); return 0; } diff --git a/common/mock_i8042.c b/common/mock_i8042.c index a8c1a01447..01d258c3c0 100644 --- a/common/mock_i8042.c +++ b/common/mock_i8042.c @@ -19,7 +19,7 @@ void i8042_command_task(void) { /* Do nothing */ while (1) - usleep(5000000); + sleep(5); } enum ec_error_list i8042_send_to_host(int len, const uint8_t *bytes) diff --git a/common/mock_temp_sensor.c b/common/mock_temp_sensor.c index 7f2a6b1dd9..3373e299a5 100644 --- a/common/mock_temp_sensor.c +++ b/common/mock_temp_sensor.c @@ -5,13 +5,14 @@ /* Mock temperature sensor module for Chrome EC */ -#include "board.h" +#include "common.h" #include "console.h" #include "temp_sensor.h" #include "timer.h" #include "util.h" -/* Defined in board_temp_sensor.c. Must be in the same order as +/* + * Defined in board_temp_sensor.c. Must be in the same order as * in enum temp_sensor_id. */ extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT]; @@ -35,7 +36,7 @@ void temp_sensor_task(void) { /* Do nothing */ while (1) - usleep(5000000); + sleep(5); } diff --git a/common/mock_x86_power.c b/common/mock_x86_power.c index ac7f969bbc..ddf99127e3 100644 --- a/common/mock_x86_power.c +++ b/common/mock_x86_power.c @@ -84,7 +84,7 @@ void x86_power_task(void) { /* Do nothing */ while (1) - usleep(5000000); + sleep(5); } diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c index cfc218d7e5..a0575820a0 100644 --- a/common/pmu_tps65090_charger.c +++ b/common/pmu_tps65090_charger.c @@ -30,10 +30,10 @@ /* Maximum retry count to revive a extremely low charge battery */ #define PRE_CHARGING_RETRY 3 -/* Time delay in usec for idle, charging and discharging. - * Defined in battery charging flow. +/* + * Time delay in usec for idle, charging and discharging. Defined in battery + * charging flow. */ -#define SECOND (1000 * 1000) #define T1_OFF_USEC (60 * SECOND) #define T1_SUSPEND_USEC (60 * SECOND) #define T1_USEC (5 * SECOND) @@ -120,7 +120,7 @@ static int notify_battery_low(void) if (chipset_in_state(CHIPSET_STATE_ON)) { now = get_time(); - if (now.val - last_notify_time.val > 60000000) { + if (now.val - last_notify_time.val > MINUTE) { CPUTS("[pmu] notify battery low (< 10%)\n"); last_notify_time = now; /* TODO(rongchang): notify AP ? */ @@ -467,12 +467,11 @@ void pmu_charger_task(void) } /* - * Throttle the charging loop. If previous loop was waked up - * by an event, sleep 0.5 seconds instead of wait for next - * event. + * Throttle the charging loop. If previous loop awakened due to + * an event, sleep 500 ms instead of waiting for next event. */ if (event & TASK_EVENT_WAKE) { - usleep(0.5 * SECOND); + msleep(500); event = 0; } else { event = task_wait_event(wait_time); diff --git a/common/smart_battery.c b/common/smart_battery.c index ee5c138946..0438d6309f 100644 --- a/common/smart_battery.c +++ b/common/smart_battery.c @@ -79,7 +79,7 @@ int battery_time_at_rate(int rate, int *minutes) return EC_SUCCESS; } else { /* wait 10ms for AT_RATE_OK */ - usleep(10000); + msleep(10); } } return EC_ERROR_TIMEOUT; diff --git a/common/temp_sensor.c b/common/temp_sensor.c index ecbe6c0825..6cfbb8cfee 100644 --- a/common/temp_sensor.c +++ b/common/temp_sensor.c @@ -119,7 +119,7 @@ void temp_sensor_task(void) while (1) { for (i = 0; i < 4; ++i) { - usleep(250000); + msleep(250); poll_fast_sensors(); } poll_slow_sensors(); diff --git a/common/thermal.c b/common/thermal.c index d280c4614c..907743bcdd 100644 --- a/common/thermal.c +++ b/common/thermal.c @@ -208,7 +208,7 @@ void thermal_task(void) { while (1) { thermal_process(); - usleep(1000000); + usleep(SECOND); } } diff --git a/common/x86_power.c b/common/x86_power.c index 2424508396..7b8b492067 100644 --- a/common/x86_power.c +++ b/common/x86_power.c @@ -26,10 +26,10 @@ * Default timeout in us; if we've been waiting this long for an input * transition, just jump to the next state. */ -#define DEFAULT_TIMEOUT 1000000 +#define DEFAULT_TIMEOUT SECOND /* Timeout for dropping back from S5 to G3 */ -#define S5_INACTIVITY_TIMEOUT 10000000 +#define S5_INACTIVITY_TIMEOUT (10 * SECOND) enum x86_state { X86_G3 = 0, /* @@ -512,14 +512,14 @@ void x86_power_task(void) * Wait 10ms after +3VALW good, since that powers * VccDSW and VccSUS. */ - usleep(10000); + msleep(10); /* Assert DPWROK, deassert RSMRST# */ gpio_set_level(GPIO_PCH_DPWROK, 1); gpio_set_level(GPIO_PCH_RSMRSTn, 1); /* Wait 5ms for SUSCLK to stabilize */ - usleep(5000); + msleep(5); state = X86_S5; break; @@ -581,7 +581,7 @@ void x86_power_task(void) hook_notify(HOOK_CHIPSET_RESUME); /* Wait 99ms after all voltages good */ - usleep(99000); + msleep(99); /* * Throttle CPU if necessary. This should only be @@ -737,7 +737,7 @@ static int command_hibernation_delay(int argc, char **argv) { char *e; uint32_t time_g3 = ((uint32_t)(get_time().val - last_shutdown_time)) - / 1000000; + / SECOND; if (argc >= 2) { uint32_t s = strtoi(argv[1], &e, 0); |