mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-08 13:58:35 +00:00
[feat][examples/pm] add power management demo,replace lowpower test demo
This commit is contained in:
parent
9fb0591d29
commit
a65e345b7f
12 changed files with 154 additions and 287 deletions
|
@ -1,4 +0,0 @@
|
|||
set(TARGET_REQUIRED_LIBS shell)
|
||||
set(mains main.c)
|
||||
generate_bin()
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
/**
|
||||
* @file main.c
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#include "hal_rtc.h"
|
||||
#include "hal_pm.h"
|
||||
#include "hal_uart.h"
|
||||
#include "shell.h"
|
||||
|
||||
void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
||||
{
|
||||
uint8_t data;
|
||||
if (state == UART_EVENT_RX_FIFO) {
|
||||
data = *(uint8_t *)args;
|
||||
shell_handler(data);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bflb_platform_init(0);
|
||||
shell_init();
|
||||
struct device *uart = device_find("debug_log");
|
||||
if (uart) {
|
||||
device_set_callback(uart, shell_irq_callback);
|
||||
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
|
||||
}
|
||||
|
||||
MSG("gpio wake up case,enter hbn1 mode\r\n");
|
||||
bflb_platform_delay_ms(50);
|
||||
|
||||
pm_hbn_mode_enter(PM_HBN_LEVEL_1);
|
||||
|
||||
while (1) {
|
||||
bflb_platform_delay_ms(100);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
**board/bl706_lp/pinmux_config.h** 中 **CONFIG_GPIO12_FUNC** 选择 **GPIO_FUN_WAKEUP**
|
||||
|
||||
|
||||
```bash
|
||||
|
||||
$ make APP=hbn_gpio_wakeup BOARD=bl706_lp
|
||||
|
||||
```
|
135
examples/pm/hbn_mode_wakeup/main.c
Normal file
135
examples/pm/hbn_mode_wakeup/main.c
Normal file
|
@ -0,0 +1,135 @@
|
|||
/**
|
||||
* @file main.c
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#include "hal_pm.h"
|
||||
#include "hal_acomp.h"
|
||||
#include "hal_uart.h"
|
||||
#include "shell.h"
|
||||
|
||||
void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
||||
{
|
||||
uint8_t data;
|
||||
if (state == UART_EVENT_RX_FIFO) {
|
||||
data = *(uint8_t *)args;
|
||||
shell_handler(data);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bflb_platform_init(0);
|
||||
shell_init();
|
||||
struct device *uart = device_find("debug_log");
|
||||
if (uart) {
|
||||
device_set_callback(uart, shell_irq_callback);
|
||||
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
|
||||
}
|
||||
|
||||
while (1) {
|
||||
bflb_platform_delay_ms(100);
|
||||
}
|
||||
}
|
||||
|
||||
int hbn0_enter(int argc, char *argv[])
|
||||
{
|
||||
acomp_device_t acomp_device;
|
||||
acomp_device.id = 0;
|
||||
acomp_device.pos_ch = ACOMP_CHANNEL_ADC_CHANNEL3; /*from gpio11 adc func*/
|
||||
acomp_device.neg_ch = ACOMP_CHANNEL_0P375VBAT;
|
||||
acomp_device.pos_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
|
||||
acomp_device.neg_hysteresis_vol = ACOMP_HYSTERESIS_VOLT_50MV;
|
||||
acomp_init(&acomp_device);
|
||||
bflb_platform_delay_ms(50); /*delay for acomp*/
|
||||
|
||||
for (uint32_t i = 0; i < 30; i++) {
|
||||
MSG("status:%d\r\n", acomp_get_result(&acomp_device));
|
||||
bflb_platform_delay_ms(100);
|
||||
}
|
||||
|
||||
MSG("acomp wake up case,enter hbn0 mode\r\n");
|
||||
bflb_platform_delay_ms(50);
|
||||
|
||||
/** cpu will wakeup when acomp status change
|
||||
* please note that if you set gpio9-gpio12 with GPIO_FUN_WAKEUP,it will also wakeup this level
|
||||
* rtc can wakeup this level when sleep time do not equal 0
|
||||
**/
|
||||
pm_hbn_mode_enter(PM_HBN_LEVEL_0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hbn1_enter(int argc, char *argv[])
|
||||
{
|
||||
int second = 0;
|
||||
|
||||
if (argc == 2) {
|
||||
second = atoi(argv[1]);
|
||||
} else {
|
||||
second = 1;
|
||||
}
|
||||
|
||||
MSG("rtc wake up case,enter hbn1 mode\r\n");
|
||||
bflb_platform_delay_ms(50);
|
||||
/** cpu will wakeup when rtc sleep time timeout
|
||||
* please note that if you set gpio9-gpio12 with GPIO_FUN_WAKEUP,it will also wakeup this level
|
||||
**/
|
||||
pm_hbn_mode_enter(PM_HBN_LEVEL_1, second);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hbn2_enter(int argc, char *argv[])
|
||||
{
|
||||
MSG("gpio wake up case,enter hbn2 mode\r\n");
|
||||
bflb_platform_delay_ms(50);
|
||||
|
||||
/*cpu will wakeup when you set gpio9-gpio12 with GPIO_FUN_WAKEUP
|
||||
* rtc can not wakeup level2
|
||||
**/
|
||||
pm_hbn_mode_enter(PM_HBN_LEVEL_2, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ATTR_HBN_RAM_SECTION void led_blink(void)
|
||||
{
|
||||
/*do something*/
|
||||
}
|
||||
|
||||
int hbn_run_in_wakeup_addr(int argc, char *argv[])
|
||||
{
|
||||
MSG("gpio wake up case,enter hbn2 mode\r\n");
|
||||
bflb_platform_delay_ms(50);
|
||||
|
||||
/*cpu will wakeup when you set gpio9-gpio12 with GPIO_FUN_WAKEUP
|
||||
* rtc can not wakeup level2
|
||||
**/
|
||||
pm_hbn_set_wakeup_callback(led_blink); /*cpu will run in wakeup callback not reset when it awakes*/
|
||||
pm_hbn_mode_enter(PM_HBN_LEVEL_0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_CMD_EXPORT(hbn0_enter, hbn0 acomp wakeup test)
|
||||
SHELL_CMD_EXPORT(hbn1_enter, hbn1 rtc wakeup test)
|
||||
SHELL_CMD_EXPORT(hbn2_enter, hbn2 gpio wakeup test)
|
||||
SHELL_CMD_EXPORT(hbn_run_in_wakeup_addr, hbn run in wakeup addr test)
|
10
examples/pm/hbn_mode_wakeup/readme.md
Normal file
10
examples/pm/hbn_mode_wakeup/readme.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
**board/bl706_lp/pinmux_config.h** 中 **CONFIG_GPIO12_FUNC** 选择 **GPIO_FUN_WAKEUP**
|
||||
|
||||
**board/bl706_lp/pinmux_config.h** 中 **CONFIG_GPIO11_FUNC** 选择 **GPIO_FUN_ADC**,ACOMP0 会使用ADC_CH3
|
||||
|
||||
|
||||
```bash
|
||||
|
||||
$ make APP=hbn_mode_wakeup BOARD=bl706_lp
|
||||
|
||||
```
|
|
@ -1,4 +0,0 @@
|
|||
set(TARGET_REQUIRED_LIBS shell)
|
||||
set(mains main.c)
|
||||
generate_bin()
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/**
|
||||
* @file main.c
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#include "hal_rtc.h"
|
||||
#include "hal_pm.h"
|
||||
#include "hal_uart.h"
|
||||
#include "shell.h"
|
||||
|
||||
void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
||||
{
|
||||
uint8_t data;
|
||||
if (state == UART_EVENT_RX_FIFO) {
|
||||
data = *(uint8_t *)args;
|
||||
shell_handler(data);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bflb_platform_init(0);
|
||||
shell_init();
|
||||
struct device *uart = device_find("debug_log");
|
||||
if (uart) {
|
||||
device_set_callback(uart, shell_irq_callback);
|
||||
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
|
||||
}
|
||||
|
||||
BL_CASE_SUCCESS;
|
||||
while (1) {
|
||||
bflb_platform_delay_ms(100);
|
||||
}
|
||||
}
|
||||
|
||||
int hbn_enter(int argc, char *argv[])
|
||||
{
|
||||
int second = 0;
|
||||
|
||||
if (argc == 2) {
|
||||
second = atoi(argv[1]);
|
||||
} else {
|
||||
second = 1;
|
||||
}
|
||||
|
||||
MSG("rtc wake up case,enter hbn1 mode\r\n");
|
||||
bflb_platform_delay_ms(50);
|
||||
|
||||
rtc_init(second); //sleep time,unit is second
|
||||
pm_hbn_mode_enter(PM_HBN_LEVEL_1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_CMD_EXPORT(hbn_enter, hbn1 rtc wakeup test)
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
```bash
|
||||
|
||||
$ make APP=hbn_rtc_wakeup BOARD=bl706_lp
|
||||
|
||||
```
|
9
examples/pm/pds_mode_wakeup/readme.md
Normal file
9
examples/pm/pds_mode_wakeup/readme.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
**board/bl706_lp/pinmux_config.h** 中 **CONFIG_GPIO12_FUNC** 选择 **GPIO_FUN_WAKEUP**
|
||||
**board/bl706_lp/pinmux_config.h** 中 **CONFIG_GPIO3_FUNC** 选择 **GPIO_FUN_WAKEUP**
|
||||
**board/bl706_lp/pinmux_config.h** 中 **CONFIG_GPIO10_FUNC** 选择 **GPIO_FUN_GPIO_EXTI_FALLING_EDGE**
|
||||
|
||||
```bash
|
||||
|
||||
$ make APP=pds_mode_wakeup BOARD=bl706_lp
|
||||
|
||||
```
|
|
@ -1,6 +0,0 @@
|
|||
set(TARGET_REQUIRED_LIBS shell)
|
||||
set(mains main.c)
|
||||
generate_bin()
|
||||
|
||||
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
/**
|
||||
* @file main.c
|
||||
* @brief
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
#include "hal_uart.h"
|
||||
#include "hal_power.h"
|
||||
#include "hal_clock.h"
|
||||
#include "shell.h"
|
||||
/**
|
||||
* @brief test low power wfi function
|
||||
*
|
||||
* @param argc
|
||||
* @param argv
|
||||
*/
|
||||
void wfi(int argc, char *argv[])
|
||||
{
|
||||
MSG("Enter Wfi Mode: System Frequency = %dMHz\r\n", system_clock_get(SYSTEM_CLOCK_ROOT_CLOCK));
|
||||
bflb_platform_delay_ms(10);
|
||||
//lp_set_clock_gate(ENABLE,CLOCK_AHB_ALL);
|
||||
//lp_power_off_dll();
|
||||
lp_enter_wfi();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief test low power pds function
|
||||
*
|
||||
* @param argc
|
||||
* @param argv
|
||||
*/
|
||||
void pds(int argc, char *argv[])
|
||||
{
|
||||
int sleepTim = 0;
|
||||
|
||||
if (argc == 2) {
|
||||
sleepTim = atoi(argv[1]);
|
||||
} else {
|
||||
sleepTim = 0;
|
||||
MSG("Enter pds mode . RTC wake up is disable,if want to use ,please enter "
|
||||
"pds tim"
|
||||
" . \r\n");
|
||||
}
|
||||
|
||||
MSG("Enter PDS Mode: System Frequency = %dMHz, wake up time is %d * 1/32k\r\n", system_clock_get(SYSTEM_CLOCK_ROOT_CLOCK), sleepTim);
|
||||
bflb_platform_delay_ms(1000);
|
||||
|
||||
lp_set_clock_gate(ENABLE, CLOCK_AHB_ALL);
|
||||
lp_set_all_gpio_hz();
|
||||
lp_enter_pds(sleepTim, NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief test low power hbn function
|
||||
*
|
||||
* @param argc
|
||||
* @param argv
|
||||
*/
|
||||
void hbn(int argc, char *argv[])
|
||||
{
|
||||
int sleepTim = 0;
|
||||
|
||||
if (argc == 2) {
|
||||
sleepTim = atoi(argv[1]);
|
||||
} else {
|
||||
sleepTim = 0;
|
||||
}
|
||||
|
||||
MSG("Enter HBN Mode: System Frequency = %dMHz, wake up time is %d * 1/32k\r\n", system_clock_get(SYSTEM_CLOCK_ROOT_CLOCK), sleepTim);
|
||||
|
||||
bflb_platform_delay_ms(1000);
|
||||
|
||||
lp_set_clock_gate(ENABLE, CLOCK_AHB_ALL);
|
||||
lp_set_all_gpio_hz();
|
||||
lp_enter_hbn(sleepTim);
|
||||
}
|
||||
|
||||
void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
||||
{
|
||||
uint8_t data;
|
||||
if (state == UART_EVENT_RX_FIFO) {
|
||||
data = *(uint8_t *)args;
|
||||
shell_handler(data);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bflb_platform_init(0);
|
||||
shell_init();
|
||||
struct device *uart = device_find("debug_log");
|
||||
if (uart) {
|
||||
device_set_callback(uart, shell_irq_callback);
|
||||
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
|
||||
}
|
||||
|
||||
MSG("Power Test Start:\r\n");
|
||||
MSG("Input Command Example:\r\n");
|
||||
MSG("wfi \r\n");
|
||||
MSG("pds wakeTim\r\n");
|
||||
MSG("hbn wakeTim\r\n\r\n");
|
||||
|
||||
BL_CASE_SUCCESS;
|
||||
while (1) {
|
||||
bflb_platform_delay_ms(100);
|
||||
}
|
||||
}
|
||||
|
||||
SHELL_CMD_EXPORT(wfi, enter wfi mode)
|
||||
SHELL_CMD_EXPORT(pds, enter pds)
|
||||
SHELL_CMD_EXPORT(hbn, enter hbn)
|
|
@ -1,5 +0,0 @@
|
|||
```bash
|
||||
|
||||
$ make APP=lowpower_test BOARD=bl706_lp
|
||||
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue