1 /*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef _PICO_TYPES_H
8 #define _PICO_TYPES_H
9
10 #include <stdint.h>
11 #include <stdbool.h>
12 #include <stddef.h>
13
14 typedef unsigned int uint;
15
16 #ifdef NDEBUG
17 /*! \typedef absolute_time_t
18 \brief An opaque 64 bit timestamp in microseconds
19
20 The type is used instead of a raw uint64_t to prevent accidentally passing relative times or times in the wrong
21 time units where an absolute time is required. It is equivalent to uint64_t in release builds.
22
23 \see to_us_since_boot
24 \see update_us_since_boot
25 */
26 typedef uint64_t absolute_time_t;
27
28 /*! fn to_us_since_boot
29 * \brief convert an absolute_time_t into a number of microseconds since boot.
30 * \param t the number of microseconds since boot
31 * \return an absolute_time_t value equivalent to t
32 */
to_us_since_boot(absolute_time_t t)33 static inline uint64_t to_us_since_boot(absolute_time_t t) {
34 return t;
35 }
36
37 /*! fn update_us_since_boot
38 * \brief update an absolute_time_t value to represent a given number of microseconds since boot
39 * \param t the absolute time value to update
40 * \param us_since_boot the number of microseconds since boot to represent
41 */
update_us_since_boot(absolute_time_t * t,uint64_t us_since_boot)42 static inline void update_us_since_boot(absolute_time_t *t, uint64_t us_since_boot) {
43 *t = us_since_boot;
44 }
45
46 #define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = value
47 #else
48 typedef struct {
49 uint64_t _private_us_since_boot;
50 } absolute_time_t;
51
to_us_since_boot(absolute_time_t t)52 static inline uint64_t to_us_since_boot(absolute_time_t t) {
53 return t._private_us_since_boot;
54 }
55
update_us_since_boot(absolute_time_t * t,uint64_t us_since_boot)56 static inline void update_us_since_boot(absolute_time_t *t, uint64_t us_since_boot) {
57 t->_private_us_since_boot = us_since_boot;
58 }
59 #define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = {value}
60 #endif
61
62 /** \struct datetime_t
63 * \ingroup util_datetime
64 * \brief Structure containing date and time information
65 *
66 * When setting an RTC alarm, set a field to -1 tells
67 * the RTC to not match on this field
68 */
69 typedef struct {
70 int16_t year; ///< 0..4095
71 int8_t month; ///< 1..12, 1 is January
72 int8_t day; ///< 1..28,29,30,31 depending on month
73 int8_t dotw; ///< 0..6, 0 is Sunday
74 int8_t hour; ///< 0..23
75 int8_t min; ///< 0..59
76 int8_t sec; ///< 0..59
77 } datetime_t;
78
79 #endif
80