Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mail_driven_task_example
Diff: Task.h
- Revision:
- 0:0c5255720d77
- Child:
- 1:381a6f6263c7
diff -r 000000000000 -r 0c5255720d77 Task.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Task.h Mon Dec 22 01:06:33 2014 +0000
@@ -0,0 +1,89 @@
+#ifndef TASK_H
+#define TASK_H
+
+#include <cstdio>
+#include <cstdarg>
+#include "mbed.h"
+#include "rtos.h"
+
+using namespace std;
+
+typedef enum {
+ LOG_DEBUG = 0,
+ LOG_INFO,
+ LOG_WARN,
+ LOG_ERR
+} LogLevel;
+
+#define MAX_MAIL_NUM 16
+#define LOG_BUF_SIZE 64
+
+typedef void (*Routine)(void const *argument);
+typedef uint32_t MessageID;
+typedef uint32_t TaskID;
+
+struct TaskConfig {
+ TaskConfig(
+ const char *task_name,
+ Routine func,
+ osPriority task_priority = osPriorityNormal,
+ uint32_t stack_size = DEFAULT_STACK_SIZE,
+ unsigned char *stack_pointer = NULL
+ ) {
+ name = task_name;
+ routine = func;
+ priority = task_priority;
+ stackSize = stack_size;
+ stackPointer = stack_pointer;
+ }
+ const char *name;
+ Routine routine;
+ osPriority priority;
+ uint32_t stackSize;
+ unsigned char *stackPointer;
+};
+
+struct MailPacket {
+ uint32_t messageId;
+ void *packet;
+};
+
+typedef Mail<MailPacket, MAX_MAIL_NUM> MailBox;
+
+class Task {
+public:
+ static void init(TaskConfig *config, uint32_t num_of_task);
+ static void sendMail(TaskID task_id, MessageID message_id, void *packet);
+ static int readClock();
+
+ Thread *thread;
+ MailPacket *waitMail();
+ void deleteMail(MailPacket *mail);
+ void log(LogLevel lv, const char *format, ...);
+
+ class Logger {
+ public:
+ Logger(const char *task_name, Stream *sp = Logger::sci);
+ static void setLogLevel(LogLevel lv);
+ void setLogStream(Stream *sp);
+ static const char *lvSym[];
+ static Stream *sci;
+ static LogLevel lv;
+ Stream *sp;
+ const char *tag;
+ char buf[LOG_BUF_SIZE];
+ };
+
+private:
+ Task(TaskConfig *config);
+ ~Task();
+
+ static Timer clock;
+ static Task **taskTable;
+ static TaskConfig *taskConfig;
+
+ MailBox mbox;
+ Logger *logger;
+};
+
+#endif