EE445M RTOS
Taken at the University of Texas Spring 2015
shell.c
Go to the documentation of this file.
1 /* -*- mode: c; c-basic-offset: 4; -*- */
2 #include "shell.h"
3 
4 #include "libuart/uart.h"
5 #include "libhw/hardware.h"
6 #include "libos/semaphore.h"
7 #include "libos/os.h"
8 
9 #include "inc/hw_memmap.h"
10 #include "inc/hw_ints.h"
11 
12 #include <stdint.h>
13 #include <stdbool.h>
14 
15 #include "driverlib/pin_map.h"
16 #include "driverlib/timer.h"
17 #include "driverlib/sysctl.h"
18 #include "driverlib/gpio.h"
19 
20 static unsigned short SHELL_BUFFER_POSITION;
22 
24 static char* SHELL_DEFAULT_PS1 = "\r\n> ";
25 
26 void shell_spawn() {
27 
28  /* TODO: have this handled by hw_connect (look at the scoreboard,
29  * see what HAS been used (don't need to initialize), what IS
30  * being used (blocked)) */
32  hw_subscribe(HW_UART, uart_metadata, shell_uart_handler);
36 }
37 
38 char* shell_represent() {
39 
40  return SHELL_BUFFER;
41 }
42 
43 /* TODO: abstract boilerplate, re: metadata */
44 void shell_kill() {
45 
47  hw_unsubscribe(HW_UART, uart_metadata, shell_uart_handler);
48 }
49 
50 /* TODO: re-doxygenize */
52 
53  char recv = note._char;
54 
55  switch(recv) {
56  case SC_CR:
57  { /* TODO: schedule */
60  uart_send_string("\r\n");
61  /* fixme: why doesn't PS1 print twice? */
63  }
64  break;
65 
66  case 127:
67  case SC_BACKSPACE:
68  SHELL_BUFFER[SHELL_BUFFER_POSITION--] = (char) 0;
69  uart_send_string("\b \b");
70  break;
71 
72  default:
75  /* Echo char to terminal for user */
76  uart_send_char(recv);
77  }
78  break;
79  }
80 }
81 
82 void shell_set_ps1(char* new_ps1) {
83 
84  /* TODO: ensure this copies a null terminator */
85  memcpy(SHELL_PS1, new_ps1, ustrlen(new_ps1));
86 }
87 
89 
90  memset(SHELL_BUFFER, 0, sizeof(SHELL_BUFFER));
92 }
93 
95 
96  uart_send_string((const char*) SHELL_PS1);
97 }
98 
100 
101  const char** arguments = NULL;
102  return system_exec(SHELL_BUFFER, arguments);
103 }
void shell_kill()
Definition: shell.c:44
void uart_send_string(const char *text)
Definition: uart.c:71
exit_status_t system_exec(const char *command, const char **arguments)
Definition: system.c:69
void shell_spawn()
Definition: shell.c:26
#define hw_subscribe(type, metadata, isr)
Definition: hardware.h:178
static char * SHELL_DEFAULT_PS1
Definition: shell.c:24
#define UART_DEFAULT_BAUD_RATE
Definition: uart.h:14
static char * SHELL_PS1[4]
Definition: shell.c:23
uint32_t ustrlen(const char *s)
Definition: nexus.c:17
void uart_send_char(const char text)
Definition: uart.c:59
void shell_set_ps1(char *new_ps1)
Definition: shell.c:82
char * shell_represent()
Definition: shell.c:38
static char SHELL_BUFFER[64]
Definition: shell.c:21
#define INT_UART0
Definition: hw_ints.h:451
#define uart_metadata_init(_baud_rate, _channel, _interrupt)
Definition: uart.h:29
void shell_clear_shell_buffer()
Definition: shell.c:88
exit_status_t shell_execute_command()
Definition: shell.c:99
#define SHELL_BUFFER_LENGTH
Definition: shell.h:20
#define SHELL_MAX_PS1_LENGTH
Definition: shell.h:17
void * memset(void *b, int c, int len)
Definition: nexus.c:4
uint8_t exit_status_t
Definition: system.h:24
void shell_print_ps1()
Definition: shell.c:94
#define UART0_BASE
Definition: hw_memmap.h:61
void * memcpy(void *str1, const void *str2, long n)
Definition: nexus.c:25
void hw_unsubscribe(HW_TYPE type, hw_metadata metadata, void(*isr)(notification note))
Definition: hardware.c:137
void shell_uart_handler(notification note)
Definition: shell.c:51
static unsigned short SHELL_BUFFER_POSITION
Definition: shell.c:20
#define NULL
Definition: defines.h:32
char _char
Definition: notify.h:25
Definition: kbd.h:9