From: Christian Lamparter Date: Fri, 15 Oct 2010 21:33:52 +0000 (+0200) Subject: carlu: add GPIO test X-Git-Tag: 1.9.1~14 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=ddaf4f22a3161d7480d73e03adab1d619784757e;p=carl9170fw.git carlu: add GPIO test This new test allows flashes the LEDs and allows the user to check if the WPS button works. Signed-off-by: Christian Lamparter --- diff --git a/tools/carlu/src/cmd.c b/tools/carlu/src/cmd.c index d83c107..56b9f8b 100644 --- a/tools/carlu/src/cmd.c +++ b/tools/carlu/src/cmd.c @@ -128,6 +128,18 @@ int carlu_cmd_write_mem(struct carlu *ar, const uint32_t addr, return err; } +int carlu_cmd_read_mem(struct carlu *ar, const uint32_t _addr, + uint32_t *val) +{ + int err; + __le32 msg, addr = { cpu_to_le32(_addr) }; + err = carlusb_cmd(ar, CARL9170_CMD_RREG, (void *) &addr, sizeof(addr), + (void *) &msg, sizeof(msg)); + + *val = le32_to_cpu(msg); + return err; +} + int carlu_cmd_read_eeprom(struct carlu *ar) { diff --git a/tools/carlu/src/main.c b/tools/carlu/src/main.c index 22adc3e..65bcfbc 100644 --- a/tools/carlu/src/main.c +++ b/tools/carlu/src/main.c @@ -134,6 +134,33 @@ out: return err ? EXIT_FAILURE : EXIT_SUCCESS; } +static int carlu_run_gpio_test(void) +{ + struct carlu *carl = NULL; + int err; + + err = carlu_init(); + if (err) + goto out; + + carl = carlusb_probe(); + if (IS_ERR_OR_NULL(carl)) { + err = PTR_ERR(carl); + goto out; + } + + err = carlu_gpio_test(carl); + if (err) + goto out_close; + +out_close: + carlusb_close(carl); + +out: + carlu_exit(); + return err ? EXIT_FAILURE : EXIT_SUCCESS; +} + static int carlu_run_loop_test(void) { struct carlu *carl; @@ -208,6 +235,7 @@ static const struct menu_struct menu[] = { MENU_ITEM('l', carlusb_print_known_devices, "list of all known ar9170 usb devices."), MENU_ITEM('p', carlu_probe_all, "probe all possible devices."), MENU_ITEM('t', carlu_run_loop_test, "run tx/rx test."), + MENU_ITEM('g', carlu_run_gpio_test, "flash the leds."), }; static int show_help(void) diff --git a/tools/carlu/src/test.c b/tools/carlu/src/test.c index 8d3e310..d31060d 100644 --- a/tools/carlu/src/test.c +++ b/tools/carlu/src/test.c @@ -193,3 +193,33 @@ void carlu_loopback_test(struct carlu *ar, const unsigned int total_runs, ar->cmd_cb = NULL; ar->tx_cb = NULL; } + +int carlu_gpio_test(struct carlu *ar) +{ + uint32_t gpio; + +#define CHK(cmd) \ + do { \ + int __err; \ + if (__err = cmd) \ + return __err; \ + } while (0) + + CHK(carlu_cmd_read_mem(ar, AR9170_GPIO_REG_PORT_DATA, &gpio)); + info("GPIO state:%x\n", gpio); + + /* turn both LEDs on */ + CHK(carlu_cmd_write_mem(ar, AR9170_GPIO_REG_PORT_DATA, + AR9170_GPIO_PORT_LED_0 | AR9170_GPIO_PORT_LED_1)); + + SDL_Delay(700); + + CHK(carlu_cmd_read_mem(ar, AR9170_GPIO_REG_PORT_DATA, &gpio)); + info("GPIO state:%x\n", gpio); + + /* turn LEDs off everything */ + CHK(carlu_cmd_write_mem(ar, AR9170_GPIO_REG_PORT_DATA, 0)); + + CHK(carlu_cmd_read_mem(ar, AR9170_GPIO_REG_PORT_DATA, &gpio)); + info("GPIO state:%x\n", gpio); +} diff --git a/tools/carlu/src/test.h b/tools/carlu/src/test.h index 5b6b495..645b55b 100644 --- a/tools/carlu/src/test.h +++ b/tools/carlu/src/test.h @@ -29,4 +29,6 @@ void carlu_loopback_test(struct carlu *ar, const unsigned int total_runs, const unsigned int interval, const unsigned int min_len, const unsigned int max_len); +int carlu_gpio_test(struct carlu *ar); + #endif /* __CARL9170USER_TEST_H */