|
|
@ -4,6 +4,7 @@ |
|
|
|
#include <libopencm3/cm3/scb.h> |
|
|
|
#include <libopencm3/cm3/scb.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <ctype.h> |
|
|
|
#include <ctype.h> |
|
|
|
|
|
|
|
#include <stdarg.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <string.h> |
|
|
|
#include <string.h> |
|
|
@ -19,12 +20,12 @@ |
|
|
|
struct usart_console { |
|
|
|
struct usart_console { |
|
|
|
char recv_buf[RECV_BUF_LEN]; |
|
|
|
char recv_buf[RECV_BUF_LEN]; |
|
|
|
void (* process_line)(void); |
|
|
|
void (* process_line)(void); |
|
|
|
|
|
|
|
FILE *fp; |
|
|
|
volatile size_t cur, next; |
|
|
|
volatile size_t cur, next; |
|
|
|
uint32_t dev; |
|
|
|
uint32_t dev; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static struct usart_console *usart[4]; |
|
|
|
static struct usart_console *usart[4]; |
|
|
|
struct usart_console user_console; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void usart_isr(struct usart_console *console) |
|
|
|
static void usart_isr(struct usart_console *console) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -168,32 +169,30 @@ static int usart_init(struct usart_console *console) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void console_init(void) |
|
|
|
FILE *console_init(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
cookie_io_functions_t console_in = { |
|
|
|
cookie_io_functions_t fops = { |
|
|
|
.read = usart_read, |
|
|
|
.read = usart_read, |
|
|
|
.write = NULL, |
|
|
|
|
|
|
|
.seek = NULL, |
|
|
|
|
|
|
|
.close = NULL, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
cookie_io_functions_t console_out = { |
|
|
|
|
|
|
|
.read = NULL, |
|
|
|
|
|
|
|
.write = usart_write, |
|
|
|
.write = usart_write, |
|
|
|
.seek = NULL, |
|
|
|
.seek = NULL, |
|
|
|
.close = NULL, |
|
|
|
.close = NULL, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
struct usart_console *console; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!(console = malloc(sizeof *console))) |
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console->dev = USART1; |
|
|
|
|
|
|
|
console->cur = 0; |
|
|
|
|
|
|
|
console->next = 0; |
|
|
|
|
|
|
|
console->process_line = NULL; |
|
|
|
|
|
|
|
usart[0] = console; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
usart_init(console); |
|
|
|
|
|
|
|
|
|
|
|
user_console.dev = USART1; |
|
|
|
console->fp = fopencookie(console, "r+w", fops); |
|
|
|
user_console.cur = 0; |
|
|
|
|
|
|
|
user_console.next = 0; |
|
|
|
|
|
|
|
usart[0] = &user_console; |
|
|
|
|
|
|
|
usart_init(&user_console); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stdin = fopencookie(&user_console, "r", console_in); |
|
|
|
setbuf(console->fp, NULL); |
|
|
|
stdout = fopencookie(&user_console, "w", console_out); |
|
|
|
|
|
|
|
stderr = fopencookie(&user_console, "w", console_out); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setbuf(stdout, NULL); |
|
|
|
return console->fp; |
|
|
|
//setlinebuf(stdout);
|
|
|
|
|
|
|
|
setbuf(stderr, NULL); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|