From: lottaviano Date: Thu, 13 Oct 2011 16:43:13 +0000 (+0000) Subject: Fix xmega initialization procedure. X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=350223735c1c49b541d69f283fb71782ce374eea;p=bertos.git Fix xmega initialization procedure. When compiled and linked the method __init() in the init_xmega.c file is generated as the code for the reset vector (vector 0). As there is also a return instruction generated, it will return from vector 0 and then execute vector 1, which is not implemented, so the reset vector is called..... So the other code does not get executed at all. Assigning the __init() method to other sections does not work either. The same problem persists. I implemented a solution which is two-fold: 1) I use the attribute "constructor" as according to the gcc domumentation (http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html) it should do exactly what we want: "The constructor attribute causes the function to be called automatically before execution enters main ()" 2) This alone did not solve the issue. I had to rename the methode to make it not get called by the reset vector so I renamed the methode to init_xmega. Signed-off-by: Onno git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5161 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/avr/hw/init_xmega.c b/bertos/cpu/avr/hw/init_xmega.c index cabde0f3..028fe051 100644 --- a/bertos/cpu/avr/hw/init_xmega.c +++ b/bertos/cpu/avr/hw/init_xmega.c @@ -32,6 +32,7 @@ * * * \author Luca Ottaviano + * \author Onno * * \brief AVR XMega initialization routine. * notest:all @@ -39,12 +40,12 @@ #include #include -void __init(void) NAKED __attribute__ ((section (".init3"))); +void init_xmega(void) NAKED __attribute__ ((constructor)); /* * Initialize all interrupt priorities present in AVR XMega CPU. */ -void __init(void) +void init_xmega(void) { PMIC.CTRL |= PMIC_LOLVLEX_bm | PMIC_MEDLVLEX_bm | PMIC_HILVLEX_bm; }