Skip to content

Commit

Permalink
hwtest/main,adcs: Add stop command for loop test
Browse files Browse the repository at this point in the history
This commit adds `stop` command for loop test.

Signed-off-by: Takuya Sasaki <takuya.sasaki@spacecubics.com>
  • Loading branch information
sasataku committed Nov 24, 2023
1 parent e827ff0 commit 59d5a7e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/hwtest/adcs/src/loop_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <stdlib.h>
#include <zephyr/kernel.h>
#include "loop_test.h"
#include "pwrctrl.h"
#include "temp_test.h"
#include "cv_test.h"
Expand All @@ -16,6 +17,8 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(loop_test);

struct k_event loop_event;

static void update_rw_idx(uint8_t *rw_idx)
{
(*rw_idx)++;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/hwtest/adcs/src/loop_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@

#include <stdint.h>

#define LOOP_STOP_EVENT (1U)

int loop_test(int32_t loop_count, uint32_t *err_cnt);
9 changes: 9 additions & 0 deletions tests/hwtest/adcs/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
16 changes: 16 additions & 0 deletions tests/hwtest/main/src/loop_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <zephyr/kernel.h>
#include "loop_test.h"
#include "pwrctrl.h"
#include "temp_test.h"
#include "cv_test.h"
Expand All @@ -16,6 +17,8 @@
#include <zephyr/logging/log.h>
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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions tests/hwtest/main/src/loop_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@

#include <stdint.h>

#define LOOP_STOP_EVENT (1U)

int loop_test(int32_t loop_count, uint32_t *err_cnt);
9 changes: 9 additions & 0 deletions tests/hwtest/main/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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),
Expand All @@ -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);

0 comments on commit 59d5a7e

Please sign in to comment.