Skip to content

Commit

Permalink
#17 in progress, additional board for mbed5 non-rtos testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Dec 3, 2020
1 parent 2840e53 commit 8461c14
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
42 changes: 42 additions & 0 deletions examples/mbed5NonRtos/mbedExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// This is an example of using mbed 5 without RTOS support
// It demonstrates raising a few tasks for scheduling and an interrupt based event.
//

#include <TaskManagerIO.h>

bool taskRunning = true;
taskid_t millisJob;

Serial serPort(USBTX, USBRX);

void log(const char* toLog) {
char sz[14];
itoa(millis(), sz, 10);
serPort.write(sz, strlen(sz));
serPort.write(toLog, strlen(toLog));
}

void setup() {
serPort.baud(115200);
taskManager.scheduleFixedRate(1, [] {
log("One second job");
}, TIME_SECONDS);

millisJob = taskManager.scheduleFixedRate(100, [] {
log("1/10th sec");
});

taskManager.scheduleFixedRate(10, [] {
log("Ten seconds up, remove millisecond job");
taskManager.cancelTask(millisJob);
}, TIME_SECONDS);
}

int main() {
setup();

while(taskRunning) {
taskManager.runLoop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

#include <mbed.h>
#include <rtos.h>
#include <TaskManagerIO.h>

// Here we create a serial object to write log statements to.
Expand Down
5 changes: 5 additions & 0 deletions src/TaskManagerIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,12 @@ volatile bool timingStarted = false;
Timer ioaTimer;

void yield() {

# if defined(MBED_CONF_RTOS_API_PRESENT) || defined(MBED_CONF_RTOS_PRESENT)
ThisThread::yield();
#else
wait(0.0000001);
#endif
}

unsigned long millis() {
Expand Down
5 changes: 4 additions & 1 deletion src/TaskPlatformDeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class TimerTask;
#else
# define IOA_USE_MBED
# include "mbed.h"
#endif
# if defined(MBED_CONF_RTOS_API_PRESENT) || defined(MBED_CONF_RTOS_PRESENT)
# include "rtos.h"
# endif // MBED_CONF_RTOS_API_PRESENT
#endif // mbed and arduino-mbed checks

#include <mbed_atomic.h>
typedef uint32_t pintype_t;
Expand Down

0 comments on commit 8461c14

Please sign in to comment.