Skip to content

Commit

Permalink
fix restyle
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-hh committed Jan 3, 2025
1 parent a0a48d2 commit 7cb6759
Show file tree
Hide file tree
Showing 25 changed files with 205 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@

#define CHIP_BLE_DEVICE_NAME "ContactSensor"

// #define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(1000)
// #define CHIP_DEVICE_CONFIG_ICD_SLOW_POLL_INTERVAL chip::System::Clock::Milliseconds32(1000)
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ to exclude the API function. */
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#ifdef __cplusplus
extern "C" void vAssertCalled( void );
extern "C" void vAssertCalled(void);
#else
extern void vAssertCalled( void );
extern void vAssertCalled(void);
#endif

#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled()
#define configASSERT(x) \
if ((x) == 0) \
vAssertCalled()

/* Overwrite some of the stack sizes allocated to various test and demo tasks.
Like all task stack sizes, the value is the number of words, not bytes. */
Expand Down
175 changes: 51 additions & 124 deletions examples/contact-sensor-app/bouffalolab/bl702l/app_pds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,129 +4,49 @@
extern "C" {
#include <bl_irq.h>
#include <bl_pds.h>
#include <bl_psram.h>
#include <bl_sec.h>
#include <bl_uart.h>
#include <bl_psram.h>
#include <hal_pds.h>
#include <hosal_uart.h>
#include <hosal_gpio.h>
#include <hosal_uart.h>

#include <btble_lib_api.h>
#include <btble_pds.h>

#include <openthread/thread.h>
#include <lmac154.h>
#include <lmac154_lp.h>
#include <zb_timer.h>
#include <openthread_port.h>
#include <mboard.h>
#include <openthread/thread.h>
#include <openthread_port.h>
#include <zb_timer.h>
}

#define PDS_TOLERANCE_TIME_32768CYCLE (164)
#define PDS_MIN_TIME_32768CYCLE (PDS_WARMUP_LATENCY_CNT + 33)
#define PDS_SLEEP_MAX_MS 3600000

