From: Christian Lamparter Date: Thu, 13 Jan 2011 13:58:41 +0000 (+0100) Subject: carlu: random number generator test X-Git-Tag: 1.9.3~21 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=007045ac7c9822009b704b856e2f92934cca2401;p=carl9170fw.git carlu: random number generator test Signed-off-by: Christian Lamparter --- diff --git a/tools/carlu/src/cmd.c b/tools/carlu/src/cmd.c index 81702b3..d77feea 100644 --- a/tools/carlu/src/cmd.c +++ b/tools/carlu/src/cmd.c @@ -116,6 +116,35 @@ int carlu_cmd_mem_dump(struct carlu *ar, const uint32_t start, return 0; } +int carlu_cmd_mem_watch(struct carlu *ar, const uint32_t mem, + const unsigned int len, void *_buf) +{ +#define RW 8 /* number of words to read at once */ +#define RB (sizeof(uint32_t) * RW) + uint8_t *buf = _buf; + unsigned int i, j, block; + int err; + __le32 offsets[RW]; + + for (i = 0; i < (len + RB - 1) / RB; i++) { + block = min_t(unsigned int, (len - RB * i) / sizeof(uint32_t), RW); + for (j = 0; j < block; j++) + offsets[j] = cpu_to_le32(mem); + + err = carlusb_cmd(ar, CARL9170_CMD_RREG, + (void *) &offsets, block * sizeof(uint32_t), + (void *) buf + RB * i, RB); + + if (err) + return err; + } + +#undef RW +#undef RB + + return 0; +} + int carlu_cmd_write_mem(struct carlu *ar, const uint32_t addr, const uint32_t val) { diff --git a/tools/carlu/src/cmd.h b/tools/carlu/src/cmd.h index 72028b3..b201ee4 100644 --- a/tools/carlu/src/cmd.h +++ b/tools/carlu/src/cmd.h @@ -32,6 +32,8 @@ int carlu_cmd_mem_dump(struct carlu *ar, const uint32_t start, const unsigned int len, void *_buf); int carlu_cmd_write_mem(struct carlu *ar, const uint32_t addr, const uint32_t val); +int carlu_cmd_mem_watch(struct carlu *ar, const uint32_t mem, + const unsigned int len, void *_buf); struct carl9170_cmd *carlu_cmd_buf(struct carlu *ar, const enum carl9170_cmd_oids cmd, const unsigned int len); diff --git a/tools/carlu/src/main.c b/tools/carlu/src/main.c index 65bcfbc..ffc1407 100644 --- a/tools/carlu/src/main.c +++ b/tools/carlu/src/main.c @@ -161,6 +161,33 @@ out: return err ? EXIT_FAILURE : EXIT_SUCCESS; } +static int carlu_run_random_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_random_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; @@ -236,6 +263,7 @@ static const struct menu_struct menu[] = { 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."), + MENU_ITEM('r', carlu_run_random_test, "get random numbers."), }; static int show_help(void) diff --git a/tools/carlu/src/test.c b/tools/carlu/src/test.c index 148f89a..e453eb3 100644 --- a/tools/carlu/src/test.c +++ b/tools/carlu/src/test.c @@ -220,3 +220,18 @@ int carlu_gpio_test(struct carlu *ar) CHK(carlu_cmd_read_mem(ar, AR9170_GPIO_REG_PORT_DATA, &gpio)); info("GPIO state:%x\n", gpio); } + +int carlu_random_test(struct carlu *ar) +{ + uint32_t buf[4096]; + int err, i; + + err = carlu_cmd_mem_watch(ar, AR9170_RAND_REG_NUM, sizeof(buf), buf); + if (err) + return err; + + for (i = 0; i < ARRAY_SIZE(buf); i++) + info("%.2x %.2x ", buf[i] & 0xff, buf[i] >> 8); + + info("\n"); +} diff --git a/tools/carlu/src/test.h b/tools/carlu/src/test.h index 645b55b..5e4abe9 100644 --- a/tools/carlu/src/test.h +++ b/tools/carlu/src/test.h @@ -30,5 +30,6 @@ void carlu_loopback_test(struct carlu *ar, const unsigned int total_runs, const unsigned int max_len); int carlu_gpio_test(struct carlu *ar); +int carlu_random_test(struct carlu *ar); #endif /* __CARL9170USER_TEST_H */