-
Notifications
You must be signed in to change notification settings - Fork 1
/
esp_crash_upload_timer.c
71 lines (57 loc) · 3.03 KB
/
esp_crash_upload_timer.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
// -----------------------------------------------------------------------------
// Includes
// -----------------------------------------------------------------------------
#include <assert.h>
#include <string.h>
#include "esp_crash.h"
#include "esp_crash_upload_timer.h"
#include "esp_log.h"
#include "esp_partition.h"
#include "esp_system.h"
#include "esp_timer.h"
// -----------------------------------------------------------------------------
// Macros and Typedefs
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Static Function Declarations
// -----------------------------------------------------------------------------
static void periodic_timer_callback(void *arg);
// -----------------------------------------------------------------------------
// Global Variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Static Variables
// -----------------------------------------------------------------------------
static const char *TAG = "esp_crash_upload_timer";
static esp_timer_handle_t periodic_timer_handle = NULL;
// -----------------------------------------------------------------------------
// Public Function Definitions
// -----------------------------------------------------------------------------
esp_err_t esp_crash_upload_timer_init()
{
if (!esp_crash_coredump_available()) {
return ESP_OK;
}
ESP_LOGI(TAG, "Coredump available, will upload %s to %s in %u seconds", CONFIG_ESP_CRASH_DEFAULT_FILENAME, CONFIG_ESP_CRASH_DEFAULT_URL,
CONFIG_ESP_CRASH_TIMER_PERIOD_S);
// Handle coredump upload timer.
const esp_timer_create_args_t periodic_coredump_check = {.callback = &periodic_timer_callback,
/* name is optional, but may help identify the timer when debugging */
.name = "upload_coredump"};
ESP_ERROR_CHECK(esp_timer_create(&periodic_coredump_check, &periodic_timer_handle));
esp_timer_start_periodic(periodic_timer_handle, CONFIG_ESP_CRASH_TIMER_PERIOD_S * 1000000ULL);
return ESP_OK;
}
// -----------------------------------------------------------------------------
// Static Function Definitions
// -----------------------------------------------------------------------------
static void periodic_timer_callback(void *arg)
{
ESP_LOGD(TAG, "Upload coredump timer...");
int res = upload_coredump(CONFIG_ESP_CRASH_DEFAULT_URL, CONFIG_ESP_CRASH_DEFAULT_FILENAME);
if (res == 0) {
ESP_LOGI(TAG, "Successful upload, erasing coredump");
esp_crash_erase_coredump();
esp_timer_delete(periodic_timer_handle);
}
}