power: Use u8/u16 for loop index

Use u8/u16 instead of i16 as the value will never be negative and the
bounds are known at compile time.

Use a decrementing loop as SDCC generates more efficient code.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2021-08-02 11:56:47 -06:00
committed by Jeremy Soller
parent 37fa06ebc8
commit d99ea41259

View File

@ -294,7 +294,7 @@ void power_on_s5(void) {
// Wait for SUSPWRDNACK validity
tPLT01;
for (int16_t i = 0; i < 5000; i++) {
for (uint16_t i = 5000; i != 0; i--) {
// If we reached S0, exit this loop
update_power_state();
if (power_state == POWER_STATE_S0) {
@ -361,7 +361,7 @@ void power_off_s5(void) {
static void power_peci_limit(bool ac) {
uint8_t watts = ac ? POWER_LIMIT_AC : POWER_LIMIT_DC;
// Retry, timeout errors happen occasionally
for (int16_t i = 0; i < 16; i++) {
for (uint8_t i = 16; i != 0; i--) {
// Set PL4 using PECI
int16_t res = peci_wr_pkg_config(60, 0, ((uint32_t)watts) * 8);
DEBUG("power_peci_limit %d = %d\n", watts, res);
@ -466,7 +466,7 @@ void power_event(void) {
bool ps_new = gpio_get(&PWR_SW_N);
if (!ps_new && ps_last) {
// Ensure press is not spurious
for (int16_t i = 0; i < 100; i++) {
for (uint8_t i = 100; i != 0; i--) {
delay_ms(1);
if (gpio_get(&PWR_SW_N) != ps_new) {
DEBUG("%02X: Spurious press\n", main_cycle);