types.h
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 "pico/assert.h"
11 
12 #include <stdint.h>
13 #include <stdbool.h>
14 #include <stddef.h>
15 
16 typedef unsigned int uint;
17 
28 #ifdef NDEBUG
29 typedef uint64_t absolute_time_t;
30 #else
31 typedef struct {
32  uint64_t _private_us_since_boot;
34 #endif
35 
42 static inline uint64_t to_us_since_boot(absolute_time_t t) {
43 #ifdef NDEBUG
44  return t;
45 #else
46  return t._private_us_since_boot;
47 #endif
48 }
49 
57 static inline void update_us_since_boot(absolute_time_t *t, uint64_t us_since_boot) {
58 #ifdef NDEBUG
59  *t = us_since_boot;
60 #else
61  assert(us_since_boot <= INT64_MAX);
62  t->_private_us_since_boot = us_since_boot;
63 #endif
64 }
65 
66 #ifdef NDEBUG
67 #define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = value
68 #else
69 #define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = {value}
70 #endif
71 
79 typedef struct {
80  int16_t year;
81  int8_t month;
82  int8_t day;
83  int8_t dotw;
84  int8_t hour;
85  int8_t min;
86  int8_t sec;
87 } datetime_t;
88 
89 #define bool_to_bit(x) ((uint)!!(x))
90 
91 #endif
datetime_t::day
int8_t day
1..28,29,30,31 depending on month
Definition: types.h:82
datetime_t
Structure containing date and time information.
Definition: types.h:79
absolute_time_t
Definition: types.h:31
datetime_t::min
int8_t min
0..59
Definition: types.h:85
datetime_t::hour
int8_t hour
0..23
Definition: types.h:84
to_us_since_boot
static uint64_t to_us_since_boot(absolute_time_t t)
convert an absolute_time_t into a number of microseconds since boot.
Definition: types.h:42
update_us_since_boot
static void update_us_since_boot(absolute_time_t *t, uint64_t us_since_boot)
update an absolute_time_t value to represent a given number of microseconds since boot
Definition: types.h:57
datetime_t::year
int16_t year
0..4095
Definition: types.h:80
datetime_t::sec
int8_t sec
0..59
Definition: types.h:86
datetime_t::dotw
int8_t dotw
0..6, 0 is Sunday
Definition: types.h:83
datetime_t::month
int8_t month
1..12, 1 is January
Definition: types.h:81