};
struct event_base *base;
-static int litex_sim_module_pads_get( struct pad_s *pads, char *name, void **signal)
+static int litex_sim_module_pads_get(struct pad_s *pads, char *name, void **signal)
{
int ret;
- void *sig=NULL;
+ 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))
- {
- sig=(void*)pads[i].signal;
+ while(pads[i].name) {
+ if(!strcmp(pads[i].name, name)) {
+ sig = (void*)pads[i].signal;
break;
}
i++;
}
out:
- *signal=sig;
+ *signal = sig;
return ret;
}
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();
+ base = (struct event_base *)b;
+ set_conio_terminal_mode();
return RC_OK;
}
void read_handler(int fd, short event, void *arg)
{
- struct session_s *s= (struct session_s*)arg;
+ struct session_s *s = (struct session_s*)arg;
char buffer[1024];
ssize_t read_len;
int i;
read_len = read(fd, buffer, 1024);
- for(i = 0; i < read_len; i++)
- {
- s->databuf[(s->data_start + s->datalen ) % 2048] = buffer[i];
+ for(i = 0; i < read_len; i++) {
+ s->databuf[(s->data_start + s->datalen ) % 2048] = buffer[i];
s->datalen++;
}
}
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);
}
}
{
int ret=RC_OK;
struct timeval tv = {1, 0};
- struct session_s *s=NULL;
+ 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)
- {
+
+ s = (struct session_s*) malloc(sizeof(struct session_s));
+ if(!s) {
ret=RC_NOENMEM;
goto out;
}
memset(s, 0, sizeof(struct session_s));
s->ev = event_new(base, fileno(stdin), EV_READ | EV_PERSIST , event_handler, s);
event_add(s->ev, &tv);
-
+
out:
- *sess=(void*)s;
+ *sess = (void*) s;
return ret;
-
}
static int serial2console_add_pads(void *sess, struct pad_list_s *plist)
{
- int ret=RC_OK;
- struct session_s *s=(struct session_s*)sess;
+ 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);
litex_sim_module_pads_get(pads, "source_ready", (void**)&s->tx_ready);
}
- if(!strcmp(plist->name, "sys_clk"))
- {
- litex_sim_module_pads_get(pads, "sys_clk", (void**)&s->sys_clk);
-
- }
+ 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;
- 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)
- {
-
+ *s->rx_valid = 0;
+ if(s->datalen) {
*s->rx=s->databuf[s->data_start];
s->data_start = (s->data_start + 1) % 2048;
s->datalen--;
- *s->rx_valid=1;
+ *s->rx_valid = 1;
}
-
+
return RC_OK;
}
serial2console_tick
};
-int litex_sim_ext_module_init(int (*register_module)(struct ext_module_s *))
+int litex_sim_ext_module_init(int (*register_module) (struct ext_module_s *))
{
- int ret=RC_OK;
+ int ret = RC_OK;
ret = register_module(&ext_mod);
return ret;
}