forked from ROMEO/obsw
z7 uart0 buffered read
This commit is contained in:
@ -1,5 +1,34 @@
|
||||
#include "xil_printf.h"
|
||||
#include "xparameters.h"
|
||||
|
||||
#include "../hardware/interface_access.h"
|
||||
#include "../hardware/interface_fds.h"
|
||||
|
||||
int _read(int file, char *ptr, int len) {
|
||||
return 0;
|
||||
// newlib offers a (weak) write implementation which
|
||||
// is reentrant by calling _read_r which in turn
|
||||
// relies on _read which we implement here.
|
||||
// This way, we get a global, reentrant read implementation
|
||||
// NOTE: This might be architecture dependent, so check your
|
||||
// newlib implementation!
|
||||
int _read(int fd, char *ptr, int len) {
|
||||
if (ptr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 0 is stdin, TODO: do we support it?
|
||||
if (fd < 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// stdout and stderr
|
||||
if (fd < 3) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fd < INTERFACE_FDS_NEXT) {
|
||||
return hw_interface_read(fd, ptr, len);
|
||||
}
|
||||
|
||||
// we do not have dynamic fds, so fd is invalid
|
||||
return -1;
|
||||
}
|
Reference in New Issue
Block a user