Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/mios/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ int cli_getc(cli_t *cli, int wait);

int cli_on_stream(struct stream *s, char promptchar);

error_t cli_dispatch_command(cli_t *c, int argc, char *argv[]);

void cli_console(char promptchar);

#define cli_flush(cli) stream_write((cli)->cl_stream, NULL, 0, 0)
23 changes: 22 additions & 1 deletion src/drivers/pl011.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,31 @@ pl011_uart_read(struct stream *s, void *buf, size_t size, size_t minbytes)
return size;
}

static task_waitable_t *
pl011_uart_poll(stream_t *s, poll_type_t type)
{
pl011_t *u = (pl011_t *)s;

irq_forbid(IRQ_LEVEL_CONSOLE);

if(type == POLL_STREAM_WRITE) {

if(TX_FIFO_SIZE - (u->tx_fifo_wrptr - u->tx_fifo_rdptr))
return NULL;
return &u->uart_tx;

} else {

if(u->rx_fifo_wrptr != u->rx_fifo_rdptr)
return NULL;
return &u->uart_rx;
}
}

static const stream_vtable_t pl011_uart_vtable = {
.read = pl011_uart_read,
.write = pl011_uart_write
.write = pl011_uart_write,
.poll = pl011_uart_poll
};

struct stream *
Expand Down
15 changes: 11 additions & 4 deletions src/shell/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,38 @@ dispatch_command(cli_t *c, char *line)
if(argc == 0)
return;

cli_dispatch_command(c, argc, c->cl_argv);
}

error_t
cli_dispatch_command(cli_t *c, int argc, char *argv[])
{
extern unsigned long _clicmd_array_begin;
extern unsigned long _clicmd_array_end;

cli_cmd_t *clicmd = (void *)&_clicmd_array_begin;
cli_cmd_t *clicmd_array_end = (void *)&_clicmd_array_end;

if(!strcmp(c->cl_argv[0], "help")) {
if(!strcmp(argv[0], "help")) {
cli_printf(c, "Available commands:\n");
for(; clicmd != clicmd_array_end; clicmd++) {
cli_printf(c, "\t%s\n", clicmd->cmd);
}
return;
return ERR_OK;
}

for(; clicmd != clicmd_array_end; clicmd++) {
if(!strcmp(c->cl_argv[0], clicmd->cmd)) {
if(!strcmp(argv[0], clicmd->cmd)) {
error_t err = clicmd->dispatch(c, argc, c->cl_argv);

if(err) {
cli_printf(c, "! Error: %s\n", error_to_string(err));
}
return;
return err;
}
}
cli_printf(c, "No such command\n");
return ERR_NOT_FOUND;
}

#define ESCAPE 27
Expand Down
2 changes: 1 addition & 1 deletion src/shell/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ history_add(const char *line)
if (history.latest == NULL) {
history.lines[0] = strdup(line);
history.latest = history.lines;
} else {
} else if (strcmp(line, *history.latest)) {
history.latest++;
if (history.latest >= &history.lines[MAX_LINES])
history.latest = history.lines;
Expand Down
6 changes: 4 additions & 2 deletions src/shell/shell.mk
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
GLOBALDEPS += ${SRC}/shell/shell.mk

SRCS += ${SRC}/shell/cli.c \
${SRC}/shell/monitor.c \
SRCS += \
${SRC}/shell/cli.c \
${SRC}/shell/cmd_gpio.c \
${SRC}/shell/cmd_i2c.c \
${SRC}/shell/history.c \
${SRC}/shell/monitor.c \
${SRC}/shell/perf.c \
${SRC}/shell/watch.c \

${MOS}/shell/cli.o : CFLAGS += ${NOFPU}
${MOS}/shell/monitor.o : CFLAGS += ${NOFPU}
Expand Down
38 changes: 38 additions & 0 deletions src/shell/watch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>

#include <mios/cli.h>
#include <mios/mios.h>


static error_t
cmd_watch(cli_t *cli, int argc, char **argv)
{
const uint64_t watchtime = 1000000;
uint64_t deadline = clock_get() + watchtime;
if (argc == 1) {
cli_printf(cli, "watch <command> <args>\n");
return ERR_INVALID_ARGS;
}
uint8_t c = 0;
const pollset_t ps = {
.obj = cli->cl_stream,
.type = POLL_STREAM_READ,
};
while (c != 0x03) {
error_t err = cli_dispatch_command(cli, argc - 1, argv + 1);
if (err)
return err;

if (poll(&ps, 1, NULL, deadline) < 0) {
deadline += watchtime;
continue;
}
stream_read(cli->cl_stream, &c, 1, 1);
}
return ERR_OK;
}

CLI_CMD_DEF("watch", cmd_watch);