Fix spiff and stdin_uart_interrupt overiding the same read function (#249)
* Fix spiff and stdin_uart_interrupt overiding the same read function * Make strong function defninition replace a weak one
This commit is contained in:
parent
98de5e573a
commit
e2e6f35288
6 changed files with 34 additions and 24 deletions
12
common.mk
12
common.mk
|
@ -134,9 +134,15 @@ $$($(1)_OBJ_DIR)%.o: $$($(1)_REAL_ROOT)%.S $$($(1)_MAKEFILE) $(wildcard $(ROOT)*
|
|||
$$($(1)_CC_BASE) -c $$< -o $$@
|
||||
$$($(1)_CC_BASE) -MM -MT $$@ -MF $$(@:.o=.d) $$<
|
||||
|
||||
# the component is shown to depend on both obj and source files so we get a meaningful error message
|
||||
# for missing explicitly named source files
|
||||
$$($(1)_AR): $$($(1)_OBJ_FILES) $$($(1)_SRC_FILES)
|
||||
$(1)_AR_IN_FILES = $$($(1)_OBJ_FILES)
|
||||
|
||||
# the component is shown to depend on both obj and source files so we get
|
||||
# a meaningful error message for missing explicitly named source files
|
||||
ifeq ($(INCLUDE_SRC_IN_AR),1)
|
||||
$(1)_AR_IN_FILES += $$($(1)_SRC_FILES)
|
||||
endif
|
||||
|
||||
$$($(1)_AR): $$($(1)_AR_IN_FILES)
|
||||
$(vecho) "AR $$@"
|
||||
$(Q) mkdir -p $$(dir $$@)
|
||||
$(Q) $(AR) cru $$@ $$^
|
||||
|
|
|
@ -59,14 +59,9 @@ __attribute__((weak)) long _write_r(struct _reent *r, int fd, const char *ptr, i
|
|||
}
|
||||
|
||||
/* syscall implementation for stdio read from UART */
|
||||
__attribute__((weak)) long _read_r( struct _reent *r, int fd, char *ptr, int len )
|
||||
__attribute__((weak)) long _read_stdin_r(struct _reent *r, int fd, char *ptr, int len)
|
||||
{
|
||||
int ch, i;
|
||||
|
||||
if(fd != r->_stdin->_file) {
|
||||
r->_errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
uart_rxfifo_wait(0, 1);
|
||||
for(i = 0; i < len; i++) {
|
||||
ch = uart_getc_nowait(0);
|
||||
|
@ -76,6 +71,15 @@ __attribute__((weak)) long _read_r( struct _reent *r, int fd, char *ptr, int len
|
|||
return i;
|
||||
}
|
||||
|
||||
__attribute__((weak)) long _read_r( struct _reent *r, int fd, char *ptr, int len )
|
||||
{
|
||||
if(fd != r->_stdin->_file) {
|
||||
r->_errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
return _read_stdin_r(r, fd, ptr, len);
|
||||
}
|
||||
|
||||
/* Stub syscall implementations follow, to allow compiling newlib functions that
|
||||
pull these in via various codepaths
|
||||
*/
|
||||
|
|
|
@ -141,21 +141,16 @@ long _write_r(struct _reent *r, int fd, const char *ptr, int len )
|
|||
return len;
|
||||
}
|
||||
|
||||
// This function is weakly defined in core/newlib_syscalls.c
|
||||
long _read_stdin_r(struct _reent *r, int fd, char *ptr, int len);
|
||||
|
||||
// This implementation replaces implementation in core/newlib_syscals.c
|
||||
long _read_r( struct _reent *r, int fd, char *ptr, int len )
|
||||
{
|
||||
int ch, i;
|
||||
|
||||
if(fd != r->_stdin->_file) {
|
||||
return SPIFFS_read(&fs, (spiffs_file)fd, ptr, len);
|
||||
}
|
||||
uart_rxfifo_wait(0, 1);
|
||||
for(i = 0; i < len; i++) {
|
||||
ch = uart_getc_nowait(0);
|
||||
if (ch < 0) break;
|
||||
ptr[i] = ch;
|
||||
}
|
||||
return i;
|
||||
return _read_stdin_r(r, fd, ptr, len);
|
||||
}
|
||||
|
||||
int _open_r(struct _reent *r, const char *pathname, int flags, int mode)
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
# for 'usage' as this module is a drop-in replacement for the original polled
|
||||
# version of reading from the UART.
|
||||
|
||||
INC_DIRS += $(ROOT)extras/stdin_uart_interrupt
|
||||
INC_DIRS += $(stdin_uart_interrupt_ROOT)
|
||||
|
||||
# args for passing into compile rule generation
|
||||
extras/stdin_uart_interrupt_INC_DIR = $(ROOT)extras/stdin_uart_interrupt
|
||||
extras/stdin_uart_interrupt_SRC_DIR = $(ROOT)extras/stdin_uart_interrupt
|
||||
stdin_uart_interrupt_SRC_DIR = $(stdin_uart_interrupt_ROOT)
|
||||
|
||||
$(eval $(call component_compile_rules,extras/stdin_uart_interrupt))
|
||||
INCLUDE_SRC_IN_AR = 0
|
||||
EXTRA_LDFLAGS = -Wl,--whole-archive $(stdin_uart_interrupt_AR) -Wl,--no-whole-archive
|
||||
|
||||
$(eval $(call component_compile_rules,stdin_uart_interrupt))
|
||||
|
|
|
@ -75,9 +75,9 @@ uint32_t uart0_num_char(void)
|
|||
return count;
|
||||
}
|
||||
|
||||
// _read_r in core/newlib_syscalls.c will be skipped by the linker in favour
|
||||
// _read_stdin_r in core/newlib_syscalls.c will be skipped by the linker in favour
|
||||
// of this function
|
||||
long _read_r(struct _reent *r, int fd, char *ptr, int len)
|
||||
long _read_stdin_r(struct _reent *r, int fd, char *ptr, int len)
|
||||
{
|
||||
if (!inited) uart0_rx_init();
|
||||
for(int i = 0; i < len; i++) {
|
||||
|
|
|
@ -42,6 +42,9 @@ PRINTF_SCANF_FLOAT_SUPPORT ?= 1
|
|||
|
||||
FLAVOR ?= release # or debug
|
||||
|
||||
# Include source files into a static library. It improves error messages.
|
||||
INCLUDE_SRC_IN_AR ?= 1
|
||||
|
||||
# Compiler names, etc. assume gdb
|
||||
CROSS ?= xtensa-lx106-elf-
|
||||
|
||||
|
|
Loading…
Reference in a new issue