我是靠谱客的博主 高大火,最近开发中收集的这篇文章主要介绍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);
          
      	}
      }
    
    

最后

以上就是高大火为你收集整理的EFR32BG22的power manager裸机实现解析---Notification机制的全部内容,希望文章能够帮你解决EFR32BG22的power manager裸机实现解析---Notification机制所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(34)

评论列表共有 0 条评论

立即
投稿
返回
顶部