Skip to content
This repository has been archived by the owner on May 7, 2019. It is now read-only.

Commit

Permalink
Implement mem utility command into shell
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl committed Mar 11, 2019
1 parent c5a5cb4 commit d1d072f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion external/cls
Submodule cls updated from 8ca14c to 189af7
9 changes: 8 additions & 1 deletion include/c/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ extern void _cmd_help(u32 argc, char* argv[]);
extern void _cmd_clear(u32 argc, char* argv[]);
extern void _cmd_time(u32 argc, char* argv[]);
extern void _cmd_gpio(u32 argc, char* argv[]);
extern void _cmd_mem(u32 argc, char* argv[]);



extern void _cmd_notfound();

Expand All @@ -64,6 +67,7 @@ extern void _cmd_notfound();
#define _CMD_ID_REBOOT 2
#define _CMD_ID_TIME 3
#define _CMD_ID_GPIO 4
#define _CMD_ID_MEM 5


static const char SHELL_CMDID_CMDSTR[][SHELL_BUFFER_SIZE] = {
Expand All @@ -72,14 +76,16 @@ static const char SHELL_CMDID_CMDSTR[][SHELL_BUFFER_SIZE] = {
[_CMD_ID_REBOOT] = "reboot",
[_CMD_ID_TIME] = "time",
[_CMD_ID_GPIO] = "gpio",
[_CMD_ID_MEM] = "mem",
};

static const char SHELL_CMDID_CMDINS[][SHELL_CMD_MAX_LEN] = {
[_CMD_ID_HELP] = "display this help message",
[_CMD_ID_CLEAR] = "clear the framebuffer using the background color",
[_CMD_ID_REBOOT] = "restart the operating system",
[_CMD_ID_TIME] = "display the system time",
[_CMD_ID_GPIO] = "control LOW/HIGH and FN SEL of GPIO"
[_CMD_ID_GPIO] = "control LOW/HIGH and FN SEL of GPIO",
[_CMD_ID_MEM] = "allows for on memory operations",
};

static const cmd_ptr SHELL_CMDID_CMDFN[] = {
Expand All @@ -88,6 +94,7 @@ static const cmd_ptr SHELL_CMDID_CMDFN[] = {
[_CMD_ID_REBOOT] = _cmd_undefined,
[_CMD_ID_TIME] = _cmd_time,
[_CMD_ID_GPIO] = _cmd_gpio,
[_CMD_ID_MEM] = _cmd_mem,
};


Expand Down
34 changes: 34 additions & 0 deletions src/lib/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,50 @@ void _cmd_time(u32 argc, char* argv[]) {
printf("%x", syscall_time());
}

void _cmd_mem(u32 argc, char* argv[]) {
// _shell_arg_debug(argc, argv);

if(argc < 3) {
return;
}

// Read/Write/Dump/... address
u32 addr = conv_hex_u32(argv[2]);
printf("using address %x\n", addr);

if(strequ(argv[1], "write")) {
// write
u32 value = conv_hex_u32(argv[3]);
PUT32(addr, value);
printf("write: %x\n", value);
printf("read: %x\n", GET32(addr));
} else if(strequ(argv[1], "read")) {
// read
printf("read: %x\n", GET32(addr));
} else if(strequ(argv[1], "dump")) {
// u32 count = conv_str_u32(argv[3]);
// TODO implement
} else {
printf("valid commands: read, write, dump\n");
}

return;
}


void _shell_arg_debug(u32 argc, char* argv[]) {
printf("\n---- ARG DEBUG ----\n");
printf("command is: "); printf(argv[0]); printf("\n");
printf("command has %x [argc]\n", argc);
printf("----\n");
printf("argv:\n");
printf("----\n");
for(u32 idx = 1; idx < argc; idx++) {
printf("%x arg: ", idx);
printf(argv[idx]);
printf("\n");
}
printf("----\n");
}


Expand Down

0 comments on commit d1d072f

Please sign in to comment.