diff --git a/ports/stm8/README-SDCC b/ports/stm8/README-SDCC new file mode 100644 index 0000000..e69de29 diff --git a/ports/stm8/atomport-asm-sdcc.s b/ports/stm8/atomport-asm-sdcc.s new file mode 100644 index 0000000..e69de29 diff --git a/ports/stm8/atomport-private.h b/ports/stm8/atomport-private.h index 3b3d4c0..34e7aa1 100644 --- a/ports/stm8/atomport-private.h +++ b/ports/stm8/atomport-private.h @@ -64,13 +64,18 @@ #define INTERRUPT @far @interrupt @svlreg #elif defined (__IAR_SYSTEMS_ICC__) #define INTERRUPT __interrupt -#elif defined(__RCSTM8__) +#elif defined(__RCSTM8__) || defined(__SDCC_stm8) #define INTERRUPT #endif /* Function prototypes */ void archInitSystemTickTimer (void); +#ifndef __SDCC_stm8 INTERRUPT void TIM1_SystemTickISR (void); +#else +void TIM1_SystemTickISR (void) __interrupt(11); +#endif #endif /* __ATOM_PORT_PRIVATE_H */ + diff --git a/ports/stm8/atomport.c b/ports/stm8/atomport.c index 5d7df1b..6f9c79f 100644 --- a/ports/stm8/atomport.c +++ b/ports/stm8/atomport.c @@ -293,6 +293,8 @@ void archInitSystemTickTimer ( void ) INTERRUPT void TIM1_SystemTickISR (void) #if defined(__RCSTM8__) interrupt 11 +#elif defined(__SDCC_stm8) +__interrupt(11) #endif { /* Call the interrupt entry routine */ diff --git a/ports/stm8/atomport.h b/ports/stm8/atomport.h index 2063bfb..0371e38 100644 --- a/ports/stm8/atomport.h +++ b/ports/stm8/atomport.h @@ -84,6 +84,14 @@ #define CRITICAL_STORE unsigned char ccr #define CRITICAL_START() ccr = _getCC_(); _sim_() #define CRITICAL_END() _setCC_(ccr) + +/* SDCC: Use custom function */ +#elif defined(__SDCC_stm8) +uint8_t get_cc(void); +void set_cc(uint8_t); +#define CRITICAL_STORE uint8_t ccr +#define CRITICAL_START() ccr = get_cc(); __asm__("sim") +#define CRITICAL_END() set_cc(ccr) #endif /* Uncomment to enable stack-checking */ diff --git a/ports/stm8/sdcc.mak b/ports/stm8/sdcc.mak new file mode 100644 index 0000000..972e879 --- /dev/null +++ b/ports/stm8/sdcc.mak @@ -0,0 +1,107 @@ +KERNEL_DIR=../../kernel +TESTS_DIR=../../tests +PERIPHS_DIR=stm8s-periphs + +CC=sdcc +ASM=sdasstm8 +LINK=sdcc + +# CPU part number +PART=STM8S105 + +# Enable stack-checking +STACK_CHECK=true + +# Directory for built objects +BUILD_DIR=build-sdcc + +# Port/application object files +APP_OBJECTS = atomport.rel tests-main.rel uart.rel +APP_ASM_OBJECTS = atomport-asm-sdcc.rel + +# STM8S Peripheral driver object files +PERIPH_OBJECTS = stm8s_gpio.rel stm8s_tim1.rel stm8s_clk.rel stm8s_uart2.rel + +# Kernel object files +KERNEL_OBJECTS = atomkernel.rel atomsem.rel atommutex.rel atomtimer.rel atomqueue.rel + +# Collection of built objects (excluding test applications) +ALL_OBJECTS = $(APP_OBJECTS) $(APP_ASM_OBJECTS) $(PERIPH_OBJECTS) $(KERNEL_OBJECTS) +BUILT_OBJECTS = $(patsubst %,$(BUILD_DIR)/%,$(ALL_OBJECTS)) + +# Test object files (dealt with separately as only one per application build) +TEST_OBJECTS = $(notdir $(patsubst %.c,%.rel,$(wildcard $(TESTS_DIR)/*.c))) + +# Target application filenames (.elf) for each test object +TEST_HEXS = $(patsubst %.rel,%.ihx,$(TEST_OBJECTS)) +TEST_ELFS = $(patsubst %.rel,%.elf,$(TEST_OBJECTS)) + +# Search build/output directory for dependencies +vpath %.rel .\$(BUILD_DIR) +vpath %.elf .\$(BUILD_DIR) +vpath %.hex .\$(BUILD_DIR) + +# Compiler/Assembler flags +CFLAGS= -mstm8 -c -D $(PART) --opt-code-size --max-allocs-per-node 300 +DBG_CFLAGS= -mstm8 -c -D $(PART) --opt-code-size --max-allocs-per-node 3000 +ASMFLAGS= -off +DBG_ASMFLAGS= -off +LINKFLAGS= -mstm8 +DBG_LINKFLAGS= -mstm8 + +# Enable stack-checking (disable if not required) +ifeq ($(STACK_CHECK),true) +CFLAGS += -D ATOM_STACK_CHECKING +DBG_CFLAGS += -D ATOM_STACK_CHECKING +endif + +################# +# Build targets # +################# + +# All tests +all: $(BUILD_DIR) $(TEST_HEXS) sdcc.mak + +# Make build/output directory +$(BUILD_DIR): + mkdir $(BUILD_DIR) + +# Test HEX files (one application build for each test) +$(TEST_HEXS): %.ihx: %.rel $(KERNEL_OBJECTS) $(PERIPH_OBJECTS) $(APP_OBJECTS) $(APP_ASM_OBJECTS) + $(LINK) $(BUILD_DIR)/$(notdir $<) $(BUILT_OBJECTS) $(LINKFLAGS) -o $(BUILD_DIR)/$@ + +# Test ELF files (one application build for each test) +$(TEST_ELFS): %.elf: %.rel $(KERNEL_OBJECTS) $(PERIPH_OBJECTS) $(APP_OBJECTS) $(APP_ASM_OBJECTS) + $(LINK) $(BUILD_DIR)/$(notdir $<) $(BUILT_OBJECTS) $(LINKFLAGS) --out-fmt-elf -o $(BUILD_DIR)/$@ + +# Kernel objects builder +$(KERNEL_OBJECTS): %.rel: $(KERNEL_DIR)/%.c + $(CC) $< $(CFLAGS) -I . -I $(PERIPHS_DIR) -o $(BUILD_DIR)/$*.rel + +# Test objects builder +$(TEST_OBJECTS): %.rel: $(TESTS_DIR)/%.c + $(CC) $< $(CFLAGS) -I . -I $(KERNEL_DIR) -I $(PERIPHS_DIR) -o $(BUILD_DIR)/$*.rel + +# Peripheral objects builder +$(PERIPH_OBJECTS): %.rel: $(PERIPHS_DIR)/%.c + $(CC) $< $(CFLAGS) -I . -I $(PERIPHS_DIR) -o $(BUILD_DIR)/$*.rel + +# Application C objects builder +$(APP_OBJECTS): %.rel: ./%.c + $(CC) $< $(CFLAGS) -I . -I $(KERNEL_DIR) -I $(TESTS_DIR) -I $(PERIPHS_DIR) -o $(BUILD_DIR)/$*.rel + +# Application asm objects builder +$(APP_ASM_OBJECTS): %.rel: ./%.s + $(ASM) $(ASMFLAGS) $(BUILD_DIR)/$(notdir $@) $< + +# Clean +clean: + rm -f *.o *.elf *.map *.hex *.bin *.lst *.stm8 *.s19 + rm -rf doxygen-kernel + rm -rf doxygen-stm8 + rm -rf build-sdcc + +doxygen: + doxygen $(KERNEL_DIR)/Doxyfile + doxygen ./Doxyfile + diff --git a/ports/stm8/stm8s-periphs/stm8s.h b/ports/stm8/stm8s-periphs/stm8s.h index 8642bf9..d2190bd 100644 --- a/ports/stm8/stm8s-periphs/stm8s.h +++ b/ports/stm8/stm8s-periphs/stm8s.h @@ -30,15 +30,23 @@ #if defined(__CSMC__) #undef _RAISONANCE_ #undef _IAR_SYSTEMS_ + #undef _SDCC_ #define _COSMIC_ #elif defined(__RCST7__) #undef _COSMIC_ #undef _IAR_SYSTEMS_ + #undef _SDCC_ #define _RAISONANCE_ #elif defined(__IAR_SYSTEMS_ICC__) #undef _COSMIC_ #undef _RAISONANCE_ + #undef _SDCC_ #define _IAR_SYSTEMS_ +#elif defined(__SDCC_stm8) + #undef _COSMIC_ + #undef _RAISONANCE_ + #undef _IAR_SYSTEMS_ + #define _SDCC_ #else #error "Unsupported Compiler!" /* Compiler defines not found */ #endif @@ -90,6 +98,11 @@ #define __CONST const #endif +#ifdef _SDCC_ + #define NEAR + #define __CONST const +#endif + #ifdef PointerAttr_Far #define PointerAttr FAR #else /* PointerAttr_Near */