aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPerry Hung <iperry@alum.mit.edu>2010-06-25 21:47:27 -0400
committerPerry Hung <iperry@alum.mit.edu>2010-06-25 21:47:27 -0400
commit2dd4b9db68c15c3be477688b215244c5a5c2ff11 (patch)
tree8bccadfadbd22b4a1e1bae7d8d49da330b6e383c
parent6f82321248c2482784ce5a5e0715b62909d1ab76 (diff)
downloadlibrambutan-2dd4b9db68c15c3be477688b215244c5a5c2ff11.tar.gz
librambutan-2dd4b9db68c15c3be477688b215244c5a5c2ff11.zip
Call init() before static constructors
Commit 70a18f96b6d55d23ce58ab40ffb61f172c8f6c73 forces init() to be called before any statically allocated object constructors for the IDE. This adds the change to the examples for users not using the IDE.
-rw-r--r--examples/blinky.cpp8
-rw-r--r--examples/debug-dtrrts.cpp10
-rw-r--r--examples/qa-slave-shield.cpp10
-rw-r--r--examples/spi_master.cpp21
-rw-r--r--examples/test-session.cpp9
5 files changed, 44 insertions, 14 deletions
diff --git a/examples/blinky.cpp b/examples/blinky.cpp
index e156bf2..b037a1f 100644
--- a/examples/blinky.cpp
+++ b/examples/blinky.cpp
@@ -42,8 +42,14 @@ void loop() {
delay(100);
}
-int main(void) {
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+ __attribute__(( constructor )) void premain() {
init();
+}
+
+int main(void)
+{
setup();
while (1) {
diff --git a/examples/debug-dtrrts.cpp b/examples/debug-dtrrts.cpp
index c85b342..f9f8b96 100644
--- a/examples/debug-dtrrts.cpp
+++ b/examples/debug-dtrrts.cpp
@@ -30,9 +30,14 @@ void loop() {
Serial2.println(usbGetRTS(), DEC);
}
-
-int main(void) {
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+ __attribute__(( constructor )) void premain() {
init();
+}
+
+int main(void)
+{
setup();
while (1) {
@@ -40,3 +45,4 @@ int main(void) {
}
return 0;
}
+
diff --git a/examples/qa-slave-shield.cpp b/examples/qa-slave-shield.cpp
index fcee9cf..b395cca 100644
--- a/examples/qa-slave-shield.cpp
+++ b/examples/qa-slave-shield.cpp
@@ -37,9 +37,14 @@ void loop() {
}
}
-
-int main(void) {
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+ __attribute__(( constructor )) void premain() {
init();
+}
+
+int main(void)
+{
setup();
while (1) {
@@ -47,3 +52,4 @@ int main(void) {
}
return 0;
}
+
diff --git a/examples/spi_master.cpp b/examples/spi_master.cpp
index 2b62c8d..9f6d81b 100644
--- a/examples/spi_master.cpp
+++ b/examples/spi_master.cpp
@@ -59,12 +59,19 @@ void loop() {
delay(1000);
}
-int main(void) {
- init();
- setup();
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+ __attribute__(( constructor )) void premain() {
+ init();
+}
+
+int main(void)
+{
+ setup();
- while (1) {
- loop();
- }
- return 0;
+ while (1) {
+ loop();
+ }
+ return 0;
}
+
diff --git a/examples/test-session.cpp b/examples/test-session.cpp
index 4f09591..9885ab3 100644
--- a/examples/test-session.cpp
+++ b/examples/test-session.cpp
@@ -555,8 +555,14 @@ void do_fast_gpio(void) {
gpio_write_bit(GPIOB_BASE, 5, 1); gpio_write_bit(GPIOB_BASE, 5, 0);
}
-int main(void) {
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+ __attribute__(( constructor )) void premain() {
init();
+}
+
+int main(void)
+{
setup();
while (1) {
@@ -564,4 +570,3 @@ int main(void) {
}
return 0;
}
-