Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main setup() for Energia MT #26

Open
robertinant opened this issue Aug 29, 2016 · 1 comment
Open

Main setup() for Energia MT #26

robertinant opened this issue Aug 29, 2016 · 1 comment

Comments

@robertinant
Copy link
Member

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.

  • Some GPIOs, ports and objects don't accept to be initialised many times (e.g. Wire).
  • The order the setup() functions in the sketches isn't known, so we don't know in which sketch to initiliase GPIOs, ports and objects.

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
Copy link
Member Author

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 energia/Energia@0a2b4bc on #629

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant