Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1
12#ifndef INFUSE_SDK_INCLUDE_INFUSE_TDF_UTIL_H_
13#define INFUSE_SDK_INCLUDE_INFUSE_TDF_UTIL_H_
14
15#include <stdint.h>
16#include <string.h>
17
18#include <zephyr/bluetooth/addr.h>
19
22#include <infuse/reboot.h>
23#include <infuse/common_boot.h>
24#include <infuse/time/epoch.h>
25#include <infuse/fs/kv_store.h>
26#include <infuse/fs/kv_types.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
45static inline uint16_t tdf_id_from_accelerometer_range(uint8_t range)
46{
47 switch (range) {
48 case 2:
49 return TDF_ACC_2G;
50 case 4:
51 return TDF_ACC_4G;
52 case 8:
53 return TDF_ACC_8G;
54 default:
55 return TDF_ACC_16G;
56 }
57}
58
66static inline uint16_t tdf_id_from_gyroscope_range(uint16_t range)
67{
68 switch (range) {
69 case 125:
70 return TDF_GYR_125DPS;
71 case 250:
72 return TDF_GYR_250DPS;
73 case 500:
74 return TDF_GYR_500DPS;
75 case 1000:
76 return TDF_GYR_1000DPS;
77 default:
78 return TDF_GYR_2000DPS;
79 }
80}
81
88static inline void tdf_reboot_info_from_state(struct infuse_reboot_state *state,
89 struct tdf_reboot_info *info)
90{
91 KV_KEY_TYPE(KV_KEY_REBOOTS) reboot = {0};
92
93#ifdef CONFIG_KV_STORE
95 info->count = reboot.count;
96#endif
97
98 info->reason = state->reason;
99 info->hardware_flags = state->hardware_reason;
100 info->uptime = state->uptime;
101 info->count = reboot.count;
103#ifdef CONFIG_ARM
104 info->param_1 = state->info.exception_full.basic.pc;
105 info->param_2 = state->info.exception_full.basic.lr;
106#else
107 /* Decoding ESF's is arch specific */
108 info->param_1 = 0;
109 info->param_2 = 0;
110#endif /* CONFIG_ARG */
111 } else {
112 /* Generic, Exception Basic, Watchdog all have the same info layout */
113 info->param_1 = state->info.generic.info1;
114 info->param_2 = state->info.generic.info2;
115 }
116 strncpy(info->thread, state->thread_name, sizeof(info->thread));
117}
118
125static inline void tdf_bt_addr_le_from_stack(const bt_addr_le_t *addr,
126 struct tdf_struct_bt_addr_le *tdf)
127{
128 tdf->type = addr->type;
129 memcpy(tdf->val, addr->a.val, 6);
130}
131
140static inline void tdf_lte_conn_status_from_monitor(struct nrf_modem_network_state *network_state,
141 struct tdf_lte_conn_status *tdf, int16_t rsrp,
142 int8_t rsrq)
143{
144 tdf->cell.mcc = network_state->cell.mcc;
145 tdf->cell.mnc = network_state->cell.mnc;
146 tdf->cell.tac = network_state->cell.tac;
147 tdf->cell.eci = network_state->cell.id;
148 tdf->status = network_state->nw_reg_status;
149 tdf->tech = network_state->lte_mode;
150 tdf->earfcn = network_state->cell.earfcn;
151 tdf->rsrq = rsrq;
152 tdf->rsrp = UINT8_MAX;
153 if (rsrp != INT16_MIN) {
154 tdf->rsrp = 0 - rsrp;
155 }
156}
157
165static inline void tdf_reboot_info_log(uint8_t logger_mask)
166{
167#ifdef CONFIG_TDF_UTIL_REBOOT_INFO_LOG
168 struct infuse_reboot_state reboot_state;
169 struct tdf_reboot_info reboot_info;
170 uint64_t t = epoch_time_from_ticks(0);
171
172 /* Construct reboot info TDF */
173 infuse_common_boot_last_reboot(&reboot_state);
174 tdf_reboot_info_from_state(&reboot_state, &reboot_info);
175 /* Push TDF at logger */
176 TDF_DATA_LOGGER_LOG(logger_mask, TDF_REBOOT_INFO, t, &reboot_info);
177 if (reboot_state.info_type == INFUSE_REBOOT_INFO_EXCEPTION_ESF) {
178 /* Except word aligned exception stack frames */
179 BUILD_ASSERT(sizeof(reboot_state.info.exception_full) % sizeof(uint32_t) == 0);
180 /* Push full exception stack frame at the logger */
182 sizeof(reboot_state.info.exception_full), t,
183 &reboot_state.info.exception_full);
184 }
185#endif /* CONFIG_TDF_UTIL_REBOOT_INFO_LOG */
186}
187
192#ifdef __cplusplus
193}
194#endif
195
196#endif /* INFUSE_SDK_INCLUDE_INFUSE_TDF_UTIL_H_ */
Interactions with the common boot logic.
TDF Data Logger.
Autogenerated TDF definitions.
Infuse-IoT time based on the GPS epoch.
#define KV_KEY_TYPE(key)
Convert key ID to key type.
Definition kv_types.h:613
@ KV_KEY_REBOOTS
Number of times device has rebooted.
Definition kv_types.h:422
@ TDF_GYR_2000DPS
Gyroscope +-2000 DPS.
Definition definitions.h:731
@ TDF_REBOOT_INFO
Information pertaining to the previous reboot.
Definition definitions.h:713
@ TDF_GYR_250DPS
Gyroscope +-250 DPS.
Definition definitions.h:725
@ TDF_EXCEPTION_STACK_FRAME
Generic exception stack frame.
Definition definitions.h:799
@ TDF_GYR_1000DPS
Gyroscope +-1000 DPS.
Definition definitions.h:729
@ TDF_ACC_4G
Accelerometer +-4G.
Definition definitions.h:717
@ TDF_GYR_125DPS
Gyroscope +-125 DPS.
Definition definitions.h:723
@ TDF_ACC_8G
Accelerometer +-8G.
Definition definitions.h:719
@ TDF_ACC_2G
Accelerometer +-2G.
Definition definitions.h:715
@ TDF_GYR_500DPS
Gyroscope +-500 DPS.
Definition definitions.h:727
@ TDF_ACC_16G
Accelerometer +-16G.
Definition definitions.h:721
uint64_t epoch_time_from_ticks(uint64_t ticks)
Get the epoch time associated with a local uptime.
int infuse_common_boot_last_reboot(struct infuse_reboot_state *state)
Query the reason for the latest reboot.
@ INFUSE_REBOOT_INFO_EXCEPTION_ESF
Exception with full stack frame.
Definition reboot.h:68
#define KV_STORE_READ(key, data)
Read a key from the KV store.
Definition kv_store.h:186
static void tdf_data_logger_log(uint8_t logger_mask, uint16_t tdf_id, uint8_t tdf_len, uint64_t time, const void *data)
Add a single TDF to multiple data loggers.
Definition tdf.h:173
#define TDF_DATA_LOGGER_LOG(logger_mask, tdf_id, tdf_time, data)
Type safe wrapper around tdf_data_logger_log.
Definition tdf.h:193
static void tdf_bt_addr_le_from_stack(const bt_addr_le_t *addr, struct tdf_struct_bt_addr_le *tdf)
Populate the TDF Bluetooth address from a Bluetooth stack structure.
Definition util.h:125
static void tdf_reboot_info_from_state(struct infuse_reboot_state *state, struct tdf_reboot_info *info)
Populate a REBOOT_INFO TDF from Infuse-IoT reboot state.
Definition util.h:88
static void tdf_reboot_info_log(uint8_t logger_mask)
Log REBOOT_INFO TDF to specified TDF data loggers.
Definition util.h:165
static uint16_t tdf_id_from_accelerometer_range(uint8_t range)
Get TDF ID to use for given accelerometer full scale range.
Definition util.h:45
static uint16_t tdf_id_from_gyroscope_range(uint16_t range)
Get TDF ID to use for given gyroscope full scale range.
Definition util.h:66
static void tdf_lte_conn_status_from_monitor(struct nrf_modem_network_state *network_state, struct tdf_lte_conn_status *tdf, int16_t rsrp, int8_t rsrq)
Populate the LTE connection status TDF from modem monitor information.
Definition util.h:140
Typed key-value store for Infuse-IoT.
Autogenerated KV definitions.
Reboot handling for Infuse-IoT applications.
Reboot state information.
Definition reboot.h:105
uint32_t hardware_reason
Hardware reboot reason flags.
Definition reboot.h:119
union infuse_reboot_info info
Reboot information.
Definition reboot.h:127
char thread_name[8]
Thread executing at reboot time.
Definition reboot.h:121
enum infuse_reboot_info_type info_type
Type of the information in info.
Definition reboot.h:123
enum infuse_reboot_reason reason
Reason for the reboot.
Definition reboot.h:117
uint32_t uptime
The device uptime at the reboot.
Definition reboot.h:115
Definition nrf_modem_monitor.h:29
struct lte_lc_cell cell
Definition nrf_modem_monitor.h:35
enum lte_lc_lte_mode lte_mode
Definition nrf_modem_monitor.h:31
enum lte_lc_nw_reg_status nw_reg_status
Definition nrf_modem_monitor.h:30
Information on service cell and registration status.
Definition definitions.h:340
struct tdf_struct_lte_cell_id_global cell
Global LTE cell identifier.
Definition definitions.h:342
uint8_t rsrp
Reference signal received power (255 = Unknown)
Definition definitions.h:350
uint8_t status
Registration status (See AT+CEREG)
Definition definitions.h:346
uint8_t tech
Access Technology (7 = LTE-M, 9 = NB-IoT)
Definition definitions.h:348
int8_t rsrq
Reference signal received quality (-128 = Unknown)
Definition definitions.h:352
uint32_t earfcn
Evolved Absolute Radio Frequency Channel (E-ARFCN)
Definition definitions.h:344
Information pertaining to the previous reboot.
Definition definitions.h:188
uint32_t param_1
Program counter/Watchdog Info/Other.
Definition definitions.h:198
uint32_t param_2
Link Register/Watchdog Info/Other.
Definition definitions.h:200
uint32_t hardware_flags
Hardware flags (hwinfo_get_reset_cause)
Definition definitions.h:192
uint32_t uptime
Uptime before reboot (seconds)
Definition definitions.h:196
char thread[8]
Running thread at reboot.
Definition definitions.h:202
uint32_t count
Reboot counter.
Definition definitions.h:194
uint8_t reason
Reboot reason (enum infuse_reboot_reason)
Definition definitions.h:190
Bluetooth address type (bt_addr_le_t)
Definition definitions.h:89
uint8_t type
Address type (0 == Public, 1 == Random)
Definition definitions.h:91
uint8_t val[6]
Address bytes.
Definition definitions.h:93
uint16_t tac
Tracking Area Code.
Definition definitions.h:71
uint32_t eci
E-UTRAN Cell ID.
Definition definitions.h:69
uint16_t mnc
Mobile Network Code.
Definition definitions.h:67
uint16_t mcc
Mobile Country Code.
Definition definitions.h:65
struct arch_esf exception_full
Definition reboot.h:94
uint32_t info1
Info 1.
Definition reboot.h:82
uint32_t info2
Info 2.
Definition reboot.h:84
struct infuse_reboot_info::@31 generic