00001 00007 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00008 00009 #include <kernel.h> 00010 #include <vararg.h> 00011 #include <device.h> 00012 #include <stdio.h> 00013 #include <uart.h> 00014 00021 syscall kputc(device *pdev, unsigned char c) 00022 { 00023 int status, irmask; 00024 struct uart *puart; 00025 volatile struct uart_csreg *pucsr; 00026 00027 if (NULL == pdev) { return SYSERR; } 00028 puart = (struct uart *)pdev->controlblk; 00029 if (NULL == puart) { puart = &uarttab[0]; } 00030 pucsr = puart->csr; 00031 if (NULL == pucsr) { pucsr = (struct uart_csreg *)pdev->csr; } 00032 00033 irmask = pucsr->ier; /* Save UART interrupt state. */ 00034 pucsr->ier = 0; /* Disable UART interrupts. */ 00035 00036 do /* Wait for transmitter */ 00037 { 00038 status = pucsr->lsr; 00039 } 00040 while ( (status & UART_LSR_TEMT) != UART_LSR_TEMT ); 00041 00042 /* Send character. */ 00043 pucsr->thr = c; 00044 puart->cout++; 00045 00046 pucsr->ier = irmask; /* Restore UART interrupts. */ 00047 return c; 00048 } 00049 00055 syscall kprintf(char *fmt, ...) 00056 { 00057 va_list ap; 00058 00059 va_start(ap, fmt); 00060 _doprnt(fmt, ap, (int (*)(int, int))kputc, (int)&devtab[SERIAL0]); 00061 va_end(ap); 00062 return OK; 00063 } 00064