pm.h File Reference

Go to the source code of this file.

Data Structures

struct  misc_para_t
 deepsleep wakeup by external xtal More...
 
struct  pm_para_t
 deepsleep wakeup status More...
 

Macros

#define PM_LONG_SUSPEND_EN   1
 
#define PM_TIM_RECOVER_MODE   0
 
#define PM_XTAL_DELAY_DURATION   500
 
#define EARLYWAKEUP_TIME_US_DEEP   1100
 
#define EARLYWAKEUP_TIME_US_SUSPEND   1250
 
#define EMPTYRUN_TIME_US   1500
 
#define PM_DCDC_DELAY_DURATION   1000
 
#define PM_LONG_SLEEP_WAKEUP_EN   0
 
#define SYS_CLK_48MRC_EN   0
 
#define DEEP_ANA_REG0   0x3a
 analog register below can store infomation when MCU in deepsleep mode store your information in these ana_regs before deepsleep by calling analog_write function when MCU wakeup from deepsleep, read the information by by calling analog_read function Reset these analog registers only by power cycle More...
 
#define DEEP_ANA_REG1   0x3b
 
#define DEEP_ANA_REG2   0x3c
 
#define DEEP_ANA_REG6   0x35
 these analog register can store data in deepsleep mode or deepsleep with SRAM retention mode. Reset these analog registers by watchdog, chip reset, RESET Pin, power cycle More...
 
#define DEEP_ANA_REG7   0x36
 
#define DEEP_ANA_REG8   0x37
 
#define DEEP_ANA_REG9   0x38
 
#define DEEP_ANA_REG10   0x39
 
#define SYS_NEED_REINIT_EXT32K   BIT(0)
 
#define SYS_DEEP_ANA_REG   DEEP_ANA_REG2
 
#define WAKEUP_STATUS_TIMER_CORE   ( WAKEUP_STATUS_TIMER | WAKEUP_STATUS_CORE)
 
#define WAKEUP_STATUS_TIMER_PAD   ( WAKEUP_STATUS_TIMER | WAKEUP_STATUS_PAD)
 

Typedefs

typedef int(* suspend_handler_t) (void)
 
typedef unsigned int(* pm_tim_recover_handler_t) (unsigned int)
 
typedef int(* cpu_pm_handler_t) (SleepMode_TypeDef sleep_mode, SleepWakeupSrc_TypeDef wakeup_src, unsigned int wakeup_tick)
 

Enumerations

enum  SleepMode_TypeDef {
  SUSPEND_MODE = 0, DEEPSLEEP_MODE = 0x80, DEEPSLEEP_MODE_RET_SRAM_LOW8K = 0x61, DEEPSLEEP_MODE_RET_SRAM_LOW16K = 0x43,
  DEEPSLEEP_MODE_RET_SRAM_LOW32K = 0x07, SHUTDOWN_MODE = 0xFF, DEEPSLEEP_RETENTION_FLAG = 0x7F
}
 sleep mode. More...
 
enum  SleepWakeupSrc_TypeDef {
  PM_WAKEUP_PAD = BIT(4), PM_WAKEUP_CORE = BIT(5), PM_WAKEUP_TIMER = BIT(6), PM_WAKEUP_COMPARATOR = BIT(7),
  PM_TIM_RECOVER_START = BIT(14), PM_TIM_RECOVER_END = BIT(15)
}
 wakeup source More...
 
enum  {
  WAKEUP_STATUS_COMPARATOR = BIT(0), WAKEUP_STATUS_TIMER = BIT(1), WAKEUP_STATUS_CORE = BIT(2), WAKEUP_STATUS_PAD = BIT(3),
  WAKEUP_STATUS_WD = BIT(6), STATUS_GPIO_ERR_NO_ENTER_PM = BIT(7), STATUS_ENTER_SUSPEND = BIT(30)
}
 wakeup status More...
 

Functions

void bls_pm_registerFuncBeforeSuspend (suspend_handler_t func)
 
static int pm_is_MCU_deepRetentionWakeup (void)
 This function serves to determine whether mcu is waked up from deep retention. More...
 
static int pm_is_deepPadWakeup (void)
 This function serves to determine whether mcu is waked up by pad. More...
 
static int pm_get_wakeup_src (void)
 This function serves to get the source of wake-up. More...
 
void cpu_stall_wakeup_by_timer0 (unsigned int tick)
 This function serves to wake up cpu from stall mode by timer0. More...
 
void cpu_stall_wakeup_by_timer1 (unsigned int tick)
 This function serves to wake up cpu from stall mode by timer1. More...
 
