VMX-pi C++ HAL Library for Raspberry Pi
VMX-pi Robotics Controller & Vision/Motion Processor
VMXTime.h
1 /* ============================================
2 VMX-pi HAL source code is placed under the MIT license
3 Copyright (c) 2017 Kauai Labs
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 The above copyright notice and this permission notice shall be included in
11 all copies or substantial portions of the Software.
12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18 THE SOFTWARE.
19 ===============================================
20 */
21 
22 #ifndef VMXTIME_H_
23 #define VMXTIME_H_
24 
25 #include <stdint.h>
26 
27 class PIGPIOClient;
28 class MISCClient;
29 class VMXTimeImpl;
30 
31 #include "VMXErrors.h"
32 #include "VMXHandlers.h"
33 
38 class VMXTime {
39 
40  friend class VMXPi;
41  friend class VMXZero;
42  friend class VMXIO;
43 
44  PIGPIOClient& pigpio;
45  MISCClient& misc;
46  VMXTimeImpl *p_impl;
47 
48  VMXTime(PIGPIOClient& pigpio_ref, MISCClient& misc_ref);
49  virtual ~VMXTime();
50  bool Init();
51  void ReleaseResources();
52  uint64_t GetTotalSystemTimeOfTick(uint32_t tick);
53 
54 public:
55  /* Returns the current linux operating system (OS) time in microseconds
56  * Note that this value is similar to but not exactly synchronized with the
57  * CurrentMicroseconds value.
58  * This value is clock-monotonic, meaning that it is reset to 0 each time
59  * the host is powered on.
60  */
62 
63  uint32_t GetCurrentMicroseconds();
64  uint64_t GetCurrentTotalMicroseconds();
66 
67  /* Blocks the current thread for the specified amount of time in seconds.
68  * The delay occurs by suspending the current thread.
69  * @param delay_ms The amount of time to delay the current thread, in seconds
70  * @returns the actual amount of time this thread was delayed, in seconds
71  */
72  uint32_t DelayMicroseconds(uint32_t delay_us);
73  uint32_t DelayMilliseconds(uint32_t delay_ms);
74  uint32_t DelaySeconds(uint32_t delay_sec);
75 
76  /* Registers for notification at an absolute timestamp [based on the Current System Timestamp] */
77  /* Note: a maximum of 10 Timer Notifications may be simultaneously registered. Each of the 10 */
78  /* is uniquely identified by timer_notify_handler */
79  bool RegisterTimerNotificationAbsolute(VMXNotifyHandler timer_notify_handler, uint64_t trigger_timestamp_us, void *param);
80  /* Registers for notification at a relative time from now */
81  /* Note: a maximum of 10 Timer Notifications may be simultaneously registered. Each of the 10 */
82  /* is uniquely identified by timer_notify_handler */
83  bool RegisterTimerNotificationRelative(VMXNotifyHandler timer_notify_handler, uint64_t time_from_now_us, void *param, bool repeat);
84  /* Unregister previously registered notify handler */
85  bool DeregisterTimerNotification(VMXNotifyHandler timer_notify_handler);
86  bool IsTimerNotificationExpired(VMXNotifyHandler timer_notify_handler, bool& expired);
87 
89  typedef enum {
97 
98  bool GetRTCTime(uint8_t& hours, uint8_t& minutes, uint8_t& seconds, uint32_t& milliseconds, VMXErrorCode *errcode);
99  bool GetRTCDate(uint8_t& weekday, uint8_t& day, uint8_t& month, uint8_t& years, VMXErrorCode *errcode);
100  bool GetRTCDaylightSavingsAdjustment(DaylightSavingsAdjustment& dsa, VMXErrorCode *errcode);
101  bool SetRTCTime(uint8_t hours, uint8_t minutes, uint8_t seconds, VMXErrorCode *errcode);
102  bool SetRTCDate(uint8_t weekday, uint8_t day, uint8_t month, uint8_t years, VMXErrorCode *errcode);
103  bool SetRTCDaylightSavingsAdjustment(DaylightSavingsAdjustment dsa, VMXErrorCode *errcode);
104 };
105 
106 #endif /* VMXTIME_H_ */
Top-level Library Class providing access to all VMX-pi functionality.
Definition: VMXPi.h:40
uint32_t DelaySeconds(uint32_t delay_sec)
Blocks the current thread for the specified amount of time in seconds.
Definition: VMXTime.cpp:297
uint64_t GetCurrentOSTimeMicroseconds()
Returns the current linux operating system (OS) time in microseconds Note that this value is similar ...
Definition: VMXTime.cpp:57
uint32_t GetCurrentMicroseconds()
Returns the low 32 bit portion of the current system Hardware Timer value in microseconds.
Definition: VMXTime.cpp:68
bool IsTimerNotificationExpired(VMXNotifyHandler timer_notify_handler, bool &expired)
Indicates whether the provided previously-registered timer_notify_handler has expired.
Definition: VMXTime.cpp:133
bool GetRTCDate(uint8_t &weekday, uint8_t &day, uint8_t &month, uint8_t &years, VMXErrorCode *errcode)
Retrieves the current VMX Real-time date value.
Definition: VMXTime.cpp:167
bool RegisterTimerNotificationRelative(VMXNotifyHandler timer_notify_handler, uint64_t time_from_now_us, void *param, bool repeat)
Register a VMXNotifyHandler which is invoked within a time period relative to now, which option to create a repeating notification.
Definition: VMXTime.cpp:114
DaylightSavingsAdjustment
Real-Time Clock Daylight Savings Adjustment Setting.
Definition: VMXTime.h:89
bool GetRTCDaylightSavingsAdjustment(DaylightSavingsAdjustment &dsa, VMXErrorCode *errcode)
Retrieves the current VMX Real-time clock daylight savings adjustment setting.
Definition: VMXTime.cpp:220
bool SetRTCTime(uint8_t hours, uint8_t minutes, uint8_t seconds, VMXErrorCode *errcode)
Sets the current VMX Real-time clock value.
Definition: VMXTime.cpp:185
bool DeregisterTimerNotification(VMXNotifyHandler timer_notify_handler)
Deregisters a previously-registered VMXNotifyHandler.
Definition: VMXTime.cpp:123
uint32_t GetCurrentMicrosecondsHighPortion()
Returns the high 32 bit portion of the current system Hardware Timer value in microseconds.
Definition: VMXTime.cpp:86
The Real-time Clock hour has one hour added to it during daylight savings time periods.
Definition: VMXTime.h:93
bool GetRTCTime(uint8_t &hours, uint8_t &minutes, uint8_t &seconds, uint32_t &milliseconds, VMXErrorCode *errcode)
Retrieves the current VMX Real-time clock value.
Definition: VMXTime.cpp:148
bool SetRTCDaylightSavingsAdjustment(DaylightSavingsAdjustment dsa, VMXErrorCode *errcode)
Sets the current VMX Real-time clock daylight savings adjustment setting.
Definition: VMXTime.cpp:248
The VMXTime class provides time management functions, including system timestamps, VMX Real-time Clock access, timer notifications and current thread time-delay.
Definition: VMXTime.h:38
The VMXIO class provides access to VMX Analog/Digital IO functions, including VMX Channel and VMX Res...
Definition: VMXIO.h:47
The Real-time Clock hour is not adjusted during daylight savings time periods.
Definition: VMXTime.h:91
uint64_t GetCurrentTotalMicroseconds()
Returns the full 64 bit current system Hardware Timer value in microseconds.
Definition: VMXTime.cpp:77
uint32_t DelayMilliseconds(uint32_t delay_ms)
Blocks the current thread for the specified amount of time in milliseconds.
Definition: VMXTime.cpp:285
Top-level Library Class providing access to all VMXzero functionality.
Definition: VMXZero.h:40
The Real-time Clock hours has one hour substracted from it during daylight savings time periods...
Definition: VMXTime.h:95
bool RegisterTimerNotificationAbsolute(VMXNotifyHandler timer_notify_handler, uint64_t trigger_timestamp_us, void *param)
Register a VMXNotifyHandler which is invoked when the system timestamp reaches the specified trigger_...
Definition: VMXTime.cpp:103
bool SetRTCDate(uint8_t weekday, uint8_t day, uint8_t month, uint8_t years, VMXErrorCode *errcode)
Sets the current VMX Real-time date value.
Definition: VMXTime.cpp:204
uint32_t DelayMicroseconds(uint32_t delay_us)
Blocks the current thread for the specified amount of time in microseconds.
Definition: VMXTime.cpp:275