Hi Mario,
My system has 2 MCU. One is QN9021 and the other is FXTH8709. FXTH8709 will send data to QN9021 through I2C if FXTH8709 got LF (125KHz) data. And QN9021 send i-beacon out.
My code snippet is as follows. The watchdog cannot reset the system if I #define SLEEP_TEST 1. But The watchdog reset the system if I comment "#define SLEEP_TEST 1". It seems enter sleep will disable the watchdog function. How to enable watchdog function when the system wake up?
Thanks
Ted Wu
At the file of app_config.h, enable watchdog
/// ADV watchdog timer
//#if (defined(CFG_ADV_WDT))
#define QN_ADV_WDT
//#endif
At the file of app_util.h
uint8_t app_set_adv_data(uint16_t disc_mode)
{
uint8_t len;
//lock system for test
while(1)
{}
if (GAP_BROADCASTER == (disc_mode & GAP_BROADCASTER)) // beacon mode
{
....
At the file of usr_design.h
void usr_sleep_restore(void)
{
#if QN_DBG_PRINT
uart_init(QN_DEBUG_UART, USARTx_CLK(0), UART_9600);
uart_tx_enable(QN_DEBUG_UART, MASK_ENABLE);
uart_rx_enable(QN_DEBUG_UART, MASK_ENABLE);
#endif
#if (defined(QN_ADV_WDT))
if(usr_env.adv_wdt_enable)
{
wdt_init(65536, WDT_INT_MOD); // 2s
}
#endif
}
At the file of app_main.h
#define SLEEP_TEST 1
int main(void)
{
int ble_sleep_st, usr_sleep_st;
// DC-DC
dc_dc_enable(QN_DC_DC_ENABLE);
rf_tx_power_level_set (TX_GAIN_LEVLE12); // 4dbm
// QN platform initialization
#if QN_NVDS_WRITE
plf_init(QN_POWER_MODE, __XTAL, QN_32K_RCO, nvds_tmp_buf, NVDS_TMP_BUF_SIZE);
#else
plf_init(QN_POWER_MODE, __XTAL, QN_32K_RCO, NULL, 0);
#endif
#if (defined(QN_9020_B1) && (!QN_PMU_VOLTAGE))
disable_patch_b1();
#endif
// System initialization, user configuration
SystemInit();
wdt_init(65536, WDT_RESET_MOD); // 2s
// Profiles register
#if (QN_WORK_MODE != WORK_MODE_HCI)
prf_register();
#endif
button_init();
// Work mode defined in the usr_config.h
ble_init((enum WORK_MODE)QN_WORK_MODE, QN_HCI_UART, QN_HCI_UART_RD, QN_HCI_UART_WR, ble_heap, BLE_HEAP_SIZE, QN_BLE_SLEEP);
set_max_sleep_duration(QN_BLE_MAX_SLEEP_DUR);
// If QN902x works on wireless SoC mode, initialize APP task
#if (QN_WORK_MODE == WORK_MODE_SOC)
app_init();
#endif
usr_init();
sleep_init();
wakeup_by_sleep_timer(__32K_TYPE);
GLOBAL_INT_START();
QPRINTF("power on\r\n");
while(1)
{
// comment it for test
// wdt_set(65536); // 2s
ke_schedule();
// Checks for sleep have to be done with interrupt disabled
GLOBAL_INT_DISABLE_WITHOUT_TUNER();
// Check whether the chip can enters sleep mode
//
// Chip enter sleep condition:
// +--------+--------+--------+--------+--------+
// | USR | | | | |
// | BLE | ACTIVE | IDLE | SLEEP | DEEP |
// +--------+--------+--------+--------+--------+
// | ACTIVE | active | active | active | active |
// | IDLE | active | idle | idle | idle |
// | SLEEP | active | idle | sleep | deep |
// +--------+--------+--------+--------+--------+
#ifdef SLEEP_TEST
// Obtain the status of the user program
usr_sleep_st = usr_sleep();
// If the user program can be sleep or deep sleep then check ble status
if(usr_sleep_st != PM_ACTIVE)
{
// Obtain the status of ble sleep mode
ble_sleep_st = ble_sleep(usr_sleep_st);
// Check if the processor clock can be gated
if(((ble_sleep_st == PM_IDLE) || (usr_sleep_st == PM_IDLE))
&& (ble_sleep_st != PM_ACTIVE))
{
enter_sleep(SLEEP_CPU_CLK_OFF,
WAKEUP_BY_ALL_IRQ_SOURCE,
NULL);
}
// Check if the processor can be power down
else if((ble_sleep_st == PM_SLEEP) && (usr_sleep_st == PM_SLEEP))
{
enter_sleep(SLEEP_NORMAL,
(WAKEUP_BY_OSC_EN | WAKEUP_BY_GPIO),
sleep_cb);
}
// Check if the system can be deep sleep
else if((ble_sleep_st == PM_SLEEP) && (usr_sleep_st == PM_DEEP_SLEEP))
{
enter_sleep(SLEEP_DEEP,
WAKEUP_BY_GPIO,
sleep_cb);
}
}
#endif
// Checks for sleep have to be done with interrupt disabled
GLOBAL_INT_RESTORE_WITHOUT_TUNER();
}
}