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
18typedef unsigned int uint;
19
30#ifdef NDEBUG
31typedef uint64_t absolute_time_t;
32#else
33typedef struct {
34 uint64_t _private_us_since_boot;
36#endif
37
44static 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
59static 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
68#ifdef NDEBUG
69#define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = value
70#else
71#define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = {value}
72#endif
73
81typedef struct {
82 int16_t year;
83 int8_t month;
84 int8_t day;
85 int8_t dotw;
86 int8_t hour;
87 int8_t min;
88 int8_t sec;
90
91#define bool_to_bit(x) ((uint)!!(x))
92
93#endif
94#endif
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
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
Definition: types.h:33
Structure containing date and time information.
Definition: types.h:81
int8_t day
1..28,29,30,31 depending on month
Definition: types.h:84
int8_t hour
0..23
Definition: types.h:86
int8_t month
1..12, 1 is January
Definition: types.h:83
int16_t year
0..4095
Definition: types.h:82
int8_t dotw
0..6, 0 is Sunday
Definition: types.h:85
int8_t min
0..59
Definition: types.h:87
int8_t sec
0..59
Definition: types.h:88