void cpu_stall_wakeup_by_timer2 (unsigned int tick)
 This function serves to wake up cpu from stall mode by timer2. More...
 
unsigned int cpu_stall (int WakeupSrc, unsigned int IntervalUs, unsigned int sysclktick)
 This function serves to wake up cpu from stall mode by timer1 or RF TX done irq. More...
 
void cpu_set_gpio_wakeup (GPIO_PinTypeDef pin, GPIO_LevelTypeDef pol, int en)
 This function configures a GPIO pin as the wakeup pin. More...
 
void start_reboot (void)
 This function serves to reboot chip. More...
 
unsigned int pm_get_32k_tick (void)
 This function serves to get the 32k tick. More...
 
void cpu_wakeup_init (void)
 This function serves to initialize MCU. More...
 
unsigned int pm_tim_recover_32k_rc (unsigned int now_tick_32k)
 This function serves to recover system timer from tick of internal 32k RC. More...
 
unsigned int pm_tim_recover_32k_xtal (unsigned int now_tick_32k)
 This function serves to recover system timer from tick of external 32k crystal. More...
 
int cpu_sleep_wakeup_32k_rc (SleepMode_TypeDef sleep_mode, SleepWakeupSrc_TypeDef wakeup_src, unsigned int wakeup_tick)
 This function serves to set the working mode of MCU based on 32k crystal,e.g. suspend mode, deepsleep mode, deepsleep with SRAM retention mode and shutdown mode. More...
 
int cpu_sleep_wakeup_32k_xtal (SleepMode_TypeDef sleep_mode, SleepWakeupSrc_TypeDef wakeup_src, unsigned int wakeup_tick)
 This function serves to set the working mode of MCU based on 32k crystal,e.g. suspend mode, deepsleep mode, deepsleep with SRAM retention mode and shutdown mode. More...
 
static void blc_pm_select_internal_32k_crystal (void)
 This function serves to determine whether wake up source is internal 32k RC. More...
 
static void blc_pm_select_external_32k_crystal (void)
 This function serves to determine whether wake up source is external 32k RC. More...
 
void sleep_start (void)
 
unsigned int pm_get_info0 (void)
 
unsigned int pm_get_info1 (void)
 
unsigned int cpu_get_32k_tick (void)
 
void soft_reboot_dly13ms_use24mRC (void)
 
void check_32k_clk_stable (void)
 

Variables

misc_para_t blt_miscParam
 
pm_para_t pmParam
 
suspend_handler_t func_before_suspend
 
pm_tim_recover_handler_t pm_tim_recover
 
cpu_pm_handler_t cpu_sleep_wakeup
 
unsigned char tl_multi_addr
 
unsigned char tl_24mrc_cal
 
unsigned short tick_32k_calib
 
unsigned int tick_cur
 
unsigned int tick_32k_cur
 

Macro Definition Documentation

◆ PM_LONG_SUSPEND_EN

#define PM_LONG_SUSPEND_EN   1

◆ PM_TIM_RECOVER_MODE

#define PM_TIM_RECOVER_MODE   0

◆ PM_XTAL_DELAY_DURATION

#define PM_XTAL_DELAY_DURATION   500

◆ EARLYWAKEUP_TIME_US_DEEP

#define EARLYWAKEUP_TIME_US_DEEP   1100

◆ EARLYWAKEUP_TIME_US_SUSPEND

#define EARLYWAKEUP_TIME_US_SUSPEND   1250

◆ EMPTYRUN_TIME_US

#define EMPTYRUN_TIME_US   1500

◆ PM_DCDC_DELAY_DURATION

#define PM_DCDC_DELAY_DURATION   1000

◆ PM_LONG_SLEEP_WAKEUP_EN

#define PM_LONG_SLEEP_WAKEUP_EN   0

◆ SYS_CLK_48MRC_EN

#define SYS_CLK_48MRC_EN   0

◆ DEEP_ANA_REG0

#define DEEP_ANA_REG0   0x3a

analog register below can store infomation when MCU in deepsleep mode store your information in these ana_regs before deepsleep by calling analog_write function when MCU wakeup from deepsleep, read the information by by calling analog_read function Reset these analog registers only by power cycle

◆ DEEP_ANA_REG1

#define DEEP_ANA_REG1   0x3b

◆ DEEP_ANA_REG2

#define DEEP_ANA_REG2   0x3c

◆ DEEP_ANA_REG6

#define DEEP_ANA_REG6   0x35

these analog register can store data in deepsleep mode or deepsleep with SRAM retention mode. Reset these analog registers by watchdog, chip reset, RESET Pin, power cycle

