Mark3 Realtime Kernel
timer.cpp
Go to the documentation of this file.
1 /*===========================================================================
2  _____ _____ _____ _____
3  ___| _|__ __|_ |__ __|__ |__ __| __ |__ ______
4 | \ / | || \ || | || |/ / ||___ |
5 | \/ | || \ || \ || \ ||___ |
6 |__/\__/|__|_||__|\__\ __||__|\__\ __||__|\__\ __||______|
7  |_____| |_____| |_____| |_____|
8 
9 --[Mark3 Realtime Platform]--------------------------------------------------
10 
11 Copyright (c) 2012 - 2019 m0slevin, all rights reserved.
12 See license.txt for more information
13 ===========================================================================*/
22 #include "mark3.h"
23 
24 namespace Mark3
25 {
27 
28 //---------------------------------------------------------------------------
30 {
32  m_u8Flags = 0;
33 }
34 
35 //---------------------------------------------------------------------------
37 {
38  if (IsInitialized()) {
40  }
41 
42  ClearNode();
43  m_u32Interval = 0;
44  m_u32TimeLeft = 0;
45  m_u8Flags = 0;
46 
48 }
49 
50 //---------------------------------------------------------------------------
51 void Timer::Start(bool bRepeat_, uint32_t u32IntervalMs_, TimerCallback pfCallback_, void* pvData_)
52 {
54 
55  if ((m_u8Flags & uTimerFlagActive) != 0) {
56  return;
57  }
58 
59  m_u32Interval = u32IntervalMs_;
60  m_pfCallback = pfCallback_;
61  m_pvData = pvData_;
62 
63  if (!bRepeat_) {
65  } else {
66  m_u8Flags = 0;
67  }
68 
69  Start();
70 }
71 
72 //---------------------------------------------------------------------------
74 {
76 
77  if ((m_u8Flags & uTimerFlagActive) != 0) {
78  return;
79  }
80 
82  TimerScheduler::Add(this);
83 }
84 
85 //---------------------------------------------------------------------------
87 {
89  if ((m_u8Flags & uTimerFlagActive) == 0) {
90  return;
91  }
93 }
94 } // namespace Mark3
uint32_t m_u32Interval
Interval of the timer in timer ticks.
Definition: timer.h:146
static void Remove(Timer *pclListNode_)
Remove Remove a timer from the timer scheduler. May implicitly stop the timer if this is the only act...
bool IsInitialized(void)
IsInitialized.
Definition: timer.h:127
uint8_t m_u8Flags
Flags for the timer, defining if the timer is one-shot or repeated.
Definition: timer.h:140
void SetInitialized()
SetInitialized.
Definition: timer.h:121
uint32_t m_u32TimeLeft
Time remaining on the timer.
Definition: timer.h:149
TimerCallback m_pfCallback
Pointer to the callback function.
Definition: timer.h:143
void Init()
Init Re-initialize the Timer to default values.
Definition: timer.cpp:36
#define KERNEL_ASSERT(x)
Definition: kerneldebug.h:36
Definition: atomic.cpp:23
void Stop()
Stop Stop a timer already in progress. Has no effect on timers that have already been stopped...
Definition: timer.cpp:86
Timer()
Timer Default Constructor - Do nothing. Allow the init call to perform the necessary object initializ...
Definition: timer.cpp:29
void(*)(Thread *pclOwner_, void *pvData_) TimerCallback
Definition: timer.h:50
static void Add(Timer *pclListNode_)
Add Add a timer to the timer scheduler. Adding a timer implicitly starts the timer as well...
Single include file given to users of the Mark3 Kernel API.
static constexpr auto m_uTimerInvalidCookie
Definition: timer.h:133
void Start()
Start Start or restart a timer using parameters previously configured via calls to Start(<with args>)...
Definition: timer.cpp:73
static TimerList m_clTimerList
TimerList object manipu32ated by the Timer Scheduler.
static constexpr auto uTimerFlagOneShot
Timer is one-shot.
Definition: timer.h:34
uint8_t m_u8Initialized
Cookie used to determine whether or not the timer is initialized.
Definition: timer.h:137
void * m_pvData
Pointer to the callback data.
Definition: timer.h:155
static constexpr auto uTimerFlagActive
Timer is currently active.
Definition: timer.h:35
static Thread * GetCurrentThread()
GetCurrentThread Return the pointer to the currently-running thread.
Definition: scheduler.h:116
Thread * m_pclOwner
Pointer to the owner thread.
Definition: timer.h:152