Task class is an implementation of mail driven thread, for it makes to use Thread and Mail classes in mbed-rtos library easier.
Dependents: mail_driven_task_example
It makes simple to implement asynchronous processing between threads. Task class is an implementation of mail driven thread, for it makes to use Thread and Mail classes in mbed-rtos library easier.
The example of the use of this library, please refer to the following program.
Import programmail_driven_task_example
Simple example of the use of mail_driven_task library
Diff: Task.h
- Revision:
- 1:381a6f6263c7
- Parent:
- 0:0c5255720d77
- Child:
- 2:b12e4c1338db
--- a/Task.h Mon Dec 22 01:06:33 2014 +0000 +++ b/Task.h Thu Dec 25 01:58:14 2014 +0000 @@ -52,18 +52,57 @@ class Task { public: + /** Initialize task config table. + @param cfg array of TaskConfig + @param num_of_task length of cfg + @return void + */ static void init(TaskConfig *config, uint32_t num_of_task); + + /** Send mail to task specified by task_id with Any data. + @param task_id destination task's id + @param message_id mail id + @param packet any data pointer + @return void + */ static void sendMail(TaskID task_id, MessageID message_id, void *packet); + + static int readClock(); Thread *thread; + + /** Wait for mail addressed to itself. + @return received MailPacket + */ MailPacket *waitMail(); + + /** Delete a mail queue block. it's responsible for received task. + @param mail received MailPacket + @return void + */ void deleteMail(MailPacket *mail); + + /** Output log to task's own stream pointer. + @param lv loglevel + @param format log format + @param ... log arguments + @return void + */ void log(LogLevel lv, const char *format, ...); class Logger { public: + /** Logger constructor + @param task_name For log prefix + @param sp Stream pointer for output destination(the default is USB serial). + */ Logger(const char *task_name, Stream *sp = Logger::sci); + + /** Log level setter + @param lv log level + @return void + */ static void setLogLevel(LogLevel lv); void setLogStream(Stream *sp); static const char *lvSym[]; @@ -75,6 +114,10 @@ }; private: + /** Create a new thread with its own logger. + @param cfg TaskConfig struct pointer + @return void + */ Task(TaskConfig *config); ~Task();