Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1
10#ifndef INFUSE_SDK_INCLUDE_INFUSE_DATA_LOGGER_LOGGER_H_
11#define INFUSE_SDK_INCLUDE_INFUSE_DATA_LOGGER_LOGGER_H_
12
13#include <stdint.h>
14
15#include <infuse/types.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
29 /* Bytes logged since reboot */
30 uint64_t bytes_logged;
31 /* Number of logical blocks on the logger */
33 /* Number of physical blocks on the logger */
35 /* Number of blocks present at boot */
36 uint32_t boot_block;
37 /* Number of logical blocks that have been written */
38 uint32_t current_block;
39 /* Earliest logical block that still exists on the logger */
41 /* Size of a single block in bytes */
42 uint16_t block_size;
43 /* Number of bytes at the start of the block that should not contain data */
45 /* Minimum erase unit of the logger in bytes */
46 uint16_t erase_unit;
47 /* Writes require the full block size to be provided */
49};
50
51/* Header on every block logged to persistent storage */
53 /* One byte wrap count (1 - 254) */
54 uint8_t block_wrap;
55 /* Type of block data */
56 uint8_t block_type;
57} __packed;
58
67 void (*block_size_update)(const struct device *dev, uint16_t block_size, void *user_data);
78 void (*write_failure)(const struct device *dev, enum infuse_type data_type, const void *mem,
79 uint16_t mem_len, int reason, void *user_data);
80 /* Arbitrary user data pointer */
81 void *user_data;
82 /* Private list iteration field */
83 sys_snode_t node;
84};
85
94#define DATA_LOGGER_DEPENDENCIES_MET(node_id) \
95 COND_CODE_1(DT_NODE_HAS_COMPAT(node_id, embeint_data_logger_epacket), \
96 (EPACKET_INTERFACE_IS_COMPILED_IN(DT_PROP(node_id, epacket))), (1))
97
105#define DATA_LOGGER_MAX_SIZE(node_id) \
106 COND_CODE_1( \
107 DT_NODE_HAS_COMPAT(node_id, embeint_data_logger_flash_map), (512), \
108 (COND_CODE_1(DT_NODE_HAS_COMPAT(node_id, embeint_data_logger_epacket), \
109 (EPACKET_INTERFACE_MAX_PAYLOAD(DT_PROP(node_id, epacket))), \
110 ((COND_CODE_1(DT_NODE_HAS_COMPAT(node_id, embeint_data_logger_exfat), \
111 (512), ()))))))
112
119void data_logger_get_state(const struct device *dev, struct data_logger_state *state);
120
138int data_logger_block_write(const struct device *dev, enum infuse_type type, void *block,
139 uint16_t block_len);
140
160int data_logger_block_read(const struct device *dev, uint32_t block_idx, uint16_t block_offset,
161 void *block, uint16_t block_len);
162
176int data_logger_erase(const struct device *dev, bool erase_all,
177 void (*erase_progress)(uint32_t blocks_erased));
178
192int data_logger_flush(const struct device *dev);
193
200void data_logger_register_cb(const struct device *dev, struct data_logger_cb *cb);
201
202#ifdef CONFIG_ZTEST
203
210void data_logger_set_erase_state(const struct device *dev, bool enabled);
211
212#endif /* CONFIG_ZTEST */
213
218#ifdef __cplusplus
219}
220#endif
221
222#endif /* INFUSE_SDK_INCLUDE_INFUSE_DATA_LOGGER_LOGGER_H_ */
void data_logger_get_state(const struct device *dev, struct data_logger_state *state)
Get the current data logger state.
int data_logger_erase(const struct device *dev, bool erase_all, void(*erase_progress)(uint32_t blocks_erased))
Completely erase a data logger.
int data_logger_flush(const struct device *dev)
Flush any data pending in a RAM buffer to the backend.
int data_logger_block_read(const struct device *dev, uint32_t block_idx, uint16_t block_offset, void *block, uint16_t block_len)
Read a block from the data logger.
int data_logger_block_write(const struct device *dev, enum infuse_type type, void *block, uint16_t block_len)
Write a block to the data logger.
void data_logger_register_cb(const struct device *dev, struct data_logger_cb *cb)
Register for event callbacks from the data logger.
infuse_type
Core Infuse Data Types.
Definition types.h:26
Core Infuse-IoT platform types.
ePacket Interface API
Definition logger.h:59
void(* block_size_update)(const struct device *dev, uint16_t block_size, void *user_data)
Data logger has changed the maximum block size.
Definition logger.h:67
void(* write_failure)(const struct device *dev, enum infuse_type data_type, const void *mem, uint16_t mem_len, int reason, void *user_data)
Writing to the data logger has failed.
Definition logger.h:78
void * user_data
Definition logger.h:81
sys_snode_t node
Definition logger.h:83
uint8_t block_type
Definition logger.h:56
uint8_t block_wrap
Definition logger.h:54
Definition logger.h:28
uint32_t current_block
Definition logger.h:38
uint32_t logical_blocks
Definition logger.h:32
uint32_t boot_block
Definition logger.h:36
uint16_t block_size
Definition logger.h:42
uint16_t erase_unit
Definition logger.h:46
bool requires_full_block_write
Definition logger.h:48
uint32_t earliest_block
Definition logger.h:40
uint32_t physical_blocks
Definition logger.h:34
uint16_t block_overhead
Definition logger.h:44
uint64_t bytes_logged
Definition logger.h:30