forked from ROMEO/obsw
portable device access api based on unix file descriptors
This commit is contained in:
@ -1,15 +1,41 @@
|
||||
#include "xil_printf.h"
|
||||
#include "xparameters.h"
|
||||
|
||||
int write(int file, char *ptr, int len) {
|
||||
#include "../hardware/interface_access.h"
|
||||
#include "../hardware/interface_fds.h"
|
||||
|
||||
|
||||
// newlib offers a (weak) write implementation which
|
||||
// is reentrant by calling _write_r which in turn
|
||||
// relies on _write which we implement here.
|
||||
// This way, we get a global, reentrant write implementation
|
||||
// NOTE: This might be architecture dependent, so check your
|
||||
// newlib implementation!
|
||||
int _write(int fd, const char *ptr, int len) {
|
||||
if (ptr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
// TODO file descriptors
|
||||
int todo;
|
||||
|
||||
for (todo = 0; todo < len; todo++) {
|
||||
outbyte(*ptr++);
|
||||
|
||||
// 0 is stdin, do not write to it
|
||||
if (fd < 1) {
|
||||
return -1; // TODO error
|
||||
}
|
||||
return len;
|
||||
// we only support a single debug UART, so
|
||||
// stdout and stderr are the same and go to the xiling stdout UART
|
||||
// TODO switch to a hw_interface_write() instead?
|
||||
if (fd < 3) {
|
||||
int todo;
|
||||
|
||||
for (todo = 0; todo < len; todo++) {
|
||||
outbyte(*ptr++);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
if (fd < INTERFACE_FDS_NEXT) {
|
||||
return hw_interface_write(fd, ptr, len);
|
||||
}
|
||||
|
||||
// we do not have dynamic fds, so fd is invalid
|
||||
return -1;
|
||||
}
|
Reference in New Issue
Block a user