EFR32BG22的power manager裸机实现解析---Notification机制

  • EFR32BG22的power manager十分复杂,通过各种标志位控制时钟的切换,又叠加notification机制来管理能量切换时的外设配置,requirement机制来判断当前可行的休眠等级。本文主要介绍power manager中的notification机制


    notification主要用于通知相关外设,对于能量等级切换做出响应。

  • 当低功耗等级由高到低(如EM2到EM0)切换时,将在低功耗等级切换后通知外设进行响应;
  • 当低功耗等级由低到高(如EM0到EM2)切换时,将在低功耗等级切换前通知外设进行响应。
  • 订阅notification的函数如下(可以理解为新建一个notification)
      //订阅通知,可通过event_info设置收到通知后的响应
      void sl_power_manager_subscribe_em_transition_event(sl_power_manager_em_transition_event_handle_t     *event_handle,
                                                        const sl_power_manager_em_transition_event_info_t *event_info);
      
      //event_info的结构体定义如下
      typedef struct {
      const sl_power_manager_em_transition_event_t event_mask;  ///< Mask of the transitions on which the callback should be called.
      const sl_power_manager_em_transition_on_event_t on_event; ///< Function that must be called when the event occurs.
      } sl_power_manager_em_transition_event_info_t;
    
    

    event_mask表示需要通知的能量切换活动,on_event是通知事件的回调函数。订阅后on_event函数将在event_mask选择的能量切换时被调用。

      //event_mask支持的bitmap
      // Power transition events
      #define SL_POWER_MANAGER_EVENT_TRANSITION_ENTERING_EM0     (1 << 0)
      #define SL_POWER_MANAGER_EVENT_TRANSITION_LEAVING_EM0      (1 << 1)
      #define SL_POWER_MANAGER_EVENT_TRANSITION_ENTERING_EM1     (1 << 2)
      #define SL_POWER_MANAGER_EVENT_TRANSITION_LEAVING_EM1      (1 << 3)
      #define SL_POWER_MANAGER_EVENT_TRANSITION_ENTERING_EM2     (1 << 4)
      #define SL_POWER_MANAGER_EVENT_TRANSITION_LEAVING_EM2      (1 << 5)
      #define SL_POWER_MANAGER_EVENT_TRANSITION_ENTERING_EM3     (1 << 6)
      #define SL_POWER_MANAGER_EVENT_TRANSITION_LEAVING_EM3      (1 << 7)
      
      //回调函数on_event的定义
      typedef void (*sl_power_manager_em_transition_on_event_t)(sl_power_manager_em_t from,
                                                              sl_power_manager_em_t to);
    
    

    一个使用notification的范例:


  • uart在em2,em3时禁用输出管脚TX,恢复em0,em1时重新配置管脚。

      static void events_handler(sl_power_manager_em_t from,
                               sl_power_manager_em_t to)
      {
      uint32_t out;
      if (((from == SL_POWER_MANAGER_EM2) 
          || (from == SL_POWER_MANAGER_EM3)) 
          && ((to == SL_POWER_MANAGER_EM1) 
          || (to == SL_POWER_MANAGER_EM0))) {
          
      	// Wake the USART Tx pin back up
      	out = GPIO_PinOutGet(SL_IOSTREAM_USART_VCOM_TX_PORT, SL_IOSTREAM_USART_VCOM_TX_PIN);
      	GPIO_PinModeSet(SL_IOSTREAM_USART_VCOM_TX_PORT, SL_IOSTREAM_USART_VCOM_TX_PIN, gpioModePushPull, out);
        
      	} else if (((to == SL_POWER_MANAGER_EM2) 
      	   || (to == SL_POWER_MANAGER_EM3)) 
      	   && ((from == SL_POWER_MANAGER_EM1) 
      	   || (from == SL_POWER_MANAGER_EM0))) {
         
       // Sleep the USART Tx pin on series 2 devices to save energy
          out = GPIO_PinOutGet(SL_IOSTREAM_USART_VCOM_TX_PORT, SL_IOSTREAM_USART_VCOM_TX_PIN);
          GPIO_PinModeSet(SL_IOSTREAM_USART_VCOM_TX_PORT, SL_IOSTREAM_USART_VCOM_TX_PIN, gpioModeDisabled, out);
          
      	}
      }
    
    
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值