Skip to content

Commit 1a7b7a3

Browse files
authored
Follow pattern of other platforms
1 parent f459bc0 commit 1a7b7a3

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

src/utils.c

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int add_iso8601_utc_datetime(char *buf, size_t size)
148148
return strftime(buf, size, "%Y-%m-%dT%H:%M:%SZ", &timeinfo);
149149
}
150150

151-
#elif defined(__BARE_METAL__)
151+
#elif defined(ARDUINO)
152152

153153
#ifndef _TIMEVAL_DEFINED
154154
struct timeval {
@@ -167,8 +167,8 @@ struct timezone {
167167
int gettimeofday(struct timeval * tp, struct timezone * tzp)
168168
{
169169
ARG_UNUSED(tzp);
170-
tp->tv_sec = 0;
171-
tp->tv_usec = 0;
170+
tp->tv_sec = micros() / 1000000;
171+
tp->tv_usec = micros() % 1000000;
172172
return 0;
173173
}
174174

@@ -178,28 +178,42 @@ int add_iso8601_utc_datetime(char* buf, size_t size) {
178178
return 0;
179179
}
180180

181-
#else
182-
183-
#error Platform test failed
181+
#elif defined(__BARE_METAL__)
184182

183+
#ifndef _TIMEVAL_DEFINED
184+
struct timeval {
185+
long tv_sec; // seconds since epoch
186+
long tv_usec; // microseconds
187+
};
185188
#endif
186189

187-
#ifdef ARDUINO
190+
#ifndef _TIMEZONE_DEFINED
191+
struct timezone {
192+
int tz_minuteswest; // minutes west of UTC
193+
int tz_dsttime; // daylight saving time flag
194+
};
195+
#endif
188196

189-
int64_t usec_now()
197+
int gettimeofday(struct timeval * tp, struct timezone * tzp)
190198
{
191-
return micros();
199+
ARG_UNUSED(tzp);
200+
tp->tv_sec = 0;
201+
tp->tv_usec = 0;
202+
return 0;
192203
}
193204

194-
void get_time(uint32_t *seconds, uint32_t *micro_seconds)
195-
{
196-
*micro_seconds = micros();
197-
*seconds = *micro_seconds / 1000000;
198-
*micro_seconds %= 1000000;
205+
int add_iso8601_utc_datetime(char* buf, size_t size) {
206+
ARG_UNUSED(buf);
207+
ARG_UNUSED(size);
208+
return 0;
199209
}
200210

201211
#else
202212

213+
#error Platform test failed
214+
215+
#endif
216+
203217
int64_t usec_now()
204218
{
205219
int64_t usec;
@@ -220,8 +234,6 @@ void get_time(uint32_t *seconds, uint32_t *micro_seconds)
220234
*micro_seconds = tv.tv_usec;
221235
}
222236

223-
#endif
224-
225237
int64_t usec_since(int64_t last)
226238
{
227239
return usec_now() - last;

0 commit comments

Comments
 (0)