adds board specific read for iss, changes read implementation
This commit is contained in:
parent
d9692688b6
commit
cef1036169
19
env/iss/bsp_read.c
vendored
Normal file
19
env/iss/bsp_read.c
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
ssize_t _bsp_read(int fd, void *ptr, size_t len) {
|
||||
uint8_t *current = (uint8_t *)ptr;
|
||||
volatile uint32_t *uart_rx = (uint32_t *)0xFFFF0000;
|
||||
ssize_t result = 0;
|
||||
if (isatty(fd)) {
|
||||
for (current = (uint8_t *)ptr; (current < ((uint8_t *)ptr) + len);
|
||||
current++) {
|
||||
*current = *uart_rx;
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return EOF;
|
||||
}
|
@ -1,62 +1,10 @@
|
||||
/* See LICENSE of license details. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include "weak_under_alias.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "stub.h"
|
||||
#include "weak_under_alias.h"
|
||||
#if defined(SEMIHOSTING)
|
||||
#include "semihosting.h"
|
||||
#endif
|
||||
extern ssize_t _bsp_read(int fd, void *ptr, size_t len);
|
||||
|
||||
ssize_t __wrap_read(int fd, void *ptr, size_t len) {
|
||||
uint8_t *current = (uint8_t *)ptr;
|
||||
#if defined(SEMIHOSTING)
|
||||
int i = sh_read(current, fd, len);
|
||||
return i;
|
||||
#endif
|
||||
#if defined(BOARD_hifive1)
|
||||
volatile uint32_t *uart_rx = (uint32_t *)(UART0_CTRL_ADDR + UART_REG_RXFIFO);
|
||||
volatile uint8_t *uart_rx_cnt =
|
||||
(uint8_t *)(UART0_CTRL_ADDR + UART_REG_RXCTRL + 2);
|
||||
#elif defined(BOARD_iss)
|
||||
volatile uint32_t *uart_rx = (uint32_t *)0xFFFF0000;
|
||||
#elif defined(BOARD_TGCP)
|
||||
// TODO: implement
|
||||
#elif !defined(BOARD_ehrenberg) && !defined(BOARD_tgc_vp)
|
||||
volatile uint32_t *uart_rx = (uint32_t *)(UART0_BASE_ADDR + UART_REG_RXFIFO);
|
||||
volatile uint8_t *uart_rx_cnt =
|
||||
(uint8_t *)(UART0_BASE_ADDR + UART_REG_RXCTRL + 2);
|
||||
#endif
|
||||
ssize_t result = 0;
|
||||
if (isatty(fd)) {
|
||||
#if defined(BOARD_ehrenberg) || defined(BOARD_tgc_vp)
|
||||
for (current = (uint8_t *)ptr; (current < ((uint8_t *)ptr) + len) &&
|
||||
(get_uart_rx_tx_reg_rx_avail(uart) > 0);
|
||||
current++) {
|
||||
*current = uart_read(uart);
|
||||
result++;
|
||||
}
|
||||
#elif defined(BOARD_iss)
|
||||
for (current = (uint8_t *)ptr; (current < ((uint8_t *)ptr) + len);
|
||||
current++) {
|
||||
*current = *uart_rx;
|
||||
result++;
|
||||
}
|
||||
#elif defined(BOARD_TGCP)
|
||||
// TODO: implement
|
||||
#else
|
||||
for (current = (uint8_t *)ptr;
|
||||
(current < ((uint8_t *)ptr) + len) && (*uart_rx_cnt > 0); current++) {
|
||||
*current = *uart_rx;
|
||||
result++;
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
return _stub(EBADF);
|
||||
return _bsp_read(fd, ptr, len);
|
||||
}
|
||||
|
||||
weak_under_alias(read);
|
||||
|
Loading…
x
Reference in New Issue
Block a user