Files
luban-lite-t3e-pro/doc/topics/sdk/pm/pm_design_guide.html

289 lines
45 KiB
HTML
Raw Normal View History

2025-01-23 16:37:00 +08:00
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn" data-whc_version="26.0">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="description" content="PM 驱动源码位于 bsp/artinchip/drv/pm/ 。 PM 框架和功耗模式 Luban-Lite 的 PM 驱动完全遵循 RT-Thread 的 PM 框架。PM 框架将系统的功耗分为多个等级,每个等级对应一个功耗模式,实现对不同功耗模式的管理。 以下是 Luban-Lite 中各功耗模式的详细描述及其在 Luban-Lite 中的实现功能: 表 1 . 功能模式及优先级描述 ..."/><meta name="DC.rights.owner" content="(C) 版权 2025"/><meta name="copyright" content="(C) 版权 2025"/><meta name="generator" content="DITA-OT"/><meta name="DC.type" content="topic"/><meta name="DC.relation" content="../../../topics/sdk/pm/pm_introduction.html"/><meta name="DC.relation" content="../../../topics/sdk/pm/pm_test_guide.html"/><meta name="DC.relation" content="../../../topics/sdk/pm/pm_faq.html"/><meta name="DC.contributor" content="yan.wang"/><meta name="DC.contributor" content="yan.wang"/><meta name="DC.date.modified" content="2024-01-15"/><meta name="DC.format" content="HTML5"/><meta name="DC.identifier" content="id"/><meta name="DC.language" content="zh-CN"/><title>设计说明</title><!-- Build number 2023110923. --><meta name="wh-path2root" content="../../../"/><meta name="wh-toc-id" content="id-d5856e3105"/><meta name="wh-source-relpath" content="topics/sdk/pm/pm_design_guide.dita"/><meta name="wh-out-relpath" content="topics/sdk/pm/pm_design_guide.html"/>
<link rel="stylesheet" type="text/css" href="../../../webhelp/app/commons.css?buildId=2023110923"/>
<link rel="stylesheet" type="text/css" href="../../../webhelp/app/topic.css?buildId=2023110923"/>
<script src="../../../webhelp/app/options/properties.js?buildId=20250121171154"></script>
<script src="../../../webhelp/app/localization/strings.js?buildId=2023110923"></script>
<script src="../../../webhelp/app/search/index/keywords.js?buildId=20250121171154"></script>
<script defer="defer" src="../../../webhelp/app/commons.js?buildId=2023110923"></script>
<script defer="defer" src="../../../webhelp/app/topic.js?buildId=2023110923"></script>
<link rel="stylesheet" type="text/css" href="../../../webhelp/template/aic-styles-web.css?buildId=2023110923"/><link rel="stylesheet" type="text/css" href="../../../webhelp/template/notes.css?buildId=2023110923"/><link rel="stylesheet" type="text/css" href="../../../webhelp/template/aic-common.css?buildId=2023110923"/><link rel="stylesheet" type="text/css" href="../../../webhelp/template/aic-images.css?buildId=2023110923"/><link rel="stylesheet" type="text/css" href="../../../webhelp/template/footnote.css?buildId=2023110923"/><link rel="stylesheet" type="text/css" href="../../../webhelp/template/aic-web-watermark.css?buildId=2023110923"/><link rel="stylesheet" type="text/css" href="../../../webhelp/template/topic-body-list.css?buildId=2023110923"/></head>
<body id="id" class="wh_topic_page frmBody">
<a href="#wh_topic_body" class="sr-only sr-only-focusable">
跳转到主要内容
</a>
<header class="navbar navbar-default wh_header">
<div class="container-fluid">
<div class="wh_header_flex_container navbar-nav navbar-expand-md navbar-dark">
<div class="wh_logo_and_publication_title_container">
<div class="wh_logo_and_publication_title">
<a href="http://www.artinchip.com" class=" wh_logo d-none d-sm-block "><img src="../../../company-logo-white.png" alt="RTOS SDK 使用指南SDK 指南文件"/></a>
<div class=" wh_publication_title "><a href="../../../index.html"><span class="booktitle"><span class="ph mainbooktitle">RTOS SDK 使用指南</span><span class="ph booktitlealt">SDK 指南文件</span></span></a></div>
</div>
</div>
<div class="wh_top_menu_and_indexterms_link collapse navbar-collapse" id="wh_top_menu_and_indexterms_link">
</div>
</div>
</div>
</header>
<div class=" wh_search_input navbar-form wh_topic_page_search search " role="form">
<form id="searchForm" method="get" role="search" action="../../../search.html"><div><input type="search" placeholder="搜索 " class="wh_search_textfield" id="textToSearch" name="searchQuery" aria-label="搜索查询" required="required"/><button type="submit" class="wh_search_button" aria-label="搜索"><span class="search_input_text">搜索</span></button></div></form>
</div>
<div class="container-fluid" id="wh_topic_container">
<div class="row">
<nav class="wh_tools d-print-none navbar-expand-md" aria-label="Tools">
<div data-tooltip-position="bottom" class=" wh_breadcrumb "><ol class="d-print-none"><li><span class="home"><a href="../../../index.html"><span>主页</span></a></span></li><li><div class="topicref" data-id="id"><div class="title"><a href="../../../topics/sdk/chapter-advanced-app.html">高级应用</a><div class="wh-tooltip"><p class="shortdesc">系统、存储、多媒体、接口、安全等模块的详细配置和设计说明。</p></div></div></div></li><li><div class="topicref" data-id="chapter-system"><div class="title"><a href="../../../topics/chapter-title/chapter-system.html">系统</a><div class="wh-tooltip"><p class="shortdesc"></p></div></div></div></li><li><div class="topicref" data-id="id"><div class="title"><a href="../../../topics/sdk/pm/pm_introduction.html">Power Management 使用指南</a></div></div></li><li class="active"><div class="topicref" data-id="id"><div class="title"><a href="../../../topics/sdk/pm/pm_design_guide.html">设计说明</a></div></div></li></ol></div>
<div class="wh_right_tools">
<button class="wh_hide_highlight" aria-label="切换搜索突出显示" title="切换搜索突出显示"></button>
<button class="webhelp_expand_collapse_sections" data-next-state="collapsed" aria-label="折叠截面" title="折叠截面"></button>
<div class=" wh_navigation_links "><span id="topic_navigation_links" class="navheader">
<span class="navprev"><a class="- topic/link link" href="../../../topics/sdk/pm/pm_test_guide.html" title="测试指南" aria-label="上一主题: 测试指南" rel="prev"></a></span>
<span class="navnext"><a class="- topic/link link" href="../../../topics/sdk/pm/pm_faq.html" title="常见问题" aria-label="下一主题: 常见问题" rel="next"></a></span> </span></div>
<div class=" wh_print_link print d-none d-md-inline-block "><button onClick="window.print()" title="打印此页" aria-label="打印此页"></button></div>
<button type="button" id="wh_toc_button" class="custom-toggler navbar-toggler collapsed wh_toggle_button navbar-light" aria-expanded="false" aria-label="Toggle publishing table of content" aria-controls="wh_publication_toc">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
</div>
<div class="wh_content_area">
<div class="row">
<nav id="wh_publication_toc" class="col-lg-3 col-md-3 col-sm-12 d-md-block d-none d-print-none" aria-label="Table of Contents Container">
<div id="wh_publication_toc_content">
<div class=" wh_publication_toc " data-tooltip-position="right"><span class="expand-button-action-labels"><span id="button-expand-action" role="button" aria-label="Expand"></span><span id="button-collapse-action" role="button" aria-label="Collapse"></span><span id="button-pending-action" role="button" aria-label="Pending"></span></span><ul role="tree" aria-label="Table of Contents"><li role="treeitem"><div data-tocid="revinfo_linux-d5856e989" class="topicref" data-id="revinfo_linux" data-state="leaf"><span role="button" class="wh-expand-btn"></span><div class="title"><a href="../../../topics/revinfo/revinfo_rtos.html" id="revinfo_linux-d5856e989-link">修订记录</a></div></div></li><li role="treeitem" aria-expanded="false"><div data-tocid="id-d5856e1003" class="topicref" data-id="id" data-state="not-ready"><span role="button" tabindex="0" aria-labelledby="button-expand-action id-d5856e1003-link" class="wh-expand-btn"></span><div class="title"><a href="../../../topics/sdk/env/sdk-compile.html" id="id-d5856e1003-link">SDK 编译</a><div class="wh-tooltip"><p class="shortdesc">介绍不同编译环境下 SDK 的详细编译流程。</p></div></div></div></li><li role="treeitem" aria-expanded="false"><div data-tocid="id-d5856e1152" class="topicref" data-id="id" data-state="not-ready"><span role="button" tabindex="0" aria-labelledby="button-expand-action id-d5856e1152-link" class="wh-expand-btn"></span><div class="title"><a href="../../../topics/sdk/advanced/sdk-usage.html" id="id-d5856e1152-link">使用指南</a><div class="wh-tooltip"><p class="shortdesc">系统镜像、编译选项、开发板、应用等相关的详细使用说明。</p></div></div></div></li><li role="treeitem" aria-expanded="false"><div data-tocid="concept_rcx_czh_pzb-d5856e1416" class="topicref" data-id="concept_rcx_czh_pzb" data-state="not-ready"><span role="button" tabindex="0" aria-labelledby="button-expand-action concept_rcx_czh_pzb-d5856e1416-link" class="wh-expand-btn"></span><div class="title"><a href="../../../topics/sdk/chapter-app.html" id="concept_rcx_czh_pzb-d5856e1416-link">应用场景</a><div class="wh-tooltip"><p class="shortdesc">描述了 SDK 在不同应用场景中的配置和使用包括系统更新、OTA、安全方案等。</p></div></div></div></li><li role="treeitem" aria-expanded="false"><div data-tocid="id-d5856e2119" class="topicref" data-id="id" data-state="not-ready"><span role="button" tabindex="0" aria-labelledby="button-expand-action id-d5856e2119-link" class="wh-expand-btn"></span><div class="title"><a href="../../../topics/sdk/peripheral/peripheral-intro.html" id="id-d5856e2119-link">外设移植</a><div class="wh-tooltip"><p class="shortdesc"><span class="ph">CTP、U 盘、SD 卡、有线和无线网络</span>等外设的介绍和使用说明。</p></div></div></div></li><li role="treeitem" aria-expanded="false"><div data-tocid="id-d5856e2244" class="topicref" data-id="id" data-state="not-ready"><span role="button" tabindex="0" aria-labelledby="button-expand-action id-d5856e2244-link" class="wh-expand-btn"></span><div class="title"><a href="../../../topics/sdk/bringup/chapter-bringup.html" id="id-d5856e2244-link">BringUp</a><div class="wh-tooltip"><p class="shortdesc">在硬件上电后快速初始化系统,为操作系统的启动准备好必要的硬件环境。</p></div></div></div></li><li role="treeitem" aria-expanded="true"><div data-tocid="id-d5856e2345" class="topicref" data-id="id" data-state="expanded"><span role="button" tabindex="0" aria-labelledby="button-collapse-action id-d5856e2345-link" class="wh-expand-btn"></span><div class="title"><a href="../../../topics/sdk/chapter-advanced-app.html" id="id-d5856e2345-link">高级应用</a><div class="wh-tooltip"><p class="shortdesc">系统、存储、多媒体、接口、安全等模块的详细配置和设计说明。</p></div></div></div><ul role="group" class="navbar-nav nav-list"><li role="treeitem" aria-expanded="false"><div data-tocid="_0-d5856e2360" class="topicref" data-id="_0" data-state="not-ready"><spa
</div>
</nav>
<div class="col-lg-7 col-md-9 col-sm-12" id="wh_topic_body">
<button id="wh_close_publication_toc_button" class="close-toc-button d-none" aria-label="Toggle publishing table of content" aria-controls="wh_publication_toc" aria-expanded="true">
<span class="close-toc-icon-container">
<span class="close-toc-icon"></span>
</span>
</button>
<button id="wh_close_topic_toc_button" class="close-toc-button d-none" aria-label="Toggle topic table of content" aria-controls="wh_topic_toc" aria-expanded="true">
<span class="close-toc-icon-container">
<span class="close-toc-icon"></span>
</span>
</button>
<div class=" wh_topic_content body "><main role="main"><article class="- topic/topic topic" role="article" aria-labelledby="ariaid-title1"><span class="edit-link" style="font-size:12px; opacity:0.6; text-align:right; vertical-align:middle"><a target="_blank" href="http://172.16.35.88/tasks/jdssno1uvvbf2mltu9kb9v3if05d5gopuakboe8hlud18rma/edit/F:/aicdita/aicdita-cn/topics/sdk/pm/pm_design_guide.dita">Edit online</a></span><h1 class="- topic/title title topictitle1" id="ariaid-title1">设计说明</h1><div class="date inPage">15 Jan 2024</div><div style="color: gray;">
Read time: 2 minute(s)
</div><div class="- topic/body body"><p class="- topic/p p" data-ofbid="d55636e19__20250121171519">PM 驱动源码位于 <span class="+ topic/ph sw-d/filepath ph filepath">bsp/artinchip/drv/pm/</span></p><section class="- topic/section section" id="id__pm" data-ofbid="id__pm"><h2 class="- topic/title title sectiontitle">PM 框架和功耗模式</h2>
<p class="- topic/p p" data-ofbid="d55636e29__20250121171519"><span class="- topic/ph ph">Luban-Lite</span> 的 PM 驱动完全遵循 RT-Thread 的 PM 框架。PM
框架将系统的功耗分为多个等级,每个等级对应一个功耗模式,实现对不同功耗模式的管理。</p>
<p class="- topic/p p" data-ofbid="d55636e35__20250121171519">以下是 <span class="- topic/ph ph">Luban-Lite</span> 中各功耗模式的详细描述及其在 <span class="- topic/ph ph">Luban-Lite</span>
中的实现功能:</p>
<div class="table-container"><table class="- topic/table table frame-all" id="id__table_bpv_bjd_bdc" data-ofbid="id__table_bpv_bjd_bdc" data-cols="5"><caption class="- topic/title title tablecap" data-caption-side="top" data-is-repeated="true"><span class="table--title-label"><span class="table--title-label-number"> 1</span><span class="table--title-label-punctuation">. </span></span><span class="table--title">功能模式及优先级描述</span></caption><colgroup><col style="width:27.31811697574893%"/><col style="width:7.132667617689016%"/><col style="width:18.33095577746077%"/><col style="width:12.482168330955778%"/><col style="width:34.73609129814551%"/></colgroup><thead class="- topic/thead thead"><tr class="- topic/row"><th class="- topic/entry entry colsep-1 rowsep-1" id="id__table_bpv_bjd_bdc__entry__1">功耗模式</th><th class="- topic/entry entry colsep-1 rowsep-1" id="id__table_bpv_bjd_bdc__entry__2">级别</th><th class="- topic/entry entry colsep-1 rowsep-1" id="id__table_bpv_bjd_bdc__entry__3">描述</th><th class="- topic/entry entry colsep-1 rowsep-1" id="id__table_bpv_bjd_bdc__entry__4"><span class="- topic/ph ph">Luban-Lite</span> 是否支持</th><th class="- topic/entry entry colsep-0 rowsep-1" id="id__table_bpv_bjd_bdc__entry__5"><span class="- topic/ph ph">Luban-Lite</span> 实现功能的区别</th></tr></thead><tbody class="- topic/tbody tbody"><tr class="- topic/row"><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__1">PM_SLEEP_MODE_NONE</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__2">0</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__3">系统处于活跃状态</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__4"></td><td class="- topic/entry entry colsep-0 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__5">
<p class="- topic/p p" data-ofbid="d55636e82__20250121171519">未做任何低功耗处理,系统处于全速运行状态。</p>
</td></tr><tr class="- topic/row"><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__1">PM_SLEEP_MODE_IDLE</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__2">1</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__3">空闲模式</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__4"></td><td class="- topic/entry entry colsep-0 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__5">
<p class="- topic/p p" data-ofbid="d55636e96__20250121171519">执行 <code class="+ topic/ph pr-d/codeph ph codeph">WFI</code>Wait For Interrupt指令使 CPU
进入空闲状态,等待中断唤醒。</p>
</td></tr><tr class="- topic/row"><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__1">PM_SLEEP_MODE_LIGHT</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__2">2</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__3">轻睡眠模式</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__4"></td><td class="- topic/entry entry colsep-0 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__5">
<p class="- topic/p p" data-ofbid="d55636e113__20250121171519">执行 <code class="+ topic/ph pr-d/codeph ph codeph">WFI</code> 指令,同时将 CPU 及总线时钟切换到 24 MHz并关闭 PLL
时钟。</p>
</td></tr><tr class="- topic/row"><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__1">PM_SLEEP_MODE_DEEP</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__2">3</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__3">深睡眠模式</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__4"></td><td class="- topic/entry entry colsep-0 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__5">执行 <code class="+ topic/ph pr-d/codeph ph codeph">WFI</code> 指令,同时将 CPU 及总线时钟切换到 24 MHz并关闭 PLL 时钟,将
PSRAM 时钟降频。</td></tr><tr class="- topic/row"><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__1">PM_SLEEP_MODE_STANDBY</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__2">4</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__3">待机模式</td><td class="- topic/entry entry colsep-1 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__4"></td><td class="- topic/entry entry colsep-0 rowsep-1" headers="id__table_bpv_bjd_bdc__entry__5">-</td></tr><tr class="- topic/row"><td class="- topic/entry entry colsep-1 rowsep-0" headers="id__table_bpv_bjd_bdc__entry__1">PM_SLEEP_MODE_SHUTDOWN</td><td class="- topic/entry entry colsep-1 rowsep-0" headers="id__table_bpv_bjd_bdc__entry__2">5</td><td class="- topic/entry entry colsep-1 rowsep-0" headers="id__table_bpv_bjd_bdc__entry__3">关机模式</td><td class="- topic/entry entry colsep-1 rowsep-0" headers="id__table_bpv_bjd_bdc__entry__4"></td><td class="- topic/entry entry colsep-0 rowsep-0" headers="id__table_bpv_bjd_bdc__entry__5">-</td></tr></tbody></table></div>
</section><section class="- topic/section section" id="id__section_yxq_jy1_ddc" data-ofbid="id__section_yxq_jy1_ddc"><h2 class="- topic/title title sectiontitle">申请和释放功耗模式</h2>
<div class="- topic/div div"><strong class="+ topic/ph hi-d/b ph b">API 接口</strong><div class="- topic/p p" data-ofbid="d55636e164__20250121171519">为了管理功耗模式RT-Thread 提供了一组 API 接口,用于申请和释放不同的功耗模式。<div class="- topic/note note note note_note" id="id__note_tkd_1bb_ddc" data-ofbid="id__note_tkd_1bb_ddc"><span class="note__title">注:</span> PM
框架中功耗模式的申请和释放必须成对使用,否则可能导致系统无法正确管理功耗状态。</div></div><ul class="- topic/ul ul" id="id__ul_ssw_ynv_hdc" data-ofbid="id__ul_ssw_ynv_hdc"><li class="- topic/li li" data-ofbid="d55636e170__20250121171519">
<div class="- topic/p p" data-ofbid="d55636e174__20250121171519">PM
框架提供的申请休眠模式的接口有:<pre class="+ topic/pre pr-d/codeblock pre codeblock language-c" id="id__codeblock_bjm_sz1_ddc" data-ofbid="id__codeblock_bjm_sz1_ddc">rt_pm_release(rt_uint8_t mode)
rt_pm_module_request(uint8_t module_id, rt_uint8_t sleep_mode)
rt_pm_sleep_request(rt_uint16_t module_id, rt_uint8_t mode)
rt_pm_sleep_none_request(rt_uint16_t module_id)
rt_pm_sleep_idle_request(rt_uint16_t module_id)
rt_pm_sleep_light_request(rt_uint16_t module_id)</pre></div>
</li><li class="- topic/li li" data-ofbid="d55636e182__20250121171519">
<div class="- topic/p p" data-ofbid="d55636e184__20250121171519">释放休眠模式的接口有:<pre class="+ topic/pre pr-d/codeblock pre codeblock language-c" id="id__codeblock_hqx_sz1_ddc" data-ofbid="id__codeblock_hqx_sz1_ddc">rt_pm_release(rt_uint8_t sleep_mode)
rt_pm_module_release(uint8_t module_id, rt_uint8_t sleep_mode)
rt_pm_module_release_all(uint8_t module_id, rt_uint8_t sleep_mode)
rt_pm_sleep_release(rt_uint16_t module_id, rt_uint8_t mode)
rt_pm_sleep_none_release(rt_uint16_t module_id)
rt_pm_sleep_idle_release(rt_uint16_t module_id)
rt_pm_sleep_light_release(rt_uint16_t module_id)</pre></div>
</li><li class="- topic/li li" data-ofbid="d55636e189__20250121171519">
<div class="- topic/div div"><strong class="+ topic/ph hi-d/b ph b"><code class="+ topic/ph pr-d/codeph ph codeph">module_id</code></strong><div class="- topic/p p" data-ofbid="d55636e195__20250121171519">RT-Thread 官方推荐使用基于
<code class="+ topic/ph pr-d/codeph ph codeph">module_id</code> 的 API
接口,用于申请和释放功耗模式。使用这些接口可以查看申请功耗的模块,也方便调试。<pre class="+ topic/pre pr-d/codeblock pre codeblock language-c" id="id__codeblock_wtb_5z1_ddc" data-ofbid="id__codeblock_wtb_5z1_ddc">rt_pm_module_request(uint8_t module_id, rt_uint8_t sleep_mode) <em class="hl-comment">// 申请进入指定的功耗模式</em>
rt_pm_module_release(uint8_t module_id, rt_uint8_t sleep_mode) <em class="hl-comment">// 释放指定的功耗模式</em></pre></div><p class="- topic/p p" data-ofbid="d55636e202__20250121171519"><code class="+ topic/ph pr-d/codeph ph codeph">module_id</code>
是在 <span class="+ topic/ph sw-d/filepath ph filepath">pm_cfg.h</span> 文件中定义的,用于表示不同的模块。开发者可以根据实际需求自行定义
<code class="+ topic/ph pr-d/codeph ph codeph">module_id</code>,以便更好地管理和调试功耗模式。</p></div>
</li></ul></div>
<div class="- topic/div div"><strong class="+ topic/ph hi-d/b ph b">申请和释放规则</strong><div class="- topic/p p" data-ofbid="d55636e219__20250121171519">当有多个线程或任务同时申请不同的功耗模式时RT-Thread PM 框架会根据以下规则决定当前系统应运行在哪个功耗模式下:<ol class="- topic/ol ol" id="id__ol_oh4_ry1_ddc" data-ofbid="id__ol_oh4_ry1_ddc"><li class="- topic/li li" data-ofbid="d55636e222__20250121171519"><strong class="+ topic/ph hi-d/b ph b">最高优先级的模式优先</strong>:如果某个线程申请了 <code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_NONE</code>
模式,而另一个线程申请了 <code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_DEEP</code> 模式,则系统会以
<code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_NONE</code> 模式运行,直到所有申请
<code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_NONE</code> 模式的任务都释放了这个模式,系统才会切换到
<code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_DEEP</code> 模式,进入 deep sleep
mode。<p class="- topic/p p" data-ofbid="d55636e242__20250121171519">RT-Thread
的功耗模式需要在代码中主动申请和释放,为了保证系统的正常运行,功耗越大的模式优先级越高。</p></li><li class="- topic/li li" data-ofbid="d55636e244__20250121171519"><strong class="+ topic/ph hi-d/b ph b">默认休眠模式</strong>:在 PM 框架初始化时,将 <code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_DEEP</code>
设置为默认休眠模式。如果没有比 <code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_DEEP</code> 更高优先级的请求,系统会立刻进入
deep sleep mode。</li><li class="- topic/li li" data-ofbid="d55636e254__20250121171519"><strong class="+ topic/ph hi-d/b ph b">初始化时的默认模式</strong>PM 框架初始化时会申请 <code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_NONE</code>
模式,以确保在 PM 初始化完成后,系统可以正常运行,而不会立即进入 deep sleep
mode。因此在应用代码中想要进入低功耗模式需要主动调用 release 相关的 API 接口释放
<code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_NONE</code> 模式。</li></ol></div></div>
</section><section class="- topic/section section" id="id__id2" data-ofbid="id__id2"><h2 class="- topic/title title sectiontitle">休眠唤醒流程</h2>
<div class="- topic/p p" data-ofbid="d55636e272__20250121171519">PM 框架休眠唤醒流程如下:<figure class="- topic/fig fig fignone" id="id__fig_u1q_zy1_ddc" data-ofbid="id__fig_u1q_zy1_ddc"><br/><div class="imagecenter"><img class="- topic/image image imagecenter" id="id__image_dpv_bjd_bdc" src="../../../images/pm/suspend_resume_flow.png" alt="suspend_resume_flow"/></div><br/><figcaption data-caption-side="bottom" class="- topic/title title figcapcenter"><span class="figtitleprefix fig--title-label"><span class="fig--title-label-number"> 1</span><span class="fig--title-label-punctuation">. </span></span><span class="fig--title">休眠唤醒流程</span></figcaption></figure>
</div>
<p class="- topic/p p" data-ofbid="d55636e283__20250121171519">如上图所示PM 框架及驱动使能后RT-Thread 会在 idle 线程进入休眠唤醒流程。在休眠唤醒流程中PM
框架会检查所有正在运行的任务和线程,确定当前系统中申请的最高优先级的功耗模式,并以最高优先级的功耗模式运行。例如,如果最高优先级是
<code class="+ topic/ph pr-d/codeph ph codeph">PM_SLEEP_MODE_DEEP</code>,系统将进入 deep sleep mode。</p>
<div class="- topic/note note note note_note" id="id__note_egr_d1b_ddc" data-ofbid="id__note_egr_d1b_ddc"><span class="note__title">注:</span> 功耗越高,优先级越高。</div>
<p class="- topic/p p" data-ofbid="d55636e292__20250121171519">在低功耗模式 ( deep sleep mode)
下,系统会等待外部中断或特定事件来触发唤醒。当外部中断或事件触发时,系统会退出低功耗模式,恢复到工作状态,继续执行被中断的任务或线程。</p>
</section><section class="- topic/section section" id="id__id3" data-ofbid="id__id3"><h2 class="- topic/title title sectiontitle">代码段保护</h2>
<div class="- topic/p p" data-ofbid="d55636e303__20250121171519">在 RT-Thread 的 PM
框架中,通过申请和释放功耗模式来保护代码段,确保在特定阶段不允许系统进入低功耗模式。例如,如果在读取数据过程中不允许进入休眠,则执行代码段保护的流程如下:<div class="- topic/note note note note_note" id="id__note_z3k_r1b_ddc" data-ofbid="id__note_z3k_r1b_ddc"><span class="note__title">注:</span> PM 框架中模式的申请和释放必须成对使用。</div><ol class="- topic/ol ol" id="id__ol_vpd_gbb_ddc" data-ofbid="id__ol_vpd_gbb_ddc"><li class="- topic/li li" data-ofbid="d55636e308__20250121171519">通过 <span class="+ topic/keyword pr-d/apiname keyword apiname">rt_pm_module_request</span>
函数申请不进入任何低功耗模式。<pre class="+ topic/pre pr-d/codeblock pre codeblock language-c" id="id__codeblock_zy5_hbb_ddc" data-ofbid="id__codeblock_zy5_hbb_ddc">rt_pm_module_request(PM_MAIN_ID, PM_SLEEP_MODE_NONE);</pre></li><li class="- topic/li li" data-ofbid="d55636e315__20250121171519">等待执行读取数据的操作。</li><li class="- topic/li li" data-ofbid="d55636e317__20250121171519">通过 <span class="+ topic/keyword pr-d/apiname keyword apiname">rt_pm_module_release</span>
函数释放不进入任何低功耗模式的请求。<pre class="+ topic/pre pr-d/codeblock pre codeblock language-c" id="id__codeblock_wnz_r1b_ddc" data-ofbid="id__codeblock_wnz_r1b_ddc">rt_pm_module_release(PM_MAIN_ID, PM_SLEEP_MODE_NONE);</pre></li></ol></div>
</section><section class="- topic/section section" id="id__id4" data-ofbid="id__id4"><h2 class="- topic/title title sectiontitle">设置唤醒源</h2>
<div class="- topic/p p" data-ofbid="d55636e331__20250121171519"><span class="- topic/ph ph">Luban-Lite</span> SDK 在 PM 框架基础上增加了设置唤醒源的接口,中断唤醒源可以唤醒系统。通过以下接口,可以设置对应的唤醒源:<ul class="- topic/ul ul" id="id__ul_i1f_jcb_ddc" data-ofbid="id__ul_i1f_jcb_ddc"><li class="- topic/li li" data-ofbid="d55636e336__20250121171519"><span class="+ topic/keyword pr-d/apiname keyword apiname">rt_device_wakeup_enable(rt_device_t dev, rt_bool_t
enable)</span>:用来设置普通外设作为唤醒源,包括 RTC、I2C 和 SPI 等。这类设备在 RR-Thread 中采用
<code class="+ topic/ph pr-d/codeph ph codeph">rt_device</code> 描述设备。</li><li class="- topic/li li" data-ofbid="d55636e343__20250121171519"><span class="+ topic/keyword pr-d/apiname keyword apiname">rt_pm_set_pin_wakeup_source(rt_base_t pin)</span>:用来设置某个 GPIO
引脚作为唤醒源。<p class="- topic/p p" data-ofbid="d55636e347__20250121171519">在 RT-Thread 中,采用 <code class="+ topic/ph pr-d/codeph ph codeph">rt_base_t</code> 描述一个具体的 GPIO
口,而没有采用 rt_device 描述,因此需要一个单独的接口来设置 GPIO
的唤醒源。</p></li></ul></div>
</section><section class="- topic/section section" id="id__id5" data-ofbid="id__id5"><h2 class="- topic/title title sectiontitle">低功耗定时器</h2>
<p class="- topic/p p" data-ofbid="d55636e361__20250121171519">系统中没有专用的低功耗定时器,<span class="- topic/ph ph">Luban-Lite</span> SDK 通过利用 CPU 的计时器 MTIME
来实现低功耗定时器。详细的实现原理和步骤如下所示:</p>
<ol class="- topic/ol ol arabic simple" id="id__ol_lpv_bjd_bdc" data-ofbid="id__ol_lpv_bjd_bdc"><li class="- topic/li li" data-ofbid="d55636e368__20250121171519">
<p class="- topic/p p" data-ofbid="d55636e370__20250121171519">修改 MTIME 的比较值寄存器,减少中断的周期性触发,从而实现 tickless 的目的。</p>
</li><li class="- topic/li li" data-ofbid="d55636e373__20250121171519">
<p class="- topic/p p" data-ofbid="d55636e375__20250121171519">获取低功耗定时器的下一次超时时间,然后加上当前的 MTIME 的计数值,再将结果写入 MTIME 的比较值寄存器。</p>
</li><li class="- topic/li li" data-ofbid="d55636e378__20250121171519">
<p class="- topic/p p" data-ofbid="d55636e380__20250121171519">当系统从低功耗模式唤醒时,需要计算 MTIME 当前计数值和休眠前计数值的差值,并将该差值补偿到 rt_tick 中。</p>
</li><li class="- topic/li li" data-ofbid="d55636e383__20250121171519">
<p class="- topic/p p" data-ofbid="d55636e385__20250121171519">在系统唤醒后,需要恢复 MTIME 的周期性触发计数。</p>
</li></ol>
</section></div></article></main></div>
</div>
<nav role="navigation" id="wh_topic_toc" aria-label="On this page" class="col-lg-2 d-none d-lg-block navbar d-print-none">
<div id="wh_topic_toc_content">
<div class=" wh_topic_toc "><div class="wh_topic_label">在本页上</div><ul><li class="section-item"><div class="section-title"><a href="#id__pm" data-tocid="id__pm">PM 框架和功耗模式</a></div></li><li class="section-item"><div class="section-title"><a href="#id__section_yxq_jy1_ddc" data-tocid="id__section_yxq_jy1_ddc">申请和释放功耗模式</a></div></li><li class="section-item"><div class="section-title"><a href="#id__id2" data-tocid="id__id2">休眠唤醒流程</a></div></li><li class="section-item"><div class="section-title"><a href="#id__id3" data-tocid="id__id3">代码段保护</a></div></li><li class="section-item"><div class="section-title"><a href="#id__id4" data-tocid="id__id4">设置唤醒源</a></div></li><li class="section-item"><div class="section-title"><a href="#id__id5" data-tocid="id__id5">低功耗定时器</a></div></li></ul></div>
</div>
</nav>
</div>
</div>
</div>
<footer class="navbar navbar-default wh_footer">
<div class=" footer-container mx-auto ">
<title>footer def</title>
<style><!--
.p1 {
font-family: FangZhengShuSong, Times, serif;
}
.p2 {
font-family: Arial, Helvetica, sans-serif;
}
.p3 {
font-family: "Lucida Console", "Courier New", monospace;
}
--></style>
<div class="webhelp.fragment.footer">
<p class="p1">Copyright © 2019-2024 广东匠芯创科技有限公司. All rights reserved.</p>
</div><div>
<div class="generation_time">
Update Time: 2025-01-21
</div>
</div>
</div>
</footer>
<div id="go2top" class="d-print-none">
<span class="oxy-icon oxy-icon-up"></span>
</div>
<div id="modal_img_large" class="modal">
<span class="close oxy-icon oxy-icon-remove"></span>
<div id="modal_img_container"></div>
<div id="caption"></div>
</div>
<script src="${pd}/publishing/publishing-styles-AIC-template/js/custom.js" defer="defer"></script>
</body>
</html>