forked from ROMEO/obsw
portable device access api based on unix file descriptors
This commit is contained in:
70
bsp_z7/hardware/interfaces.c
Normal file
70
bsp_z7/hardware/interfaces.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include <hardware/interfaces.h>
|
||||
#include <xparameters_ps.h>
|
||||
#include <xuartps.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "interface_access.h"
|
||||
#include "interface_fds.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;
|
||||
}
|
||||
|
||||
int hw_device_open(const char *path, size_t path_len) {
|
||||
if (compare_string_chars("uart0", path, path_len) == 1) {
|
||||
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 send_uart(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:
|
||||
send_uart(XPS_UART0_BASEADDR, ptr, len);
|
||||
return len;
|
||||
case UART_1:
|
||||
send_uart(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 0;
|
||||
case UART_1:
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
Reference in New Issue
Block a user