-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.c
61 lines (47 loc) · 1.92 KB
/
system.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
#include "system.h"
#include <stdint.h>
#include <time.h>
#include <errno.h>
extern char _end, _eram;
static char *s_heap_start, *s_heap_end, *s_brk;
void call_start_cpu0()
{
s_heap_start = s_brk = &_end, s_heap_end = &_eram;
for (char *p = &_sbss; p < &_ebss;)
*p++ = '\0';
// Enable TIMG0
*REG(PCR_TIMERGROUP0_TIMER_CLK_CONF_REG) = 0; // RC_XTAL_CLK
*REG(PCR_TIMERGROUP0_TIMER_CLK_CONF_REG) |= BIT(22); // Enable
uint32_t t0_config = 40 << 13;
t0_config |= BIT(31) | BIT(30);
*REG(TIMG_T0CONFIG_REG) = t0_config;
wdt_disable();
spin(500000); // Few ms so we can start serial monitor
uint32_t rst_reas = esp_rom_get_reset_reason(0);
esp_rom_printf("Reset reason: 0x%02X\n", rst_reas);
main();
}
volatile uint32_t *watchdog_protect_register = LP_WDT_RWDT_WPROTECT_REG;
volatile uint32_t *reset_watchdog_register = LP_WDT_RWDT_RTC_WDT_FEED;
volatile uint32_t *superwatchdog_protect_reg = LP_WDT_SWD_WPROTECT_REG;
volatile uint32_t *superwatchdog_config_register = LP_WDT_SWD_CONFIG_REG;
volatile uint32_t *timg0_wdt_protect = TIMG0_WDTWPROTECT_REG;
volatile uint32_t *timg0_wdt_feed = TIMG0_WDTFEED_REG;
volatile uint32_t *timg1_wdt_protect = TIMG1_WDTWPROTECT_REG;
volatile uint32_t *timg1_wdt_feed = TIMG1_WDTFEED_REG;
void wdt_disable()
{
*REG(LP_WDT_RWDT_RTC_WDT_FEED) |= BIT(31);
*REG(TIMG0_WDTWPROTECT_REG) = WDT_PROTECT_VALUE;
*REG(TIMG1_WDTWPROTECT_REG) = WDT_PROTECT_VALUE;
*REG(LP_WDT_RWDT_WPROTECT_REG) = WDT_PROTECT_VALUE;
*REG(LP_WDT_SWD_WPROTECT_REG) = WDT_PROTECT_VALUE;
*REG(LP_WDT_SWD_CONFIG_REG) |= BIT(18); // Disable
*REG(TIMG0_WDTCONFIG0_REG) = 0; // Disable
*REG(TIMG1_WDTCONFIG0_REG) = 0; // Disable
*REG(LP_WDT_RWDT_CONFIG0_REG) = 0; // Disable
*REG(TIMG0_WDTWPROTECT_REG) = 0;
*REG(TIMG1_WDTWPROTECT_REG) = 0;
*REG(LP_WDT_RWDT_WPROTECT_REG) = 0;
*REG(LP_WDT_SWD_WPROTECT_REG) = 0;
}