#include #include #include #include #include "interface_access.h" #include "interface_fds.h" #include "uart.h" int compare_string_chars(const char *c_string, const char *chars, size_t chars_len) { for(int i = 0; i < chars_len; i++) { if (c_string[i] == 0) { return 0; } if (c_string[i] != chars[i]) {; return 0; } } return 1; } //TODO no dual open int hw_device_open(const char *path, size_t path_len) { if (compare_string_chars("uart0", path, path_len) == 1) { uart0_enable_receiver(); return UART_0; } if (compare_string_chars("uart1", path, path_len) == 1) { return UART_1; } return -1; } ssize_t hw_device_transfer(int fd, void *sendbuffer, void *receivebuffer, size_t buffer_len) { return -1; } // we could implement interrupt based nonblocking sending using a queue // like we do receiving (where we need it for the small hw buffer) // but in the end, we do not want too many interrupts, so we do it blocking void uart_send(uint32_t BaseAddress, const char *data, int data_len) { int todo; for (todo = 0; todo < data_len; todo++) { XUartPs_SendByte(BaseAddress, *data++); } } int hw_interface_write(int fd, const char *ptr, int len) { enum InterfaceFileDescriptors fd_enum = fd; switch (fd) { case UART_0: uart_send(XPS_UART0_BASEADDR, ptr, len); return len; case UART_1: uart_send(XPS_UART1_BASEADDR, ptr, len); return len; } return -1; } int hw_interface_read(int fd, char *ptr, int len) { enum InterfaceFileDescriptors fd_enum = fd; switch (fd) { case UART_0: return uart0_read(ptr,len); case UART_1: return 0; } return -1; }