diff --git a/tests/hwtest/adcs/src/loop_test.c b/tests/hwtest/adcs/src/loop_test.c index cda1e84e..7d10d149 100644 --- a/tests/hwtest/adcs/src/loop_test.c +++ b/tests/hwtest/adcs/src/loop_test.c @@ -6,6 +6,7 @@ #include #include +#include "loop_test.h" #include "pwrctrl.h" #include "temp_test.h" #include "cv_test.h" @@ -16,6 +17,8 @@ #include LOG_MODULE_REGISTER(loop_test); +struct k_event loop_event; + static void update_rw_idx(uint8_t *rw_idx) { (*rw_idx)++; @@ -74,6 +77,15 @@ static int verify_status(enum rw_pos pos, uint32_t sec, uint32_t *err_cnt) return all_ret; } +static bool is_loop_stop(void) +{ + if (k_event_wait(&loop_event, LOOP_STOP_EVENT, false, K_NO_WAIT) != 0) { + return true; + } + + return false; +} + int loop_test(int32_t loop_count, uint32_t *err_cnt) { int ret; @@ -90,6 +102,10 @@ int loop_test(int32_t loop_count, uint32_t *err_cnt) } for (int i=1; i<=loop_count; i++) { + if (is_loop_stop()) { + break; + } + LOG_INF("===[Loop Test %d Start (total err: %d)]===", i, *err_cnt); LOG_INF("===[RW Start (total err: %d)]===", *err_cnt); diff --git a/tests/hwtest/adcs/src/loop_test.h b/tests/hwtest/adcs/src/loop_test.h index 044174cc..1d879318 100644 --- a/tests/hwtest/adcs/src/loop_test.h +++ b/tests/hwtest/adcs/src/loop_test.h @@ -8,4 +8,6 @@ #include +#define LOOP_STOP_EVENT (1U) + int loop_test(int32_t loop_count, uint32_t *err_cnt); diff --git a/tests/hwtest/adcs/src/main.c b/tests/hwtest/adcs/src/main.c index 578a56cc..4f0169e4 100644 --- a/tests/hwtest/adcs/src/main.c +++ b/tests/hwtest/adcs/src/main.c @@ -24,6 +24,7 @@ K_THREAD_STACK_DEFINE(cmd_thread_stack, 2048); static struct k_thread cmd_thread; static struct k_event exec_event; +extern struct k_event loop_event; LOG_MODULE_REGISTER(adcs_main); @@ -54,6 +55,7 @@ static void cmd_handler(void * p1, void * p2, void * p3) ret = rw_test(&err_cnt); } else if (strcmp(cmd, "loop") == 0) { ret = loop_test(atoi(arg), &err_cnt); + k_event_clear(&loop_event, LOOP_STOP_EVENT); } else { goto end; } @@ -100,6 +102,12 @@ static int start_cmd_thread(const struct shell *sh, size_t argc, char **argv) return ret; } +static int stop_cmd(const struct shell *sh, size_t argc, char **argv) +{ + k_event_set(&loop_event, LOOP_STOP_EVENT); + return 0; +} + int main(void) { printk("This is for HW test program for %s\n", CONFIG_BOARD); @@ -125,3 +133,4 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_hwtest, SHELL_SUBCMD_SET_END ); SHELL_CMD_REGISTER(hwtest, &sub_hwtest, "SC-Sat1 HW test commands", NULL); +SHELL_CMD_REGISTER(stop, NULL, "SC-Sat1 HW test stop", stop_cmd); diff --git a/tests/hwtest/main/src/loop_test.c b/tests/hwtest/main/src/loop_test.c index dd2e75b3..af715091 100644 --- a/tests/hwtest/main/src/loop_test.c +++ b/tests/hwtest/main/src/loop_test.c @@ -5,6 +5,7 @@ */ #include +#include "loop_test.h" #include "pwrctrl.h" #include "temp_test.h" #include "cv_test.h" @@ -16,6 +17,8 @@ #include LOG_MODULE_REGISTER(loop_test); +struct k_event loop_event; + static void update_mtq_idx(uint8_t *axes_idx, uint8_t *pol_idx) { if (*pol_idx < 2) { @@ -78,6 +81,15 @@ static int one_loop(uint32_t *err_cnt) return all_ret; } +static bool is_loop_stop(void) +{ + if (k_event_wait(&loop_event, LOOP_STOP_EVENT, false, K_NO_WAIT) != 0) { + return true; + } + + return false; +} + int loop_test(int32_t loop_count, uint32_t *err_cnt) { int ret; @@ -101,6 +113,10 @@ int loop_test(int32_t loop_count, uint32_t *err_cnt) } for (int i=1; i<=loop_count; i++) { + if (is_loop_stop()) { + break; + } + LOG_INF("===[Loop Test %d Start (total err: %d)]===", i, *err_cnt); diff --git a/tests/hwtest/main/src/loop_test.h b/tests/hwtest/main/src/loop_test.h index 044174cc..1d879318 100644 --- a/tests/hwtest/main/src/loop_test.h +++ b/tests/hwtest/main/src/loop_test.h @@ -8,4 +8,6 @@ #include +#define LOOP_STOP_EVENT (1U) + int loop_test(int32_t loop_count, uint32_t *err_cnt); diff --git a/tests/hwtest/main/src/main.c b/tests/hwtest/main/src/main.c index aac03996..53ff1d0e 100644 --- a/tests/hwtest/main/src/main.c +++ b/tests/hwtest/main/src/main.c @@ -27,6 +27,7 @@ LOG_MODULE_REGISTER(main); K_THREAD_STACK_DEFINE(cmd_thread_stack, 2048); static struct k_thread cmd_thread; static struct k_event exec_event; +extern struct k_event loop_event; static void cmd_handler(void * p1, void * p2, void * p3) { @@ -57,6 +58,7 @@ static void cmd_handler(void * p1, void * p2, void * p3) ret = mtq_test(&err_cnt); } else if (strcmp(cmd, "loop") == 0) { ret = loop_test(atoi(arg), &err_cnt); + k_event_clear(&loop_event, LOOP_STOP_EVENT); } else { goto end; } @@ -116,6 +118,12 @@ int main(void) return 0; } +static int stop_cmd(const struct shell *sh, size_t argc, char **argv) +{ + k_event_set(&loop_event, LOOP_STOP_EVENT); + return 0; +} + SHELL_STATIC_SUBCMD_SET_CREATE(sub_hwtest, SHELL_CMD(info, NULL, "MAIN Board Information", start_cmd_thread), SHELL_CMD(init, NULL, "MAIN Board Initialization", start_cmd_thread), @@ -129,3 +137,4 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_hwtest, SHELL_SUBCMD_SET_END ); SHELL_CMD_REGISTER(hwtest, &sub_hwtest, "SC-Sat1 HW test commands", NULL); +SHELL_CMD_REGISTER(stop, NULL, "SC-Sat1 HW test stop", stop_cmd);