Better TLSR Deep Sleep

This commit is contained in:
atc1441
2024-04-25 01:41:10 +02:00
parent 50e029d2dd
commit c1171b2e99
11 changed files with 87 additions and 54 deletions

View File

@@ -117,6 +117,33 @@ extern "C"
EV_POLL_MAX,
} ev_poll_e;
#define PA7_FUNC AS_GPIO
#define PD2_FUNC AS_GPIO
#define PD3_FUNC AS_GPIO
#define PA0_FUNC AS_GPIO
#define PB1_FUNC AS_GPIO
#define PD4_FUNC AS_GPIO
#define PD7_FUNC AS_GPIO
#define PA1_FUNC AS_GPIO
#define PB4_FUNC AS_GPIO
#define PB5_FUNC AS_GPIO
#define PB6_FUNC AS_GPIO
#define PC5_FUNC AS_GPIO
#define PC0_FUNC AS_GPIO
#define PC1_FUNC AS_GPIO
#define PC6_FUNC AS_GPIO
#define PC4_FUNC AS_GPIO
#define PULL_WAKEUP_SRC_PD4 PM_PIN_PULLUP_1M
#define PULL_WAKEUP_SRC_PD7 PM_PIN_PULLUP_1M
#define PULL_WAKEUP_SRC_PA1 PM_PIN_PULLUP_1M
#define PULL_WAKEUP_SRC_PB4 PM_PIN_PULLUP_1M
#define PULL_WAKEUP_SRC_PB5 PM_PIN_PULLUP_1M
#define PULL_WAKEUP_SRC_PB6 PM_PIN_PULLUP_1M
#define PULL_WAKEUP_SRC_PC5 PM_PIN_PULLUP_1M
enum{
CLOCK_SYS_CLOCK_1S = CLOCK_SYS_CLOCK_HZ,
CLOCK_SYS_CLOCK_1MS = (CLOCK_SYS_CLOCK_1S / 1000),

View File

@@ -28,8 +28,8 @@ const char *BLE_conn_string[] = {"", "B"};
RAM uint8_t epd_temperature_is_read = 0;
RAM uint8_t epd_temperature = 0;
uint8_t epd_buffer[epd_buffer_size];
uint8_t epd_temp[epd_buffer_size]; // for OneBitDisplay to draw into
uint8_t *epd_buffer = (uint8_t *)0x84C000;
uint8_t *epd_temp = (uint8_t *)(0x84C000 + epd_buffer_size);
OBDISP obd; // virtual display structure
// With this we can force a display if it wasnt detected correctly

View File

@@ -87,66 +87,71 @@ int main(void)
{
startup_state_e state = drv_platform_init();
u8 isRetention = (state == SYSTEM_DEEP_RETENTION) ? 1 : 0;
isRetention = 0; // keep the compiler happy
noApShown = false;
drv_enable_irq();
init_led();
init_uart();
init_nfc();
printf("\r\n\r\n\r\nSTARTING\r\n\r\n\r\n\r\n");
u32 flash_mid = 0;
u8 flash_uid[16] = {0};
printf("Reading UID");
int flag = flash_read_mid_uid_with_check(&flash_mid, flash_uid);
if (flag)
{
for (int i = 0; i < 16; i++)
{
printf(" %02X", flash_uid[i]);
}
printf("\r\n");
for (int i = 0; i < 8; i++)
{
mSelfMac[i] = flash_uid[i + 8];
}
}
else
{
printf(" - Failed!\r\n");
}
sprintf(ownMacString, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", mSelfMac[7], mSelfMac[6], mSelfMac[5], mSelfMac[4], mSelfMac[3], mSelfMac[2], mSelfMac[1], mSelfMac[0]);
batteryVoltage = get_battery_mv();
printf("Battery mv: %d Millis: %d\r\n", batteryVoltage, getMillis());
// epd_display("Boot", batteryVoltage, ownMacString, 1);
initializeProto();
currentChannel = showChannelSelect();
printf("\r\n\r\n\r\nSTARTING %02X\r\n\r\n\r\n\r\n", isRetention);
wdt10s();
if (currentChannel)
if (isRetention == 0)
{
our_ch = currentChannel;
printf("AP Found\r\n");
epd_display("AP Found", batteryVoltage, ownMacString, 1);
initPowerSaving(INTERVAL_BASE);
doSleep(5000UL);
u32 flash_mid = 0;
u8 flash_uid[16] = {0};
printf("Reading UID");
int flag = flash_read_mid_uid_with_check(&flash_mid, flash_uid);
if (flag)
{
for (int i = 0; i < 16; i++)
{
printf(" %02X", flash_uid[i]);
}
printf("\r\n");
for (int i = 0; i < 8; i++)
{
mSelfMac[i] = flash_uid[i + 8];
}
}
else
{
printf(" - Failed!\r\n");
}
sprintf(ownMacString, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", mSelfMac[7], mSelfMac[6], mSelfMac[5], mSelfMac[4], mSelfMac[3], mSelfMac[2], mSelfMac[1], mSelfMac[0]);
batteryVoltage = get_battery_mv();
printf("Battery mv: %d Millis: %d\r\n", batteryVoltage, getMillis());
// epd_display("Boot", batteryVoltage, ownMacString, 1);
initializeProto();
currentChannel = showChannelSelect();
if (currentChannel)
{
our_ch = currentChannel;
printf("AP Found\r\n");
epd_display("AP Found", batteryVoltage, ownMacString, 1);
initPowerSaving(INTERVAL_BASE);
doSleep(5000UL);
}
else
{
printf("No AP found\r\n");
epd_display("No AP Found", batteryVoltage, ownMacString, 1);
initPowerSaving(INTERVAL_AT_MAX_ATTEMPTS);
noApShown = true;
doSleep(120000UL);
}
}
else
{
printf("No AP found\r\n");
epd_display("No AP Found", batteryVoltage, ownMacString, 1);
initPowerSaving(INTERVAL_AT_MAX_ATTEMPTS);
noApShown = true;
doSleep(120000UL);
printf("Saved Mac after reboot: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\r\n", mSelfMac[7], mSelfMac[6], mSelfMac[5], mSelfMac[4], mSelfMac[3], mSelfMac[2], mSelfMac[1], mSelfMac[0]);
}
while (1)
{
batteryVoltage = get_battery_mv();

View File

@@ -53,9 +53,9 @@ void doSleepGpio(uint32_t t, GPIO_PinTypeDef pin)
// WaitMs(2000);
// return;
uint32_t r = drv_disable_irq();
pm_wakeup_pad_cfg(pin, !drv_gpio_read(pin), 1);
//pm_wakeup_pad_cfg(pin, !drv_gpio_read(pin), 1);
drv_pm_longSleep(PM_SLEEP_MODE_SUSPEND, PM_WAKEUP_SRC_TIMER | PM_WAKEUP_SRC_PAD, t);
pm_wakeup_pad_cfg(pin, !drv_gpio_read(pin), 0);
//pm_wakeup_pad_cfg(pin, !drv_gpio_read(pin), 0);
drv_restore_irq(r);
uart_ndma_clear_tx_index(); // UART will be garbled otherwise
}
@@ -70,7 +70,7 @@ void doSleep(uint32_t t)
// return;
uint32_t r = drv_disable_irq();
pm_wakeup_pad_cfg(NFC_IRQ, PM_WAKEUP_LEVEL_LOW, 1);
drv_pm_longSleep(PM_SLEEP_MODE_SUSPEND, PM_WAKEUP_SRC_TIMER | PM_WAKEUP_SRC_PAD, t);
drv_pm_longSleep(PM_SLEEP_MODE_DEEP_WITH_RETENTION, PM_WAKEUP_SRC_TIMER | PM_WAKEUP_SRC_PAD, t);
pm_wakeup_pad_cfg(NFC_IRQ, PM_WAKEUP_LEVEL_LOW, 0);
drv_restore_irq(r);
uart_ndma_clear_tx_index(); // UART will be garbled otherwise

View File

@@ -22,6 +22,7 @@ void init_uart(void)
dma_chn_irq_enable(0, 0);
uart_irq_enable(0, 0);
uart_ndma_irq_triglevel(0, 0);
uart_ndma_clear_tx_index(); // UART will be garbled otherwise
}
void puts(const char *str)

View File

@@ -94,7 +94,7 @@ SECTIONS
}
PROVIDE(_end_bss_ = .);
/* ASSERT((_end_bss_ < 0x848000), "RETENTION OVERFOLWN!!!!!") */
ASSERT((_end_bss_ < 0x848000), "RETENTION OVERFOLWN!!!!!")
. = (((. + 3) / 4)*4);
PROVIDE(_custom_stored_ = _dstored_ + _end_data_ - _start_data_);