forked from memfault/memfault-firmware-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memfault_platform_port.c
112 lines (93 loc) · 3.85 KB
/
memfault_platform_port.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//!
//! Glue layer between the Memfault SDK and the underlying platform
//!
//! TODO: Fill in FIXMEs below for your platform
#include "memfault/components.h"
#include "memfault/ports/reboot_reason.h"
#include <stdbool.h>
void memfault_platform_get_device_info(sMemfaultDeviceInfo *info) {
// !FIXME: Populate with platform device information
// IMPORTANT: All strings returned in info must be constant
// or static as they will be used _after_ the function returns
// See https://mflt.io/version-nomenclature for more context
*info = (sMemfaultDeviceInfo) {
// An ID that uniquely identifies the device in your fleet
// (i.e serial number, mac addr, chip id, etc)
// Regular expression defining valid device serials: ^[-a-zA-Z0-9_]+$
.device_serial = "DEMOSERIAL",
// A name to represent the firmware running on the MCU.
// (i.e "ble-fw", "main-fw", or a codename for your project)
.software_type = "app-fw",
// The version of the "software_type" currently running.
// "software_type" + "software_version" must uniquely represent
// a single binary
.software_version = "1.0.0",
// The revision of hardware for the device. This value must remain
// the same for a unique device.
// (i.e evt, dvt, pvt, or rev1, rev2, etc)
// Regular expression defining valid hardware versions: ^[-a-zA-Z0-9_\.\+]+$
.hardware_version = "dvt1",
};
}
//! Last function called after a coredump is saved. Should perform
//! any final cleanup and then reset the device
void memfault_platform_reboot(void) {
// !FIXME: Perform any final system cleanup here
// !FIXME: Reset System
// NVIC_SystemReset()
while (1) { } // unreachable
}
bool memfault_platform_time_get_current(sMemfaultCurrentTime *time) {
// !FIXME: If the device tracks real time, update 'unix_timestamp_secs' with seconds since epoch
// This will cause events logged by the SDK to be timestamped on the device rather than when they
// arrive on the server
*time = (sMemfaultCurrentTime) {
.type = kMemfaultCurrentTimeType_UnixEpochTimeSec,
.info = {
.unix_timestamp_secs = 0
},
};
// !FIXME: If device does not track time, return false, else return true if time is valid
return false;
}
size_t memfault_platform_sanitize_address_range(void *start_addr, size_t desired_size) {
static const struct {
uint32_t start_addr;
size_t length;
} s_mcu_mem_regions[] = {
// !FIXME: Update with list of valid memory banks to collect in a coredump
{.start_addr = 0x00000000, .length = 0xFFFFFFFF},
};
for (size_t i = 0; i < MEMFAULT_ARRAY_SIZE(s_mcu_mem_regions); i++) {
const uint32_t lower_addr = s_mcu_mem_regions[i].start_addr;
const uint32_t upper_addr = lower_addr + s_mcu_mem_regions[i].length;
if ((uint32_t)start_addr >= lower_addr && ((uint32_t)start_addr < upper_addr)) {
return MEMFAULT_MIN(desired_size, upper_addr - (uint32_t)start_addr);
}
}
return 0;
}
//! !FIXME: This function _must_ be called by your main() routine prior
//! to starting an RTOS or baremetal loop.
int memfault_platform_boot(void) {
// !FIXME: Add init to any platform specific ports here.
// (This will be done in later steps in the getting started Guide)
memfault_build_info_dump();
memfault_device_info_dump();
memfault_platform_reboot_tracking_boot();
static uint8_t s_event_storage[1024];
const sMemfaultEventStorageImpl *evt_storage =
memfault_events_storage_boot(s_event_storage, sizeof(s_event_storage));
memfault_trace_event_boot(evt_storage);
memfault_reboot_tracking_collect_reset_info(evt_storage);
sMemfaultMetricBootInfo boot_info = {
.unexpected_reboot_count = memfault_reboot_tracking_get_crash_count(),
};
memfault_metrics_boot(evt_storage, &boot_info);
MEMFAULT_LOG_INFO("Memfault Initialized!");
return 0;
}