energia / msp432-core

MSP432 Core and Framework
14 stars 10 forks source link

Main setup() for Energia MT #26

Open robertinant opened 8 years ago

robertinant commented 8 years ago

From @rei-vilo on June 15, 2015 8:25

The setup() functions in the Energia MT examples often initiliase the GPIOs, ports and objects as many times as sketches, e.g. Serial.begin(115200);.

This raises two issues.

The idea is to have a specific setup() function names rtosSetup() called before all the other setup() functions of the sketches.

  1. Add in main.cpp
void rtosSetup() __attribute__((weak));

and

    rtosSetup();

just before BIOS_start();

  1. Declare rtosSetup() in the main sketch.

Because rtosSetup() is weak, the declaration of the function rtosSetup() can be omitted.

Copied from original issue: energia/Energia#631

robertinant commented 8 years ago

From @rei-vilo on June 20, 2015 9:40

The file main.template has been edited with

///
/// @brief      main setup function
/// @note       rtosSetup() is called before all other tasks
/// *   Optional declaration
/// *   Defined in main sketch or in rtosGlobals
/// @warning    No delay() in rtosSetup()!
///
void rtosSetup() __attribute__((weak));

///
/// @brief  Proxy function for Task_create()
/// @note   Task_create() requires non-weak functions
///
void rtos_Setup() { rtosSetup(); };

///
/// @brief  Proxy function for Task_create()
/// @note   Task_create() requires non-weak functions
///
void rtos_Loop() { ; }

and

    // Add rtosSetup() as first tasks
    taskParams.arg0 = (xdc_UArg) rtos_Setup;
    taskParams.arg1 = (xdc_UArg) rtos_Loop;
    taskParams.instance->name = (xdc_String) "rtosSetup";
    Task_create(the_task, &taskParams, NULL);

The function rtosSetup() is declared —or not— on main sketch —or the optional rtosGloblas.h. Here, in file MainSetup.ino.

// Optional rtosSetup function
// defined in main sketch or in rtosGlobals
// no delay() in rtosSetup()!
void rtosSetup()
{
    Serial.begin(115200);
    Serial.print("rtosSetup...");

    pinMode(BLUE_LED, OUTPUT);
    digitalWrite(BLUE_LED, HIGH);

    Serial.println("done");
}

See pull-request https://github.com/energia/Energia/commit/0a2b4bc75e05ece4a8908aad28c88b2b858eaa1d on #629