Skip to content

Commit 64aa51e

Browse files
committed
sys/log, fs/fcb: Add trailer per entry in logs and fcb
- Add syscfgs for controlling the functionality along with callbacks - This is an optional feature enabled only if LOG_FLAGS_TRAILER_SUPPORT: 1
1 parent a9db4b1 commit 64aa51e

File tree

12 files changed

+766
-169
lines changed

12 files changed

+766
-169
lines changed

fs/fcb2/include/fcb/fcb2.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ int fcb2_clear(struct fcb2 *fcb);
304304
*/
305305
int fcb2_area_info(struct fcb2 *fcb, int sector, int *elemsp, int *bytesp);
306306

307+
/**
308+
* Length of data in flash considering alignment
309+
*
310+
* @param range Active range
311+
* @param len Length to be calculated using alignment
312+
*
313+
*/
314+
int fcb2_len_in_flash(const struct flash_sector_range *range, uint16_t len);
315+
307316
#ifdef __cplusplus
308317
}
309318

fs/fcb2/src/fcb.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ fcb2_init(struct fcb2 *fcb)
101101
return rc;
102102
}
103103

104+
int
105+
fcb2_len_in_flash(const struct flash_sector_range *range, uint16_t len)
106+
{
107+
if (range->fsr_align <= 1) {
108+
return len;
109+
}
110+
return (len + (range->fsr_align - 1)) & ~(range->fsr_align - 1);
111+
}
112+
104113
int
105114
fcb2_free_sector_cnt(struct fcb2 *fcb)
106115
{

fs/fcb2/src/fcb_priv.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ struct fcb2_sector_info {
4040
uint16_t si_sector_in_range; /* Sector number relative to si_range */
4141
};
4242

43-
static inline int
44-
fcb2_len_in_flash(const struct flash_sector_range *range, uint16_t len)
45-
{
46-
if (range->fsr_align <= 1) {
47-
return len;
48-
}
49-
return (len + (range->fsr_align - 1)) & ~(range->fsr_align - 1);
50-
}
51-
5243
int fcb2_getnext_in_area(struct fcb2 *fcb, struct fcb2_entry *loc);
5344

5445
static inline int

hw/mcu/native/src/hal_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static int
152152
flash_native_write_internal(uint32_t address, const void *src, uint32_t length,
153153
int allow_overwrite)
154154
{
155-
static uint8_t buf[256];
155+
uint8_t buf[256] = {0};
156156
uint32_t cur;
157157
uint32_t end;
158158
int chunk_sz;

sys/log/common/include/log_common/log_common.h

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern "C" {
2828
#endif
2929

3030
struct log;
31+
struct log_entry_hdr;
3132

3233
#define LOG_VERSION_V3 3
3334

@@ -132,11 +133,79 @@ typedef void log_append_cb(struct log *log, uint32_t idx);
132133

133134
/** @typdef log_notify_rotate_cb
134135
* @brief Callback that is executed each time we are about to rotate a log.
135-
*
136-
* @param log The log that is about to rotate
136+
*
137+
* @param log The log that is about to rotate
137138
*/
138139
typedef void log_notify_rotate_cb(const struct log *log);
139140

141+
/** @typedef log_trailer_append_cb
142+
* @brief Callback that is executed each time the corresponding log entry is
143+
* appended to
144+
*
145+
* @param log The log that was just appended to
146+
* @param buf Buffer to append trailer to
147+
* @param buflen Pointer to the length of the trailer to be filled up
148+
* optionally
149+
* @param loc Argument pointing to the location of
150+
* the entry
151+
* @param f_offset Pointer to the offset(optional) at which append should
152+
* happen
153+
*
154+
* @return 0 on success, non-zero on failure
155+
*/
156+
typedef int log_trailer_append_cb(struct log *log, uint8_t *buf,
157+
uint16_t *buflen, void *loc,
158+
uint16_t *f_offset);
159+
160+
/** @typedef log_mbuf_trailer_append_cb
161+
* @brief Callback that is executed each time the corresponding log entry is
162+
* appended to
163+
*
164+
* @param log The log that was just appended to
165+
* @param om Pointer to the mbuf that contains the log entry
166+
* @param loc Argument pointing to the location of
167+
* the entry
168+
* @param f_offset The offset(optional) at which append should
169+
* happen
170+
*
171+
* @return 0 on success, non-zero on failure
172+
*/
173+
typedef int log_trailer_mbuf_append_cb(struct log *log, struct os_mbuf *om,
174+
void *loc, uint16_t f_offset);
175+
176+
/** @typedef log_process_trailer_cb
177+
* @brief Callback that is executed each time a trailer is processed
178+
*
179+
* @param log The log that was just appended to
180+
* @param arg Void pointer for a custom arg
181+
* @param dptr Pointer to the data buffer
182+
* @param len Length of the trailer
183+
*
184+
* @return 0 on success, non-zero on failure
185+
*/
186+
typedef int log_process_trailer_cb(struct log *log, void *arg, const void *dptr,
187+
uint16_t len);
188+
189+
/** @typedef log_trailer_len_cb
190+
* @brief Callback used to read length of trailer in a log entry
191+
*
192+
* @param log The log the trailer is to be read from
193+
* @param hdr Log entry header of the log entry the log is
194+
* read from
195+
* @return Length of the appended trailer
196+
*/
197+
typedef uint16_t log_trailer_len_cb(struct log *log, const struct log_entry_hdr *hdr);
198+
199+
/** @typedef log_trailer_data_len_cb
200+
* @brief Callback used to read length of trailer data in a log entry
201+
*
202+
* @param log The log the trailer is to be read from
203+
* @param hdr Log entry header of the log entry the log is
204+
* read from
205+
* @return Length of the appended trailer data
206+
*/
207+
typedef uint16_t log_trailer_data_len_cb(struct log *log, const struct log_entry_hdr *hdr);
208+
140209
#ifdef __cplusplus
141210
}
142211
#endif

0 commit comments

Comments
 (0)