build/sim: cleanup serial2console and fix terminal mode

This commit is contained in:
Florent Kermarrec 2017-06-28 17:38:09 +02:00
parent ebded4a1b9
commit c3710ec139
1 changed files with 40 additions and 61 deletions

View File

@ -31,16 +31,14 @@ static int litex_sim_module_pads_get( struct pad_s *pads, char *name, void **sig
void *sig = NULL;
int i;
if(!pads || !name || !signal)
{
if(!pads || !name || !signal) {
ret=RC_INVARG;
goto out;
}
i = 0;
while(pads[i].name)
{
if(!strcmp(pads[i].name, name))
{
while(pads[i].name) {
if(!strcmp(pads[i].name, name)) {
sig = (void*)pads[i].signal;
break;
}
@ -57,15 +55,14 @@ void set_conio_terminal_mode(void)
struct termios new_termios;
tcgetattr(0, &new_termios);
cfmakeraw(&new_termios);
new_termios.c_lflag &= ~(ECHO | ICANON);
tcsetattr(0, TCSANOW, &new_termios);
}
static int serial2console_start(void *b)
{
base = (struct event_base *)b;
printf("Loaded %p!\n", base);
// set_conio_terminal_mode();
set_conio_terminal_mode();
return RC_OK;
}
@ -77,8 +74,7 @@ void read_handler(int fd, short event, void *arg)
int i;
read_len = read(fd, buffer, 1024);
for(i = 0; i < read_len; i++)
{
for(i = 0; i < read_len; i++) {
s->databuf[(s->data_start + s->datalen ) % 2048] = buffer[i];
s->datalen++;
}
@ -86,9 +82,7 @@ void read_handler(int fd, short event, void *arg)
static void event_handler(int fd, short event, void *arg)
{
//printf("hit\n");
if (event & EV_READ)
{
if (event & EV_READ) {
read_handler(fd, event, arg);
}
}
@ -99,15 +93,13 @@ static int serial2console_new(void **sess, char *args)
struct timeval tv = {1, 0};
struct session_s *s = NULL;
if(!sess)
{
if(!sess) {
ret = RC_INVARG;
goto out;
}
s = (struct session_s*) malloc(sizeof(struct session_s));
if(!s)
{
if(!s) {
ret=RC_NOENMEM;
goto out;
}
@ -118,7 +110,6 @@ static int serial2console_new(void **sess, char *args)
out:
*sess = (void*) s;
return ret;
}
static int serial2console_add_pads(void *sess, struct pad_list_s *plist)
@ -126,14 +117,13 @@ static int serial2console_add_pads(void *sess, struct pad_list_s *plist)
int ret = RC_OK;
struct session_s *s = (struct session_s*) sess;
struct pad_s *pads;
if(!sess || !plist)
{
if(!sess || !plist) {
ret = RC_INVARG;
goto out;
}
pads = plist->pads;
if(!strcmp(plist->name, "serial"))
{
if(!strcmp(plist->name, "serial")) {
litex_sim_module_pads_get(pads, "sink_data", (void**)&s->rx);
litex_sim_module_pads_get(pads, "sink_valid", (void**)&s->rx_valid);
litex_sim_module_pads_get(pads, "sink_ready", (void**)&s->rx_ready);
@ -143,40 +133,29 @@ static int serial2console_add_pads(void *sess, struct pad_list_s *plist)
}
if(!strcmp(plist->name, "sys_clk"))
{
litex_sim_module_pads_get(pads, "sys_clk", (void**) &s->sys_clk);
}
out:
return ret;
}
static int serial2console_tick(void *sess)
{
static int serial2console_tick(void *sess) {
struct session_s *s = (struct session_s*)sess;
if(*s->sys_clk == 0)
{
if(*s->sys_clk == 0) {
return RC_OK;
}
*s->tx_ready = 1;
if(*s->tx_valid)
{
if(*s->tx_valid) {
if(*s->tx == '\n')
{
printf("\r");
}
printf("%c", *s->tx);
fflush(stdout);
}
*s->rx_valid = 0;
if(s->datalen)
{
if(s->datalen) {
*s->rx=s->databuf[s->data_start];
s->data_start = (s->data_start + 1) % 2048;
s->datalen--;