Skip to content

Commit e7c4d29

Browse files
Loic Poulainjukkar
Loic Poulain
authored andcommitted
drivers: wifi: eswifi: Add debug shell
Add a esWiFi shell for device specific controls. For now used to send at commands. Signed-off-by: Loic Poulain <[email protected]>
1 parent f851462 commit e7c4d29

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

drivers/wifi/eswifi/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ if(CONFIG_WIFI_ESWIFI)
1414
eswifi_offload.c
1515
eswifi_socket.c
1616
)
17+
18+
zephyr_sources_ifdef(CONFIG_WIFI_ESWIFI_SHELL eswifi_shell.c)
19+
1720
zephyr_sources_ifdef(CONFIG_NET_SOCKETS_OFFLOAD eswifi_socket_offload.c)
1821
endif()

drivers/wifi/eswifi/Kconfig.eswifi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ config WIFI_ESWIFI_THREAD_PRIO
2424
This option sets the priority of the esWiFi threads.
2525
Do not touch it unless you know what you are doing.
2626

27+
config WIFI_ESWIFI_SHELL
28+
bool "esWiFi shell"
29+
depends on SHELL
30+
help
31+
Enable esWiFi shell
32+
2733
endif

drivers/wifi/eswifi/eswifi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,10 @@ int __eswifi_bind(struct eswifi_dev *eswifi, struct eswifi_off_socket *socket,
144144
int eswifi_socket_offload_init(struct eswifi_dev *leswifi);
145145
#endif
146146

147+
#if defined(CONFIG_WIFI_ESWIFI_SHELL)
148+
void eswifi_shell_register(struct eswifi_dev *dev);
149+
#else
150+
#define eswifi_shell_register(dev)
151+
#endif
152+
147153
#endif

drivers/wifi/eswifi/eswifi_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ static int eswifi_init(struct device *dev)
671671

672672
k_work_init(&eswifi->request_work, eswifi_request_work);
673673

674+
eswifi_shell_register(eswifi);
675+
674676
return 0;
675677
}
676678

drivers/wifi/eswifi/eswifi_shell.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright (c) 2020 Linaro
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <kernel.h>
8+
#include <shell/shell.h>
9+
10+
#include "eswifi.h"
11+
12+
static struct eswifi_dev *eswifi;
13+
14+
void eswifi_shell_register(struct eswifi_dev *dev)
15+
{
16+
/* only one instance supported */
17+
if (eswifi) {
18+
return;
19+
}
20+
21+
eswifi = dev;
22+
}
23+
24+
static int eswifi_shell_atcmd(const struct shell *shell, size_t argc,
25+
char **argv)
26+
{
27+
int i;
28+
29+
if (eswifi == NULL) {
30+
shell_print(shell, "no eswifi device registered");
31+
return -ENOEXEC;
32+
}
33+
34+
if (argc < 2) {
35+
shell_help(shell);
36+
return -ENOEXEC;
37+
}
38+
39+
eswifi_lock(eswifi);
40+
41+
memset(eswifi->buf, 0, sizeof(eswifi->buf));
42+
for (i = 1; i < argc; i++) {
43+
strcat(eswifi->buf, argv[i]);
44+
}
45+
strcat(eswifi->buf, "\r");
46+
47+
shell_print(shell, "> %s", eswifi->buf);
48+
eswifi_at_cmd(eswifi, eswifi->buf);
49+
shell_print(shell, "< %s", eswifi->buf);
50+
51+
eswifi_unlock(eswifi);
52+
53+
return 0;
54+
}
55+
56+
SHELL_STATIC_SUBCMD_SET_CREATE(eswifi_shell,
57+
SHELL_CMD(atcmd, NULL, "<atcmd>", eswifi_shell_atcmd),
58+
SHELL_SUBCMD_SET_END /* Array terminated. */
59+
);
60+
61+
SHELL_CMD_REGISTER(eswifi, &eswifi_shell, "esWiFi debug shell", NULL);

0 commit comments

Comments
 (0)