static int command_mem_dump(int argc, char **argv) { volatile uint32_t *address; uint32_t value, num = 1, i; char *e; if (argc < 2) return EC_ERROR_PARAM_COUNT; address = (uint32_t *)(uintptr_t)strtoi(argv[1], &e, 0); if (*e) return EC_ERROR_PARAM1; if (argc >= 3) num = strtoi(argv[2], &e, 0); for (i = 0; i < num; i++) { value = address[i]; if (0 == (i%4)) ccprintf("\n%08X: %08x", address+i, value); else ccprintf(" %08x", value); cflush(); /* Lots of output could take a while. * Let other things happen, too */ if (!(i % 0x100)) { watchdog_reload(); usleep(10 * MSEC); } } ccprintf("\n"); cflush(); return EC_SUCCESS; }
static int command_powerbtn(int argc, char **argv) { int ms = 200; /* Press duration in ms */ char *e; if (argc > 1) { ms = strtoi(argv[1], &e, 0); if (*e) return EC_ERROR_PARAM1; } ccprintf("Simulating %d ms power button press.\n", ms); simulate_power_pressed = 1; power_button_is_stable = 0; hook_call_deferred(power_button_change_deferred, 0); msleep(ms); ccprintf("Simulating power button release.\n"); simulate_power_pressed = 0; power_button_is_stable = 0; hook_call_deferred(power_button_change_deferred, 0); return EC_SUCCESS; }
static int command_accel_read_xyz(int argc, char **argv) { char *e; int id, n = 1, ret; struct motion_sensor_t *sensor; vector_3_t v; if (argc < 2) return EC_ERROR_PARAM_COUNT; /* First argument is sensor id. */ id = strtoi(argv[1], &e, 0); if (*e || id < 0 || id >= motion_sensor_count) return EC_ERROR_PARAM1; if (argc >= 3) n = strtoi(argv[2], &e, 0); sensor = &motion_sensors[id]; while ((n == -1) || (n-- > 0)) { ret = sensor->drv->read(sensor, v); if (ret == 0) ccprintf("Current data %d: %-5d %-5d %-5d\n", id, v[X], v[Y], v[Z]); else ccprintf("vector not ready\n"); ccprintf("Last calib. data %d: %-5d %-5d %-5d\n", id, sensor->xyz[X], sensor->xyz[Y], sensor->xyz[Z]); task_wait_event(MIN_MOTION_SENSE_WAIT_TIME); } return EC_SUCCESS; }
static int command_powerindebug(int argc, char **argv) { const struct power_signal_info *s = power_signal_list; int i; char *e; /* If one arg, set the mask */ if (argc == 2) { int m = strtoi(argv[1], &e, 0); if (*e) return EC_ERROR_PARAM1; in_debug = m; } /* Print the mask */ ccprintf("power in: 0x%04x\n", in_signals); ccprintf("debug mask: 0x%04x\n", in_debug); /* Print the decode */ ccprintf("bit meanings:\n"); for (i = 0; i < POWER_SIGNAL_COUNT; i++, s++) { int mask = 1 << i; ccprintf(" 0x%04x %d %s\n", mask, in_signals & mask ? 1 : 0, s->name); } return EC_SUCCESS; };
static void do_print_later(void) { int lines_per_loop = 32; /* too much at once fails */ int copy_of_stuff_in; int copy_of_overflow; interrupt_disable(); copy_of_stuff_in = stuff_in; copy_of_overflow = stuff_overflow; stuff_overflow = 0; interrupt_enable(); if (copy_of_overflow) ccprintf("*** WARNING: %d MESSAGES WERE LOST ***\n", copy_of_overflow); while (lines_per_loop && stuff_out != copy_of_stuff_in) { ccprintf("at %.6ld: ", stuff_to_print[stuff_out].t); ccprintf(stuff_to_print[stuff_out].fmt, stuff_to_print[stuff_out].a0, stuff_to_print[stuff_out].a1, stuff_to_print[stuff_out].a2, stuff_to_print[stuff_out].a3, stuff_to_print[stuff_out].a4); ccprintf("\n"); stuff_out = (stuff_out + 1) % MAX_ENTRIES; lines_per_loop--; } }
static void show_charging_progress(void) { int rv, minutes, to_full; if (!curr.batt_is_charging) { rv = battery_time_to_empty(&minutes); to_full = 0; } else { rv = battery_time_to_full(&minutes); to_full = 1; } if (rv) CPRINTS("Battery %d%% / ??h:?? %s%s", curr.batt.state_of_charge, to_full ? "to full" : "to empty", is_full ? ", not accepting current" : ""); else CPRINTS("Battery %d%% / %dh:%d %s%s", curr.batt.state_of_charge, minutes / 60, minutes % 60, to_full ? "to full" : "to empty", is_full ? ", not accepting current" : ""); if (debugging) { ccprintf("battery:\n"); print_battery_debug(); ccprintf("charger:\n"); print_charger_debug(); ccprintf("chg:\n"); dump_charge_state(); } }
static int command_gpio_get(int argc, char **argv) { int changed, v, i; /* If a signal is specified, print only that one */ if (argc == 2) { i = find_signal_by_name(argv[1]); if (i == GPIO_COUNT) return EC_ERROR_PARAM1; v = gpio_get_level(i); changed = last_val_changed(i, v); ccprintf(" %d%c %s\n", v, (changed ? '*' : ' '), gpio_get_name(i)); return EC_SUCCESS; } /* Otherwise print them all */ for (i = 0; i < GPIO_COUNT; i++) { if (!gpio_is_implemented(i)) continue; /* Skip unsupported signals */ v = gpio_get_level(i); changed = last_val_changed(i, v); ccprintf(" %d%c %s\n", v, (changed ? '*' : ' '), gpio_get_name(i)); /* Flush console to avoid truncating output */ cflush(); } return EC_SUCCESS; }
static int print_status(void) { int value; print_temps("Local", TMP432_LOCAL, TMP432_LOCAL_THERM_LIMIT, TMP432_LOCAL_HIGH_LIMIT_R, TMP432_LOCAL_LOW_LIMIT_R); print_temps("Remote1", TMP432_REMOTE1, TMP432_REMOTE1_THERM_LIMIT, TMP432_REMOTE1_HIGH_LIMIT_R, TMP432_REMOTE1_LOW_LIMIT_R); print_temps("Remote2", TMP432_REMOTE2, TMP432_REMOTE2_THERM_LIMIT, TMP432_REMOTE2_HIGH_LIMIT_R, TMP432_REMOTE2_LOW_LIMIT_R); ccprintf("\n"); if (raw_read8(TMP432_STATUS, &value) == EC_SUCCESS) ccprintf("STATUS: %08b\n", value); if (raw_read8(TMP432_CONFIGURATION1_R, &value) == EC_SUCCESS) ccprintf("CONFIG1: %08b\n", value); if (raw_read8(TMP432_CONFIGURATION2_R, &value) == EC_SUCCESS) ccprintf("CONFIG2: %08b\n", value); return EC_SUCCESS; }
/** * Print status of a PWM channel. * * @param ch Channel to print. */ static void print_channel(enum pwm_channel ch) { if (pwm_get_enabled(ch)) ccprintf(" %d: %d%%\n", ch, pwm_get_duty(ch)); else ccprintf(" %d: disabled\n", ch); }
int verify_key(int c, int r, int pressed) { struct host_cmd_handler_args args; uint8_t mkbp_out[KEYBOARD_COLS]; int i; if (c >= 0 && r >= 0) { ccprintf("Verify %s (%d, %d)\n", action[pressed], c, r); set_state(c, r, pressed); } else { ccprintf("Verify last state\n"); } args.version = 0; args.command = EC_CMD_MKBP_STATE; args.params = NULL; args.params_size = 0; args.response = mkbp_out; args.response_max = sizeof(mkbp_out); args.response_size = 0; if (host_command_process(&args) != EC_RES_SUCCESS) return 0; for (i = 0; i < KEYBOARD_COLS; ++i) if (mkbp_out[i] != state[i]) return 0; return 1; }
static int command_power(int argc, char **argv) { int v; if (argc < 2) { enum power_state_t state; state = PSTATE_UNKNOWN; if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) state = PSTATE_OFF; if (chipset_in_state(CHIPSET_STATE_SUSPEND)) state = PSTATE_SUSPEND; if (chipset_in_state(CHIPSET_STATE_ON)) state = PSTATE_ON; ccprintf("%s\n", state_name[state]); return EC_SUCCESS; } if (!parse_bool(argv[1], &v)) return EC_ERROR_PARAM1; power_request = v ? POWER_REQ_ON : POWER_REQ_OFF; ccprintf("Requesting power %s\n", power_req_name[power_request]); task_wake(TASK_ID_CHIPSET); return EC_SUCCESS; }
static int motion_sense_read_fifo(int argc, char **argv) { int count, i; struct ec_response_motion_sensor_data v; if (argc < 1) return EC_ERROR_PARAM_COUNT; /* Limit the amount of data to avoid saturating the UART buffer */ count = MIN(queue_count(&motion_sense_fifo), 16); for (i = 0; i < count; i++) { queue_peek_units(&motion_sense_fifo, &v, i, 1); if (v.flags & (MOTIONSENSE_SENSOR_FLAG_TIMESTAMP | MOTIONSENSE_SENSOR_FLAG_FLUSH)) { uint64_t timestamp; memcpy(×tamp, v.data, sizeof(v.data)); ccprintf("Timestamp: 0x%016lx%s\n", timestamp, (v.flags & MOTIONSENSE_SENSOR_FLAG_FLUSH ? " - Flush" : "")); } else { ccprintf("%d %d: %-5d %-5d %-5d\n", i, v.sensor_num, v.data[X], v.data[Y], v.data[Z]); } } return EC_SUCCESS; }
static int wait_until_stop_sent(int port) { timestamp_t deadline; timestamp_t slow_cutoff; uint8_t is_slow; deadline = slow_cutoff = get_time(); deadline.val += TIMEOUT_STOP_SENT_US; slow_cutoff.val += SLOW_STOP_SENT_US; while (STM32_I2C_CR1(port) & (1 << 9)) { if (timestamp_expired(deadline, NULL)) { ccprintf("Stop event deadline passed:\ttask=%d" "\tCR1=%016b\n", (int)task_get_current(), STM32_I2C_CR1(port)); return EC_ERROR_TIMEOUT; } if (is_slow) { /* If we haven't gotten a fast response, sleep */ usleep(STOP_SENT_RETRY_US); } else { /* Check to see if this request is taking a while */ if (timestamp_expired(slow_cutoff, NULL)) { ccprintf("Stop event taking a while: task=%d", (int)task_get_current()); is_slow = 1; } } } return EC_SUCCESS; }
static int command_hang_detect(int argc, char **argv) { ccprintf("flags: 0x%x\n", hdparams.flags); ccputs("event: "); if (hdparams.host_event_timeout_msec) ccprintf("%d ms\n", hdparams.host_event_timeout_msec); else ccputs("disabled\n"); ccputs("reboot: "); if (hdparams.warm_reboot_timeout_msec) ccprintf("%d ms\n", hdparams.warm_reboot_timeout_msec); else ccputs("disabled\n"); ccputs("status: "); if (active) ccprintf("active for %s\n", timeout_will_reboot ? "reboot" : "event"); else ccputs("inactive\n"); return EC_SUCCESS; }
static int command_crash(int argc, char **argv) { if (argc < 2) return EC_ERROR_PARAM1; if (!strcasecmp(argv[1], "assert")) { ASSERT(0); } else if (!strcasecmp(argv[1], "divzero")) { int zero = 0; cflush(); if (argc >= 3 && !strcasecmp(argv[2], "unsigned")) ccprintf("%08x", (unsigned long)1 / zero); else ccprintf("%08x", (long)1 / zero); #ifdef CONFIG_CMD_STACKOVERFLOW } else if (!strcasecmp(argv[1], "stack")) { stack_overflow_recurse(1); #endif } else if (!strcasecmp(argv[1], "unaligned")) { cflush(); ccprintf("%08x", *(volatile int *)0xcdef); } else if (!strcasecmp(argv[1], "watchdog")) { while (1) ; } else { return EC_ERROR_PARAM1; } /* Everything crashes, so shouldn't get back here */ return EC_ERROR_UNKNOWN; }
static int command_peci_temp(int argc, char **argv) { int t = peci_get_cpu_temp(); if (t == -1) { ccprintf("PECI error 0x%04x\n", LM4_PECI_M0D0 & 0xffff); return EC_ERROR_UNKNOWN; } ccprintf("CPU temp = %d K = %d C\n", t, K_TO_C(t)); return EC_SUCCESS; }
static int command_version(int argc, char **argv) { ccprintf("Chip: %s %s %s\n", system_get_chip_vendor(), system_get_chip_name(), system_get_chip_revision()); ccprintf("Board: %d\n", system_get_board_version()); ccprintf("RO: %s\n", system_get_version(SYSTEM_IMAGE_RO)); ccprintf("RW: %s\n", system_get_version(SYSTEM_IMAGE_RW)); ccprintf("Build: %s\n", system_get_build_info()); return EC_SUCCESS; }
static int command_accel_data_rate(int argc, char **argv) { char *e; int id, data, round = 1, ret; struct motion_sensor_t *sensor; enum sensor_config config_id; if (argc < 2 || argc > 4) return EC_ERROR_PARAM_COUNT; /* First argument is sensor id. */ id = strtoi(argv[1], &e, 0); if (*e || id < 0 || id >= motion_sensor_count) return EC_ERROR_PARAM1; sensor = &motion_sensors[id]; if (argc >= 3) { /* Second argument is data to write. */ data = strtoi(argv[2], &e, 0); if (*e) return EC_ERROR_PARAM2; if (argc == 4) { /* Third argument is rounding flag. */ round = strtoi(argv[3], &e, 0); if (*e) return EC_ERROR_PARAM3; } /* * Write new data rate, if it returns invalid arg, then * return a parameter error. */ config_id = motion_sense_get_ec_config(); sensor->config[config_id].odr = data | (round ? ROUND_UP_FLAG : 0); ret = motion_sense_set_data_rate(sensor); if (ret) return EC_ERROR_PARAM2; /* Sensor might be out of suspend, check the ec_rate */ motion_sense_set_accel_interval(); } else { ccprintf("Data rate for sensor %d: %d\n", id, sensor->drv->get_data_rate(sensor)); ccprintf("EC rate for sensor %d: %d\n", id, motion_sense_ec_rate(sensor)); ccprintf("Current EC rate: %d\n", accel_interval); } return EC_SUCCESS; }
static int command_tmp432(int argc, char **argv) { char *command; char *e; int data; int offset; int rv; if (!has_power()) { ccprintf("ERROR: Temp sensor not powered.\n"); return EC_ERROR_NOT_POWERED; } /* If no args just print status */ if (argc == 1) return print_status(); if (argc < 3) return EC_ERROR_PARAM_COUNT; command = argv[1]; offset = strtoi(argv[2], &e, 0); if (*e || offset < 0 || offset > 255) return EC_ERROR_PARAM2; if (!strcasecmp(command, "getbyte")) { rv = raw_read8(offset, &data); if (rv < 0) return rv; ccprintf("Byte at offset 0x%02x is %08b\n", offset, data); return rv; } /* Remaining commands are "tmp432 set-command offset data" */ if (argc != 4) return EC_ERROR_PARAM_COUNT; data = strtoi(argv[3], &e, 0); if (*e) return EC_ERROR_PARAM3; if (!strcasecmp(command, "settemp")) { ccprintf("Setting 0x%02x to %dC\n", offset, data); rv = tmp432_set_temp(offset, data); } else if (!strcasecmp(command, "setbyte")) { ccprintf("Setting 0x%02x to 0x%02x\n", offset, data); rv = raw_write8(offset, data); } else return EC_ERROR_PARAM1; return rv; }
static void showbits(uint32_t b) { int i; for (i = 0; i < 32; i++) if (b & (1 << i)) { if (deezbits[i]) ccprintf(" %s", deezbits[i]); else ccprintf(" %d", i); } ccprintf("\n"); }
static void ir357x_dump(void) { int i; for (i = 0; i < 256; i++) { if (!(i & 0xf)) { ccprintf("\n%02x: ", i); cflush(); } ccprintf("%02x ", ir357x_read(i)); } ccprintf("\n"); }
static int test_low_battery(void) { test_setup(1); ccprintf("[CHARGING TEST] Low battery with AC\n"); sb_write(SB_RELATIVE_STATE_OF_CHARGE, 2); wait_charging_state(); mock_chipset_state = CHIPSET_STATE_SOFT_OFF; hook_notify(HOOK_CHIPSET_SHUTDOWN); TEST_ASSERT(!is_hibernated); ccprintf("[CHARGING TEST] Low battery shutdown S0->S5\n"); mock_chipset_state = CHIPSET_STATE_ON; hook_notify(HOOK_CHIPSET_PRE_INIT); hook_notify(HOOK_CHIPSET_STARTUP); gpio_set_level(GPIO_AC_PRESENT, 0); is_hibernated = 0; sb_write(SB_CURRENT, -1000); sb_write(SB_RELATIVE_STATE_OF_CHARGE, 2); wait_charging_state(); mock_chipset_state = CHIPSET_STATE_SOFT_OFF; hook_notify(HOOK_CHIPSET_SHUTDOWN); wait_charging_state(); TEST_ASSERT(is_hibernated); ccprintf("[CHARGING TEST] Low battery shutdown S5\n"); is_hibernated = 0; sb_write(SB_RELATIVE_STATE_OF_CHARGE, 10); wait_charging_state(); sb_write(SB_RELATIVE_STATE_OF_CHARGE, 2); wait_charging_state(); TEST_ASSERT(is_hibernated); ccprintf("[CHARGING TEST] Low battery AP shutdown\n"); is_shutdown = 0; mock_chipset_state = CHIPSET_STATE_ON; sb_write(SB_RELATIVE_STATE_OF_CHARGE, 10); gpio_set_level(GPIO_AC_PRESENT, 1); sb_write(SB_CURRENT, 1000); wait_charging_state(); gpio_set_level(GPIO_AC_PRESENT, 0); sb_write(SB_CURRENT, -1000); sb_write(SB_RELATIVE_STATE_OF_CHARGE, 2); wait_charging_state(); usleep(32 * SECOND); wait_charging_state(); TEST_ASSERT(is_shutdown); return EC_SUCCESS; }
static int interrupt_test(void) { timestamp_t deadline = get_time(); deadline.val += SECOND / 2; while (!timestamp_expired(deadline, NULL)) ++main_count; ccprintf("Interrupt count: %d\n", interrupt_count); ccprintf("Main thread tick: %d\n", main_count); TEST_ASSERT(!has_error); TEST_ASSERT(!in_interrupt_context()); return EC_SUCCESS; }
/* Dump all readable registers on bd99955 */ static int console_bd99955_dump_regs(int argc, char **argv) { int i; uint8_t regs[] = { 0x14, 0x15, 0x3c, 0x3d, 0x3e, 0x3f }; /* Battery group registers */ for (i = 0; i < ARRAY_SIZE(regs); ++i) ccprintf("BAT REG %4x: %4x\n", regs[i], read_bat(regs[i])); /* Extended group registers */ for (i = 0; i < 0x7f; ++i) ccprintf("EXT REG %4x: %4x\n", i, read_ext(i)); return 0; }
static int command_external_power_limit(int argc, char **argv) { int max_current; int max_voltage; char *e; if (argc >= 2) { max_current = strtoi(argv[1], &e, 10); if (*e) return EC_ERROR_PARAM1; } else max_current = EC_POWER_LIMIT_NONE; if (argc >= 3) { max_voltage = strtoi(argv[2], &e, 10); if (*e) return EC_ERROR_PARAM1; } else max_voltage = EC_POWER_LIMIT_NONE; charge_manager_set_external_power_limit(max_current, max_voltage); ccprintf("max req: %dmA %dmV\n", max_current, max_voltage); return EC_SUCCESS; }
/* Initialize host settings by interrupt */ void lpc_lreset_pltrst_handler(void) { int pltrst_asserted; /* Clear pending bit of WUI */ SET_BIT(NPCX_WKPCL(MIWU_TABLE_0 , MIWU_GROUP_5), 7); /* Ignore PLTRST# from SOC if it is not valid */ if (chipset_pltrst_is_valid && !chipset_pltrst_is_valid()) return; pltrst_asserted = lpc_get_pltrst_asserted(); ccprintf("LPC RESET# %sasserted", pltrst_asserted ? "" : "de"); /* * Once LRESET is de-asserted (low -> high), we need to initialize lpc * settings once. If RSTCTL_LRESET_PLTRST_MODE is active, LPC registers * won't be reset by Host domain reset but Core domain does. */ if (!pltrst_asserted) host_register_init(); else { #ifdef CONFIG_CHIPSET_RESET_HOOK /* Notify HOOK_CHIPSET_RESET */ hook_call_deferred(&lpc_chipset_reset_data, MSEC); #endif } }
static void board_handle_reboot(void) { int flags; if (system_jumped_to_this_image()) return; if (system_get_board_version() < BOARD_MIN_ID_LOD_EN) return; /* Interrogate current reset flags from previous reboot. */ flags = system_get_reset_flags(); if (!(flags & PMIC_RESET_FLAGS)) return; /* Preserve AP off request. */ if (flags & RESET_FLAG_AP_OFF) chip_save_reset_flags(RESET_FLAG_AP_OFF); ccprintf("Restarting system with PMIC.\n"); /* Flush console */ cflush(); /* Bring down all rails but RTC rail (including EC power). */ gpio_set_flags(GPIO_BATLOW_L_PMIC_LDO_EN, GPIO_OUT_HIGH); while (1) ; /* wait here */ }
static int command_usart_info(int argc, char **argv) { struct usart_configs configs = usart_get_configs(); size_t i; for (i = 0; i < configs.count; i++) { struct usart_config const *config = configs.configs[i]; if (config == NULL) continue; ccprintf("USART%d\n" " dropped %d bytes\n" " overran %d times\n", config->hw->index + 1, atomic_read_clear(&(config->state->rx_dropped)), atomic_read_clear(&(config->state->rx_overrun))); if (config->rx->info) config->rx->info(config); if (config->tx->info) config->tx->info(config); } return EC_SUCCESS; }
static int command_set_mode(int argc, char **argv) { int port_id = -1; int mode = -1; char *e; if (argc == 1) { ccprintf("Port 0: %d\nPort 1: %d\n", charge_mode[0], charge_mode[1]); return EC_SUCCESS; } if (argc != 3) return EC_ERROR_PARAM_COUNT; port_id = strtoi(argv[1], &e, 0); if (*e || port_id < 0 || port_id >= USB_CHARGE_PORT_COUNT) return EC_ERROR_PARAM1; mode = strtoi(argv[2], &e, 0); if (*e || mode < 0 || mode >= USB_CHARGE_MODE_COUNT) return EC_ERROR_PARAM2; return usb_charge_set_mode(port_id, mode); }
static int cmd_btn_press(int argc, char **argv) { enum gpio_signal gpio; char *e; int v; if (argc < 2) return EC_ERROR_PARAM_COUNT; if (!strcasecmp(argv[1], "volup")) gpio = GPIO_BTN_VOLU_L; else if (!strcasecmp(argv[1], "voldown")) gpio = GPIO_BTN_VOLD_L; else return EC_ERROR_PARAM1; if (argc < 3) { /* Just reading */ ccprintf("Button %s pressed = %d\n", argv[1], !gpio_get_level(gpio)); return EC_SUCCESS; } v = strtoi(argv[2], &e, 0); if (*e) return EC_ERROR_PARAM2; if (v) gpio_set_flags(gpio, GPIO_OUT_LOW); else gpio_set_flags(gpio, GPIO_INPUT | GPIO_PULL_UP); return EC_SUCCESS; }