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 #ifndef __ASSEMBLER__
11 
12 #include "pico/assert.h"
13 
14 #include <stdint.h>
15 #include <stdbool.h>
16 #include <stddef.h>
17 
18 typedef unsigned int uint;
19 
30 #ifdef NDEBUG
31 typedef uint64_t absolute_time_t;
32 #else
33 typedef struct {
34  uint64_t _private_us_since_boot;
36 #endif
37 
44 static inline uint64_t to_us_since_boot(absolute_time_t t) {
45 #ifdef NDEBUG
46  return t;
47 #else
48  return t._private_us_since_boot;
49 #endif
50 }
51 
59 static inline void update_us_since_boot(absolute_time_t *t, uint64_t us_since_boot) {
60 #ifdef NDEBUG
61  *t = us_since_boot;
62 #else
63  assert(us_since_boot <= INT64_MAX);
64  t->_private_us_since_boot = us_since_boot;
65 #endif
66 }
67 
74 static inline absolute_time_t from_us_since_boot(uint64_t us_since_boot) {
76  update_us_since_boot(&t, us_since_boot);
77  return t;
78 }
79 
80 #ifdef NDEBUG
81 #define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = value
82 #else
83 #define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = {value}
84 #endif
85 
93 typedef struct {
94  int16_t year;
95  int8_t month;
96  int8_t day;
97  int8_t dotw;
98  int8_t hour;
99  int8_t min;
100  int8_t sec;
101 } datetime_t;
102 
103 #define bool_to_bit(x) ((uint)!!(x))
104 
105 #endif
106 #endif
datetime_t::day
int8_t day
1..28,29,30,31 depending on month
Definition: types.h:96
datetime_t
Structure containing date and time information.
Definition: types.h:93
absolute_time_t
Definition: types.h:33
datetime_t::min
int8_t min
0..59
Definition: types.h:99
datetime_t::hour
int8_t hour
0..23
Definition: types.h:98
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:44
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:59
datetime_t::year
int16_t year
0..4095
Definition: types.h:94
datetime_t::sec
int8_t sec
0..59
Definition: types.h:100
datetime_t::dotw
int8_t dotw
0..6, 0 is Sunday
Definition: types.h:97
from_us_since_boot
static absolute_time_t from_us_since_boot(uint64_t us_since_boot)
convert a number of microseconds since boot to an absolute_time_t
Definition: types.h:74
datetime_t::month
int8_t month
1..12, 1 is January
Definition: types.h:95