From 928bf6b6c13bf8de81ac78499a56830b9b04bdfb Mon Sep 17 00:00:00 2001 From: Joakim Eriksson Date: Wed, 6 Apr 2011 20:08:48 +0200 Subject: [PATCH] fixed cpu/msp430 for compilation with IAR compiler --- cpu/msp430/Makefile.msp430 | 44 +++++++++++++++++++++++++++++++++++--- cpu/msp430/dev/hwconf.h | 7 ++++++ cpu/msp430/dev/lpm.h | 1 - cpu/msp430/flash.c | 8 ++++++- cpu/msp430/msp430def.h | 4 ++++ cpu/msp430/mtarch.c | 10 +++++++++ cpu/msp430/mtarch.h | 2 +- cpu/msp430/rtimer-arch.c | 6 ++++++ cpu/msp430/rtimer-arch.h | 1 - 9 files changed, 76 insertions(+), 7 deletions(-) diff --git a/cpu/msp430/Makefile.msp430 b/cpu/msp430/Makefile.msp430 index 599a7cf01..870e3137f 100644 --- a/cpu/msp430/Makefile.msp430 +++ b/cpu/msp430/Makefile.msp430 @@ -25,6 +25,40 @@ CONTIKI_TARGET_SOURCEFILES += $(MSP430) \ CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) ### Compiler definitions +ifdef IAR +CC = icc430 +LD = xlink +AS = iasm430 +AR = xar +OBJCOPY = ielftool +STRIP = strip + + +ifndef IAR_PATH +# This works with cygwin... +IAR_BIN_PATH = $(shell dirname `which $(CC)`) +IAR_PATH_C = $(shell dirname $(IAR_BIN_PATH)) +IAR_PATH = $(shell cygpath -m $(IAR_PATH_C)) +endif + +CFLAGSNO = --dlib_config $(IAR_PATH)/LIB/DLIB/dl430xlfn.h -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X $(CFLAGSWERROR) --data_model large --double=32 +CUSTOM_RULE_C_TO_O = 1 +%.o: %.c + $(CC) $(CFLAGS) $< -o $@ + +CUSTOM_RULE_C_TO_OBJECTDIR_O = 1 +$(OBJECTDIR)/%.o: %.c + $(CC) $(CFLAGS) $< -o $@ +# @$(FINALIZE_DEPENDENCY) +CUSTOM_RULE_C_TO_CO = 1 +%.co: %.c + $(CC) $(CFLAGS) -DAUTOSTART_ENABLE $< -o $@ + +AROPTS = -o +LDFLAGS += -B $(IAR_PATH)/lib/dlib/dl430xlfn.r43 -f $(IAR_PATH)/config/lnk430f5437.xcl -l contiki-$(TARGET).map -Fintel-extended -s __program_start + +else +GCC = 1 CC = msp430-gcc LD = msp430-gcc AS = msp430-as @@ -33,12 +67,16 @@ NM = msp430-nm OBJCOPY = msp430-objcopy STRIP = msp430-strip BSL = msp430-bsl -ifdef WERROR -CFLAGSWERROR=-Werror -endif CFLAGSNO = -Wall -mmcu=$(MCU) -g $(CFLAGSWERROR) CFLAGS += $(CFLAGSNO) -Os LDFLAGS += -mmcu=$(MCU) -Wl,-Map=contiki-$(TARGET).map +endif + +ifdef WERROR +CFLAGSWERROR=-Werror +endif + +CFLAGS += $(CFLAGSNO) ### These flags can reduce the code size and RAM usage with up to 10% diff --git a/cpu/msp430/dev/hwconf.h b/cpu/msp430/dev/hwconf.h index 34d850f06..9c764c5b9 100644 --- a/cpu/msp430/dev/hwconf.h +++ b/cpu/msp430/dev/hwconf.h @@ -35,7 +35,14 @@ #include "sys/cc.h" +#ifdef __GNUC__ #include +#include +#endif + +#ifdef __IAR_SYSTEMS_ICC__ +#include +#endif #define HWCONF_PIN(name, port, bit) \ static CC_INLINE void name##_SELECT() {P##port##SEL &= ~(1 << bit);} \ diff --git a/cpu/msp430/dev/lpm.h b/cpu/msp430/dev/lpm.h index b921aaf59..f68d7b207 100644 --- a/cpu/msp430/dev/lpm.h +++ b/cpu/msp430/dev/lpm.h @@ -33,7 +33,6 @@ #ifndef __LPM_H__ #define __LPM_H__ -#include #include "contiki-conf.h" #ifdef LPM_CONF_ON diff --git a/cpu/msp430/flash.c b/cpu/msp430/flash.c index 50ff315a2..febe777d1 100644 --- a/cpu/msp430/flash.c +++ b/cpu/msp430/flash.c @@ -35,9 +35,15 @@ * */ -#include +#include "contiki.h" +#ifdef __IAR_SYSTEMS_ICC__ +#include +#else +#include #include #include +#endif + #include "dev/flash.h" #include "dev/watchdog.h" diff --git a/cpu/msp430/msp430def.h b/cpu/msp430/msp430def.h index 77bc48999..ca2a7b4f6 100644 --- a/cpu/msp430/msp430def.h +++ b/cpu/msp430/msp430def.h @@ -69,7 +69,11 @@ void splx_(spl_t); spl_t splhigh_(void); #define splhigh() splhigh_() +#ifdef __IAR_SYSTEMS_ICC__ +#define splx(sr) sr = __get_SR_register() +#else #define splx(sr) __asm__ __volatile__("bis %0, r2" : : "r" (sr)) +#endif /* Workaround for bug in msp430-gcc compiler */ #if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND diff --git a/cpu/msp430/mtarch.c b/cpu/msp430/mtarch.c index 0a184ab2f..59e9f0694 100644 --- a/cpu/msp430/mtarch.c +++ b/cpu/msp430/mtarch.c @@ -34,6 +34,10 @@ #include #include "sys/mt.h" +#ifdef __IAR_SYSTEMS_ICC__ +#define __asm__ asm +#endif + static unsigned short *sptmp; static struct mtarch_thread *running; @@ -97,8 +101,14 @@ sw(void) __asm__("push r14"); __asm__("push r15"); +#ifdef __IAR_SYSTEMS_ICC__ +/* use IAR intrinsic functions */ + running->sp = (unsigned short *) __get_SP_register(); + __set_SP_register((unsigned short) sptmp); +#else __asm__("mov.w r1,%0" : "=r" (running->sp)); __asm__("mov.w %0,r1" : : "m" (sptmp)); +#endif __asm__("pop r15"); __asm__("pop r14"); diff --git a/cpu/msp430/mtarch.h b/cpu/msp430/mtarch.h index fd9cc9557..68913d866 100644 --- a/cpu/msp430/mtarch.h +++ b/cpu/msp430/mtarch.h @@ -39,7 +39,7 @@ struct mtarch_thread { unsigned short stack[MTARCH_STACKSIZE]; unsigned short *sp; void *data; - void *function; + void (* function)(void *); }; struct mt_thread; diff --git a/cpu/msp430/rtimer-arch.c b/cpu/msp430/rtimer-arch.c index 8f2fc49fa..f60dd59e5 100644 --- a/cpu/msp430/rtimer-arch.c +++ b/cpu/msp430/rtimer-arch.c @@ -38,8 +38,14 @@ * Adam Dunkels */ +#ifdef __GNUC__ #include #include +#endif + +#ifdef __IAR_SYSTEMS_ICC__ +#include +#endif #include "sys/energest.h" #include "sys/rtimer.h" diff --git a/cpu/msp430/rtimer-arch.h b/cpu/msp430/rtimer-arch.h index 52c96502c..d90d1e437 100644 --- a/cpu/msp430/rtimer-arch.h +++ b/cpu/msp430/rtimer-arch.h @@ -41,7 +41,6 @@ #ifndef __RTIMER_ARCH_H__ #define __RTIMER_ARCH_H__ -#include #include "sys/rtimer.h" #define RTIMER_ARCH_SECOND (4096U*8)