carlu: add GPIO test
authorChristian Lamparter <chunkeey@googlemail.com>
Fri, 15 Oct 2010 21:33:52 +0000 (23:33 +0200)
committerChristian Lamparter <chunkeey@googlemail.com>
Fri, 15 Oct 2010 21:33:52 +0000 (23:33 +0200)
This new test allows flashes the LEDs and allows
the user to check if the WPS button works.

Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
tools/carlu/src/cmd.c
tools/carlu/src/main.c
tools/carlu/src/test.c
tools/carlu/src/test.h

index d83c107bdae9353f8395ef975d0e1bcfbea91dfb..56b9f8b7c956d7b79773abddf9efa7fe528c467f 100644 (file)
@@ -128,6 +128,18 @@ int carlu_cmd_write_mem(struct carlu *ar, const uint32_t addr,
        return err;
 }
 
        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)
 {
 
 int carlu_cmd_read_eeprom(struct carlu *ar)
 {
 
index 22adc3e945618192a359af2f268e61d65ab5a5d9..65bcfbcd4411f336f427402587d0501a0951fbb7 100644 (file)
@@ -134,6 +134,33 @@ out:
        return err ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
        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;
 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('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)
 };
 
 static int show_help(void)
index 8d3e310a57023689b42a5836ac52efd4bcb4423e..d31060d870b5fd5616a28c2065b68cbe89faaca1 100644 (file)
@@ -193,3 +193,33 @@ void carlu_loopback_test(struct carlu *ar, const unsigned int total_runs,
        ar->cmd_cb = NULL;
        ar->tx_cb = NULL;
 }
        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);
+}
index 5b6b4956ce68beeba686ae8d6b7c05c0ce2898e7..645b55b5bb5d9869efe282be1a343178cb3615e5 100644 (file)
@@ -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);
 
                         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 */
 #endif /* __CARL9170USER_TEST_H */