Skip to content

Commit dbac1d5

Browse files
authored
Merge pull request #62 from TcMenu/main-logging
#61 Move to new logging framework, fix platform determination.
2 parents df3f36f + 4f6ff7e commit dbac1d5

File tree

9 files changed

+31
-103
lines changed

9 files changed

+31
-103
lines changed

cmake/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ target_compile_definitions(TaskManagerIO
1010
)
1111

1212
target_include_directories(TaskManagerIO PUBLIC
13-
${PROJECT_SOURCE_DIR}/TaskManagerIO/src
13+
${PROJECT_SOURCE_DIR}/lib/TaskManagerIO/src
1414
)
1515

16-
target_link_libraries(TaskManagerIO PUBLIC pico_stdlib pico_sync)
16+
target_link_libraries(TaskManagerIO PUBLIC TcMenuLog pico_stdlib pico_sync)

examples/mbedRtos/mbedExample.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <TaskManagerIO.h>
1414
#include <TmLongSchedule.h>
1515

16-
#define LOG_TASK_MANGER_DEBUG 0
17-
1816
// Here we create a serial object to write log statements to.
1917
BufferedSerial console(USBTX, USBRX, 115200);
2018

@@ -207,15 +205,6 @@ void anotherProc() {
207205
int main() {
208206
log("starting up taskmanager example");
209207

210-
#if LOG_TASK_MANGER_DEBUG != 0
211-
// this is how we get diagnostic information from task manager
212-
// it will notify of significant events to the loggingDelegate.
213-
tm_internal::setLoggingDelegate([](tm_internal::TmErrorCode code, int task) {
214-
log("Taskmgr notification code: ", code);
215-
log(" -> Task num: ", task);
216-
});
217-
#endif //LOG_TASK_MANGER_DEBUG
218-
219208
setupTasks();
220209

221210
threadEventMgr.start(taskPump);

examples/taskManagement/taskManagement.ino

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ void setup() {
104104
Serial.print(", blocks = ");
105105
Serial.println(DEFAULT_TASK_BLOCKS);
106106

107-
// if you want to receive notifications from task manager, provide a loggingDelegate as below.
108-
tm_internal::setLoggingDelegate([] (tm_internal::TmErrorCode code, int id) {
109-
Serial.print("TM Notification code=");
110-
Serial.print(code);
111-
Serial.print(", id=");
112-
Serial.println(id);
113-
});
114-
115107
// connect a switch to interruptPin, so you can raise interrupts.
116108
pinMode(interruptPin, INPUT);
117109

library.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
"maintainer": true
1414
}
1515
],
16-
"version": "1.4.3",
16+
"dependencies": [
17+
{
18+
"name": "TcMenuLog"
19+
}
20+
],
21+
"version": "1.5.0",
1722
"license": "Apache-2.0",
1823
"frameworks": "arduino, mbed",
1924
"platforms": "*"

library.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name=TaskManagerIO
2-
version=1.4.3
2+
version=1.5.0
33
maintainer=https://www.thecoderscorner.com
44
author=davetcc
55
category=Other
66
url=https://github.com/TcMenu/TaskManagerIO
77
sentence=Task manager for Arduino and mbed with marshalled interrupts, first class support for events and timed execution. Thread safe for RTOS use.
88
paragraph=Simple efficient task management with interrupt marshalling. Provides the ability to schedule things to be done either at certain times or on event triggers. This library can also marshall interrupts into task manager
99
includes=TaskManager.h
10+
depends=TcMenuLog

platformio-test.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ board = esp32dev
55
extra_scripts = post:merge-bin.py
66

77
lib_deps =
8-
davetcc/IoAbstraction@^4.0.2
8+
tcmenu/IoAbstraction@^4.0.2
99
TaskManagerIO
1010

1111
test_testing_command =

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
framework = arduino
33

44
lib_deps =
5-
davetcc/IoAbstraction@^4.0.2
5+
TcMenu/IoAbstraction@^4.0.2
66
TaskManagerIO
77

88
[env:megaatmega2560]

src/TaskManagerIO.cpp

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "TaskPlatformDeps.h"
77
#include "TaskManagerIO.h"
88
#include "ExecWithParameter.h"
9+
#include <IoLogging.h>
910

1011
#ifdef BUILD_FOR_PICO_CMAKE
1112
critical_section_t* tm_internal::tmLock;
@@ -20,22 +21,10 @@ void tm_internal::initPicoTmLock() {
2021
void yield() {
2122
sleep_us(1);
2223
}
23-
24-
unsigned long millis() {
25-
return to_ms_since_boot(get_absolute_time());
26-
}
27-
28-
unsigned long micros() {
29-
return to_us_since_boot(get_absolute_time());
30-
}
31-
3224
#endif
3325

3426
#ifdef IOA_USE_MBED
3527

36-
volatile bool timingStarted = false;
37-
Timer ioaTimer;
38-
3928
void yield() {
4029

4130
# if !defined(PIO_NEEDS_RTOS_WORKAROUND)
@@ -44,36 +33,11 @@ void yield() {
4433
wait(0.0000001);
4534
#endif
4635
}
47-
48-
unsigned long millis() {
49-
if(!timingStarted) {
50-
timingStarted = true;
51-
ioaTimer.start();
52-
}
53-
return ioaTimer.read_ms();
54-
}
55-
56-
unsigned long micros() {
57-
if(!timingStarted) {
58-
timingStarted = true;
59-
ioaTimer.start();
60-
}
61-
return (unsigned long) ioaTimer.read_high_resolution_us();
62-
}
63-
6436
#endif
6537

6638

6739
TaskManager taskManager;
6840

69-
namespace tm_internal {
70-
LoggingDelegate loggingDelegate = nullptr;
71-
72-
void setLoggingDelegate(LoggingDelegate delegate) {
73-
loggingDelegate = delegate;
74-
}
75-
}
76-
7741
class TmSpinLock {
7842
private:
7943
tm_internal::TmAtomicBool* lockObject;
@@ -85,14 +49,14 @@ class TmSpinLock {
8549
locked = tm_internal::atomicSwapBool(lockObject, false, true);
8650
if(!locked) {
8751
yield(); // something else has the lock, let it get control to finish up!
88-
if(++count == 1000) tm_internal::tmNotification(tm_internal::TM_WARN_HIGH_SPINCOUNT, TASKMGR_INVALIDID);
52+
if(++count == 1000) serlogF(SER_WARNING, "TM spin>1000");
8953
}
9054
} while(!locked);
9155
}
9256

9357
~TmSpinLock() {
9458
if(!tm_internal::atomicSwapBool(lockObject, true, false)) {
95-
tm_internal::tmNotification(tm_internal::TM_ERROR_LOCK_FAILURE, TASKMGR_INVALIDID);
59+
serlogF(SER_ERROR, "TM lock fail");
9660
}
9761
}
9862
};
@@ -129,14 +93,14 @@ taskid_t TaskManager::findFreeTask() {
12993
for (taskid_t i=0; i<numberOfBlocks;i++) {
13094
auto taskId = taskBlocks[i]->allocateTask();
13195
if(taskId != TASKMGR_INVALIDID) {
132-
tm_internal::tmNotification(tm_internal::TM_INFO_TASK_ALLOC, taskId);
96+
serlogF2(SER_IOA_DEBUG, "TM alloc", taskId);
13397
return taskId;
13498
}
13599
}
136100

137101
// already full, cannot allocate further.
138102
if(numberOfBlocks == DEFAULT_TASK_BLOCKS) {
139-
tm_internal::tmNotification(tm_internal::TM_ERROR_FULL, TASKMGR_INVALIDID);
103+
serlogF(SER_ERROR, "TM full");
140104
return TASKMGR_INVALIDID;
141105
}
142106

@@ -148,11 +112,11 @@ taskid_t TaskManager::findFreeTask() {
148112
auto nextIdSpace = taskBlocks[numberOfBlocks - 1]->lastSlot() + 1;
149113
taskBlocks[numberOfBlocks] = new TaskBlock(nextIdSpace);
150114
if(taskBlocks[numberOfBlocks] != nullptr) {
151-
tm_internal::tmNotification(tm_internal::TM_INFO_REALLOC, numberOfBlocks);
115+
serlogF2(SER_IOA_DEBUG, "TM alloc: ", numberOfBlocks);
152116
numberOfBlocks++;
153117
}
154118
else {
155-
tm_internal::tmNotification(tm_internal::TM_ERROR_FULL, numberOfBlocks);
119+
serlogF(SER_ERROR, "TM full");
156120
break; // no point to continue here, new has failed.
157121
}
158122
}
@@ -229,7 +193,7 @@ void TaskManager::cancelTask(taskid_t taskId) {
229193
if (task) {
230194
taskManager.execute(new ExecWith2Parameters<TimerTask*, TaskManager*>([](TimerTask* task, TaskManager* tm) {
231195
tm->removeFromQueue(task);
232-
tm_internal::tmNotification(tm_internal::TM_INFO_TASK_FREE, TASKMGR_INVALIDID);
196+
serlogF(SER_IOA_DEBUG, "TM free");
233197
task->clear();
234198
}, task, this), true);
235199
}
@@ -278,7 +242,7 @@ void TaskManager::dealWithInterrupt() {
278242
}
279243
else {
280244
task->clear();
281-
tm_internal::tmNotification(tm_internal::TM_INFO_TASK_FREE, TASKMGR_INVALIDID);
245+
serlogF(SER_IOA_DEBUG, "TM free int");
282246
}
283247
}
284248
else {
@@ -309,7 +273,7 @@ void TaskManager::runLoop() {
309273
putItemIntoQueue(tm);
310274
} else {
311275
tm->clear();
312-
tm_internal::tmNotification(tm_internal::TM_INFO_TASK_FREE, TASKMGR_INVALIDID);
276+
serlogF(SER_IOA_DEBUG, "TM free loop");
313277
}
314278
}
315279
tm = tm->getNext();
@@ -485,7 +449,7 @@ void TaskManager::setInterruptCallback(InterruptFn handler) {
485449
}
486450

487451
char* TaskManager::checkAvailableSlots(char* data, size_t dataSize) const {
488-
auto maxLen = min(taskid_t(dataSize - 1), taskBlocks[numberOfBlocks - 1]->lastSlot());
452+
auto maxLen = internal_min(taskid_t(dataSize - 1), taskBlocks[numberOfBlocks - 1]->lastSlot());
489453
size_t position = 0;
490454

491455
for(taskid_t i=0; i<numberOfBlocks;i++) {

src/TaskPlatformDeps.h

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ class TimerTask;
2727
#if defined(BUILD_FOR_PICO_CMAKE)
2828
#include <pico/stdlib.h>
2929
#include <valarray>
30-
#ifndef min
31-
#define min(a, b) (((a) < (b)) ? (a) : (b))
32-
#define max(a, b) (((a) > (b)) ? (a) : (b))
33-
#endif
3430
#elif !defined(__MBED__)
3531
#include <Arduino.h>
3632
#endif
@@ -393,33 +389,6 @@ typedef uint32_t sched_t;
393389
#endif // DEFAULT_TASK_BLOCKS not defined when task size is
394390
#endif // DEFAULT_TASK_SIZE defined already
395391

396-
namespace tm_internal {
397-
enum TmErrorCode {
398-
/** reallocating memory by adding another block, number of blocks in the second parameter */
399-
TM_INFO_REALLOC = 1,
400-
/** A task slot has been allocated, taskid in second parameter */
401-
TM_INFO_TASK_ALLOC = 2,
402-
/** A task slot has been freed, taskid in second parameter */
403-
TM_INFO_TASK_FREE = 3,
404-
405-
// warnings and errors are over 100, info level 0..99
406-
407-
/** probable bug, the lock status was not as expected, please report along with sketch to reproduce */
408-
TM_ERROR_LOCK_FAILURE = 100,
409-
/** high concurrency is resulting in very high spin counts, performance may be affected */
410-
TM_WARN_HIGH_SPINCOUNT,
411-
/** task manager is full, consider settings the default task settings higher. */
412-
TM_ERROR_FULL
413-
};
414-
typedef void (*LoggingDelegate)(TmErrorCode code, int task);
415-
extern LoggingDelegate loggingDelegate;
416-
void setLoggingDelegate(LoggingDelegate delegate);
417-
418-
inline void tmNotification(TmErrorCode code, int task) {
419-
if(loggingDelegate) loggingDelegate(code, task);
420-
}
421-
}
422-
423392
//
424393
// Here we define an attribute needed for interrupt support on ESP8266 and ESP32 boards, any interrupt code that is
425394
// going to run on these boards should be marked with this attribute.
@@ -441,4 +410,12 @@ namespace tm_internal {
441410
#endif // _has_include
442411
#endif // GCC>=5 and !TM_ALLOW_CAPTURED_LAMBDA
443412

413+
#ifndef internal_min
414+
#define internal_min(a, b) ((a) > (b) ? (b) : (a))
415+
#endif // internal_min
416+
417+
#ifndef internal_max
418+
#define internal_max(a, b) ((a) < (b) ? (b) : (a));
419+
#endif // internal_max
420+
444421
#endif //TASKMANGERIO_PLATFORMDETERMINATION_H

0 commit comments

Comments
 (0)