diff --git a/Makefile b/Makefile index 75ace692e..d6e319111 100644 --- a/Makefile +++ b/Makefile @@ -1,35 +1,16 @@ -TOOLCHAIN=arm-none-eabi -COMPILER=llvm - -ifeq ($(COMPILER),llvm) -CC=clang -CXX=clang++ -else -CC=$(TOOLCHAIN)-gcc -CXX=$(TOOLCHAIN)-g++ +PLATFORM ?= stm32f429 +#PLATFORM=simulator +include Makefile.$(PLATFORM) +ifndef USE_LIBA + $(error Makefile.PLATFORM should define USE_LIBA) endif - -LD=$(TOOLCHAIN)-ld.bfd -GDB=$(TOOLCHAIN)-gdb -OBJCOPY=$(TOOLCHAIN)-objcopy - -# Compiler flags -# Note: We're using CFLAGS, CXXFLAGS, and SFLAGS. SFLAGS are shared flags for both C and C++ - -# Flags - Arch -ifeq ($(COMPILER),llvm) - SFLAGS += -target thumbv7em-unknown-eabi -else - SFLAGS += -mthumb -march=armv7e-m -mfloat-abi=softfp -endif -SFLAGS += -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 +SFLAGS += -DUSE_LIBA=$(USE_LIBA) # Flags - Header search path SFLAGS += -Ilib -I. -#-Iexternal/freertos/include -Iexternal -Iexternal/freertos/portable/GCC/ARM_CM4F -Iexternal/newlib/libc/include # Flags - Building options -SFLAGS += -Wall -ffreestanding -nostdinc +SFLAGS += -Wall # Flags - Optimizations ifeq ($(PRODUCTION),1) @@ -42,7 +23,7 @@ endif # Language-specific flags CFLAGS = -std=c99 -CXXFLAGS = -std=c++11 -fno-exceptions -fno-unwind-tables -fno-rtti -nostdlib +CXXFLAGS = -std=c++11 -fno-exceptions -fno-unwind-tables -fno-rtti products := boot.elf boot.hex boot.bin @@ -51,17 +32,41 @@ products := boot.elf boot.hex boot.bin lib/private/mem5.o: CFLAGS += -w -objs += src/hello.o +#objs += src/hello.o +.PHONY: default info +default: info clean boot.elf -default: clean boot.elf +ifeq ($(VERBOSE),1) +info: + @echo "========= BUILD SETTINGS ======" + @echo "PLATFORM = $(PLATFORM)" + @echo "CC = $(CC)" + @echo "CXX = $(CXX)" + @echo "LD = $(LD)" + @echo "CFLAGS = $(CFLAGS)" + @echo "CXXFLAGS = $(CXXFLAGS)" + @echo "SFLAGS = $(SFLAGS)" + @echo "LDFLAGS = $(LDFLAGS)" + @echo "===============================" +else +info: +endif +include boot/Makefile +ifeq ($(USE_LIBA),0) +LDFLAGS += -lc -lc++ -lcrt1.o +else +SFLAGS += -ffreestanding -nostdinc -nostdlib include liba/Makefile include libaxx/Makefile -include platform/Makefile +endif +include ion/Makefile include kandinsky/Makefile include poincare/Makefile +objs += src/hello.o + run: boot.elf $(GDB) -x gdb_script.gdb boot.elf @@ -81,7 +86,7 @@ boot.bin: boot.elf boot.elf: $(objs) @echo "LD $@" - @$(LD) -T platform/stm32f429/boot/flash.ld $(objs) -o $@ + @$(LD) $(LDFLAGS) $(objs) -o $@ %.o: %.c @echo "CC $@" diff --git a/Makefile.simulator b/Makefile.simulator new file mode 100644 index 000000000..47f4f7c85 --- /dev/null +++ b/Makefile.simulator @@ -0,0 +1,7 @@ +CC=clang +CXX=clang++ +LD=ld +#GDB=gdb +#OBJCOPY=$(TOOLCHAIN)-objcopy + +USE_LIBA=0 diff --git a/Makefile.stm32f429 b/Makefile.stm32f429 new file mode 100644 index 000000000..0b28786c2 --- /dev/null +++ b/Makefile.stm32f429 @@ -0,0 +1,27 @@ +TOOLCHAIN=arm-none-eabi +COMPILER=llvm + +ifeq ($(COMPILER),llvm) +CC=clang +CXX=clang++ +else +CC=$(TOOLCHAIN)-gcc +CXX=$(TOOLCHAIN)-g++ +endif + +LD=$(TOOLCHAIN)-ld.bfd +GDB=$(TOOLCHAIN)-gdb +OBJCOPY=$(TOOLCHAIN)-objcopy + +# Flags - Arch +ifeq ($(COMPILER),llvm) + SFLAGS += -target thumbv7em-unknown-eabi +else + SFLAGS += -mthumb -march=armv7e-m -mfloat-abi=softfp +endif +SFLAGS += -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 + +LDFLAGS += -T boot/stm32f429/flash.ld + +# Platform configuration +USE_LIBA=1 diff --git a/boot/Makefile b/boot/Makefile new file mode 100644 index 000000000..5614f33a7 --- /dev/null +++ b/boot/Makefile @@ -0,0 +1,2 @@ +objs += boot/boot.o +include boot/$(PLATFORM)/Makefile diff --git a/boot/README.txt b/boot/README.txt new file mode 100644 index 000000000..09d5fe97d --- /dev/null +++ b/boot/README.txt @@ -0,0 +1,3 @@ +Boot + +Code in boot is responsible for creating an executable that can be started on the PLATFORM. diff --git a/boot/boot.c b/boot/boot.c new file mode 100644 index 000000000..233b9c325 --- /dev/null +++ b/boot/boot.c @@ -0,0 +1,20 @@ +#if USE_LIBA +#include +#endif + +#if USE_ION +#include +#endif + +#include + +void boot() { +#if USE_LIBA + liba_init(); +#endif +#if USE_ION + ion_ini(); +#endif + + hello(); +} diff --git a/boot/boot.h b/boot/boot.h new file mode 100644 index 000000000..480d9736e --- /dev/null +++ b/boot/boot.h @@ -0,0 +1,6 @@ +#ifndef PLATFORM_PLATFORM_H +#define PLATFORM_PLATFORM_H + +void boot(); + +#endif diff --git a/boot/simulator/Makefile b/boot/simulator/Makefile new file mode 100644 index 000000000..e2f218e22 --- /dev/null +++ b/boot/simulator/Makefile @@ -0,0 +1 @@ +objs += $(addprefix boot/simulator/, main.o) diff --git a/boot/simulator/main.c b/boot/simulator/main.c new file mode 100644 index 000000000..7a4fb5e80 --- /dev/null +++ b/boot/simulator/main.c @@ -0,0 +1,5 @@ +#include + +int main(int argc, char * argv[]) { + boot(); +} diff --git a/boot/stm32f429/Makefile b/boot/stm32f429/Makefile new file mode 100644 index 000000000..1daaf7035 --- /dev/null +++ b/boot/stm32f429/Makefile @@ -0,0 +1 @@ +objs += $(addprefix boot/stm32f429/, isr.o crt0.o) diff --git a/platform/stm32f429/boot/crt0.c b/boot/stm32f429/crt0.c similarity index 97% rename from platform/stm32f429/boot/crt0.c rename to boot/stm32f429/crt0.c index 8c900c142..e79cb9f20 100644 --- a/platform/stm32f429/boot/crt0.c +++ b/boot/stm32f429/crt0.c @@ -1,5 +1,6 @@ #include #include +#include extern char _data_section_start_flash; extern char _data_section_start_ram; @@ -7,8 +8,6 @@ extern char _data_section_end_ram; extern char _bss_section_start_ram; extern char _bss_section_end_ram; -void init(); - void abort() { // TODO: #ifdef NDEBUG, maybe trigger a reset? while (1) { @@ -32,7 +31,7 @@ void _start(void) { size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram); memset(&_bss_section_start_ram, 0, bssSectionLength); - init(); + boot(); abort(); } diff --git a/platform/stm32f429/boot/flash.ld b/boot/stm32f429/flash.ld similarity index 99% rename from platform/stm32f429/boot/flash.ld rename to boot/stm32f429/flash.ld index 3773a2e8e..9394f2082 100644 --- a/platform/stm32f429/boot/flash.ld +++ b/boot/stm32f429/flash.ld @@ -144,9 +144,9 @@ SECTIONS { } >SRAM .ccm_heap : { - _ccm_heap_start = .; + _liba_heap_start = .; . += LENGTH(CCM); - _ccm_heap_end = .; + _liba_heap_end = .; } >CCM .ccm_stack : { diff --git a/platform/stm32f429/boot/isr.c b/boot/stm32f429/isr.c similarity index 100% rename from platform/stm32f429/boot/isr.c rename to boot/stm32f429/isr.c diff --git a/platform/stm32f429/boot/isr.h b/boot/stm32f429/isr.h similarity index 100% rename from platform/stm32f429/boot/isr.h rename to boot/stm32f429/isr.h diff --git a/ion/Makefile b/ion/Makefile new file mode 100644 index 000000000..dc4bb21d6 --- /dev/null +++ b/ion/Makefile @@ -0,0 +1,3 @@ +SFLAGS += -Iion/include -DKD_CONFIG_H=1 +include ion/src/platform/$(PLATFORM)/Makefile +objs += $(addprefix ion/src/, ion.o) diff --git a/ion/README.txt b/ion/README.txt new file mode 100644 index 000000000..c8d78e42d --- /dev/null +++ b/ion/README.txt @@ -0,0 +1,3 @@ +ION is the hardware abstraction layer. It does I/O. + +It exposes a set of headers that are implemented for various hardwares (device, simulator) diff --git a/ion/include/ion.h b/ion/include/ion.h new file mode 100644 index 000000000..8ca589a87 --- /dev/null +++ b/ion/include/ion.h @@ -0,0 +1,18 @@ +#ifndef ION_ION_H +#define ION_ION_H + +#include + +void ion_init(); + +void ion_display_on(); +void ion_display_off(); + +extern void * ion_framebuffer_address; +extern uint16_t ion_framebuffer_width; +extern uint16_t ion_framebuffer_height; +extern uint8_t ion_framebuffer_bits_per_pixel; + +char ion_getchar(); + +#endif diff --git a/ion/include/kandinsky_config.h b/ion/include/kandinsky_config.h new file mode 100644 index 000000000..0de6a2c94 --- /dev/null +++ b/ion/include/kandinsky_config.h @@ -0,0 +1,3 @@ +#include +#define KD_FRAMEBUFFER_ADDRESS ion_framebuffer_address +#define KD_FRAMEBUFFER_WIDTH ion_framebuffer_width diff --git a/platform/fx92kbd/fx92kbd.c b/ion/src/drivers/fx92kbd/fx92kbd.c similarity index 100% rename from platform/fx92kbd/fx92kbd.c rename to ion/src/drivers/fx92kbd/fx92kbd.c diff --git a/platform/fx92kbd/fx92kbd.h b/ion/src/drivers/fx92kbd/fx92kbd.h similarity index 100% rename from platform/fx92kbd/fx92kbd.h rename to ion/src/drivers/fx92kbd/fx92kbd.h diff --git a/platform/ili9341/ili9341.c b/ion/src/drivers/ili9341/ili9341.c similarity index 100% rename from platform/ili9341/ili9341.c rename to ion/src/drivers/ili9341/ili9341.c diff --git a/platform/ili9341/ili9341.h b/ion/src/drivers/ili9341/ili9341.h similarity index 100% rename from platform/ili9341/ili9341.h rename to ion/src/drivers/ili9341/ili9341.h diff --git a/ion/src/ion.c b/ion/src/ion.c new file mode 100644 index 000000000..49ead2155 --- /dev/null +++ b/ion/src/ion.c @@ -0,0 +1,6 @@ +#include + +void * ion_framebuffer_address = 0; +uint16_t ion_framebuffer_width = 0; +uint16_t ion_framebuffer_height = 0; +uint8_t ion_framebuffer_bits_per_pixel = 0; diff --git a/ion/src/platform/simulator/Makefile b/ion/src/platform/simulator/Makefile new file mode 100644 index 000000000..b30e20f9f --- /dev/null +++ b/ion/src/platform/simulator/Makefile @@ -0,0 +1,2 @@ +objs += $(addprefix ion/src/platform/simulator/, init.o) +#objs += $(addprefix ion/src/drivers/, ili9341/ili9341.o fx92kbd/fx92kbd.o) diff --git a/ion/src/platform/simulator/init.c b/ion/src/platform/simulator/init.c new file mode 100644 index 000000000..2009fff08 --- /dev/null +++ b/ion/src/platform/simulator/init.c @@ -0,0 +1,4 @@ +#include + +void ion_init() { +} diff --git a/ion/src/platform/stm32f429/Makefile b/ion/src/platform/stm32f429/Makefile new file mode 100644 index 000000000..ce0795890 --- /dev/null +++ b/ion/src/platform/stm32f429/Makefile @@ -0,0 +1,2 @@ +objs += $(addprefix ion/src/platform/stm32f429/, platform.o init.o display.o init_kbd.o) +objs += $(addprefix ion/src/drivers/, ili9341/ili9341.o fx92kbd/fx92kbd.o) diff --git a/platform/stm32f429/init_lcd.c b/ion/src/platform/stm32f429/display.c similarity index 87% rename from platform/stm32f429/init_lcd.c rename to ion/src/platform/stm32f429/display.c index a000c3445..eb5f9cf54 100644 --- a/platform/stm32f429/init_lcd.c +++ b/ion/src/platform/stm32f429/display.c @@ -14,7 +14,7 @@ * SCL | PF7 | SPI clock * SDI/SDO | PF9 | SPI data * - * The entry point is init_lcd(); + * The entry point is init_display(); * * Some info regarding the built-in LCD panel of the STM32F429I Discovery: * -> The pin EXTC of the ili9341 is not connected to Vdd. It reads as "0", and @@ -25,39 +25,32 @@ * It doesn't seem right though, because some extended commands do work... */ -#include -#include "registers.h" -#include -#include +#include +#include "platform.h" +#include "registers/registers.h" +#include -extern char _framebuffer_start; -extern char _framebuffer_end; +void ion_display_on() { +} + +void ion_display_off() { +} static void init_spi_interface(); static void init_rgb_interface(); static void init_panel(); -static void check_framebuffer(); -void init_lcd() { +void init_display() { /* This routine is responsible for initializing the LCD panel. * Its interface with the outer world is the framebuffer: after execution of * this routine, everyone can expect to write to the LCD by writing to the * framebuffer. */ - Platform.framebuffer_width = 240; - Platform.framebuffer_height = 320; - Platform.framebuffer_bits_per_pixel = 8; - Platform.framebuffer_address = &_framebuffer_start; - init_spi_interface(); init_rgb_interface(); init_panel(); - -#ifndef NDEBUG - check_framebuffer(); -#endif } // SPI interface @@ -190,11 +183,11 @@ static void init_rgb_timings() { // seems to match our hardware. Here are the values of interest: int lcd_panel_hsync = 10; int lcd_panel_hbp = 20; - int lcd_panel_hadr = Platform.framebuffer_width; + int lcd_panel_hadr = ion_framebuffer_width; int lcd_panel_hfp = 10; int lcd_panel_vsync = 2; int lcd_panel_vbp = 2; - int lcd_panel_vadr = Platform.framebuffer_height; + int lcd_panel_vadr = ion_framebuffer_height; int lcd_panel_vfp = 4; // The LCD-TFT programmable synchronous timings are: @@ -275,13 +268,13 @@ static void init_rgb_layers() { LTDC_LPFCR(LTDC_LAYER1) = LTDC_PF_L8; - LTDC_LCFBAR(LTDC_LAYER1) = (uint32_t)Platform.framebuffer_address; + LTDC_LCFBAR(LTDC_LAYER1) = (uint32_t)ion_framebuffer_address; LTDC_LCFBLR(LTDC_LAYER1) = - LTDC_CFBLL(Platform.framebuffer_width + 3) | // Number of bytes per lines in the framebuffer. 240 * 4 (RGBA888). +3, per doc; - LTDC_CFBP(Platform.framebuffer_width); // Width of a line in bytes + LTDC_CFBLL(ion_framebuffer_width + 3) | // Number of bytes per lines in the framebuffer. 240 * 4 (RGBA888). +3, per doc; + LTDC_CFBP(ion_framebuffer_width); // Width of a line in bytes - LTDC_LCFBLNR(LTDC_LAYER1) = LTDC_CFBLNR(Platform.framebuffer_height); // Number of lines + LTDC_LCFBLNR(LTDC_LAYER1) = LTDC_CFBLNR(ion_framebuffer_height); // Number of lines // STEP 8 : Enable layer 1 // Don't enable color keying nor color look-up table @@ -304,11 +297,10 @@ static void gpio_c2_write(bool pin_state); static void gpio_d13_write(bool pin_state); static void init_panel() { - ili9341_t * panel = &(Platform.display); - panel->chip_select_pin_write = gpio_c2_write; - panel->data_command_pin_write = gpio_d13_write; - panel->spi_write = spi_5_write; - ili9341_initialize(panel); + Platform.display.chip_select_pin_write = gpio_c2_write; + Platform.display.data_command_pin_write = gpio_d13_write; + Platform.display.spi_write = spi_5_write; + ili9341_initialize(&(Platform.display)); } static void spi_5_write(char * data, size_t size) { @@ -330,11 +322,3 @@ void gpio_c2_write(bool pin_state) { void gpio_d13_write(bool pin_state) { REGISTER_SET_VALUE(GPIO_ODR(GPIOD), ODR(13), pin_state); } - -// Framebuffer checks - -static void check_framebuffer() { - assert(&_framebuffer_start == Platform.framebuffer_address); - char * fb_end = &_framebuffer_start + (Platform.framebuffer_width*Platform.framebuffer_height*Platform.framebuffer_bits_per_pixel/8); - assert(&_framebuffer_end == fb_end); -} diff --git a/ion/src/platform/stm32f429/display.h b/ion/src/platform/stm32f429/display.h new file mode 100644 index 000000000..02addf344 --- /dev/null +++ b/ion/src/platform/stm32f429/display.h @@ -0,0 +1 @@ +void init_display(); diff --git a/ion/src/platform/stm32f429/init.c b/ion/src/platform/stm32f429/init.c new file mode 100644 index 000000000..ab5fc1296 --- /dev/null +++ b/ion/src/platform/stm32f429/init.c @@ -0,0 +1,21 @@ +#include +#include "display.h" +#include "init_kbd.h" + +extern char _framebuffer_start; +extern char _framebuffer_end; + +void ion_init() { + ion_framebuffer_address = &_framebuffer_start; + ion_framebuffer_width = 240; + ion_framebuffer_height = 320; + ion_framebuffer_bits_per_pixel = 8; + +#if DEBUG + char * computed_framebuffer_end = ion_framebuffer_address + (ion_framebuffer_width*ion_framebuffer_height*ion_framebuffer_bits_per_pixel)/8; + assert(&_framebuffer_end == computed_framebuffer_end); +#endif + + init_kbd(); + init_display(); +} diff --git a/platform/stm32f429/init_heap.c b/ion/src/platform/stm32f429/init_heap.c similarity index 100% rename from platform/stm32f429/init_heap.c rename to ion/src/platform/stm32f429/init_heap.c diff --git a/platform/stm32f429/init_heap.h b/ion/src/platform/stm32f429/init_heap.h similarity index 100% rename from platform/stm32f429/init_heap.h rename to ion/src/platform/stm32f429/init_heap.h diff --git a/platform/stm32f429/init_kbd.c b/ion/src/platform/stm32f429/init_kbd.c similarity index 96% rename from platform/stm32f429/init_kbd.c rename to ion/src/platform/stm32f429/init_kbd.c index c5727a119..849139f77 100644 --- a/platform/stm32f429/init_kbd.c +++ b/ion/src/platform/stm32f429/init_kbd.c @@ -8,10 +8,11 @@ #include #include -#include "registers.h" +#include +#include "platform.h" +#include "registers/registers.h" #include "init_kbd.h" -#include -#include +#include // The row pins are driven high or low in software. static gpio_pin_t row_pins[] = { @@ -141,7 +142,7 @@ char charFromKey[] = { ' ', // FX92_KEY_NONE = 0, }; -char getc() { +char ion_getchar() { char character = ' '; while (character == ' ') { fx92kbd_key_t key = fx92kbd_getkey(&Platform.keyboard); diff --git a/platform/stm32f429/init_kbd.h b/ion/src/platform/stm32f429/init_kbd.h similarity index 100% rename from platform/stm32f429/init_kbd.h rename to ion/src/platform/stm32f429/init_kbd.h diff --git a/platform/platform.c b/ion/src/platform/stm32f429/platform.c similarity index 100% rename from platform/platform.c rename to ion/src/platform/stm32f429/platform.c diff --git a/ion/src/platform/stm32f429/platform.h b/ion/src/platform/stm32f429/platform.h new file mode 100644 index 000000000..e975ff406 --- /dev/null +++ b/ion/src/platform/stm32f429/platform.h @@ -0,0 +1,9 @@ +#include +#include + +typedef struct { + ili9341_t display; + fx92kbd_t keyboard; +} platform_t; + +extern platform_t Platform; diff --git a/platform/stm32f429/registers/gpio.h b/ion/src/platform/stm32f429/registers/gpio.h similarity index 100% rename from platform/stm32f429/registers/gpio.h rename to ion/src/platform/stm32f429/registers/gpio.h diff --git a/platform/stm32f429/registers/ltdc.h b/ion/src/platform/stm32f429/registers/ltdc.h similarity index 100% rename from platform/stm32f429/registers/ltdc.h rename to ion/src/platform/stm32f429/registers/ltdc.h diff --git a/platform/stm32f429/registers/rcc.h b/ion/src/platform/stm32f429/registers/rcc.h similarity index 100% rename from platform/stm32f429/registers/rcc.h rename to ion/src/platform/stm32f429/registers/rcc.h diff --git a/platform/stm32f429/registers.h b/ion/src/platform/stm32f429/registers/registers.h similarity index 86% rename from platform/stm32f429/registers.h rename to ion/src/platform/stm32f429/registers/registers.h index cd4700c48..7fa316b37 100644 --- a/platform/stm32f429/registers.h +++ b/ion/src/platform/stm32f429/registers/registers.h @@ -10,10 +10,10 @@ #define BIT_MASK(high, low) ((((uint32_t)1<<((high)-(low)+1))-1)<<(low)) #define BIT_VALUE(value, high, low) (((value)<<(low))&BIT_MASK(high, low)) -#include "registers/rcc.h" -#include "registers/gpio.h" -#include "registers/spi.h" -#include "registers/ltdc.h" +#include "rcc.h" +#include "gpio.h" +#include "spi.h" +#include "ltdc.h" #define REGISTER_FIELD_MASK(field) (BIT_MASK(HIGH_BIT_##field,LOW_BIT_##field)) #define REGISTER_FIELD_VALUE(field, value) (BIT_VALUE(value,HIGH_BIT_##field,LOW_BIT_##field)) diff --git a/platform/stm32f429/registers/spi.h b/ion/src/platform/stm32f429/registers/spi.h similarity index 100% rename from platform/stm32f429/registers/spi.h rename to ion/src/platform/stm32f429/registers/spi.h diff --git a/kandinsky/src/config.h b/kandinsky/src/config.h index 7eebf244a..2c9e6c84d 100644 --- a/kandinsky/src/config.h +++ b/kandinsky/src/config.h @@ -1,10 +1,28 @@ #ifndef KANDINSKY_CONFIG_H #define KANDINSKY_CONFIG_H +#ifdef KD_CONFIG_H +#include "kandinsky_config.h" +#endif + +#ifndef KD_FRAMEBUFFER_ADDRESS +#error Kandinsky expects KD_FRAMEBUFFER_ADDRESS to be defined to the start of the framebuffer +#endif + +#ifndef KD_FRAMEBUFFER_WIDTH +#error Kandinsky expects KD_FRAMEBUFFER_WIDTH to be defined to the width of the framebuffer +#endif + +// FIXME: #define this +typedef uint8_t KDColor; + +/* #include #define KD_FRAMEBUFFER_ADDRESS Platform.framebuffer_address #define KD_FRAMEBUFFER_WIDTH Platform.framebuffer_width typedef uint8_t KDColor; +*/ + #endif diff --git a/liba/Makefile b/liba/Makefile index 7893b8a3d..6c7e541c7 100644 --- a/liba/Makefile +++ b/liba/Makefile @@ -2,4 +2,4 @@ SFLAGS += -Iliba/include liba/src/external/sqlite/mem5.o: CFLAGS += -w -objs += $(addprefix liba/src/, assert.o errno.o malloc.o memcpy.o memset.o strlen.o external/sqlite/mem5.o) +objs += $(addprefix liba/src/, assert.o errno.o liba.o malloc.o memcpy.o memset.o strlen.o external/sqlite/mem5.o) diff --git a/liba/README.txt b/liba/README.txt index dd6b21be9..d7b5175f5 100644 --- a/liba/README.txt +++ b/liba/README.txt @@ -1,5 +1,7 @@ liba is an adhoc libc. +Warning: you must call "liba_init()" before using liba. + We need a very small subset of the functionality provided by the standard C library. We could use an available libc implementation, but those are usually way to large and may have problematic licenses. diff --git a/liba/include/liba.h b/liba/include/liba.h new file mode 100644 index 000000000..58b5bfbf4 --- /dev/null +++ b/liba/include/liba.h @@ -0,0 +1,6 @@ +#ifndef LIBA_LIBA_H +#define LIBA_LIBA_H + +void liba_init(); + +#endif diff --git a/liba/src/liba.c b/liba/src/liba.c new file mode 100644 index 000000000..d927650f9 --- /dev/null +++ b/liba/src/liba.c @@ -0,0 +1,23 @@ +#include +#include + +int memsys5Init(void *NotUsed); + +heap_config_t HeapConfig; + +extern char _liba_heap_start; +extern char _liba_heap_end; + +static void liba_init_heap() { + HeapConfig.nHeap = (&_liba_heap_end - &_liba_heap_start); + HeapConfig.pHeap = &_liba_heap_start; + HeapConfig.mnReq = 1; + HeapConfig.bMemstat = 0; + HeapConfig.xLog = 0; + + memsys5Init(0); +} + +void liba_init() { + liba_init_heap(); +} diff --git a/liba/src/malloc.c b/liba/src/malloc.c index 56534e3bd..9c127c029 100644 --- a/liba/src/malloc.c +++ b/liba/src/malloc.c @@ -1,6 +1,8 @@ #include #include +#include +// Memsys headers cannot be included easily so we rewrite them here void memsys5FreeUnsafe(void *pOld); void * memsys5MallocUnsafe(int nByte); void * memsys5Realloc(void *pPrior, int nBytes); diff --git a/platform/Makefile b/platform/Makefile deleted file mode 100644 index 175277dc8..000000000 --- a/platform/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -objs += platform/platform.o -objs += $(addprefix platform/stm32f429/, boot/isr.o boot/crt0.o init.o init_lcd.o init_heap.o init_kbd.o) -objs += platform/ili9341/ili9341.o -objs += platform/fx92kbd/fx92kbd.o diff --git a/platform/platform.h b/platform/platform.h deleted file mode 100644 index 41b668ba0..000000000 --- a/platform/platform.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PLATFORM_H -#define PLATFORM_H - -#include -#include - -typedef struct { - int framebuffer_width; - int framebuffer_height; - int framebuffer_bits_per_pixel; - char * framebuffer_address; - fx92kbd_t keyboard; - ili9341_t display; -} platform_t; - -extern platform_t Platform; - -#endif diff --git a/platform/stm32f429/init.c b/platform/stm32f429/init.c deleted file mode 100644 index 15955cd9f..000000000 --- a/platform/stm32f429/init.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "init_lcd.h" -#include "init_heap.h" -#include "init_kbd.h" -#include - -void init() { - init_kbd(); - init_lcd(); - init_heap(); - hello(); -} diff --git a/platform/stm32f429/init_lcd.h b/platform/stm32f429/init_lcd.h deleted file mode 100644 index 56de91d0d..000000000 --- a/platform/stm32f429/init_lcd.h +++ /dev/null @@ -1 +0,0 @@ -void init_lcd(); diff --git a/src/hello.cpp b/src/hello.cpp index e83c61b19..a01a0c9a1 100644 --- a/src/hello.cpp +++ b/src/hello.cpp @@ -2,12 +2,11 @@ extern "C" { #include "hello.h" #include #include -#include +#include } #include - void hello() { /*char letter = 'Z'; @@ -62,7 +61,7 @@ void hello() { int index = 0; while (1) { - char character = getc(); + char character = ion_getchar(); if (character == 'X') { input[index] = 0; index = 0;