#include "../include/osd.h" #include void setup(void) { // 8-N-1 at 115200 bps outw(0x8000, IO_UART1_MSR); outw(14, IO_UART1_BRSR); // Mask all interrupts outw(0, IO_INTC_EINT0); outw(0, IO_INTC_EINT1); outw(0, IO_INTC_EINT2); } void putc(char ch) { // Wait for room in FIFO while ((inw(IO_UART1_TFCR) & 0x3f) >= 0x20); // Write character outw(ch, IO_UART1_DTRR); } void put(const char *str) { while (*str) { putc(*str++); } } void nl(void) { putc('\r'); putc('\n'); } void puthex(unsigned long n) { unsigned int i; for (i = 0; i != 8; i++) { unsigned int digit = n >> 28; putc(digit >= 10 ? digit - 10 + 'A' : digit + '0'); n <<= 4; } } void putbin(unsigned short n) { unsigned int i; for (i = 0; i != 16; i++) { putc((n >> 15) ? '1' : '0'); n <<= 1; if (i == 7) { putc(' '); } } } #define truth(x) ((x) ? "true" : "false") #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) char getc(void) { // Abort if FIFO is empty if ((inw(IO_UART1_RFCR) & 0x3f) == 0) { return 0; } // Read character return (char)inw(IO_UART1_DTRR); } #define GIO_REG_SET IO_GIO_BITSET2 #define GIO_REG_CLR IO_GIO_BITCLR2 #define GIO_REG_STR "2" int main(void) { setup(); nl(); nl(); put("uart-gio-outs rev 1"); nl(); put("reg: " GIO_REG_STR); nl(); for (;;) { unsigned int i; char ch; for (i = 0; i < 16; i++) { const unsigned int mask = 1 << i; putc(i >= 10 ? i - 10 + 'A' : i + '0'); putc(':'); putc((inw(GIO_REG_SET) & mask) ? '*' : ' '); putc(' '); } putc('\r'); ch = getc(); if (ch != 0) { // Toggle the specified bit unsigned int bit, mask; if ('0' <= ch && ch <= '9') { bit = ch - '0'; } else if ('A' <= ch && ch <= 'F') { bit = ch - 'A' + 10; } else if ('a' <= ch && ch <= 'f') { bit = ch - 'a' + 10; } else { continue; } mask = 1 << bit; if (inw(GIO_REG_SET) & mask) { outw(mask, GIO_REG_CLR); } else { outw(mask, GIO_REG_SET); } } } return 0; }