#include "xil_printf.h" #include "xparameters.h" #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 check len // 0 is stdin, do not write to it if (fd < 1) { return -1; // TODO error } // we only support a single debug UART, so // stdout and stderr are the same and go to the xiling stdout UART // We output directely to avoid loops and allow debugging (not via a write) 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; }