2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
5 #include <kernel/kernel.h>
6 #include <boot/stage2.h>
8 #include <kernel/arch/dbg_console.h>
10 int arch_dbg_con_init(kernel_args
*ka
)
12 volatile uint16
*scif16
= (uint16
*)0xffe80000;
13 volatile uint8
*scif8
= (uint8
*)0xffe80000;
16 /* Disable interrupts, transmit/receive, and use internal clock */
19 /* 8N1, use P0 clock */
22 /* Set baudrate, N = P0/(32*B)-1 */
23 // scif8[4] = (50000000 / (32 * baud_rate)) - 1;
25 // scif8[4] = 80; // 19200
26 // scif8[4] = 40; // 38400
27 // scif8[4] = 26; // 57600
28 scif8
[4] = 13; // 115200
30 /* Reset FIFOs, enable hardware flow control */
31 scif16
[24/2] = 4; //12;
33 for(x
= 0; x
< 100000; x
++);
34 scif16
[24/2] = 0; //8;
36 /* Disable manual pin control */
43 /* Enable transmit/receive */
46 for(x
= 0; x
< 100000; x
++);
48 arch_dbg_con_puts("serial initted\n");
53 int arch_dbg_con_init2(kernel_args
*ka
)
58 char arch_dbg_con_read()
60 volatile uint16
*status
= (uint16
*)0xffe8001c;
61 volatile uint16
*ack
= (uint16
*)0xffe80010;
62 volatile uint8
*fifo
= (uint8
*)0xffe80014;
65 /* Check input FIFO */
66 while ((*status
& 0x1f) == 0);
68 /* Get the input char */
77 /* Flush all FIFO'd bytes out of the serial port buffer */
78 static void arch_dbg_con_flush() {
79 volatile uint16
*ack
= (uint16
*)0xffe80010;
82 while (!(*ack
& 0x40))
87 static void _arch_dbg_con_putch(const char c
)
89 volatile uint16
*ack
= (uint16
*)0xffe80010;
90 volatile uint8
*fifo
= (uint8
*)0xffe8000c;
92 /* Wait until the transmit buffer has space */
93 while (!(*ack
& 0x20))
102 char arch_dbg_con_putch(const char c
)
105 _arch_dbg_con_putch('\r');
106 _arch_dbg_con_putch('\n');
107 } else if (c
!= '\r')
108 _arch_dbg_con_putch(c
);
113 void arch_dbg_con_puts(const char *s
)
116 arch_dbg_con_putch(*s
);
121 ssize_t
arch_dbg_con_write(const void *buf
, ssize_t len
)
123 const char *cbuf
= (const char *)buf
;
127 arch_dbg_con_putch(*cbuf
);