2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /*******************************************************************************
20 *******************************************************************************/
22 /******************************************************************************
23 * File name :Clock_API.h
24 * System name :_CWORD107__PND-A
25 * Subsystem name :System common functions header file
27 * Publishing department
28 ****************************************************************************/
29 #ifndef POSITIONING_CLIENT_INCLUDE_CLOCK_API_H_
30 #define POSITIONING_CLIENT_INCLUDE_CLOCK_API_H_
32 #include <vehicle_service/positioning_base_library.h>
33 #include "CommonDefine.h"
41 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
42 /* For time calculation */
43 #define CLOCK_TIMESTAMP_GETTIME(x) ((x) & (0x00FFFFFFU)) /* Macros that Get Time Counter Values */
44 #define CLOCK_TIMESTAMP_GETFLAG(x) (((x) & (0xE0000000U)) >> (29U)) /* Macros that Get Your Own Count Values */
45 #define CLOCK_TIMESTAMP_NORMAL (0U) /* Normal count */
46 #define CLOCK_TIMESTAMP_INDIPENDENT (1U) /* Own count */
48 #define CLOCK_TIMESTAMP_UNION(x, y) (((x) << (29U)) | (y)) /* Macro that combines the unique count value (x) and the time counter value (y) */
50 /* Timestamp Shared Memory Related */
51 #define TIMESTAMP_RETRY_COUNTE (10U) /* Number of time stamp retries */
52 #define TIMESTAMP_RETRY_INTERVAL (10U) /* Time stamp retry interval(100[msec]) */
54 /* Time Management Shared Memory Related */
55 #define CLKMNG_RETRY_COUNTE (10U) /* Time management retries */
56 #define CLKMNG_RETRY_INTERVAL (10U) /* Time Management Retry Interval(100[msec]) */
58 /* Day of the week definition */
59 #define CLKMNG_SUN (0U) /* Sunday */
60 #define CLKMNG_MON (1U) /* Mondays */
61 #define CLKMNG_TUE (2U) /* Tuesdays */
62 #define CLKMNG_WED (3U) /* Wednesdays */
63 #define CLKMNG_THU (4U) /* Thursdays */
64 #define CLKMNG_FRI (5U) /* Fridays */
65 #define CLKMNG_SAT (6U)
67 /* Related to the accuracy of time */
68 #define CLOCK_CORRECTED_TIME (0U) /* GPS corrected time completed */
69 #define CLOCK_NOT_CORRECTED_TIME (1U) /* GPS uncorrected time */
70 #define CLOCK_RTC_TIME (2U) /* GPS RTC time */
71 #define CLOCK_INVALID_TIME (3U) /* GPS error time */
73 /* Time Stamp Status Storage Data Module Related Definition */
74 #define TIMESTAMPDM_NAME "TIMESTAMP_DATA" /* Name of time stamp status storage data module */
75 #define TIMESTAMPDM_SEM_NAME "TIMESTAMP_SEM" /* Timestamp status storage data module semaphore name */
77 /* Time Management Status Storage Data Module Related Definition */
78 #define CLKMNG_DM_NAME "CLOCK_GPS_DATA" /* Name of time management status storage data module */
79 #define CLKMNG_DM_SEM_NAME "CLOCK_GPS_SEM" /* Time management status storage data module semaphore name */
81 /* Messaging communication */
82 #define CLKMNG_MSG_BUF_SIZE (128U) /* Message communication buffer size */
83 #define CLKMNG_SETTIME_MSGBODYSIZE (4U) /* Date/Time Setting Response Notification Data Size */
84 #define CLKMNG_NOTIOBSERVERS_MSGSZ (4U) /* Time change notification data body size */
85 #define CLKMNG_NOTIACCURACY_MSGSZ (4U) /* Change notification data body size from time accuracy */
86 #define CLKMNG_NOTIOBSERVERS_ENTRY_MSGSZ (4U) /* Time change notification registration data body size */
87 #define CLKMNG_NOTIACCURACY_ENTRY_MSGSZ (0U) /* Change Notification Stored Data Size from Time Accuracy */
89 /* Semaphore Related Extensions */
90 #define CLOCK_SEM_RETRY_INTERVAL (10) /* Retry interval for semaphore acquisition/release processing 10ms */
94 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
95 /* Time-stamped data */
96 typedef struct TagTimestampData {
97 u_int16 trip; /* Trip counters */
98 u_int16 reserve; /* Reservation(Always 0) */
99 u_int32 time; /* Time counter */
100 u_int8 day; /* Number of days */
101 u_int8 hour; /* Time */
102 u_int8 min; /* Minutes */
103 u_int8 sec; /* Second */
106 /* TIMESTAMP INTERNAL COUNTER MODULE STRUCTURE DEFINITION */
108 u_int16 trip; /* Trip counters */
109 u_int32 time; /* Time counter */
112 /* Time management status storage area */
113 typedef struct TagClockStatus {
114 u_int8 status; /* GPS status */
115 u_int8 hour; /* Time of final correction */
116 u_int8 min; /* Minutes */
117 u_int8 sec; /* Second */
120 /* Status storage area for writing time management shared memory */
121 typedef struct TagClkMngTimerSetTime {
122 T_APIMSG_MSGBUF_HEADER hdr; /* Message header */
123 u_int8 reserve1[1]; /* (Not used) */
124 u_int8 gps_timer_state; /* GPS time status */
125 u_int16 year; /* Year */
126 u_int8 month; /* Month */
127 u_int8 day; /* Day */
128 u_int8 hour; /* Hour */
129 u_int8 min; /* Minutes */
130 u_int8 sec; /* Second */
131 u_int8 reserve2[3]; /* (Not used) */
132 } CLKMNG_TIMER_SET_TIME;
134 /* Existing sys_timerapi.h data */
136 /* User time status */
137 #define TIMEDATA_INVALID 0 /* Time invalid */
138 #define TIMEDATA_VALID 1 /* Time valid */
140 /* Time Definition AM/PM */
143 /* Change to Enumeration */
144 /* Time notification unit */
145 typedef enum TagNotifyUnit {
146 CLOCK_NOTIFY_SECOND = (1U), /* Second notifications */
147 CLOCK_NOTIFY_MINUTE, /* Minute Notification */
148 CLOCK_NOTIFY_HOUR /* Hourly notification */
151 /* Return value definition */
152 typedef enum TagClockReturn {
153 CLOCK_OK, /* Normal completion */
154 CLOCK_ERROR, /* ABENDs */
155 CLOCK_ERROR_ARGUMENTS /* Invalid argument */
158 /* Time Type Definition */
159 typedef struct TagTimeData {
160 u_int16 year; /* Year */
161 u_int8 month; /* Month */
162 u_int8 day; /* Day */
163 u_int8 hour; /* Hour */
164 u_int8 minute; /* Minutes */
165 u_int8 second; /* Second */
168 /* Offset time type definition */
169 typedef struct TagOffsetData {
170 BOOL sign; /* Operator */
171 TimeData time; /* Date and time */
174 /* Data Definition for System Time Delivery Registration */
175 typedef struct TagSystemTimeRegistData {
176 NOTIFYUNIT unit; /* Notification unit(Hour,Minutes,One of the seconds) */
177 } SYSTEMTIME_REGISTDATA;
179 /* Data Definition for Setting User Time */
180 typedef struct TagUserTimSetData {
181 TimeData time; /* Time */
182 u_int8 day_of_week; /* Day-of-week */
185 /* Data Definition for User Time Delivery Registration */
186 typedef struct TagUserTimeRegistData {
187 NOTIFYUNIT unit; /* Notification unit(Hour,Minutes,One of the seconds) */
188 } USERTIME_REGISTDATA;
192 Time Management Thread -> External Message Definition
193 - - - - - - - - - - - - - - - - - - - - - - */
194 /* Message data type */
195 typedef struct TagClkMngRecMsg {
196 T_APIMSG_MSGBUF_HEADER hdr; /* Message header */
197 u_int8 data[CLKMNG_MSG_BUF_SIZE];
200 /* For time management Time Set Response Message */
201 typedef struct TagClkMngRetTimeMsg { /* Time Set Response Message */
202 T_APIMSG_MSGBUF_HEADER header; /* Message header */
203 int8 result; /* Processing result */
205 } CLKMNG_RETTIME_MSG;
207 /* Change Notification Message from Time for Time Management */
208 typedef struct TagClkMngNotiAccuracyMsg {
209 T_APIMSG_MSGBUF_HEADER header; /* Message header */
210 u_int8 gps_status; /* GPS time status(Likelihood) */
212 } CLKMNG_NOTIACCURACY_MSG;
214 /* Time change notification message for time management */
215 typedef struct TagClkMngNotiObserversMsg {
216 T_APIMSG_MSGBUF_HEADER header; /* Message header */
217 u_int8 hour; /* Hour */
218 u_int8 min; /* Minutes */
219 u_int8 sec; /* Second */
221 } CLKMNG_NOTIOBSERVERS_MSG;
224 Time Management API -> Time Management Thread Message Definition
225 - - - - - - - - - - - - - - - - - - - - - - */
226 /* Change Notification Registration Message from the Accuracy of Time for Time Management */
227 typedef struct TagClkMngNotAccuracyEntryMsg {
228 T_APIMSG_MSGBUF_HEADER header; /* Message header */
229 } CLKMNG_NOTIACCURACY_ENTRY_MSG;
231 /* Time change notification registration message for time management */
232 typedef struct TagClkMngNotiObserversEntryMsg {
233 T_APIMSG_MSGBUF_HEADER header; /* Message header */
234 u_int8 notify_time; /* Notification unit (Hour,Minutes,One of the seconds) */
236 } CLKMNG_NOTIOBSERVERS_ENTRY_MSG;
239 API Function Prototype Declaration
240 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
241 RET_API ClockInitApi(void); /* API initialization processing */
242 RET_API ClockGetLocalTime(RealTimeData *real_time, TimestampData *timestamp); /* Current time reference processing */
243 RET_API ClockGetLocalTimeBcd(RealTimeDataBcd *real_time_bcd, TimestampData *timestamp); /* Current time reference processing(BCD) */
244 RET_API ClockGetUtcTime(RealTimeData* real_time, TimestampData *timestamp); /* Current UTC time reference processing */
245 RET_API ClockCnvDateToSec(const LPSYSTEMTIME sys_time, u_int32* sec); /* Date and time,Total seconds conversion */
246 RET_API ClockCnvSecToDate(const u_int32* sec, LPSYSTEMTIME sys_time); /* Total seconds,Date and time conversion */
247 RET_API ClockGetAddOpeTime(u_int32 *ope_time); /* Accumulated operating time reference processing */
248 RET_API ClockSetSystemTime(PNO snd_pno, const SysTimeData* sys_time, u_int8 gps_status); /* System time setting process */
250 RET_API ClockNotifyObserversClock(PNO snd_pno, u_int8 rsc_id, u_int8 notify_time); /* Fixed period time change notification registration */
251 RET_API ClockNotifyObserversAccuracy(PNO snd_pno, u_int8 rsc_id); /* Register change notification based on the time probability */
252 RET_API ClockNotifyObserversAdjustClock(PNO snd_pno, u_int8 rsc_id); /* System time setting change notification registration */
258 #endif // POSITIONING_CLIENT_INCLUDE_CLOCK_API_H_