]> Git Repo - pico-vscode.git/blob - web/docs/group__pico__flash.html
Merge branch 'main' into main
[pico-vscode.git] / web / docs / group__pico__flash.html
1 <!-- HTML header for doxygen 1.8.20-->
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5         <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
6         <meta http-equiv="X-UA-Compatible" content="IE=9"/>
7         <meta name="generator" content="Doxygen 1.9.4"/>
8         <meta name="viewport" content="width=device-width, initial-scale=1"/>
9         <title>Raspberry Pi Pico SDK: pico_flash</title>
10         <!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
11         <script type="text/javascript" src="jquery.js"></script>
12         <script type="text/javascript" src="dynsections.js"></script>
13         <link href="navtree.css" rel="stylesheet" type="text/css"/>
14 <script type="text/javascript" src="resize.js"></script>
15 <script type="text/javascript" src="navtreedata.js"></script>
16 <script type="text/javascript" src="navtree.js"></script>
17         <link href="search/search.css" rel="stylesheet" type="text/css"/>
18 <script type="text/javascript" src="search/searchdata.js"></script>
19 <script type="text/javascript" src="search/search.js"></script>
20     <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
21         <link href="doxygen.css" rel="stylesheet" type="text/css" />
22         <link href="normalise.css" rel="stylesheet" type="text/css"/>
23 <link href="main.css" rel="stylesheet" type="text/css"/>
24 <link href="styles.css" rel="stylesheet" type="text/css"/>
25 </head>
26 <body>
27         <div class="navigation-mobile">
28                 <div class="logo--mobile">
29                         <a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
30                 </div>
31                 <div class="navigation-toggle">
32                         <span class="line-1"></span>
33                         <span class="line-2">
34                                 <p>Menu Toggle</p>
35                         </span>
36                         <span class="line-3"></span>
37                 </div>
38         </div>
39         <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
40                 <div class="logo">
41                         <a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
42                         <span style="display: inline-block; margin-top: 10px;">
43                                 v2.0.0
44                         </span>
45                 </div>
46                 <div class="navigation-footer">
47                         <img src="logo-mobile.svg" alt="Raspberry Pi">
48                         <a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
49                 </div>
50 <!--            <div class="search">
51                         <form>
52                                 <input type="search" name="search" id="search" placeholder="Search">
53                                 <input type="submit" value="Search">
54                         </form>
55                 </div> -->
56 <!-- Generated by Doxygen 1.9.4 -->
57 <script type="text/javascript">
58 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
59 var searchBox = new SearchBox("searchBox", "search",'Search','.html');
60 /* @license-end */
61 </script>
62 <script type="text/javascript" src="menudata.js"></script>
63 <script type="text/javascript" src="menu.js"></script>
64 <script type="text/javascript">
65 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
66 $(function() {
67   initMenu('',true,false,'search.php','Search');
68   $(document).ready(function() { init_search(); });
69 });
70 /* @license-end */
71 </script>
72 <div id="main-nav"></div>
73 </div><!-- top -->
74 <div id="side-nav" class="ui-resizable side-nav-resizable">
75   <div id="nav-tree">
76     <div id="nav-tree-contents">
77       <div id="nav-sync" class="sync"></div>
78     </div>
79   </div>
80   <div id="splitbar" style="-moz-user-select:none;" 
81        class="ui-resizable-handle">
82   </div>
83 </div>
84 <script type="text/javascript">
85 /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
86 $(document).ready(function(){initNavTree('group__pico__flash.html',''); initResizable(); });
87 /* @license-end */
88 </script>
89 <div id="doc-content">
90 <!-- window showing the filter options -->
91 <div id="MSearchSelectWindow"
92      onmouseover="return searchBox.OnSearchSelectShow()"
93      onmouseout="return searchBox.OnSearchSelectHide()"
94      onkeydown="return searchBox.OnSearchSelectKey(event)">
95 </div>
96
97 <!-- iframe showing the search results (closed by default) -->
98 <div id="MSearchResultsWindow">
99 <iframe src="javascript:void(0)" frameborder="0" 
100         name="MSearchResults" id="MSearchResults">
101 </iframe>
102 </div>
103
104 <div class="header">
105   <div class="summary">
106 <a href="#func-members">Functions</a>  </div>
107   <div class="headertitle"><div class="title">pico_flash<div class="ingroups"><a class="el" href="group__high__level.html">High Level APIs</a></div></div></div>
108 </div><!--header-->
109 <div class="contents">
110
111 <p>High level flash API.  
112 <a href="#details">More...</a></p>
113 <table class="memberdecls">
114 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
115 Functions</h2></td></tr>
116 <tr class="memitem:ga2ad3247806ca16dec03e655eaec1775f"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init</a> (void)</td></tr>
117 <tr class="memdesc:ga2ad3247806ca16dec03e655eaec1775f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize a core such that the other core can lock it out during <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a>.  <a href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">More...</a><br /></td></tr>
118 <tr class="separator:ga2ad3247806ca16dec03e655eaec1775f"><td class="memSeparator" colspan="2">&#160;</td></tr>
119 <tr class="memitem:gaed14b762cb5fd483995bd36fc8ad338d"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#gaed14b762cb5fd483995bd36fc8ad338d">flash_safe_execute_core_deinit</a> (void)</td></tr>
120 <tr class="memdesc:gaed14b762cb5fd483995bd36fc8ad338d"><td class="mdescLeft">&#160;</td><td class="mdescRight">De-initialize work done by <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init</a>.  <a href="group__pico__flash.html#gaed14b762cb5fd483995bd36fc8ad338d">More...</a><br /></td></tr>
121 <tr class="separator:gaed14b762cb5fd483995bd36fc8ad338d"><td class="memSeparator" colspan="2">&#160;</td></tr>
122 <tr class="memitem:ga679076dc10c5beb73d5f1abdb52d6735"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> (void(*func)(void *), void *param, uint32_t enter_exit_timeout_ms)</td></tr>
123 <tr class="memdesc:ga679076dc10c5beb73d5f1abdb52d6735"><td class="mdescLeft">&#160;</td><td class="mdescRight">Execute a function with IRQs disabled and with the other core also not executing/reading flash.  <a href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">More...</a><br /></td></tr>
124 <tr class="separator:ga679076dc10c5beb73d5f1abdb52d6735"><td class="memSeparator" colspan="2">&#160;</td></tr>
125 <tr class="memitem:gaee44bd9bc42463f0521535825e8d90b2"><td class="memItemLeft" align="right" valign="top"><a class="el" href="structflash__safety__helper__t.html">flash_safety_helper_t</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__pico__flash.html#gaee44bd9bc42463f0521535825e8d90b2">get_flash_safety_helper</a> (void)</td></tr>
126 <tr class="memdesc:gaee44bd9bc42463f0521535825e8d90b2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Internal method to return the flash safety helper implementation.  <a href="group__pico__flash.html#gaee44bd9bc42463f0521535825e8d90b2">More...</a><br /></td></tr>
127 <tr class="separator:gaee44bd9bc42463f0521535825e8d90b2"><td class="memSeparator" colspan="2">&#160;</td></tr>
128 </table>
129 <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
130 <p >High level flash API. </p>
131 <p >Flash cannot be erased or written to when in XIP mode. However the system cannot directly access memory in the flash address space when not in XIP mode.</p>
132 <p >It is therefore critical that no code or data is being read from flash while flash is been written or erased.</p>
133 <p >If only one core is being used, then the problem is simple - just disable interrupts; however if code is running on the other core, then it has to be asked, nicely, to avoid flash for a bit. This is hard to do if you don't have complete control of the code running on that core at all times.</p>
134 <p >This library provides a <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> method which calls a function back having successfully gotten into a state where interrupts are disabled, and the other core is not executing or reading from flash.</p>
135 <p >How it does this is dependent on the supported environment (Free RTOS SMP or pico_multicore). Additionally the user can provide their own mechanism by providing a strong definition of <a class="el" href="group__pico__flash.html#gaee44bd9bc42463f0521535825e8d90b2">get_flash_safety_helper()</a>.</p>
136 <p >Using the default settings, flash_safe_execute will only call the callback function if the state is safe otherwise returning an error (or an assert depending on PICO_FLASH_ASSERT_ON_UNSAFE).</p>
137 <p >There are conditions where safety would not be guaranteed:</p>
138 <ol type="1">
139 <li>FreeRTOS smp with <code>configNUM_CORES=1</code> - FreeRTOS still uses pico_multicore in this case, so <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> cannot know what the other core is doing, and there is no way to force code execution between a FreeRTOS core and a non FreeRTOS core.</li>
140 <li>FreeRTOS non SMP with pico_multicore - Again, there is no way to force code execution between a FreeRTOS core and a non FreeRTOS core.</li>
141 <li>pico_multicore without <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init()</a> having been called on the other core - The <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a> method does not know if code is executing on the other core, so it has to assume it is. Either way, it is not able to intervene if <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init()</a> has not been called on the other core.</li>
142 </ol>
143 <p >Fortunately, all is not lost in this situation, you may:</p>
144 <ul>
145 <li>Set PICO_FLASH_ASSUME_CORE0_SAFE=1 to explicitly say that core 0 is never using flash.</li>
146 <li>Set PICO_FLASH_ASSUME_CORE1_SAFE=1 to explicitly say that core 1 is never using flash. </li>
147 </ul>
148 <h2 class="groupheader">Function Documentation</h2>
149 <a id="ga679076dc10c5beb73d5f1abdb52d6735" name="ga679076dc10c5beb73d5f1abdb52d6735"></a>
150 <h2 class="memtitle"><span class="permalink"><a href="#ga679076dc10c5beb73d5f1abdb52d6735">&#9670;&nbsp;</a></span>flash_safe_execute()</h2>
151
152 <div class="memitem">
153 <div class="memproto">
154       <table class="memname">
155         <tr>
156           <td class="memname">int flash_safe_execute </td>
157           <td>(</td>
158           <td class="paramtype">void(*)(void *)&#160;</td>
159           <td class="paramname"><em>func</em>, </td>
160         </tr>
161         <tr>
162           <td class="paramkey"></td>
163           <td></td>
164           <td class="paramtype">void *&#160;</td>
165           <td class="paramname"><em>param</em>, </td>
166         </tr>
167         <tr>
168           <td class="paramkey"></td>
169           <td></td>
170           <td class="paramtype">uint32_t&#160;</td>
171           <td class="paramname"><em>enter_exit_timeout_ms</em>&#160;</td>
172         </tr>
173         <tr>
174           <td></td>
175           <td>)</td>
176           <td></td><td></td>
177         </tr>
178       </table>
179 </div><div class="memdoc">
180
181 <p>Execute a function with IRQs disabled and with the other core also not executing/reading flash. </p>
182 <dl class="params"><dt>Parameters</dt><dd>
183   <table class="params">
184     <tr><td class="paramname">func</td><td>the function to call </td></tr>
185     <tr><td class="paramname">param</td><td>the parameter to pass to the function </td></tr>
186     <tr><td class="paramname">enter_exit_timeout_ms</td><td>the timeout for each of the enter/exit phases when coordinating with the other core</td></tr>
187   </table>
188   </dd>
189 </dl>
190 <dl class="section return"><dt>Returns</dt><dd>PICO_OK on success (the function will have been called). PICO_ERROR_TIMEOUT on timeout (the function may have been called). PICO_ERROR_NOT_PERMITTED if safe execution is not possible (the function will not have been called). PICO_ERROR_INSUFFICIENT_RESOURCES if the method fails due to dynamic resource exhaustion (the function will not have been called) </dd></dl>
191 <dl class="section note"><dt>Note</dt><dd>if PICO_FLASH_ASSERT_ON_UNSAFE is 1, this function will assert in debug mode vs returning PICO_ERROR_NOT_PERMITTED </dd></dl>
192
193 </div>
194 </div>
195 <a id="gaed14b762cb5fd483995bd36fc8ad338d" name="gaed14b762cb5fd483995bd36fc8ad338d"></a>
196 <h2 class="memtitle"><span class="permalink"><a href="#gaed14b762cb5fd483995bd36fc8ad338d">&#9670;&nbsp;</a></span>flash_safe_execute_core_deinit()</h2>
197
198 <div class="memitem">
199 <div class="memproto">
200       <table class="memname">
201         <tr>
202           <td class="memname">bool flash_safe_execute_core_deinit </td>
203           <td>(</td>
204           <td class="paramtype">void&#160;</td>
205           <td class="paramname"></td><td>)</td>
206           <td></td>
207         </tr>
208       </table>
209 </div><div class="memdoc">
210
211 <p>De-initialize work done by <a class="el" href="group__pico__flash.html#ga2ad3247806ca16dec03e655eaec1775f">flash_safe_execute_core_init</a>. </p>
212 <dl class="section return"><dt>Returns</dt><dd>true on success </dd></dl>
213
214 </div>
215 </div>
216 <a id="ga2ad3247806ca16dec03e655eaec1775f" name="ga2ad3247806ca16dec03e655eaec1775f"></a>
217 <h2 class="memtitle"><span class="permalink"><a href="#ga2ad3247806ca16dec03e655eaec1775f">&#9670;&nbsp;</a></span>flash_safe_execute_core_init()</h2>
218
219 <div class="memitem">
220 <div class="memproto">
221       <table class="memname">
222         <tr>
223           <td class="memname">bool flash_safe_execute_core_init </td>
224           <td>(</td>
225           <td class="paramtype">void&#160;</td>
226           <td class="paramname"></td><td>)</td>
227           <td></td>
228         </tr>
229       </table>
230 </div><div class="memdoc">
231
232 <p>Initialize a core such that the other core can lock it out during <a class="el" href="group__pico__flash.html#ga679076dc10c5beb73d5f1abdb52d6735">flash_safe_execute</a>. </p>
233 <dl class="section note"><dt>Note</dt><dd>This is not necessary for FreeRTOS SMP, but should be used when launching via <a class="el" href="group__pico__multicore.html#ga46ea5e2efc181aba1d4d1de06a375c59">multicore_launch_core1</a> </dd></dl>
234 <dl class="section return"><dt>Returns</dt><dd>true on success; there is no need to call <a class="el" href="group__pico__flash.html#gaed14b762cb5fd483995bd36fc8ad338d">flash_safe_execute_core_deinit()</a> on failure. </dd></dl>
235
236 </div>
237 </div>
238 <a id="gaee44bd9bc42463f0521535825e8d90b2" name="gaee44bd9bc42463f0521535825e8d90b2"></a>
239 <h2 class="memtitle"><span class="permalink"><a href="#gaee44bd9bc42463f0521535825e8d90b2">&#9670;&nbsp;</a></span>get_flash_safety_helper()</h2>
240
241 <div class="memitem">
242 <div class="memproto">
243       <table class="memname">
244         <tr>
245           <td class="memname"><a class="el" href="structflash__safety__helper__t.html">flash_safety_helper_t</a> * get_flash_safety_helper </td>
246           <td>(</td>
247           <td class="paramtype">void&#160;</td>
248           <td class="paramname"></td><td>)</td>
249           <td></td>
250         </tr>
251       </table>
252 </div><div class="memdoc">
253
254 <p>Internal method to return the flash safety helper implementation. </p>
255 <p >Advanced users can provide their own implementation of this function to perform different inter-core coordination before disabling XIP mode.</p>
256 <dl class="section return"><dt>Returns</dt><dd>the <a class="el" href="structflash__safety__helper__t.html">flash_safety_helper_t</a> </dd></dl>
257
258 </div>
259 </div>
260 </div><!-- contents -->
261 </div><!-- doc-content -->
262
263         <script src="main.js"></script>
264 </body>
265 </html>
This page took 0.043601 seconds and 4 git commands to generate.