Skip to content

Commit 8461c14

Browse files
author
dave
committed
#17 in progress, additional board for mbed5 non-rtos testing.
1 parent 2840e53 commit 8461c14

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// This is an example of using mbed 5 without RTOS support
3+
// It demonstrates raising a few tasks for scheduling and an interrupt based event.
4+
//
5+
6+
#include <TaskManagerIO.h>
7+
8+
bool taskRunning = true;
9+
taskid_t millisJob;
10+
11+
Serial serPort(USBTX, USBRX);
12+
13+
void log(const char* toLog) {
14+
char sz[14];
15+
itoa(millis(), sz, 10);
16+
serPort.write(sz, strlen(sz));
17+
serPort.write(toLog, strlen(toLog));
18+
}
19+
20+
void setup() {
21+
serPort.baud(115200);
22+
taskManager.scheduleFixedRate(1, [] {
23+
log("One second job");
24+
}, TIME_SECONDS);
25+
26+
millisJob = taskManager.scheduleFixedRate(100, [] {
27+
log("1/10th sec");
28+
});
29+
30+
taskManager.scheduleFixedRate(10, [] {
31+
log("Ten seconds up, remove millisecond job");
32+
taskManager.cancelTask(millisJob);
33+
}, TIME_SECONDS);
34+
}
35+
36+
int main() {
37+
setup();
38+
39+
while(taskRunning) {
40+
taskManager.runLoop();
41+
}
42+
}

examples/mbedExample/mbedExample.cpp renamed to examples/mbedRtos/mbedExample.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
#include <mbed.h>
10-
#include <rtos.h>
1110
#include <TaskManagerIO.h>
1211

1312
// Here we create a serial object to write log statements to.

src/TaskManagerIO.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,12 @@ volatile bool timingStarted = false;
408408
Timer ioaTimer;
409409

410410
void yield() {
411+
412+
# if defined(MBED_CONF_RTOS_API_PRESENT) || defined(MBED_CONF_RTOS_PRESENT)
411413
ThisThread::yield();
414+
#else
415+
wait(0.0000001);
416+
#endif
412417
}
413418

414419
unsigned long millis() {

src/TaskPlatformDeps.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class TimerTask;
1919
#else
2020
# define IOA_USE_MBED
2121
# include "mbed.h"
22-
#endif
22+
# if defined(MBED_CONF_RTOS_API_PRESENT) || defined(MBED_CONF_RTOS_PRESENT)
23+
# include "rtos.h"
24+
# endif // MBED_CONF_RTOS_API_PRESENT
25+
#endif // mbed and arduino-mbed checks
2326

2427
#include <mbed_atomic.h>
2528
typedef uint32_t pintype_t;

0 commit comments

Comments
 (0)