Change API for getch to make it the caller's responsibility to poll for
input, allowing it to do other stuff if it wants to.
This commit is contained in:
3
main.c
3
main.c
@@ -172,7 +172,8 @@ int main(void) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
char c;
|
char c;
|
||||||
putstr("prompt> ");
|
putstr("prompt> ");
|
||||||
c = getch();
|
while (!getch(&c))
|
||||||
|
FP0XVAL ^= 0x04000000;
|
||||||
if (c == 0x0a)
|
if (c == 0x0a)
|
||||||
continue;
|
continue;
|
||||||
putch(c);
|
putch(c);
|
||||||
|
|||||||
15
uart.c
15
uart.c
@@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
#define UARTBASE 0xE000C000
|
#define UARTBASE 0xE000C000
|
||||||
|
|
||||||
#define FP0XVAL (*((volatile unsigned int *) 0x3FFFC014))
|
|
||||||
|
|
||||||
#define RBR 0x00
|
#define RBR 0x00
|
||||||
#define THR 0x00
|
#define THR 0x00
|
||||||
#define DLL 0x00
|
#define DLL 0x00
|
||||||
@@ -172,14 +170,11 @@ void puthex(unsigned int n) {
|
|||||||
putstr(s+i);
|
putstr(s+i);
|
||||||
}
|
}
|
||||||
|
|
||||||
char getch(void) {
|
bool getch(char *c) {
|
||||||
char c;
|
if (uart_rxread == uart_rxwrite)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
while (uart_rxread == uart_rxwrite) {
|
*c = uart_rxbuf[uart_rxread];
|
||||||
FP0XVAL ^= 0x04000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = uart_rxbuf[uart_rxread];
|
|
||||||
uart_rxread = (uart_rxread + 1) % UART_RXBUFSIZE;
|
uart_rxread = (uart_rxread + 1) % UART_RXBUFSIZE;
|
||||||
return c;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|||||||
4
uart.h
4
uart.h
@@ -1,11 +1,13 @@
|
|||||||
#ifndef __UART_H
|
#ifndef __UART_H
|
||||||
#define __UART_H
|
#define __UART_H
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
void init_uart(void);
|
void init_uart(void);
|
||||||
void putch(char c);
|
void putch(char c);
|
||||||
void putstr(char *s);
|
void putstr(char *s);
|
||||||
void putint(unsigned int n);
|
void putint(unsigned int n);
|
||||||
void puthex(unsigned int n);
|
void puthex(unsigned int n);
|
||||||
char getch(void);
|
bool getch(char *c);
|
||||||
|
|
||||||
#endif /* __UART_H */
|
#endif /* __UART_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user