@@ -1194,6 +1194,13 @@ namespace DW1000Ng {
1194
1194
DW1000NgUtils::writeValueToBytes (enable_mask, 0x005FFF00 , LEN_RX_CONF_SUB);
1195
1195
_writeBytesToRegister (RF_CONF, RF_CONF_SUB, enable_mask, LEN_RX_CONF_SUB);
1196
1196
}
1197
+
1198
+ void _uploadConfigToAON () {
1199
+ /* Write 1 in UPL_CFG_BIT */
1200
+ _writeToRegister (AON, AON_CTRL_SUB, 0x04 , LEN_AON_CTRL);
1201
+ /* Clear the register */
1202
+ _writeToRegister (AON, AON_CTRL_SUB, 0x00 , LEN_AON_CTRL);
1203
+ }
1197
1204
}
1198
1205
1199
1206
/* ####################### PUBLIC ###################### */
@@ -1388,31 +1395,35 @@ namespace DW1000Ng {
1388
1395
_writeBytesToRegister (GPIO_CTRL, GPIO_MODE_SUB, gpiomode, LEN_GPIO_MODE);
1389
1396
}
1390
1397
1391
- void deepSleep ( ) {
1398
+ void applySleepConfiguration ( sleep_configuration_t sleep_config ) {
1392
1399
byte aon_wcfg[LEN_AON_WCFG];
1393
- memset (aon_wcfg, 0 , LEN_AON_WCFG);
1394
1400
_readBytes (AON, AON_WCFG_SUB, aon_wcfg, LEN_AON_WCFG);
1401
+ byte aon_cfg0[1 ];
1402
+ memset (aon_cfg0, 0 , 1 );
1403
+
1404
+ DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_RADC_BIT, sleep_config.onWakeUpRunADC );
1405
+ DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_RX_BIT, sleep_config.onWakeUpReceive );
1406
+ DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_LEUI_BIT, sleep_config.onWakeUpLoadEUI );
1395
1407
DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_LDC_BIT, true );
1396
- DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_PRES_SLEEP_BIT, false );
1408
+ DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_L64P_BIT, sleep_config.onWakeUpLoadL64Param );
1409
+ DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_PRES_SLEEP_BIT, sleep_config.preserveSleep );
1397
1410
DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_LLDE_BIT, true );
1398
- DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_LDD0_BIT , true );
1411
+ DW1000NgUtils::setBit (aon_wcfg, LEN_AON_WCFG, ONW_LLDO_BIT , true );
1399
1412
_writeBytesToRegister (AON, AON_WCFG_SUB, aon_wcfg, LEN_AON_WCFG);
1400
1413
1401
- byte aon_cfg0[LEN_AON_CFG0];
1402
- memset (aon_cfg0, 0 , LEN_AON_CFG0);
1403
- _readBytes (AON, AON_CFG0_SUB, aon_cfg0, LEN_AON_CFG0);
1404
- DW1000NgUtils::setBit (aon_cfg0, LEN_AON_CFG0, WAKE_PIN_BIT, true );
1405
- DW1000NgUtils::setBit (aon_cfg0, LEN_AON_CFG0, WAKE_SPI_BIT, true );
1406
- DW1000NgUtils::setBit (aon_cfg0, LEN_AON_CFG0, WAKE_CNT_BIT, false );
1407
- DW1000NgUtils::setBit (aon_cfg0, LEN_AON_CFG0, SLEEP_EN_BIT, true );
1408
- _writeBytesToRegister (AON, AON_CFG0_SUB, aon_cfg0, LEN_AON_CFG0);
1409
-
1410
- byte aon_ctrl[LEN_AON_CTRL];
1411
- memset (aon_ctrl, 0 , LEN_AON_CTRL);
1412
- _readBytes (AON, AON_CTRL_SUB, aon_ctrl, LEN_AON_CTRL);
1413
- // DW1000NgUtils::setBit(aon_ctrl, LEN_AON_CTRL, UPL_CFG_BIT, true);
1414
- DW1000NgUtils::setBit (aon_ctrl, LEN_AON_CTRL, SAVE_BIT, true );
1415
- _writeBytesToRegister (AON, AON_CTRL_SUB, aon_ctrl, LEN_AON_CTRL);
1414
+ DW1000NgUtils::setBit (aon_cfg0, 1 , WAKE_PIN_BIT, sleep_config.enableWakePIN );
1415
+ DW1000NgUtils::setBit (aon_cfg0, 1 , WAKE_SPI_BIT, sleep_config.enableWakeSPI );
1416
+ DW1000NgUtils::setBit (aon_cfg0, 1 , WAKE_CNT_BIT, false );
1417
+ DW1000NgUtils::setBit (aon_cfg0, 1 , SLEEP_EN_BIT, sleep_config.enableSLP );
1418
+ _writeBytesToRegister (AON, AON_CFG0_SUB, aon_cfg0, 1 ); // Deletes 3 bits of the unused LPCLKDIVA
1419
+ }
1420
+
1421
+ /* Puts the device into sleep/deepSleep mode. This function also upload sleep config to AON. */
1422
+ void deepSleep () {
1423
+ /* Clear the register */
1424
+ _writeToRegister (AON, AON_CTRL_SUB, 0x00 , LEN_AON_CTRL);
1425
+ /* Write 1 in SAVE_BIT */
1426
+ _writeToRegister (AON, AON_CTRL_SUB, 0x02 , LEN_AON_CTRL);
1416
1427
}
1417
1428
1418
1429
void spiWakeup (){
0 commit comments