Skip to content

Commit 1cc6e4b

Browse files
GUIDINGLIanchao
authored andcommitted
sim: add uart dma mode & use work instead of loop.
Signed-off-by: ligd <[email protected]>
1 parent 739688f commit 1cc6e4b

File tree

27 files changed

+233
-119
lines changed

27 files changed

+233
-119
lines changed

arch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ config ARCH_SIM
106106
select ONESHOT
107107
select SERIAL_CONSOLE
108108
select SERIAL_IFLOWCONTROL
109+
select SCHED_HPWORK
109110
---help---
110111
Linux/Cygwin user-mode simulation.
111112

arch/sim/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,14 @@ endif
504504

505505
menu "Simulated UART"
506506

507+
config SIM_UART_DMA
508+
bool "SIM UART use DMA mode"
509+
default y
510+
select SERIAL_TXDMA
511+
select SERIAL_RXDMA
512+
---help---
513+
console use DMA mode or single char mode
514+
507515
config SIM_UART_NUMBER
508516
int "Number of simulated UART ports"
509517
default 0

arch/sim/src/sim/posix/sim_hostuart.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,37 @@ void host_uart_close(int fd)
131131
}
132132

133133
/****************************************************************************
134-
* Name: host_uart_putc
134+
* Name: host_uart_puts
135135
****************************************************************************/
136136

137-
int host_uart_putc(int fd, int ch)
137+
ssize_t host_uart_puts(int fd, const char *buf, size_t size)
138138
{
139-
return write(fd, &ch, 1) == 1 ? ch : -1;
139+
ssize_t ret;
140+
141+
do
142+
{
143+
ret = write(fd, buf, size);
144+
}
145+
while (ret < 0 && errno == EINTR);
146+
147+
return ret < 0 ? -errno : ret;
140148
}
141149

142150
/****************************************************************************
143-
* Name: host_uart_getc
151+
* Name: host_uart_gets
144152
****************************************************************************/
145153

146-
int host_uart_getc(int fd)
154+
ssize_t host_uart_gets(int fd, char *buf, size_t size)
147155
{
148-
int ret;
149-
unsigned char ch;
156+
ssize_t ret;
157+
158+
do
159+
{
160+
ret = read(fd, buf, size);
161+
}
162+
while (ret < 0 && errno == EINTR);
150163

151-
ret = read(fd, &ch, 1);
152-
return ret < 0 ? ret : ch;
164+
return ret < 0 ? -errno : ret;
153165
}
154166

155167
/****************************************************************************

arch/sim/src/sim/sim_initialize.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ static int sim_loop_task(int argc, char **argv)
166166

167167
sched_lock();
168168

169-
/* Handle UART data availability */
170-
171-
sim_uartloop();
172-
173169
#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK) || \
174170
defined(CONFIG_SIM_BUTTONS)
175171
/* Drive the X11 event loop */

arch/sim/src/sim/sim_internal.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,18 @@ void sim_timer_update(void);
209209
/* sim_uart.c ***************************************************************/
210210

211211
void sim_uartinit(void);
212-
void sim_uartloop(void);
213212

214213
/* sim_hostuart.c ***********************************************************/
215214

216-
void host_uart_start(void);
217-
int host_uart_open(const char *pathname);
218-
void host_uart_close(int fd);
219-
int host_uart_putc(int fd, int ch);
220-
int host_uart_getc(int fd);
221-
bool host_uart_checkin(int fd);
222-
bool host_uart_checkout(int fd);
223-
int host_uart_setcflag(int fd, unsigned int cflag);
224-
int host_uart_getcflag(int fd, unsigned int *cflag);
215+
void host_uart_start(void);
216+
int host_uart_open(const char *pathname);
217+
void host_uart_close(int fd);
218+
ssize_t host_uart_puts(int fd, const char *buf, size_t size);
219+
ssize_t host_uart_gets(int fd, char *buf, size_t size);
220+
bool host_uart_checkin(int fd);
221+
bool host_uart_checkout(int fd);
222+
int host_uart_setcflag(int fd, unsigned int cflag);
223+
int host_uart_getcflag(int fd, unsigned int *cflag);
225224

226225
/* sim_deviceimage.c ********************************************************/
227226

0 commit comments

Comments
 (0)