diff --git a/Makefile b/Makefile index cce919a53..b79fd1d53 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ include Makefile.$(PLATFORM) ifndef USE_LIBA $(error Makefile.PLATFORM should define USE_LIBA) endif -SFLAGS += -DPLATFORM=$(PLATFORM) -DUSE_LIBA=$(USE_LIBA) +SFLAGS += -DPLATFORM=$(PLATFORM) # Flags - Header search path SFLAGS += -Ilib -I. @@ -77,6 +77,7 @@ endif include ion/Makefile include kandinsky/Makefile include poincare/Makefile +include app/Makefile # Quiz should be included at the end include quiz/Makefile diff --git a/app/Makefile b/app/Makefile new file mode 100644 index 000000000..c864d58b8 --- /dev/null +++ b/app/Makefile @@ -0,0 +1,2 @@ +objs += $(addprefix app/, app.o) +app.elf: app/app.o diff --git a/src/hello.cpp b/app/app.cpp similarity index 95% rename from src/hello.cpp rename to app/app.cpp index 55450534a..961dde1a2 100644 --- a/src/hello.cpp +++ b/app/app.cpp @@ -1,5 +1,4 @@ extern "C" { -#include "hello.h" #include #include #include @@ -7,7 +6,7 @@ extern "C" { #include -void hello() { +void ion_app() { KDDrawString("Hello, world!", (KDPoint){.x = 10, .y = 10}); diff --git a/src/blinky.c b/app/blinky.c similarity index 100% rename from src/blinky.c rename to app/blinky.c diff --git a/src/freertos_blinky.c b/app/freertos_blinky.c similarity index 100% rename from src/freertos_blinky.c rename to app/freertos_blinky.c diff --git a/src/spi.c b/app/spi.c similarity index 100% rename from src/spi.c rename to app/spi.c diff --git a/ion/include/ion.h b/ion/include/ion.h index b81e0d9ff..15687472d 100644 --- a/ion/include/ion.h +++ b/ion/include/ion.h @@ -4,7 +4,13 @@ #include #include -void ion_init(); +/* ION is not your regular library. It is a library you link against, but it + * will take care of configuring the whole environment for you. In POSIX terms, + * ION will implement the "main" function. + * Don't worry though, once all its initialization will be performed, ION will + * jump to your code at ion_app, which you have to implement yourself. */ + +void ion_app(); void ion_display_on(); void ion_display_off(); diff --git a/ion/src/device/Makefile b/ion/src/device/Makefile index 614e5999c..a27296c79 100644 --- a/ion/src/device/Makefile +++ b/ion/src/device/Makefile @@ -1,3 +1,4 @@ include ion/src/device/boot/Makefile -objs += $(addprefix ion/src/device/, init.o display.o framebuffer.o keyboard.o display/dma.o display/gpio.o display/spi.o) -objs += $(addprefix ion/drivers/, st7586/st7586.o) +objs += $(addprefix ion/src/device/, init.o) +objs += $(addprefix ion/src/device/display/, display.o dma.o framebuffer.o gpio.o spi.o st7586.o) +objs += $(addprefix ion/src/device/keyboard/, keyboard.o) diff --git a/ion/src/device/boot/crt0.c b/ion/src/device/boot/crt0.c index 8e909b070..338ed235c 100644 --- a/ion/src/device/boot/crt0.c +++ b/ion/src/device/boot/crt0.c @@ -1,6 +1,7 @@ #include #include -#include "../../shared/boot/boot.h" +#include +#include "../init.h" extern char _data_section_start_flash; extern char _data_section_start_ram; @@ -8,14 +9,6 @@ extern char _data_section_end_ram; extern char _bss_section_start_ram; extern char _bss_section_end_ram; -#define CPACR (*(volatile uint32_t *)(0xE000ED88)) - -void enable_fpu() { - // http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/BABDBFBJ.html - CPACR |= (0xF << 20); // Set the bits 20-23 to enable CP10 and CP11 coprocessors - // FIXME: The pipeline should be flushed at this point -} - void abort() { // TODO: #ifdef NDEBUG, maybe trigger a reset? while (1) { @@ -39,9 +32,9 @@ void _start(void) { size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram); memset(&_bss_section_start_ram, 0, bssSectionLength); - enable_fpu(); + init_platform(); - boot(); + ion_app(); abort(); } diff --git a/ion/src/device/display.h b/ion/src/device/display.h deleted file mode 100644 index 02addf344..000000000 --- a/ion/src/device/display.h +++ /dev/null @@ -1 +0,0 @@ -void init_display(); diff --git a/ion/src/device/display.c b/ion/src/device/display/display.c similarity index 89% rename from ion/src/device/display.c rename to ion/src/device/display/display.c index e274c95c9..61a5c9e40 100644 --- a/ion/src/device/display.c +++ b/ion/src/device/display/display.c @@ -20,14 +20,13 @@ #include #include -#include "display/gpio.h" -#include "display/spi.h" -#include "display/dma.h" +#include "../registers/registers.h" +#include "gpio.h" +#include "spi.h" +#include "dma.h" #include "framebuffer.h" -#include "registers/registers.h" -#include -#include "display/dma.h" +#include "st7586.h" static st7586_t * sDisplayController = NULL; diff --git a/ion/src/device/display/display.h b/ion/src/device/display/display.h new file mode 100644 index 000000000..9d2b4d272 --- /dev/null +++ b/ion/src/device/display/display.h @@ -0,0 +1,6 @@ +#ifndef ION_DEVICE_DISPLAY_H +#define ION_DEVICE_DISPLAY_H + +void init_display(); + +#endif diff --git a/ion/src/device/display/dma.c b/ion/src/device/display/dma.c index 65b91260f..9a3ac29e8 100644 --- a/ion/src/device/display/dma.c +++ b/ion/src/device/display/dma.c @@ -1,5 +1,5 @@ #include "../registers/registers.h" -#include "../framebuffer.h" +#include "framebuffer.h" // DMA 1, channel 0, stream 4 = SPI2_TX #define LCD_DMA_CHANNEL 0 diff --git a/ion/src/device/framebuffer.c b/ion/src/device/display/framebuffer.c similarity index 100% rename from ion/src/device/framebuffer.c rename to ion/src/device/display/framebuffer.c diff --git a/ion/src/device/framebuffer.h b/ion/src/device/display/framebuffer.h similarity index 100% rename from ion/src/device/framebuffer.h rename to ion/src/device/display/framebuffer.h diff --git a/ion/drivers/st7586/st7586.c b/ion/src/device/display/st7586.c similarity index 100% rename from ion/drivers/st7586/st7586.c rename to ion/src/device/display/st7586.c diff --git a/ion/drivers/st7586/st7586.h b/ion/src/device/display/st7586.h similarity index 88% rename from ion/drivers/st7586/st7586.h rename to ion/src/device/display/st7586.h index 58242c6f4..38c1cf332 100644 --- a/ion/drivers/st7586/st7586.h +++ b/ion/src/device/display/st7586.h @@ -1,5 +1,5 @@ -#ifndef PLATFORM_ST7586_H -#define PLATFORM_ST7586_H 1 +#ifndef ION_DEVICE_DISPLAY_ST7586_H +#define ION_DEVICE_DISPLAY_ST7586_H #include #include @@ -18,4 +18,5 @@ typedef struct { void st7586_initialize(st7586_t * controller); void st7586_set_display_area(st7586_t * controller, uint16_t x_start, uint16_t x_length, uint16_t y_start, uint16_t y_length); void st7586_enable_frame_data_upload(st7586_t * controller); + #endif diff --git a/ion/src/device/init.c b/ion/src/device/init.c index 569b22fe2..e528b7402 100644 --- a/ion/src/device/init.c +++ b/ion/src/device/init.c @@ -1,22 +1,23 @@ #include #include -#include "display.h" -#include "keyboard.h" +#include "init.h" +#include "display/display.h" +#include "keyboard/keyboard.h" -//#extern char _framebuffer_end; +#define CPACR (*(volatile uint32_t *)(0xE000ED88)) -void ion_init() { - /* -#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 -*/ +void enable_fpu() { + // http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/BABDBFBJ.html + CPACR |= (0xF << 20); // Set the bits 20-23 to enable CP10 and CP11 coprocessors + // FIXME: The pipeline should be flushed at this point +} +void init_platform() { + enable_fpu(); init_keyboard(); init_display(); } void ion_sleep() { - // FIXME + // FIXME: Do something, and also move this function to its own file } diff --git a/ion/src/device/init.h b/ion/src/device/init.h new file mode 100644 index 000000000..fd72445cb --- /dev/null +++ b/ion/src/device/init.h @@ -0,0 +1,6 @@ +#ifndef ION_DEVICE_PLATFORM_INIT_H +#define ION_DEVICE_PLATFORM_INIT_H + +void init_platform(); + +#endif diff --git a/ion/src/device/keyboard.h b/ion/src/device/keyboard.h deleted file mode 100644 index 7726a3c48..000000000 --- a/ion/src/device/keyboard.h +++ /dev/null @@ -1 +0,0 @@ -void init_keyboard(); diff --git a/ion/src/device/keyboard.c b/ion/src/device/keyboard/keyboard.c similarity index 98% rename from ion/src/device/keyboard.c rename to ion/src/device/keyboard/keyboard.c index ef183402b..7da05f06f 100644 --- a/ion/src/device/keyboard.c +++ b/ion/src/device/keyboard/keyboard.c @@ -35,7 +35,7 @@ */ #include -#include "registers/registers.h" +#include "../registers/registers.h" // We'll make the assertion that the row and column pins are contiguous #define ROW_PIN_START 0 diff --git a/ion/src/device/keyboard/keyboard.h b/ion/src/device/keyboard/keyboard.h new file mode 100644 index 000000000..2e78d677d --- /dev/null +++ b/ion/src/device/keyboard/keyboard.h @@ -0,0 +1,6 @@ +#ifndef ION_DEVICE_KEYBOARD_H +#define ION_DEVICE_KEYBOARD_H + +void init_keyboard(); + +#endif diff --git a/ion/src/shared/Makefile b/ion/src/shared/Makefile new file mode 100644 index 000000000..cc8875e25 --- /dev/null +++ b/ion/src/shared/Makefile @@ -0,0 +1 @@ +objs += $(addprefix ion/src/shared/, keyboard.o) diff --git a/ion/src/shared/boot/boot.c b/ion/src/shared/boot/boot.c deleted file mode 100644 index cdb48d0ae..000000000 --- a/ion/src/shared/boot/boot.c +++ /dev/null @@ -1,14 +0,0 @@ -#if USE_LIBA -#include -#endif - -#include -#include - -void boot() { -#if USE_LIBA - liba_init(); -#endif - ion_init(); - hello(); -} diff --git a/ion/src/shared/boot/boot.h b/ion/src/shared/boot/boot.h deleted file mode 100644 index 480d9736e..000000000 --- a/ion/src/shared/boot/boot.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef PLATFORM_PLATFORM_H -#define PLATFORM_PLATFORM_H - -void boot(); - -#endif diff --git a/liba/Makefile b/liba/Makefile index 6c7e541c7..7893b8a3d 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 liba.o malloc.o memcpy.o memset.o strlen.o external/sqlite/mem5.o) +objs += $(addprefix liba/src/, assert.o errno.o malloc.o memcpy.o memset.o strlen.o external/sqlite/mem5.o) diff --git a/liba/include/liba.h b/liba/include/liba.h deleted file mode 100644 index 58b5bfbf4..000000000 --- a/liba/include/liba.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef LIBA_LIBA_H -#define LIBA_LIBA_H - -void liba_init(); - -#endif diff --git a/liba/src/liba.c b/liba/src/liba.c deleted file mode 100644 index d927650f9..000000000 --- a/liba/src/liba.c +++ /dev/null @@ -1,23 +0,0 @@ -#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 9c127c029..ce92c4b44 100644 --- a/liba/src/malloc.c +++ b/liba/src/malloc.c @@ -2,7 +2,25 @@ #include #include +extern char _liba_heap_start; +extern char _liba_heap_end; + +heap_config_t HeapConfig = { + .nHeap = 0 +}; + +static void configure_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); +} + // Memsys headers cannot be included easily so we rewrite them here +int memsys5Init(void *NotUsed); void memsys5FreeUnsafe(void *pOld); void * memsys5MallocUnsafe(int nByte); void * memsys5Realloc(void *pPrior, int nBytes); @@ -16,6 +34,9 @@ void free(void *ptr) { void * malloc(size_t size) { void * p = NULL; + if (HeapConfig.nHeap == 0) { + configure_heap(); + } if (size > 0) { p = memsys5MallocUnsafe(memsys5Roundup(size)); } diff --git a/src/hello.h b/src/hello.h deleted file mode 100644 index 9bb085a0d..000000000 --- a/src/hello.h +++ /dev/null @@ -1 +0,0 @@ -void hello();