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 VMXIO;
42 
43  PIGPIOClient& pigpio;
44  MISCClient& misc;
45  VMXTimeImpl *p_impl;
46 
47  VMXTime(PIGPIOClient& pigpio_ref, MISCClient& misc_ref);
48  virtual ~VMXTime();
49  bool Init();
50  void ReleaseResources();
51  uint64_t GetTotalSystemTimeOfTick(uint32_t tick);
52 
53 public:
54  /* Returns the current linux operating system (OS) time in microseconds
55  * Note that this value is similar to but not exactly synchronized with the
56  * CurrentMicroseconds value.
57  * This value is clock-monotonic, meaning that it is reset to 0 each time
58  * the host is powered on.
59  */
61 
62  uint32_t GetCurrentMicroseconds();
63  uint64_t GetCurrentTotalMicroseconds();
65 
66  /* Blocks the current thread for the specified amount of time in seconds.
67  * The delay occurs by suspending the current thread.
68  * @param delay_ms The amount of time to delay the current thread, in seconds
69  * @returns the actual amount of time this thread was delayed, in seconds
70  */
71  uint32_t DelayMicroseconds(uint32_t delay_us);
72  uint32_t DelayMilliseconds(uint32_t delay_ms);
73  uint32_t DelaySeconds(uint32_t delay_sec);
74 
75  /* Registers for notification at an absolute timestamp [based on the Current System Timestamp] */
76  /* Note: a maximum of 10 Timer Notifications may be simultaneously registered. Each of the 10 */
77  /* is uniquely identified by timer_notify_handler */
78  bool RegisterTimerNotificationAbsolute(VMXNotifyHandler timer_notify_handler, uint64_t trigger_timestamp_us, void *param);
79  /* Registers for notification at a relative time from now */
80  /* Note: a maximum of 10 Timer Notifications may be simultaneously registered. Each of the 10 */
81  /* is uniquely identified by timer_notify_handler */
82  bool RegisterTimerNotificationRelative(VMXNotifyHandler timer_notify_handler, uint64_t time_from_now_us, void *param, bool repeat);
83  /* Unregister previously registered notify handler */
84  bool DeregisterTimerNotification(VMXNotifyHandler timer_notify_handler);
85  bool IsTimerNotificationExpired(VMXNotifyHandler timer_notify_handler, bool& expired);
86 
88  typedef enum {
96 
97  bool GetRTCTime(uint8_t& hours, uint8_t& minutes, uint8_t& seconds, uint32_t& milliseconds, VMXErrorCode *errcode = 0);
98  bool GetRTCDate(uint8_t& weekday, uint8_t& day, uint8_t& month, uint8_t& years, VMXErrorCode *errcode = 0);
99  bool GetRTCDaylightSavingsAdjustment(DaylightSavingsAdjustment& dsa, VMXErrorCode *errcode = 0);
100  bool SetRTCTime(uint8_t hours, uint8_t minutes, uint8_t seconds, VMXErrorCode *errcode = 0);
101  bool SetRTCDate(uint8_t weekday, uint8_t day, uint8_t month, uint8_t years, VMXErrorCode *errcode = 0);
102  bool SetRTCDaylightSavingsAdjustment(DaylightSavingsAdjustment dsa, VMXErrorCode *errcode = 0);
103 };
104 
105 #endif /* VMXTIME_H_ */
Top-level Library Class providing access to all VMX-pi functionality.
Definition: VMXPi.h:37
uint32_t DelaySeconds(uint32_t delay_sec)
Blocks the current thread for the specified amount of time in seconds.
Definition: VMXTime.cpp:292
uint64_t GetCurrentOSTimeMicroseconds()
Returns the current linux operating system (OS) time in microseconds Note that this value is similar ...
Definition: VMXTime.cpp:52
uint32_t GetCurrentMicroseconds()
Returns the low 32 bit portion of the current system Hardware Timer value in microseconds.
Definition: VMXTime.cpp:63
bool GetRTCDate(uint8_t &weekday, uint8_t &day, uint8_t &month, uint8_t &years, VMXErrorCode *errcode=0)
Retrieves the current VMX Real-time date value.
Definition: VMXTime.cpp:162
bool IsTimerNotificationExpired(VMXNotifyHandler timer_notify_handler, bool &expired)
Indicates whether the provided previously-registered timer_notify_handler has expired.
Definition: VMXTime.cpp:128
bool SetRTCTime(uint8_t hours, uint8_t minutes, uint8_t seconds, VMXErrorCode *errcode=0)
Sets the current VMX Real-time clock value.
Definition: VMXTime.cpp:180
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:109
DaylightSavingsAdjustment
Real-Time Clock Daylight Savings Adjustment Setting.
Definition: VMXTime.h:88
bool SetRTCDaylightSavingsAdjustment(DaylightSavingsAdjustment dsa, VMXErrorCode *errcode=0)
Sets the current VMX Real-time clock daylight savings adjustment setting.
Definition: VMXTime.cpp:243
bool DeregisterTimerNotification(VMXNotifyHandler timer_notify_handler)
Deregisters a previously-registered VMXNotifyHandler.
Definition: VMXTime.cpp:118
bool GetRTCDaylightSavingsAdjustment(DaylightSavingsAdjustment &dsa, VMXErrorCode *errcode=0)
Retrieves the current VMX Real-time clock daylight savings adjustment setting.
Definition: VMXTime.cpp:215
bool GetRTCTime(uint8_t &hours, uint8_t &minutes, uint8_t &seconds, uint32_t &milliseconds, VMXErrorCode *errcode=0)
Retrieves the current VMX Real-time clock value.
Definition: VMXTime.cpp:143
uint32_t GetCurrentMicrosecondsHighPortion()
Returns the high 32 bit portion of the current system Hardware Timer value in microseconds.
Definition: VMXTime.cpp:81
The Real-time Clock hour has one hour added to it during daylight savings time periods.
Definition: VMXTime.h:92
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
bool SetRTCDate(uint8_t weekday, uint8_t day, uint8_t month, uint8_t years, VMXErrorCode *errcode=0)
Sets the current VMX Real-time date value.
Definition: VMXTime.cpp:199
The VMXIO class provides access to VMX Analog/Digital IO functions, including VMX Channel and VMX Res...
Definition: VMXIO.h:41
The Real-time Clock hour is not adjusted during daylight savings time periods.
Definition: VMXTime.h:90
uint64_t GetCurrentTotalMicroseconds()
Returns the full 64 bit current system Hardware Timer value in microseconds.
Definition: VMXTime.cpp:72
uint32_t DelayMilliseconds(uint32_t delay_ms)
Blocks the current thread for the specified amount of time in milliseconds.
Definition: VMXTime.cpp:280
The Real-time Clock hours has one hour substracted from it during daylight savings time periods...
Definition: VMXTime.h:94
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:98
uint32_t DelayMicroseconds(uint32_t delay_us)
Blocks the current thread for the specified amount of time in microseconds.
Definition: VMXTime.cpp:270