btble_app_conf_t app_pds_conf =
{
.print_enable = 0,//1: enable uart print in library; 0: disable uart print in library
.gpio_irq_restore = 1, //1: restore gpio irq after pds wakeup; 0: do not restore gpio irq after pds wakeup
.gpio_num = 2, //3,
.gpio_index = {CHIP_RESET_PIN, CHIP_CONTACT_PIN},
.pull_type = {INPUT_PULL_DOWN, INPUT_PULL_DOWN},
.trigger_type = {HOSAL_IRQ_TRIG_SYNC_FALLING_RISING_EDGE, HOSAL_IRQ_TRIG_SYNC_FALLING_RISING_EDGE},
#define PDS_SLEEP_MAX_MS 3600000

btble_app_conf_t app_pds_conf = {
.print_enable = 0, // 1: enable uart print in library; 0: disable uart print in library
.gpio_irq_restore = 1, // 1: restore gpio irq after pds wakeup; 0: do not restore gpio irq after pds wakeup
.gpio_num = 2, // 3,
.gpio_index = { CHIP_RESET_PIN, CHIP_CONTACT_PIN },
.pull_type = { INPUT_PULL_DOWN, INPUT_PULL_DOWN },
.trigger_type = { HOSAL_IRQ_TRIG_SYNC_FALLING_RISING_EDGE, HOSAL_IRQ_TRIG_SYNC_FALLING_RISING_EDGE },
};

static uint32_t low_power_pds_lmac154_backup[72];
static hosal_gpio_dev_t gpio_key = { .port = CHIP_RESET_PIN, .config = INPUT_PULL_DOWN, .priv = NULL };
static hosal_gpio_dev_t gpio_contact = { .port = CHIP_CONTACT_PIN, .config = INPUT_PULL_DOWN, .priv = NULL };
static hosal_gpio_dev_t gpio_key = { .port = CHIP_RESET_PIN, .config = INPUT_PULL_DOWN, .priv = NULL };
static hosal_gpio_dev_t gpio_contact = { .port = CHIP_CONTACT_PIN, .config = INPUT_PULL_DOWN, .priv = NULL };
static hosal_gpio_irq_handler_t app_pds_irq_handler = NULL;
static int app_pds_wakeup_source = -1;
static uint32_t app_pds_wakeup_pin = -1;
static int app_pds_wakeup_source = -1;
static uint32_t app_pds_wakeup_pin = -1;

extern "C" void btble_pds_fastboot_done_callback(void);

uint64_t wakeup_time = 0;
uint64_t wakeup_time = 0;
uint64_t sleep_calling_time = 0;
uint64_t sleep_time = 0;

// extern "C" void vApplicationSleep( TickType_t xExpectedIdleTime )
// {
// eSleepModeStatus eSleepStatus;
// uint32_t xExpectedSleepTime = xExpectedIdleTime;
// uint32_t sleepCycles;
// uint32_t sleepTime;

// eSleepStatus = eTaskConfirmSleepModeStatus();
// if(eSleepStatus == eAbortSleep){
// return;
// }

// if(xExpectedIdleTime > PDS_SLEEP_MAX_MS)
// xExpectedIdleTime = PDS_SLEEP_MAX_MS;

// extern int ble_connection_number(void);
// if (OT_DEVICE_ROLE_CHILD != otThreadGetDeviceRole(otrGetInstance()) || ble_connection_number() || false == otr_isStackIdle()) {
// return;
// }

// bl_rtc_process_xtal_cnt_32k();

// bl_pds_set_psram_retention(1);
// lmac154_sleepStoreRegs(low_power_pds_lmac154_backup);

// sleepCycles = bl_rtc_ms_to_counter(xExpectedIdleTime);
// if(sleepCycles < PDS_TOLERANCE_TIME_32768CYCLE + PDS_MIN_TIME_32768CYCLE){
// return;
// }

// sleepTime = hal_pds_enter_with_time_compensation(31, sleepCycles);

// RomDriver_AON_Power_On_XTAL();
// RomDriver_HBN_Set_ROOT_CLK_Sel(HBN_ROOT_CLK_XTAL);

// if (lmac154_isDisabled()) {

// lmac154_sleepRestoreRegs(low_power_pds_lmac154_backup);
// lmac154_disableRx();

// zb_timer_cfg(bl_rtc_get_counter() * (32768 >> LMAC154_US_PER_SYMBOL_BITS));

// zb_timer_restore_events(true);

// // bl_irq_register(M154_IRQn, lmac154_get2015InterruptHandler());
// bl_irq_enable(M154_IRQn);
// }
// bl_sec_init();

// extern hosal_uart_dev_t uart_stdio;
// bl_uart_init(uart_stdio.config.uart_id, uart_stdio.config.tx_pin, uart_stdio.config.rx_pin,
// uart_stdio.config.cts_pin, uart_stdio.config.rts_pin, uart_stdio.config.baud_rate);

// extern BaseType_t TrapNetCounter, *pTrapNetCounter;
// if (app_pds_wakeup_source == PDS_WAKEUP_BY_RTC) {
// extern void * pxCurrentTCB;
// ChipLogProgress(NotSpecified, "wakeup source: rtc. %lu vs %lu ms @ %lu\r\n",
// xExpectedSleepTime, sleepTime, (uint32_t)bl_rtc_get_timestamp_ms());

// ChipLogProgress(NotSpecified, "application_sleep; %lu, %lu, %lu\r\n", (uint32_t)sleep_calling_time, (uint32_t)sleep_time, (uint32_t)wakeup_time);

// } else if(app_pds_wakeup_source == PDS_WAKEUP_BY_GPIO) {

// if (((1 << CHIP_RESET_PIN) & app_pds_wakeup_pin) && app_pds_irq_handler) {
// app_pds_irq_handler(&gpio_key);
// }

// if (((1 << CHIP_CONTACT_PIN) & app_pds_wakeup_pin) && app_pds_irq_handler) {
// app_pds_irq_handler(&gpio_contact);
// }

// printf("[%lu] wakeup source: gpio -> 0x%08lX. %lu vs %lu ms.\r\n",
// app_pds_wakeup_pin, xExpectedSleepTime, sleepTime, (uint32_t)bl_rtc_get_timestamp_ms());
// }

// app_pds_wakeup_source = -1;
// app_pds_wakeup_pin = -1;
// }
uint64_t sleep_time = 0;

extern "C" void vApplicationSleep(TickType_t xExpectedIdleTime)
{
Expand All @@ -137,36 +57,41 @@ extern "C" void vApplicationSleep(TickType_t xExpectedIdleTime)
btble_vApplicationSleepExt(xExpectedIdleTime);

extern BaseType_t TrapNetCounter, *pTrapNetCounter;
if (app_pds_wakeup_source == PDS_WAKEUP_BY_RTC) {
if (app_pds_wakeup_source == PDS_WAKEUP_BY_RTC)
{
extern void * pxCurrentTCB;

ChipLogProgress(NotSpecified, "wakeup source: rtc. %lu vs %lu ms @ %lu\r\n",
xExpectedIdleTime, (uint32_t)(bl_rtc_get_timestamp_ms() - sleep_before), (uint32_t)bl_rtc_get_timestamp_ms());
ChipLogProgress(NotSpecified, "wakeup source: rtc. %lu vs %lu ms @ %lu\r\n", xExpectedIdleTime,
(uint32_t) (bl_rtc_get_timestamp_ms() - sleep_before), (uint32_t) bl_rtc_get_timestamp_ms());

ChipLogProgress(NotSpecified, "application_sleep; %lu, %lu, %lu\r\n", (uint32_t)sleep_calling_time, (uint32_t)sleep_time, (uint32_t)wakeup_time);

} else if(app_pds_wakeup_source == PDS_WAKEUP_BY_GPIO) {
ChipLogProgress(NotSpecified, "application_sleep; %lu, %lu, %lu\r\n", (uint32_t) sleep_calling_time, (uint32_t) sleep_time,
(uint32_t) wakeup_time);
}
else if (app_pds_wakeup_source == PDS_WAKEUP_BY_GPIO)
{

if (((1 << CHIP_RESET_PIN) & app_pds_wakeup_pin) && app_pds_irq_handler) {
if (((1 << CHIP_RESET_PIN) & app_pds_wakeup_pin) && app_pds_irq_handler)
{
app_pds_irq_handler(&gpio_key);
}

if (((1 << CHIP_CONTACT_PIN) & app_pds_wakeup_pin) && app_pds_irq_handler) {
if (((1 << CHIP_CONTACT_PIN) & app_pds_wakeup_pin) && app_pds_irq_handler)
{
app_pds_irq_handler(&gpio_contact);
}

ChipLogProgress(NotSpecified, "wakeup source: gpio -> 0x%08lX. %lu vs %lu ms @ %lu\r\n",
app_pds_wakeup_pin, xExpectedIdleTime, (uint32_t)(bl_rtc_get_timestamp_ms() - sleep_before), (uint32_t)bl_rtc_get_timestamp_ms());
ChipLogProgress(NotSpecified, "wakeup source: gpio -> 0x%08lX. %lu vs %lu ms @ %lu\r\n", app_pds_wakeup_pin,
xExpectedIdleTime, (uint32_t) (bl_rtc_get_timestamp_ms() - sleep_before),
(uint32_t) bl_rtc_get_timestamp_ms());
}


app_pds_wakeup_source = -1;
app_pds_wakeup_pin = -1;
app_pds_wakeup_pin = -1;
}

void app_pds_config_pin(void)
void app_pds_config_pin(void)
{
uint8_t wakeup_pin [] = {gpio_key.port, gpio_contact.port};
uint8_t wakeup_pin[] = { gpio_key.port, gpio_contact.port };

hosal_gpio_init(&gpio_key);
hosal_gpio_init(&gpio_contact);
Expand All @@ -176,14 +101,14 @@ void app_pds_config_pin(void)
bl_pds_gpio_wakeup_cfg(wakeup_pin, sizeof(wakeup_pin) / sizeof(wakeup_pin[0]), PDS_GPIO_EDGE_BOTH);
}

void app_pds_fastboot_done_callback(void)
void app_pds_fastboot_done_callback(void)
{
wakeup_time = bl_rtc_get_timestamp_ms();

#if CHIP_PROGRESS_LOGGING || CHIP_ERROR_LOGGING
extern hosal_uart_dev_t uart_stdio;
bl_uart_init(uart_stdio.config.uart_id, uart_stdio.config.tx_pin, uart_stdio.config.rx_pin,
uart_stdio.config.cts_pin, uart_stdio.config.rts_pin, uart_stdio.config.baud_rate);
bl_uart_init(uart_stdio.config.uart_id, uart_stdio.config.tx_pin, uart_stdio.config.rx_pin, uart_stdio.config.cts_pin,
uart_stdio.config.rts_pin, uart_stdio.config.baud_rate);
#endif

btble_pds_fastboot_done_callback();
Expand All @@ -193,16 +118,17 @@ void app_pds_fastboot_done_callback(void)
// app_pds_config_pin();

app_pds_wakeup_source = bl_pds_get_wakeup_source();
app_pds_wakeup_pin = bl_pds_get_wakeup_gpio();
app_pds_wakeup_pin = bl_pds_get_wakeup_gpio();
}

int app_pds_before_sleep_callback(void)
int app_pds_before_sleep_callback(void)
{
if (otr_isStackIdle()) {
if (otr_isStackIdle())
{

bl_pds_set_psram_retention(1);
lmac154_sleepStoreRegs(low_power_pds_lmac154_backup);

sleep_time = bl_rtc_get_timestamp_ms();

return 0;
Expand All @@ -211,9 +137,10 @@ int app_pds_before_sleep_callback(void)
return -1;
}

void app_pds_after_sleep_callback(void)
void app_pds_after_sleep_callback(void)
{
if (lmac154_isDisabled()) {
if (lmac154_isDisabled())
{

lmac154_sleepRestoreRegs(low_power_pds_lmac154_backup);
lmac154_disableRx();
Expand All @@ -227,7 +154,7 @@ void app_pds_after_sleep_callback(void)
bl_sec_init();
}

void app_pds_init(hosal_gpio_irq_handler_t pinHandler)
void app_pds_init(hosal_gpio_irq_handler_t pinHandler)
{
btble_pds_init(&app_pds_conf);

Expand Down
2 changes: 1 addition & 1 deletion examples/contact-sensor-app/bouffalolab/bl702l/mboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
#define CHIP_UART_PIN_TX 14

#define CHIP_CONTACT_PIN 20
#define CHIP_RESET_PIN 16
#define CHIP_RESET_PIN 16
Loading

0 comments on commit 7cb6759

Please sign in to comment.