◆ DEEP_ANA_REG7

#define DEEP_ANA_REG7   0x36

◆ DEEP_ANA_REG8

#define DEEP_ANA_REG8   0x37

◆ DEEP_ANA_REG9

#define DEEP_ANA_REG9   0x38

◆ DEEP_ANA_REG10

#define DEEP_ANA_REG10   0x39

◆ SYS_NEED_REINIT_EXT32K

#define SYS_NEED_REINIT_EXT32K   BIT(0)

◆ SYS_DEEP_ANA_REG

#define SYS_DEEP_ANA_REG   DEEP_ANA_REG2

◆ WAKEUP_STATUS_TIMER_CORE

#define WAKEUP_STATUS_TIMER_CORE   ( WAKEUP_STATUS_TIMER | WAKEUP_STATUS_CORE)

◆ WAKEUP_STATUS_TIMER_PAD

#define WAKEUP_STATUS_TIMER_PAD   ( WAKEUP_STATUS_TIMER | WAKEUP_STATUS_PAD)

Typedef Documentation

◆ suspend_handler_t

typedef int(* suspend_handler_t) (void)

◆ pm_tim_recover_handler_t

typedef unsigned int(* pm_tim_recover_handler_t) (unsigned int)

◆ cpu_pm_handler_t

typedef int(* cpu_pm_handler_t) (SleepMode_TypeDef sleep_mode, SleepWakeupSrc_TypeDef wakeup_src, unsigned int wakeup_tick)

Enumeration Type Documentation

◆ SleepMode_TypeDef

sleep mode.

Enumerator
SUSPEND_MODE 
DEEPSLEEP_MODE 
DEEPSLEEP_MODE_RET_SRAM_LOW8K 
DEEPSLEEP_MODE_RET_SRAM_LOW16K 
DEEPSLEEP_MODE_RET_SRAM_LOW32K 
SHUTDOWN_MODE 
DEEPSLEEP_RETENTION_FLAG 

◆ SleepWakeupSrc_TypeDef

wakeup source

Enumerator
PM_WAKEUP_PAD 
PM_WAKEUP_CORE 
PM_WAKEUP_TIMER 
PM_WAKEUP_COMPARATOR 
PM_TIM_RECOVER_START 
PM_TIM_RECOVER_END 

◆ anonymous enum

anonymous enum

wakeup status

Enumerator
WAKEUP_STATUS_COMPARATOR 
WAKEUP_STATUS_TIMER 
WAKEUP_STATUS_CORE 
WAKEUP_STATUS_PAD 
WAKEUP_STATUS_WD 
STATUS_GPIO_ERR_NO_ENTER_PM 
STATUS_ENTER_SUSPEND 

Function Documentation

◆ bls_pm_registerFuncBeforeSuspend()

void bls_pm_registerFuncBeforeSuspend ( suspend_handler_t  func)

◆ pm_is_MCU_deepRetentionWakeup()

static int pm_is_MCU_deepRetentionWakeup ( void  )
inlinestatic

This function serves to determine whether mcu is waked up from deep retention.

Parameters
[in]none.
Returns
1- yes , 0- no.

◆ pm_is_deepPadWakeup()

static int pm_is_deepPadWakeup ( void  )
inlinestatic

This function serves to determine whether mcu is waked up by pad.

Parameters
[in]none.
Returns
1- yes , 0- no.

◆ pm_get_wakeup_src()

static int pm_get_wakeup_src ( void  )
inlinestatic

This function serves to get the source of wake-up.

Parameters
[in]none.
Returns
wakeup source.

◆ cpu_stall_wakeup_by_timer0()

void cpu_stall_wakeup_by_timer0 ( unsigned int  tick)

This function serves to wake up cpu from stall mode by timer0.

Parameters
tick- capture value of timer0.
Returns
none.

◆ cpu_stall_wakeup_by_timer1()

void cpu_stall_wakeup_by_timer1 ( unsigned int  tick)

This function serves to wake up cpu from stall mode by timer1.

Parameters
tick- capture value of timer1.
Returns
none.

◆ cpu_stall_wakeup_by_timer2()

void cpu_stall_wakeup_by_timer2 ( unsigned int  tick)

This function serves to wake up cpu from stall mode by timer2.

Parameters
tick- capture value of timer2.
Returns
none.

◆ cpu_stall()

unsigned int cpu_stall ( int  WakeupSrc,
unsigned int  IntervalUs,
unsigned int  sysclktick 
)

This function serves to wake up cpu from stall mode by timer1 or RF TX done irq.

Parameters
WakeupSrc- timer1.
IntervalUs- capture value of timer1.
sysclktick- tick value of per us based on system clock.
Returns
none.

◆ cpu_set_gpio_wakeup()

void cpu_set_gpio_wakeup ( GPIO_PinTypeDef  pin,
GPIO_LevelTypeDef  pol,
int  en 
)

This function configures a GPIO pin as the wakeup pin.

Parameters
[in]pin- the pin needs to be configured as wakeup pin
[in]pol- the wakeup polarity of the pad pin(0: low-level wakeup, 1: high-level wakeup)
[in]en- enable or disable the wakeup function for the pan pin(1: Enable, 0: Disable)
Returns
none

◆ start_reboot()

void start_reboot ( void  )

This function serves to reboot chip.

Parameters
none.
Returns
none.

◆ pm_get_32k_tick()

unsigned int pm_get_32k_tick ( void  )

This function serves to get the 32k tick.

Parameters
none
Returns
tick of 32k .

◆ cpu_wakeup_init()

void cpu_wakeup_init ( void  )

This function serves to initialize MCU.

Parameters
none
Returns
none

◆ pm_tim_recover_32k_rc()

unsigned int pm_tim_recover_32k_rc ( unsigned int  now_tick_32k)

This function serves to recover system timer from tick of internal 32k RC.

Parameters
none.
Returns
none.

◆ pm_tim_recover_32k_xtal()

unsigned int pm_tim_recover_32k_xtal ( unsigned int  now_tick_32k)

This function serves to recover system timer from tick of external 32k crystal.

Parameters
none.
Returns
none.

◆ cpu_sleep_wakeup_32k_rc()

int cpu_sleep_wakeup_32k_rc ( SleepMode_TypeDef  sleep_mode,
SleepWakeupSrc_TypeDef  wakeup_src,
unsigned int  wakeup_tick 
)

This function serves to set the working mode of MCU based on 32k crystal,e.g. suspend mode, deepsleep mode, deepsleep with SRAM retention mode and shutdown mode.

Parameters
[in]sleep_mode- sleep mode type select.
[in]wakeup_src- wake up source select.
[in]wakeup_tick- the time of short sleep, which means MCU can sleep for less than 5 minutes.
Returns
indicate whether the cpu is wake up successful.

◆ cpu_sleep_wakeup_32k_xtal()

int cpu_sleep_wakeup_32k_xtal ( SleepMode_TypeDef  sleep_mode,
SleepWakeupSrc_TypeDef  wakeup_src,
unsigned int  wakeup_tick 
)

This function serves to set the working mode of MCU based on 32k crystal,e.g. suspend mode, deepsleep mode, deepsleep with SRAM retention mode and shutdown mode.

Parameters
[in]sleep_mode- sleep mode type select.
[in]wakeup_src- wake up source select.
[in]wakeup_tick- the time of short sleep, which means MCU can sleep for less than 5 minutes.
Returns
indicate whether the cpu is wake up successful.

◆ blc_pm_select_internal_32k_crystal()

static void blc_pm_select_internal_32k_crystal ( void  )
inlinestatic

This function serves to determine whether wake up source is internal 32k RC.

Parameters
[in]none.
Returns
none.

◆ blc_pm_select_external_32k_crystal()

static void blc_pm_select_external_32k_crystal ( void  )
inlinestatic

This function serves to determine whether wake up source is external 32k RC.

Parameters
[in]none.
Returns
none.

◆ sleep_start()

void sleep_start ( void  )

◆ pm_get_info0()

unsigned int pm_get_info0 ( void  )

◆ pm_get_info1()

unsigned int pm_get_info1 ( void  )

◆ cpu_get_32k_tick()

unsigned int cpu_get_32k_tick ( void  )

◆ soft_reboot_dly13ms_use24mRC()

void soft_reboot_dly13ms_use24mRC ( void  )

◆ check_32k_clk_stable()

void check_32k_clk_stable ( void  )

Variable Documentation

◆ blt_miscParam

misc_para_t blt_miscParam

◆ pmParam

pm_para_t pmParam

◆ func_before_suspend

suspend_handler_t func_before_suspend

◆ pm_tim_recover

pm_tim_recover_handler_t pm_tim_recover

◆ cpu_sleep_wakeup

cpu_pm_handler_t cpu_sleep_wakeup

◆ tl_multi_addr

unsigned char tl_multi_addr

◆ tl_24mrc_cal

unsigned char tl_24mrc_cal

◆ tick_32k_calib

unsigned short tick_32k_calib

◆ tick_cur

unsigned int tick_cur

◆ tick_32k_cur

unsigned int tick_32k_cur