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 <developer@gorgoz.org>
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5161
38d2e660-2303-0410-9eaa-
f027e97ec537
*
*
* \author Luca Ottaviano <lottaviano@develer.com>
+ * \author Onno <developer@gorgoz.org>
*
* \brief AVR XMega initialization routine.
* notest:all
#include <cfg/macros.h>
#include <avr/io.h>
-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;
}