![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
a
include/TaskManager/taskmanager.hpp@1:ceee5a608e7c, 2019-03-28 (annotated)
- Committer:
- alexpirciu
- Date:
- Thu Mar 28 07:44:42 2019 +0000
- Revision:
- 1:ceee5a608e7c
assa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexpirciu | 1:ceee5a608e7c | 1 | /** |
alexpirciu | 1:ceee5a608e7c | 2 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 3 | * @file TaskManager.hpp |
alexpirciu | 1:ceee5a608e7c | 4 | * @author RBRO/PJ-IU |
alexpirciu | 1:ceee5a608e7c | 5 | * @version V1.0.0 |
alexpirciu | 1:ceee5a608e7c | 6 | * @date day-month-2017 |
alexpirciu | 1:ceee5a608e7c | 7 | * @brief This file contains the class declaration for task manager. |
alexpirciu | 1:ceee5a608e7c | 8 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 9 | */ |
alexpirciu | 1:ceee5a608e7c | 10 | |
alexpirciu | 1:ceee5a608e7c | 11 | /* Inclusion guard */ |
alexpirciu | 1:ceee5a608e7c | 12 | #ifndef TASK_MANAGER_HPP |
alexpirciu | 1:ceee5a608e7c | 13 | #define TASK_MANAGER_HPP |
alexpirciu | 1:ceee5a608e7c | 14 | |
alexpirciu | 1:ceee5a608e7c | 15 | #include <mbed.h> |
alexpirciu | 1:ceee5a608e7c | 16 | |
alexpirciu | 1:ceee5a608e7c | 17 | namespace task{ |
alexpirciu | 1:ceee5a608e7c | 18 | /** |
alexpirciu | 1:ceee5a608e7c | 19 | * @brief It is used for implementing the task functionality. |
alexpirciu | 1:ceee5a608e7c | 20 | * |
alexpirciu | 1:ceee5a608e7c | 21 | */ |
alexpirciu | 1:ceee5a608e7c | 22 | class CTask |
alexpirciu | 1:ceee5a608e7c | 23 | { |
alexpirciu | 1:ceee5a608e7c | 24 | public: |
alexpirciu | 1:ceee5a608e7c | 25 | /* Constructor */ |
alexpirciu | 1:ceee5a608e7c | 26 | CTask(uint32_t f_period); |
alexpirciu | 1:ceee5a608e7c | 27 | /* Destructor */ |
alexpirciu | 1:ceee5a608e7c | 28 | virtual ~CTask(); |
alexpirciu | 1:ceee5a608e7c | 29 | /* Run method */ |
alexpirciu | 1:ceee5a608e7c | 30 | virtual void run(); |
alexpirciu | 1:ceee5a608e7c | 31 | /* Timer callback */ |
alexpirciu | 1:ceee5a608e7c | 32 | void timerCallback() |
alexpirciu | 1:ceee5a608e7c | 33 | { |
alexpirciu | 1:ceee5a608e7c | 34 | m_ticks++; |
alexpirciu | 1:ceee5a608e7c | 35 | if (m_ticks >= m_period) |
alexpirciu | 1:ceee5a608e7c | 36 | { |
alexpirciu | 1:ceee5a608e7c | 37 | m_ticks = 0; |
alexpirciu | 1:ceee5a608e7c | 38 | Trigger(); |
alexpirciu | 1:ceee5a608e7c | 39 | } |
alexpirciu | 1:ceee5a608e7c | 40 | } |
alexpirciu | 1:ceee5a608e7c | 41 | /* Trigger */ |
alexpirciu | 1:ceee5a608e7c | 42 | void Trigger() |
alexpirciu | 1:ceee5a608e7c | 43 | { |
alexpirciu | 1:ceee5a608e7c | 44 | m_triggered = true; |
alexpirciu | 1:ceee5a608e7c | 45 | } |
alexpirciu | 1:ceee5a608e7c | 46 | protected: |
alexpirciu | 1:ceee5a608e7c | 47 | /* _run methof */ |
alexpirciu | 1:ceee5a608e7c | 48 | virtual void _run() = 0; |
alexpirciu | 1:ceee5a608e7c | 49 | /* period */ |
alexpirciu | 1:ceee5a608e7c | 50 | const uint32_t m_period; |
alexpirciu | 1:ceee5a608e7c | 51 | /* ticks */ |
alexpirciu | 1:ceee5a608e7c | 52 | uint32_t m_ticks; |
alexpirciu | 1:ceee5a608e7c | 53 | /* trigger flag */ |
alexpirciu | 1:ceee5a608e7c | 54 | bool m_triggered; |
alexpirciu | 1:ceee5a608e7c | 55 | }; |
alexpirciu | 1:ceee5a608e7c | 56 | |
alexpirciu | 1:ceee5a608e7c | 57 | /** |
alexpirciu | 1:ceee5a608e7c | 58 | * @brief It is used for implementing the task manager functionality. |
alexpirciu | 1:ceee5a608e7c | 59 | * |
alexpirciu | 1:ceee5a608e7c | 60 | */ |
alexpirciu | 1:ceee5a608e7c | 61 | class CTaskManager |
alexpirciu | 1:ceee5a608e7c | 62 | { |
alexpirciu | 1:ceee5a608e7c | 63 | public: |
alexpirciu | 1:ceee5a608e7c | 64 | /* Constructor */ |
alexpirciu | 1:ceee5a608e7c | 65 | CTaskManager(CTask** f_taskList, uint32_t f_taskCount, float f_baseFreq); |
alexpirciu | 1:ceee5a608e7c | 66 | /* Destructor */ |
alexpirciu | 1:ceee5a608e7c | 67 | virtual ~CTaskManager(); |
alexpirciu | 1:ceee5a608e7c | 68 | /* Main callback */ |
alexpirciu | 1:ceee5a608e7c | 69 | inline void mainCallback() |
alexpirciu | 1:ceee5a608e7c | 70 | { |
alexpirciu | 1:ceee5a608e7c | 71 | for(uint32_t i = 0; i < m_taskCount; i++) |
alexpirciu | 1:ceee5a608e7c | 72 | { |
alexpirciu | 1:ceee5a608e7c | 73 | m_taskList[i]->run(); |
alexpirciu | 1:ceee5a608e7c | 74 | } |
alexpirciu | 1:ceee5a608e7c | 75 | } |
alexpirciu | 1:ceee5a608e7c | 76 | /* Timer callback */ |
alexpirciu | 1:ceee5a608e7c | 77 | inline void timerCallback() |
alexpirciu | 1:ceee5a608e7c | 78 | { |
alexpirciu | 1:ceee5a608e7c | 79 | for(uint32_t i = 0; i < m_taskCount; i++) |
alexpirciu | 1:ceee5a608e7c | 80 | { |
alexpirciu | 1:ceee5a608e7c | 81 | m_taskList[i]->timerCallback(); |
alexpirciu | 1:ceee5a608e7c | 82 | } |
alexpirciu | 1:ceee5a608e7c | 83 | } |
alexpirciu | 1:ceee5a608e7c | 84 | private: |
alexpirciu | 1:ceee5a608e7c | 85 | /* Callback */ |
alexpirciu | 1:ceee5a608e7c | 86 | static void callback(void *thisPointer); |
alexpirciu | 1:ceee5a608e7c | 87 | /* task list */ |
alexpirciu | 1:ceee5a608e7c | 88 | CTask** m_taskList; |
alexpirciu | 1:ceee5a608e7c | 89 | /* task count */ |
alexpirciu | 1:ceee5a608e7c | 90 | uint32_t m_taskCount; |
alexpirciu | 1:ceee5a608e7c | 91 | /* ticker */ /* A Ticker is used to call a function at a recurring interval */ |
alexpirciu | 1:ceee5a608e7c | 92 | Ticker m_ticker; |
alexpirciu | 1:ceee5a608e7c | 93 | }; |
alexpirciu | 1:ceee5a608e7c | 94 | |
alexpirciu | 1:ceee5a608e7c | 95 | }; // namespace task |
alexpirciu | 1:ceee5a608e7c | 96 | |
alexpirciu | 1:ceee5a608e7c | 97 | #endif |