Consider using the ULP to have a timer that waits for hours or days or????
Here is some code I got from someplace and changed it a little for my own use:
Code: Select all
void ULP_BLINK_RUN(uint32_t us);
int int_Pin = 2;
volatile unsigned int IntCount = 0;
const int ULP_WAKE_INTERVAL = 1000; // a microsecond value
setup()
{
ULP_BLINK_RUN( ULP_WAKE_INTERVAL );
}
/*
Using the blink demo, the ULP is loaded with a value, the value changes the state of GPIO2 which is used as an input for an interrupt that triggers a function.
So, if you want to use the data over reboot, store it into the RTC memory by defining a global variable with RTC_DATA_ATTR attribute. For example, RTC_DATA_ATTR int bootCount = 0;
*/
void ULP_BLINK_RUN(uint32_t us)
{
int memPortState = 8000; // memory address outside of program space to use
int memCounts = 8001; // memory address to hold a count
size_t load_addr = 0;
RTC_SLOW_MEM[memPortState] = 0;
RTC_SLOW_MEM[memCounts] = 0;
ulp_set_wakeup_period(0, us);
const ulp_insn_t ulp_blink[] =
{
I_MOVI( R2, memCounts ), // get info from memCounts address
I_LD( R1, R2, 0 ), // put contents of memCounts into R1
I_ADDI( R1, R1, 1 ), // Add 1 to R1 holding result into R1
I_ST( R1, R2, 0 ), // Put R1 into mem address pointed to by R2
I_MOVI(R3, memPortState), // memPortState -> R3
I_LD(R0, R3, 0), // R0 = RTC_SLOW_MEM[R3(memPortState)]
M_BL(1, 1), // GOTO M_LABEL(1) IF R0 < 1
I_WR_REG(RTC_GPIO_OUT_REG, 26, 27, 1), // RTC_GPIO2 = 1
I_SUBI(R0, R0, 1), // R0 = R0 - 1, R0 = 1, R0 = 0
I_ST(R0, R3, 0), // RTC_SLOW_MEM[R3(memPortState)] = R0
M_BX(2), // GOTO M_LABEL(2)
M_LABEL(1), // M_LABEL(1)
I_WR_REG(RTC_GPIO_OUT_REG, 26, 27, 0), // RTC_GPIO2 = 0
I_ADDI(R0, R0, 1), // R0 = R0 + 1, R0 = 0, R0 = 1
I_ST(R0, R3, 0), // RTC_SLOW_MEM[R3(memPortState)] = R0
M_LABEL(2), // M_LABEL(2)
I_HALT() // HALT COPROCESSOR
};
rtc_gpio_init( GPIO_NUM_2 ); // GPIO2 built in led
rtc_gpio_set_direction( GPIO_NUM_2, RTC_GPIO_MODE_INPUT_OUTPUT );
rtc_gpio_set_level( GPIO_NUM_2, 0);
size_t size = sizeof(ulp_blink) / sizeof(ulp_insn_t);
ulp_process_macros_and_load( load_addr, ulp_blink, &size);
ulp_run( load_addr );
} // void ULP_BLINK_RUN(uint32_t us)
Instead of counting up some large uS number just set a few variables in the RTC ram and use it like days:hours:minues:seconds...
These are 2 32bit address spaces set aside in rtc ram:
Code: Select all
int memPortState = 8000; // memory address outside of program space to use
int memCounts = 8001; // memory address to hold a count
Starting at RTC address 8K you can get about 100 variables.