Skip to content
Snippets Groups Projects
Commit 6fae3c24 authored by brian's avatar brian
Browse files

feat: full functionning UART

sudo minicom -D /dev/ttyUSB0 -b 9600

for local echo
CTRL-A, e
parent 9efa67a8
No related branches found
No related tags found
No related merge requests found
...@@ -66,12 +66,12 @@ void ask_user_input(void) { ...@@ -66,12 +66,12 @@ void ask_user_input(void) {
char switch_cmd[] = "switch"; char switch_cmd[] = "switch";
char status_cmd[] = "status"; char status_cmd[] = "status";
PRINT("(%s) Would you like to `switch` or display `status` errors : ", PRINT("\r\n(%s) Would you like to `switch` or display `status` errors : ",
is_supervisor_mode ? "Supervisor" : "User") is_supervisor_mode ? "Supervisor" : "User");
;
// fflush(stdin); // fflush(stdin);
// fscanf(stdin, "%s", buff); // fscanf(stdin, "%s", buff);
uart_scanf(buff); uart_scanf(buff);
PRINT("\r\n");
if (strncmp(buff, switch_cmd, strlen(switch_cmd)) == 0) { if (strncmp(buff, switch_cmd, strlen(switch_cmd)) == 0) {
// permute through svc depending on flag // permute through svc depending on flag
...@@ -81,14 +81,14 @@ void ask_user_input(void) { ...@@ -81,14 +81,14 @@ void ask_user_input(void) {
if (strncmp(buff, status_cmd, strlen(status_cmd)) == 0) { if (strncmp(buff, status_cmd, strlen(status_cmd)) == 0) {
if (idx_error == 0) { if (idx_error == 0) {
PRINT("No errors have occurred yet\n") PRINT("No errors have occurred yet\r\n")
; ;
return; return;
} }
for (int i = 0; i < idx_error; i++) { for (int i = 0; i < idx_error; i++) {
if (i < BUF_SIZE) { if (i < BUF_SIZE) {
PRINT("Address that shat the bed : 0x%x\tError code : 0x%x\n", PRINT("Address that shat the bed : 0x%x\tError code : 0x%x\r\n",
arr_addr[i], arr_err_code[i]) arr_addr[i], arr_err_code[i])
; ;
} }
......
...@@ -31,15 +31,16 @@ void SVC_Handler() { ...@@ -31,15 +31,16 @@ void SVC_Handler() {
void uart_scanf(char *buff) { void uart_scanf(char *buff) {
char user_input[USER_INPUT_SIZE] = { 0 }; char user_input[USER_INPUT_SIZE] = { 0 };
size_t idx = 1; char current = 0;
size_t idx = 0;
while (user_input[idx - 1] != '\n') { while (current != '\r') {
idx--; current = uart0_rec_byte_ref();
user_input[idx] = uart0_rec_byte_ref(); user_input[idx] = current;
idx++; idx++;
} }
user_input[idx - 1] = '\0'; user_input[idx-1] = '\0';
memcpy(buff, user_input, USER_INPUT_SIZE); memcpy(buff, user_input, USER_INPUT_SIZE);
} }
...@@ -49,10 +50,8 @@ void exec_user_read_write() { ...@@ -49,10 +50,8 @@ void exec_user_read_write() {
int i = 0, coma_nb = 0, value_idx; int i = 0, coma_nb = 0, value_idx;
unsigned addr, value; unsigned addr, value;
PRINT( PRINT("Write an hexadecimal address for reading <addr> or <addr>,<value> for writing (%s):\r\n",
"Write an hexadecimal address for reading <addr> or <addr>,<value> for writing (%s):\n", is_supervisor_mode ? "Supervisor" : "User");
is_supervisor_mode ? "Supervisor" : "User")
;
// fflush(stdin); // fflush(stdin);
// fscanf(stdin, "%s", str); // fscanf(stdin, "%s", str);
......
...@@ -18,7 +18,8 @@ static char uart_stdout[UART_STDOUT_SIZE] = { 0 }; ...@@ -18,7 +18,8 @@ static char uart_stdout[UART_STDOUT_SIZE] = { 0 };
#define uart_printf(...) \ #define uart_printf(...) \
snprintf(uart_stdout, UART_STDOUT_SIZE, __VA_ARGS__); \ snprintf(uart_stdout, UART_STDOUT_SIZE, __VA_ARGS__); \
uart0_send_ref((uint8_t *)uart_stdout, UART_STDOUT_SIZE); uart0_send_ref((uint8_t *)uart_stdout, UART_STDOUT_SIZE); \
memset(uart_stdout, 0, UART_STDOUT_SIZE);
#if !UART_ENABLE #if !UART_ENABLE
#define PRINT printf #define PRINT printf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment