diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-12-08 15:07:52 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-12-08 15:07:52 +0100 |
commit | dcf84169ae75b11c1656d45dbc6c626d93da6a10 (patch) | |
tree | d78ad84e6aba1f5f13037e40141013f3a3061d54 /src/arch | |
parent | 56f2d90751f1c1b2db925da215a14721cf18d483 (diff) |
Add output support (broken on esp8266)
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/esp8266/Makefile.inc | 5 | ||||
-rw-r--r-- | src/arch/esp8266/arch.cc | 5 | ||||
-rw-r--r-- | src/arch/esp8266/driver/stdout.cc | 25 | ||||
-rw-r--r-- | src/arch/msp430fr5969lp/Makefile.inc | 1 | ||||
-rw-r--r-- | src/arch/msp430fr5969lp/driver/stdout.cc | 33 | ||||
-rw-r--r-- | src/arch/posix/Makefile.inc | 1 | ||||
-rw-r--r-- | src/arch/posix/driver/stdout.cc | 14 |
7 files changed, 83 insertions, 1 deletions
diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc index b0fc4ce..9a08678 100644 --- a/src/arch/esp8266/Makefile.inc +++ b/src/arch/esp8266/Makefile.inc @@ -9,6 +9,7 @@ CC = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-gcc CXX = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-g++ AR = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-ar LD = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-gcc +OBJCOPY = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-objcopy INCLUDES += -Iinclude/esp8266 -I${SDK_BASE}/include COMMON_FLAGS += -nostdlib -mlongcalls -D__ets__ -DICACHE_FLASH @@ -16,17 +17,19 @@ CXXFLAGS = -std=c++11 LDFLAGS += -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static TARGETS += src/arch/esp8266/arch.cc src/arch/esp8266/driver/gpio.cc +TARGETS += src/arch/esp8266/driver/stdout.cc OBJECTS = ${TARGETS:.cc=.o} .cc.o: ${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc} + ${OBJCOPY} --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal $@ build/system.ar: ${OBJECTS} ${AR} cru $@ ${OBJECTS} build/system.elf: build/system.ar - ${CC} -L${SDK_BASE}/lib -T${SDK_BASE}/lib/eagle.app.v6.ld ${LDFLAGS} \ + ${CC} -L${SDK_BASE}/lib -T${SDK_BASE}/lib/eagle.app.v6-derf.ld ${LDFLAGS} \ -Wl,--start-group -lc -lgcc -lhal -lpp -lphy -lnet80211 -llwip -lwpa \ -lmain $< -Wl,--end-group -o $@ diff --git a/src/arch/esp8266/arch.cc b/src/arch/esp8266/arch.cc index 0e11f2d..f5d1c91 100644 --- a/src/arch/esp8266/arch.cc +++ b/src/arch/esp8266/arch.cc @@ -10,6 +10,8 @@ extern "C" { void ets_timer_arm_new(os_timer_t *ptimer, uint32_t milliseconds, bool repeat_flag, bool us_flag); void ets_timer_disarm(os_timer_t *ptimer); void ets_timer_setfn(os_timer_t *ptimer, os_timer_func_t *pfunction, void *parg); +extern void (*__init_array_start)(); +extern void (*__init_array_end)(); } #define user_procTaskPrio 0 @@ -30,6 +32,9 @@ extern int main(void); void ICACHE_FLASH_ATTR jump_to_main(void) { + for (void (**p)() = &__init_array_start; p != &__init_array_start; p++) { + (*p)(); + } #ifdef WITH_LOOP os_timer_disarm(&loop_timer); os_timer_setfn(&loop_timer, (os_timer_func_t *)jump_to_loop, (void *)0); diff --git a/src/arch/esp8266/driver/stdout.cc b/src/arch/esp8266/driver/stdout.cc new file mode 100644 index 0000000..b35275b --- /dev/null +++ b/src/arch/esp8266/driver/stdout.cc @@ -0,0 +1,25 @@ +#include "driver/stdout.h" +extern "C" { +#include "osapi.h" +#include "user_interface.h" +#include "gpio.h" +void uart_div_modify(uint8_t uart_no, uint32 DivLatchValue); +void os_printf_plus(const char *s, ...); +} + +void StandardOutput::setup() +{ + uart_div_modify(0, UART_CLK_FREQ / 115200); +} + +void StandardOutput::put(char c) +{ + os_printf("%c", c); +} + +void StandardOutput::write(const char *s) +{ + os_printf("%s", s); +} + +StandardOutput kout; diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc index 04069ae..f4b96fe 100644 --- a/src/arch/msp430fr5969lp/Makefile.inc +++ b/src/arch/msp430fr5969lp/Makefile.inc @@ -11,6 +11,7 @@ CXX = /opt/msp430/ti/gcc/bin/msp430-elf-g++ OBJCOPY = /opt/msp430/ti/gcc/bin/msp430-elf-objcopy TARGETS += src/arch/msp430fr5969lp/arch.cc src/arch/msp430fr5969lp/driver/gpio.cc +TARGETS += src/arch/msp430fr5969lp/driver/stdout.cc OBJECTS = ${TARGETS:.cc=.o} diff --git a/src/arch/msp430fr5969lp/driver/stdout.cc b/src/arch/msp430fr5969lp/driver/stdout.cc new file mode 100644 index 0000000..321785b --- /dev/null +++ b/src/arch/msp430fr5969lp/driver/stdout.cc @@ -0,0 +1,33 @@ +#include "driver/stdout.h" +#include <msp430.h> + +void StandardOutput::setup() +{ + UCA0CTLW0 |= UCSWRST; + UCA0CTLW0 = UCSWRST | UCSSEL__SMCLK; + UCA0MCTLW = UCOS16 | (10<<5) | 0xF700; + UCA0BR0 = 8; + + UCA0IRCTL = 0; + UCA0ABCTL = 0; + + P2SEL0 &= ~(BIT0 | BIT1); + P2SEL1 |= BIT0 | BIT1; + P2DIR |= BIT0; + + UCA0CTLW0 &= ~UCSWRST; + + //UCA0IE |= UCRXIE; +} + +void StandardOutput::put(char c) +{ + while (!(UCA0IFG & UCTXIFG)); + UCA0TXBUF = c; + + if (c == '\n') { + put('\r'); + } +} + +StandardOutput kout; diff --git a/src/arch/posix/Makefile.inc b/src/arch/posix/Makefile.inc index caf16a7..9dd723d 100644 --- a/src/arch/posix/Makefile.inc +++ b/src/arch/posix/Makefile.inc @@ -5,6 +5,7 @@ CXX = g++ INCLUDES += -Iinclude/posix TARGETS += src/arch/posix/arch.cc src/arch/posix/driver/gpio.cc +TARGETS += src/arch/posix/driver/stdout.cc OBJECTS = ${TARGETS:.cc=.o} diff --git a/src/arch/posix/driver/stdout.cc b/src/arch/posix/driver/stdout.cc new file mode 100644 index 0000000..e409389 --- /dev/null +++ b/src/arch/posix/driver/stdout.cc @@ -0,0 +1,14 @@ +#include "driver/stdout.h" +#include <stdio.h> + +void StandardOutput::put(char c) +{ + fputc(c, stdout); +} + +void StandardOutput::flush() +{ + fflush(stdout); +} + +StandardOutput kout; |