Question
In C programming I need code that fulfills the TODO things that are commented. /** * Synchronously read a character from a UART. This blocks
In C programming I need code that fulfills the TODO things that are commented.
/** * Synchronously read a character from a UART. This blocks until a character is * available. The interrupt handler is not used. * * @return * The character read from the UART as an unsigned char
cast * to an int
. */ syscall kgetc(void) { volatile struct pl011_uart_csreg *regptr;
/* Pointer to the UART control and status registers. */ regptr = (struct pl011_uart_csreg *)0x3F201000;
// TODO: First, check the unget buffer for a character. // Otherwise, check UART flags register, and // once the receiver is not empty, get character c.
return SYSERR; }
/** * kcheckc - check to see if a character is available. * @return true if a character is available, false otherwise. */ syscall kcheckc(void) { volatile struct pl011_uart_csreg *regptr; regptr = (struct pl011_uart_csreg *)0x3F201000;
// TODO: Check the unget buffer and the UART for characters.
return SYSERR; }
/** * kungetc - put a serial character "back" into a local buffer. * @param c character to unget. * @return c on success, SYSERR on failure. */ syscall kungetc(unsigned char c) { // TODO: Check for room in unget buffer, put the character in or discard.
return SYSERR; }
/** * Synchronously write a character to a UART. This blocks until the character * has been written to the hardware. The interrupt handler is not used. * * @param c * The character to write. * * @return * The character written to the UART as an unsigned char
cast * to an int
. */ syscall kputc(uchar c) { volatile struct pl011_uart_csreg *regptr;
/* Pointer to the UART control and status registers. */ regptr = (struct pl011_uart_csreg *)0x3F201000;
// TODO: Check UART flags register. // Once the Transmitter FIFO is not full, send character c.
return SYSERR; }
/** * kernel printf: formatted, synchronous output to SERIAL0. * * @param format * The format string. Not all standard format specifiers are supported by * this implementation. See _doprnt() for a description of supported * conversion specifications. * @param ... * Arguments matching those in the format string. * * @return * The number of characters written. */ syscall kprintf(const char *format, ...) { int retval; va_list ap;
va_start(ap, format); retval = _doprnt(format, ap, (int (*)(int, int))kputc, 0); va_end(ap); return retval; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started