sdev->dev = dev;
dev->underlay = sdev;
+ waitq_init(&sdev->wq_rxdone);
+ waitq_init(&sdev->wq_txdone);
fifo_init(&sdev->rxbuf, valloc(RXBUF_SIZE), RXBUF_SIZE, 0);
llist_append(&serial_devs, &sdev->sdev_list);
// llist_init_head(&sdev->cmds);
#define UART_rLS_BI (1 << 4)
#define UART_rII_FIFOEN (0b11 << 6)
-#define UART_rII_ID 0b1110
+#define UART_rII_ID 0b1111
#define UART_rFC_EN 1
+#define UART_rFC_DMA1 (1 << 3)
#define UART_rFC_XMIT_RESET (1 << 2)
#define UART_rFC_RCVR_RESET (1 << 1)
}
static inline void
-uart_setie(struct uart16550* uart)
+uart_clrie(struct uart16550* uart)
{
uart->cntl_save.rie = uart->read_reg(uart, UART_rIE);
uart->write_reg(uart, UART_rIE, 0);
}
static inline void
-uart_clrie(struct uart16550* uart)
+uart_setie(struct uart16550* uart)
{
uart->write_reg(uart, UART_rIE, uart->cntl_save.rie | 1);
}
static inline int
uart_enable_fifo(struct uart16550* uart, int trig_lvl)
{
- uart->cntl_save.rfc = UART_rFC_EN | (trig_lvl & 0b11);
+ uart->cntl_save.rfc =
+ UART_rFC_EN | ((trig_lvl & 0b11) << 6) | UART_rFC_DMA1;
uart->write_reg(uart, UART_rFC, uart->cntl_save.rfc);
return uart->read_reg(uart, UART_rII) & UART_rII_FIFOEN;
uart_intr_identify(struct uart16550* uart)
{
u32_t rii = uart->read_reg(uart, UART_rII);
- return (!!(rii & UART_rII_FIFOEN) << 3) | ((rii & UART_rII_ID) >> 1);
+ return (rii & UART_rII_ID);
}
static inline u8_t
llist_for_each(pos, n, ports, local_ports)
{
int is = uart_intr_identify(pos);
- if (iv == pos->iv && is == UART_DATA_OK) {
- break;
+ if (iv == pos->iv && (is == UART_DATA_OK || is == UART_CHR_TIMEOUT)) {
+ goto done;
}
}
- if (!pos) {
- return;
- }
+ return;
+done:
char recv;
int i = 0;
while ((recv = uart_read_byte(pos))) {
*((volatile int*)irqs[i]) = 0;
}
- uart_setup(uart);
uart_enable_fifo(uart, UART_FIFO8);
llist_append(&com_ports, &uart->local_ports);
uart->sdev = sdev;
+ uart_setup(uart);
+ uart_setie(uart);
uart = NULL;
}
{
isr_param* p = isrm;
ptr_t fp = cpu_get_fp();
- int prev_fromusr = uspace_context(p);
+ int prev_fromusr = 0;
kprintf(KDEBUG "\n");
kprintf(KDEBUG "stack trace (pid=%d)\n", __current->pid);
-no-shutdown \
-d cpu_reset \
-d trace:ide_dma_cb \
- -serial tcp::12345,server,nowait\
+ -serial telnet::12345,server,nowait\
-drive id=disk,file="machine/disk0.vdi",if=none \
-drive id=cdrom,file="$(1)",readonly=on,if=none,format=raw \
-device ahci,id=ahci \
app-list += signal_demo
app-list += sh
app-list += cat
+app-list += testp
mkapp-list := $(addprefix app-, $(app-list))
--- /dev/null
+#include <errno.h>
+#include <fcntl.h>
+#include <lunaix/lunaix.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+void
+test_serial()
+{
+ int fd = open("/dev/ttyS0", FO_WRONLY);
+ if (fd < 0) {
+ printf("ttyS0 not accessable (%d)\n", errno);
+ return;
+ }
+
+ char buf[32];
+ int sz = 0;
+
+ printf("ttyS0 input: ");
+
+ if ((sz = read(fd, buf, 31)) < 0) {
+ printf("write to ttyS0 failed (%d)\n", errno);
+ }
+
+ buf[sz] = 0;
+
+ printf("%s", buf);
+
+ close(fd);
+}
+
+int
+main(int argc, char* argv[])
+{
+ if (argc <= 1) {
+ return 1;
+ }
+
+ char* target = argv[1];
+
+ if (!strcmp(target, "serial")) {
+ test_serial();
+ } else {
+ printf("unknown test: %s\n", target);
+ return 1;
+ }
+
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+define src_files
+ main.c
+endef
+
+obj_files := $(addsuffix .o,$(src_files))
+include_opt := $(addprefix -I,$(INCLUDES))
+
+out := $(BUILD_DIR)/bin
+
+%.c.o: %.c
+ $(call status_,CC,$<)
+ @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
+
+$(out)/$(BUILD_NAME): $(obj_files)
+ $(call status_,LD,$(@F))
+ @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
+
+all: $(out)/$(BUILD_NAME)
+
+clean:
+ @rm -f $(obj_files)
\ No newline at end of file