Skip to content

Commit bf177c7

Browse files
jhirsirlubos
authored andcommitted
samples: nrf9160: modem_shell: a kill button #1
Pressing a long press of button #1 to kill/abort running ping/iperf instances, including all th -command threads. Jira: MOSH-143 Signed-off-by: Jani Hirsimäki <[email protected]>
1 parent 6bf2f13 commit bf177c7

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

samples/nrf9160/modem_shell/README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,17 @@ Building and running
379379

380380
.. include:: /includes/build_and_run_nrf9160.txt
381381

382+
DK buttons
383+
==========
384+
385+
The buttons have the following functions:
386+
387+
Button 1:
388+
Raises a kill or abort signal. A long press of the button will kill or abort all supported running commands. You can abort commands ``iperf3`` (also with ``th``), ``curl``, ``ping`` and ``sock send``.
389+
390+
Button 2:
391+
Enables or disables the UARTs for power consumption measurements. Toggles between UARTs enabled and disabled.
392+
382393
Testing
383394
=======
384395

samples/nrf9160/modem_shell/src/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@
4747
#if defined(CONFIG_MOSH_WORKER_THREADS)
4848
#include "th/th_ctrl.h"
4949
#endif
50+
#include "mosh_defines.h"
5051

5152
/* global variables */
5253
struct modem_param_info modem_param;
54+
struct k_poll_signal mosh_signal;
55+
5356
/**
5457
* @brief Global shell pointer that can be used for printing.
5558
*
@@ -87,6 +90,17 @@ static void mosh_print_version_info(void)
8790

8891
static void button_handler(uint32_t button_states, uint32_t has_changed)
8992
{
93+
if (has_changed & button_states & DK_BTN1_MSK) {
94+
shell_print(shell_global, "Button 1 pressed - raising a kill signal");
95+
k_poll_signal_raise(&mosh_signal, MOSH_SIGNAL_KILL);
96+
#if defined(CONFIG_MOSH_WORKER_THREADS)
97+
th_ctrl_kill_em_all();
98+
#endif
99+
} else if (has_changed & ~button_states & DK_BTN1_MSK) {
100+
shell_print(shell_global, "Button 1 released - resetting a kill signal");
101+
k_poll_signal_reset(&mosh_signal);
102+
}
103+
90104
if (has_changed & button_states & DK_BTN2_MSK) {
91105
shell_print(shell_global, "Button 2 pressed, toggling UART power state");
92106
uart_toggle_power_state(shell_global);
@@ -182,6 +196,7 @@ void main(void)
182196
#if defined(CONFIG_BOOTLOADER_MCUBOOT)
183197
boot_write_img_confirmed();
184198
#endif
199+
k_poll_signal_init(&mosh_signal);
185200

186201
/* Resize terminal width and height of the shell to have proper command editing. */
187202
shell_execute_cmd(shell_global, "resize");

samples/nrf9160/modem_shell/src/mosh_defines.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@
1717

1818
#define MOSH_AT_CMD_RESPONSE_MAX_LEN 2700
1919

20+
enum mosh_signals {
21+
MOSH_SIGNAL_KILL,
22+
};
23+
2024
#endif /* MOSH_DEFINES_H */

samples/nrf9160/modem_shell/src/ping/icmp_ping.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "utils/net_utils.h"
2424
#include "link_api.h"
25+
#include "mosh_defines.h"
2526

2627
#include "icmp_ping.h"
2728

@@ -39,6 +40,8 @@
3940
#define ICMP6_ECHO_REQ 128
4041
#define ICMP6_ECHO_REP 129
4142

43+
extern struct k_poll_signal mosh_signal;
44+
4245
enum ping_rai {
4346
PING_RAI_NONE,
4447
PING_RAI_ONGOING,
@@ -525,6 +528,7 @@ static void icmp_ping_tasks_execute(const struct shell *shell)
525528
uint32_t count = 0;
526529
uint32_t rtt_min = 0xFFFFFFFF;
527530
uint32_t rtt_max = 0;
531+
int set, res;
528532
enum ping_rai rai;
529533
uint32_t ping_t;
530534

@@ -540,6 +544,13 @@ static void icmp_ping_tasks_execute(const struct shell *shell)
540544
}
541545
ping_t = send_ping_wait_reply(shell, rai);
542546

547+
k_poll_signal_check(&mosh_signal, &set, &res);
548+
if (set && res == MOSH_SIGNAL_KILL) {
549+
k_poll_signal_reset(&mosh_signal);
550+
shell_error(shell, "KILL signal received - exiting");
551+
break;
552+
}
553+
543554
if (ping_t > 0) {
544555
count++;
545556
sum += ping_t;

samples/nrf9160/modem_shell/src/shell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
extern const struct shell *shell_global;
4646
extern struct k_sem nrf_modem_lib_initialized;
47-
47+
extern struct k_poll_signal mosh_signal;
4848
/**
4949
* @brief Overriding modem library error handler.
5050
*/
@@ -162,7 +162,7 @@ int lwm2m_carrier_event_handler(const lwm2m_carrier_event_t *event)
162162
#if defined(CONFIG_MOSH_IPERF3)
163163
static int cmd_iperf3(const struct shell *shell, size_t argc, char **argv)
164164
{
165-
(void)iperf_main(argc, argv, NULL, 0, NULL);
165+
(void)iperf_main(argc, argv, NULL, 0, &mosh_signal);
166166
return 0;
167167
}
168168
#endif

samples/nrf9160/modem_shell/src/th/th_ctrl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ void th_ctrl_status_print(const struct shell *shell)
159159
th_ctrl_data_status_print(shell, &th_work_data_2);
160160
}
161161

162+
void th_ctrl_kill_em_all(void)
163+
{
164+
if (k_work_is_pending(&(th_work_data_1.work))) {
165+
k_poll_signal_raise(&th_work_data_1.kill_signal, 1);
166+
}
167+
if (k_work_is_pending(&(th_work_data_2.work))) {
168+
k_poll_signal_raise(&th_work_data_2.kill_signal, 2);
169+
}
170+
}
171+
162172
void th_ctrl_kill(const struct shell *shell, int nbr)
163173
{
164174
if (nbr == 1) {

samples/nrf9160/modem_shell/src/th/th_ctrl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ void th_ctrl_status_print(const struct shell *shell);
1616
void th_ctrl_start(const struct shell *shell, size_t argc, char **argv,
1717
bool bg_thread);
1818
void th_ctrl_kill(const struct shell *shell, int nbr);
19+
void th_ctrl_kill_em_all(void);
1920

2021
#endif /* TH_CTRL_H */

0 commit comments

Comments
 (0)