Modified call-before-main mechanism

Added a new function (mbed_sdk_init) that can be used by the SDK itself to
do initializations before main() is called.
pull/159/merge
Bogdan Marinescu 2014-01-31 11:39:31 +02:00
parent 74409cbd59
commit 2665d5bac4
2 changed files with 11 additions and 1 deletions

View File

@ -398,15 +398,23 @@ extern "C" WEAK void __cxa_pure_virtual(void) {
// **************************************************************************** // ****************************************************************************
// mbed_main is a function that is called before main() // mbed_main is a function that is called before main()
// mbed_sdk_init() is also a function that is called before main(), but unlike
// mbed_main(), it is not meant for user code, but for the SDK itself to perform
// initializations before main() is called.
extern "C" WEAK void mbed_main(void); extern "C" WEAK void mbed_main(void);
extern "C" WEAK void mbed_main(void) { extern "C" WEAK void mbed_main(void) {
} }
extern "C" WEAK void mbed_sdk_init(void);
extern "C" WEAK void mbed_sdk_init(void) {
}
#if defined(TOOLCHAIN_ARM) #if defined(TOOLCHAIN_ARM)
extern "C" int $Super$$main(void); extern "C" int $Super$$main(void);
extern "C" int $Sub$$main(void) { extern "C" int $Sub$$main(void) {
mbed_sdk_init();
mbed_main(); mbed_main();
return $Super$$main(); return $Super$$main();
} }
@ -414,6 +422,7 @@ extern "C" int $Sub$$main(void) {
extern "C" int __real_main(void); extern "C" int __real_main(void);
extern "C" int __wrap_main(void) { extern "C" int __wrap_main(void) {
mbed_sdk_init();
mbed_main(); mbed_main();
return __real_main(); return __real_main();
} }
@ -424,6 +433,7 @@ extern "C" int __wrap_main(void) {
// code will call a function to setup argc and argv (__iar_argc_argv) if it is defined. // code will call a function to setup argc and argv (__iar_argc_argv) if it is defined.
// Since mbed doesn't use argc/argv, we use this function to call our mbed_main. // Since mbed doesn't use argc/argv, we use this function to call our mbed_main.
extern "C" void __iar_argc_argv() { extern "C" void __iar_argc_argv() {
mbed_sdk_init();
mbed_main(); mbed_main();
} }
#endif #endif

View File

@ -3,7 +3,7 @@
#include "wait_api.h" #include "wait_api.h"
// called before main // called before main
void mbed_main() void mbed_sdk_init()
{ {
gpio_t modemEn, modemRst, modemPwrOn, modemLvlOe, modemILvlOe, modemUsbDet; gpio_t modemEn, modemRst, modemPwrOn, modemLvlOe, modemILvlOe, modemUsbDet;
gpio_t gpsEn, gpsRst, led, modemRts; gpio_t gpsEn, gpsRst, led, modemRts;