a very simple shell framework

simple, clear, easy to DIY
This commit is contained in:
daishengdong
2020-01-08 13:54:56 +08:00
parent dea65a2d66
commit 72481955e2
66 changed files with 12408 additions and 240 deletions

View File

@@ -334,7 +334,7 @@ int tos_at_raw_data_send(at_echo_t *echo, uint32_t timeout, const uint8_t *buf,
*
* @return None
*/
void tos_at_uart_write_byte(uint8_t data);
void tos_at_uart_input_byte(uint8_t data);
/**
* @brief Read data from the uart.

View File

@@ -594,7 +594,7 @@ __API__ void tos_at_deinit(void)
/* To completely decouple the uart intterupt and at agent, we need a more powerful
hal(driver framework), that would be a huge work, we place it in future plans. */
__API__ void tos_at_uart_write_byte(uint8_t data)
__API__ void tos_at_uart_input_byte(uint8_t data)
{
if (tos_chr_fifo_push(&AT_AGENT->uart_rx_fifo, data) == K_ERR_NONE) {
tos_evtdrv_event_set(AT_AGENT->at_task_id, EVENT_AT_UART_INCOMING);

View File

@@ -0,0 +1,88 @@
#include "tos_shell.h"
#include "tos_hal.h"
#define CMD_LEN_MAX 128
char cmd_buf[CMD_LEN_MAX];
hal_uart_t shell_uart;
void uart_output(const char *str)
{
tos_hal_uart_write(&shell_uart, (const uint8_t *)str, strlen(str), 0xFF);
#if 0
/* if using c lib printf through uart, a simpler one is: */
printf(str);
#endif
}
__STATIC__ int cmd_test00(int argc, char *argv[])
{
int i = 0;
tos_shell_printf("test00:\n");
for (i = 0; i < argc; ++i) {
tos_shell_printf("argv[%d]: %s\n", i, argv[i]);
}
return 0;
}
__STATIC__ int cmd_test01(int argc, char *argv[])
{
tos_shell_printf("test01:\n");
return 0;
}
__STATIC__ int cmd_test10(int argc, char *argv[])
{
int i = 0;
tos_shell_printf("test10:\n");
for (i = 0; i < argc; ++i) {
tos_shell_printf("argv[%d]: %s\n", i, argv[i]);
}
return 0;
}
__STATIC__ int cmd_test11(int argc, char *argv[])
{
tos_shell_printf("test11:\n");
return 0;
}
__STATIC__ const shell_cmd_t custom_shell_cmds0[] = {
{ "test00", cmd_test00, "test00 cmd" },
{ "test01", cmd_test01, "test01 cmd" },
{ K_NULL, K_NULL, K_NULL }, /* never forget this!!!*/
};
__STATIC__ shell_cmd_set_t custom_shell_cmd_set0 = {
.list = TOS_SLIST_NODE(dummy),
.commands = custom_shell_cmds0,
};
__STATIC__ const shell_cmd_t custom_shell_cmds1[] = {
{ "test10", cmd_test10, "test10 cmd" },
{ "test11", cmd_test11, "test11 cmd" },
{ K_NULL, K_NULL, K_NULL }, /* never forget this!!!*/
};
__STATIC__ shell_cmd_set_t custom_shell_cmd_set1 = {
.list = TOS_SLIST_NODE(dummy),
.commands = custom_shell_cmds1,
};
void application_entry(void *arg)
{
/* if test on ALIENTEK_STM32F429, switch HAL_UART_PORT_2 to HAL_UART_PORT_1 */
tos_hal_uart_init(&shell_uart, HAL_UART_PORT_2);
tos_shell_init(cmd_buf, sizeof(cmd_buf), uart_output, &custom_shell_cmd_set0);
tos_shell_cmd_set_regiser(&custom_shell_cmd_set1);
while (1) {
tos_task_delay(1000);
}
}