arch.h 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438
  1. /****************************************************************************
  2. * include/nuttx/arch.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_NUTTX_ARCH_H
  21. #define __INCLUDE_NUTTX_ARCH_H
  22. /* This header file contains function prototypes for the interfaces between
  23. * (1) the nuttx core-code, (2) the microprocessor specific logic that
  24. * resides under the arch/ sub-directory, and (3) the board-specific logic
  25. * that resides under boards/
  26. *
  27. * Naming conventions:
  28. *
  29. * 1. Common Microprocessor Interfaces.
  30. *
  31. * Any interface that is common across all microprocessors should be
  32. * prefixed with up_ and prototyped in this header file. These
  33. * definitions provide the common interface between NuttX and the
  34. * architecture-specific implementation in arch/
  35. *
  36. * This chip related declarations are retained in this header file.
  37. *
  38. * NOTE: up_ is supposed to stand for microprocessor; the u is like the
  39. * Greek letter micron.
  40. *
  41. * 2. Microprocessor-Specific Interfaces.
  42. *
  43. * An interface which is unique to a certain microprocessor should be
  44. * prefixed with the name of the microprocessor, for example stm32_,
  45. * and be prototyped in some header file in the arch/ directories.
  46. *
  47. * There is also a arch/<architecture>/include/<chip>/chip.h header file
  48. * that can be used to communicate other microprocessor-specific
  49. * information between the board logic and even application logic.
  50. * Application logic may, for example, need to know specific capabilities
  51. * of the chip. Prototypes in that chip.h header file should follow the
  52. * microprocessor specific naming convention.
  53. *
  54. * 3. Common Board Interfaces.
  55. *
  56. * Any interface that is common across all boards should be prefixed
  57. * with board_ and should be prototyped in the board.h header file.
  58. * These board_ definitions provide the interface between the board-level
  59. * logic and the architecture-specific logic.
  60. *
  61. * 4. Board-Specific Interfaces.
  62. *
  63. * Any interface that is unique to a board should be prefixed with
  64. * the board name, for example stm32f4discovery_. Sometimes the board
  65. * name is too long so stm32_ would be okay too. These should be
  66. * prototyped in boards/<arch>/<chip><board>/src/<board>.h and should
  67. * not be used outside of that board directory since board-specific
  68. * definitions have no meaning outside of the board directory.
  69. */
  70. /****************************************************************************
  71. * Included Files
  72. ****************************************************************************/
  73. #include <nuttx/config.h>
  74. #include <stdint.h>
  75. #include <stdbool.h>
  76. #include <sched.h>
  77. #include <arch/arch.h>
  78. #include <nuttx/compiler.h>
  79. #include <nuttx/cache.h>
  80. /****************************************************************************
  81. * Pre-processor definitions
  82. ****************************************************************************/
  83. /****************************************************************************
  84. * Public Types
  85. ****************************************************************************/
  86. typedef CODE void (*sig_deliver_t)(FAR struct tcb_s *tcb);
  87. typedef CODE void (*phy_enable_t)(bool enable);
  88. /****************************************************************************
  89. * Public Data
  90. ****************************************************************************/
  91. #undef EXTERN
  92. #if defined(__cplusplus)
  93. #define EXTERN extern "C"
  94. extern "C"
  95. {
  96. #else
  97. #define EXTERN extern
  98. #endif
  99. #ifdef CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP
  100. /* By default, the RTOS tickless logic assumes that the range of times that
  101. * can be represented by the underlying hardware timer is so large that no
  102. * special precautions need to be taken. That is not always the case. If
  103. * there is a limit to the maximum timing interval that can be represented by
  104. * the timer, then that limit must be respected.
  105. *
  106. * If CONFIG_SCHED_TICKLESS_LIMIT_MAX_SLEEP is defined, then use a 32-bit
  107. * global variable called g_oneshot_maxticks variable is enabled. This
  108. * variable is initialized by platform-specific logic at runtime to the
  109. * maximum delay that the timer can wait (in configured clock ticks).
  110. * The RTOS tickless logic will then limit all requested delays to this
  111. * value (in ticks).
  112. */
  113. EXTERN uint32_t g_oneshot_maxticks;
  114. #endif
  115. #ifdef CONFIG_RTC
  116. /* Variable determines the state of the RTC module.
  117. *
  118. * After initialization value is set to 'true' if RTC starts successfully.
  119. * The value can be changed to false also during operation if RTC for
  120. * some reason fails.
  121. */
  122. EXTERN volatile bool g_rtc_enabled;
  123. #endif
  124. #ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
  125. /* This is the interrupt vector mapping table. This must be provided by
  126. * architecture specific logic if CONFIG_ARCH_MINIMAL_VECTORTABLE is define
  127. * in the configuration. See declaration in include/nuttx/irq.h
  128. */
  129. /* EXTERN const irq_mapped_t g_irqmap[NR_IRQS]; */
  130. #endif
  131. /****************************************************************************
  132. * Public Function Prototypes
  133. ****************************************************************************/
  134. /****************************************************************************
  135. * These are standard interfaces that must be exported to the base RTOS
  136. * logic from architecture-specific code.
  137. ****************************************************************************/
  138. /****************************************************************************
  139. * Name: up_initialize
  140. *
  141. * Description:
  142. * up_initialize will be called once during OS initialization after the
  143. * basic OS services have been initialized. The architecture specific
  144. * details of initializing the OS will be handled here. Such things as
  145. * setting up interrupt service routines, starting the clock, and
  146. * registering device drivers are some of the things that are different
  147. * for each processor and hardware platform.
  148. *
  149. * up_initialize is called after the OS initialized but before the initial
  150. * application has been started and before the libraries have been
  151. * initialized. OS services and driver services are available.
  152. *
  153. ****************************************************************************/
  154. void up_initialize(void);
  155. /****************************************************************************
  156. * Name: up_systemreset
  157. *
  158. * Description:
  159. * The function up_systemreset() will reset the MCU. Optional!
  160. * Availability of this function is dependent upon the architecture
  161. * support.
  162. *
  163. ****************************************************************************/
  164. void up_systemreset(void) noreturn_function;
  165. /****************************************************************************
  166. * Name: up_idle
  167. *
  168. * Description:
  169. * up_idle() is the logic that will be executed when there is no other
  170. * ready-to-run task. This is processor idle time and will continue until
  171. * some interrupt occurs to cause a context switch from the idle task.
  172. *
  173. * Processing in this state may be processor-specific. e.g.,
  174. * this is where power management operations might be performed.
  175. *
  176. ****************************************************************************/
  177. void up_idle(void);
  178. /****************************************************************************
  179. * Name: up_initial_state
  180. *
  181. * Description:
  182. * A new thread is being started and a new TCB has been created.
  183. * This function is called to initialize the processor specific portions
  184. * of the new TCB.
  185. *
  186. * This function must setup the initial architecture registers and/or
  187. * stack so that execution will begin at tcb->start on the next context
  188. * switch.
  189. *
  190. ****************************************************************************/
  191. void up_initial_state(FAR struct tcb_s *tcb);
  192. /****************************************************************************
  193. * Name: up_create_stack
  194. *
  195. * Description:
  196. * Allocate a stack for a new thread and setup up stack-related information
  197. * in the TCB.
  198. *
  199. * The following TCB fields must be initialized by this function:
  200. *
  201. * - adj_stack_size: Stack size after adjustment for hardware, processor,
  202. * etc. This value is retained only for debug purposes.
  203. * - stack_alloc_ptr: Pointer to allocated stack
  204. * - adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
  205. * the stack pointer.
  206. *
  207. * Input Parameters:
  208. * - tcb: The TCB of new task
  209. * - stack_size: The requested stack size. At least this much
  210. * must be allocated.
  211. * - ttype: The thread type. This may be one of following (defined in
  212. * include/nuttx/sched.h):
  213. *
  214. * TCB_FLAG_TTYPE_TASK Normal user task
  215. * TCB_FLAG_TTYPE_PTHREAD User pthread
  216. * TCB_FLAG_TTYPE_KERNEL Kernel thread
  217. *
  218. * This thread type is normally available in the flags field of the TCB,
  219. * however, there are certain contexts where the TCB may not be fully
  220. * initialized when up_create_stack is called.
  221. *
  222. * If CONFIG_BUILD_PROTECTED or CONFIG_BUILD_KERNEL are is defined, then
  223. * this thread type may affect how the stack is allocated. For example,
  224. * kernel thread stacks should be allocated from protected kernel memory.
  225. * Stacks for user tasks and threads must come from memory that is
  226. * accessible to user code.
  227. *
  228. ****************************************************************************/
  229. int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype);
  230. /****************************************************************************
  231. * Name: up_use_stack
  232. *
  233. * Description:
  234. * Setup stack-related information in the TCB using pre-allocated stack
  235. * memory. This function is called only from nxtask_init() when a task or
  236. * kernel thread is started (never for pthreads).
  237. *
  238. * The following TCB fields must be initialized:
  239. *
  240. * - adj_stack_size: Stack size after adjustment for hardware,
  241. * processor, etc. This value is retained only for debug
  242. * purposes.
  243. * - stack_alloc_ptr: Pointer to allocated stack
  244. * - adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The
  245. * initial value of the stack pointer.
  246. *
  247. * Input Parameters:
  248. * - tcb: The TCB of new task
  249. * - stack: The new stack to be used.
  250. * - stack_size: The allocated stack size.
  251. *
  252. * NOTE: Unlike up_stack_create() and up_stack_release, this function
  253. * does not require the task type (ttype) parameter. The TCB flags will
  254. * always be set to provide the task type to up_use_stack() if it needs
  255. * that information.
  256. *
  257. ****************************************************************************/
  258. int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size);
  259. /****************************************************************************
  260. * Name: up_stack_frame
  261. *
  262. * Description:
  263. * Allocate a stack frame in the TCB's stack to hold thread-specific data.
  264. * This function may be called any time after up_create_stack() or
  265. * up_use_stack() have been called but before the task has been started.
  266. *
  267. * Thread data may be kept in the stack (instead of in the TCB) if it is
  268. * accessed by the user code directly. This includes such things as
  269. * argv[]. The stack memory is guaranteed to be in the same protection
  270. * domain as the thread.
  271. *
  272. * The following TCB fields will be re-initialized:
  273. *
  274. * - adj_stack_size: Stack size after removal of the stack frame from
  275. * the stack
  276. * - adj_stack_ptr: Adjusted initial stack pointer after the frame has
  277. * been removed from the stack. This will still be the initial value
  278. * of the stack pointer when the task is started.
  279. *
  280. * Input Parameters:
  281. * - tcb: The TCB of new task
  282. * - frame_size: The size of the stack frame to allocate.
  283. *
  284. * Returned Value:
  285. * - A pointer to bottom of the allocated stack frame. NULL will be
  286. * returned on any failures. The alignment of the returned value is
  287. * the same as the alignment of the stack itself.
  288. *
  289. ****************************************************************************/
  290. FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size);
  291. /****************************************************************************
  292. * Name: up_release_stack
  293. *
  294. * Description:
  295. * A task has been stopped. Free all stack related resources retained in
  296. * the defunct TCB.
  297. *
  298. * Input Parameters:
  299. * - dtcb: The TCB containing information about the stack to be released
  300. * - ttype: The thread type. This may be one of following (defined in
  301. * include/nuttx/sched.h):
  302. *
  303. * TCB_FLAG_TTYPE_TASK Normal user task
  304. * TCB_FLAG_TTYPE_PTHREAD User pthread
  305. * TCB_FLAG_TTYPE_KERNEL Kernel thread
  306. *
  307. * This thread type is normally available in the flags field of the TCB,
  308. * however, there are certain error recovery contexts where the TCB may
  309. * not be fully initialized when up_release_stack is called.
  310. *
  311. * If CONFIG_BUILD_PROTECTED or CONFIG_BUILD_KERNEL are defined, then
  312. * this thread type may affect how the stack is freed. For example,
  313. * kernel thread stacks may have been allocated from protected kernel
  314. * memory. Stacks for user tasks and threads must have come from memory
  315. * that is accessible to user code.
  316. *
  317. * Returned Value:
  318. * None
  319. *
  320. ****************************************************************************/
  321. void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype);
  322. /****************************************************************************
  323. * Name: up_unblock_task
  324. *
  325. * Description:
  326. * A task is currently in an inactive task list
  327. * but has been prepped to execute. Move the TCB to the
  328. * ready-to-run list, restore its context, and start execution.
  329. *
  330. * This function is called only from the NuttX scheduling
  331. * logic. Interrupts will always be disabled when this
  332. * function is called.
  333. *
  334. * Input Parameters:
  335. * tcb: Refers to the tcb to be unblocked. This tcb is
  336. * in one of the waiting tasks lists. It must be moved to
  337. * the ready-to-run list and, if it is the highest priority
  338. * ready to run task, executed.
  339. *
  340. ****************************************************************************/
  341. void up_unblock_task(FAR struct tcb_s *tcb);
  342. /****************************************************************************
  343. * Name: up_block_task
  344. *
  345. * Description:
  346. * The currently executing task at the head of the ready to run list must
  347. * be stopped. Save its context and move it to the inactive list
  348. * specified by task_state.
  349. *
  350. * This function is called only from the NuttX scheduling logic.
  351. * Interrupts will always be disabled when this function is called.
  352. *
  353. * Input Parameters:
  354. * tcb: Refers to a task in the ready-to-run list (normally the task at
  355. * the head of the list). It must be stopped, its context saved and
  356. * moved into one of the waiting task lists. If it was the task at the
  357. * head of the ready-to-run list, then a context switch to the new ready
  358. * to run task must be performed.
  359. * task_state: Specifies which waiting task list should be
  360. * hold the blocked task TCB.
  361. *
  362. ****************************************************************************/
  363. void up_block_task(FAR struct tcb_s *tcb, tstate_t task_state);
  364. /****************************************************************************
  365. * Name: up_release_pending
  366. *
  367. * Description:
  368. * When tasks become ready-to-run but cannot run because
  369. * pre-emption is disabled, they are placed into a pending
  370. * task list. This function releases and makes ready-to-run
  371. * all of the tasks that have collected in the pending task
  372. * list. This can cause a context switch if a new task is
  373. * placed at the head of the ready to run list.
  374. *
  375. * This function is called only from the NuttX scheduling
  376. * logic when pre-emptioni is re-enabled. Interrupts will
  377. * always be disabled when this function is called.
  378. *
  379. ****************************************************************************/
  380. void up_release_pending(void);
  381. /****************************************************************************
  382. * Name: up_reprioritize_rtr
  383. *
  384. * Description:
  385. * Called when the priority of a running or
  386. * ready-to-run task changes and the reprioritization will
  387. * cause a context switch. Two cases:
  388. *
  389. * 1) The priority of the currently running task drops and the next
  390. * task in the ready to run list has priority.
  391. * 2) An idle, ready to run task's priority has been raised above the
  392. * the priority of the current, running task and it now has the
  393. * priority.
  394. *
  395. * This function is called only from the NuttX scheduling
  396. * logic. Interrupts will always be disabled when this
  397. * function is called.
  398. *
  399. * Input Parameters:
  400. * tcb: The TCB of the task that has been reprioritized
  401. * priority: The new task priority
  402. *
  403. ****************************************************************************/
  404. void up_reprioritize_rtr(FAR struct tcb_s *tcb, uint8_t priority);
  405. /****************************************************************************
  406. * Name: up_exit
  407. *
  408. * Description:
  409. * This function causes the currently executing task to cease
  410. * to exist. This is a special case of task_delete() where the task to
  411. * be deleted is the currently executing task. It is more complex because
  412. * a context switch must be perform to the next ready to run task.
  413. *
  414. * Unlike other UP APIs, this function may be called directly from user
  415. * programs in various states. The implementation of this function should
  416. * disable interrupts before performing scheduling operations.
  417. *
  418. ****************************************************************************/
  419. void up_exit() noreturn_function;
  420. /* Prototype is in unistd.h */
  421. /****************************************************************************
  422. * Name: up_assert
  423. *
  424. * Description:
  425. * Assertions may be handled in an architecture-specific way.
  426. *
  427. ****************************************************************************/
  428. void up_assert(FAR const char *filename, int linenum);
  429. /****************************************************************************
  430. * Name: up_schedule_sigaction
  431. *
  432. * Description:
  433. * This function is called by the OS when one or more
  434. * signal handling actions have been queued for execution.
  435. * The architecture specific code must configure things so
  436. * that the 'igdeliver' callback is executed on the thread
  437. * specified by 'tcb' as soon as possible.
  438. *
  439. * This function may be called from interrupt handling logic.
  440. *
  441. * This operation should not cause the task to be unblocked
  442. * nor should it cause any immediate execution of sigdeliver.
  443. * Typically, a few cases need to be considered:
  444. *
  445. * (1) This function may be called from an interrupt handler
  446. * During interrupt processing, all xcptcontext structures
  447. * should be valid for all tasks. That structure should
  448. * be modified to invoke sigdeliver() either on return
  449. * from (this) interrupt or on some subsequent context
  450. * switch to the recipient task.
  451. * (2) If not in an interrupt handler and the tcb is NOT
  452. * the currently executing task, then again just modify
  453. * the saved xcptcontext structure for the recipient
  454. * task so it will invoke sigdeliver when that task is
  455. * later resumed.
  456. * (3) If not in an interrupt handler and the tcb IS the
  457. * currently executing task -- just call the signal
  458. * handler now.
  459. *
  460. ****************************************************************************/
  461. void up_schedule_sigaction(FAR struct tcb_s *tcb, sig_deliver_t sigdeliver);
  462. /****************************************************************************
  463. * Name: up_task_start
  464. *
  465. * Description:
  466. * In this kernel mode build, this function will be called to execute a
  467. * task in user-space. When the task is first started, a kernel-mode
  468. * stub will first run to perform some housekeeping functions. This
  469. * kernel-mode stub will then be called transfer control to the user-mode
  470. * task by calling this function.
  471. *
  472. * Normally the a user-mode start-up stub will also execute before the
  473. * task actually starts. See libc/sched/task_startup.c
  474. *
  475. * Input Parameters:
  476. * taskentry - The user-space entry point of the task.
  477. * argc - The number of parameters being passed.
  478. * argv - The parameters being passed. These lie in kernel-space memory
  479. * and will have to be reallocated in user-space memory.
  480. *
  481. * Returned Value:
  482. * This function should not return. It should call the user-mode start-up
  483. * stub and that stub should call exit if/when the user task terminates.
  484. *
  485. ****************************************************************************/
  486. #if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
  487. void up_task_start(main_t taskentry, int argc, FAR char *argv[])
  488. noreturn_function;
  489. #endif
  490. /****************************************************************************
  491. * Name: up_pthread_start
  492. *
  493. * Description:
  494. * In this kernel mode build, this function will be called to execute a
  495. * pthread in user-space. When the pthread is first started, a kernel-mode
  496. * stub will first run to perform some housekeeping functions. This
  497. * kernel-mode stub will then be called transfer control to the user-mode
  498. * pthread by calling this function.
  499. *
  500. * Normally the a user-mode start-up stub will also execute before the
  501. * pthread actually starts. See libc/pthread/pthread_startup.c
  502. *
  503. * Input Parameters:
  504. * entrypt - The user-space address of the pthread entry point
  505. * arg - Standard argument for the pthread entry point
  506. *
  507. * Returned Value:
  508. * This function should not return. It should call the user-mode start-up
  509. * stub and that stub should call pthread_exit if/when the user pthread
  510. * terminates.
  511. *
  512. ****************************************************************************/
  513. #if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) && \
  514. !defined(CONFIG_DISABLE_PTHREAD)
  515. void up_pthread_start(pthread_startroutine_t entrypt, pthread_addr_t arg)
  516. noreturn_function;
  517. #endif
  518. /****************************************************************************
  519. * Name: up_signal_dispatch
  520. *
  521. * Description:
  522. * In this kernel mode build, this function will be called to execute a
  523. * a signal handler in user-space. When the signal is delivered, a
  524. * kernel-mode stub will first run to perform some housekeeping functions.
  525. * This kernel-mode stub will then be called transfer control to the user
  526. * mode signal handler by calling this function.
  527. *
  528. * Normally the a architecture, user-mode signal handling stub will also
  529. * execute before the ultimate signal handler is called. That stub
  530. * function is the user-space, signal handler trampoline function. It is
  531. * called from up_signal_dispatch() in user-mode.
  532. *
  533. * Input Parameters:
  534. * sighand - The address user-space signal handling function
  535. * signo, info, and ucontext - Standard arguments to be passed to the
  536. * signal handling function.
  537. *
  538. * Returned Value:
  539. * None. This function does not return in the normal sense. It returns
  540. * via an architecture specific system call made by up_signal_handler()
  541. * (see below). However, this will look like a normal return by the
  542. * caller of up_signal_dispatch.
  543. *
  544. ****************************************************************************/
  545. #if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__)
  546. void up_signal_dispatch(_sa_sigaction_t sighand, int signo,
  547. FAR siginfo_t *info, FAR void *ucontext);
  548. #endif
  549. /****************************************************************************
  550. * Name: up_signal_handler
  551. *
  552. * Description:
  553. * This function is the user-space, signal handler trampoline function that
  554. * must be provided by architecture-specific logic. It is called from
  555. * up_signal_dispatch() in user-mode.
  556. *
  557. * Input Parameters:
  558. * sighand - The address user-space signal handling function
  559. * signo, info, and ucontext - Standard arguments to be passed to the
  560. * signal handling function.
  561. *
  562. * Returned Value:
  563. * None. This function does not return in the normal sense. It returns
  564. * via an architecture specific system call.
  565. *
  566. ****************************************************************************/
  567. #if defined(CONFIG_BUILD_PROTECTED) && !defined(__KERNEL__)
  568. void up_signal_handler(_sa_sigaction_t sighand, int signo,
  569. FAR siginfo_t *info, FAR void *ucontext)
  570. noreturn_function;
  571. #endif
  572. /****************************************************************************
  573. * Name: up_allocate_heap
  574. *
  575. * Description:
  576. * This function will be called to dynamically set aside the heap region.
  577. *
  578. * For the kernel build (CONFIG_BUILD_PROTECTED=y) with both kernel- and
  579. * user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides the
  580. * size of the unprotected, user-space heap.
  581. *
  582. * If a protected kernel-space heap is provided, the kernel heap must be
  583. * allocated (and protected) by an analogous up_allocate_kheap().
  584. *
  585. ****************************************************************************/
  586. void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
  587. /****************************************************************************
  588. * Name: up_allocate_kheap
  589. *
  590. * Description:
  591. * For the kernel builds (CONFIG_BUILD_PROTECTED=y or
  592. * CONFIG_BUILD_KERNEL=y) there may be both kernel- and user-space heaps
  593. * as determined by CONFIG_MM_KERNEL_HEAP=y. This function allocates (and
  594. * protects) the kernel-space heap.
  595. *
  596. ****************************************************************************/
  597. #ifdef CONFIG_MM_KERNEL_HEAP
  598. void up_allocate_kheap(FAR void **heap_start, size_t *heap_size);
  599. #endif
  600. /****************************************************************************
  601. * Name: up_allocate_pgheap
  602. *
  603. * Description:
  604. * If there is a page allocator in the configuration, then this function
  605. * must be provided by the platform-specific code. The OS initialization
  606. * logic will call this function early in the initialization sequence to
  607. * get the page heap information needed to configure the page allocator.
  608. *
  609. ****************************************************************************/
  610. #ifdef CONFIG_MM_PGALLOC
  611. void up_allocate_pgheap(FAR void **heap_start, size_t *heap_size);
  612. #endif
  613. /****************************************************************************
  614. * Name: pgalloc
  615. *
  616. * Description:
  617. * If there is a page allocator in the configuration and if an MMU is
  618. * available to map physical addresses to virtual address, then this
  619. * function must be provided by the platform-specific code. This is part
  620. * of the implementation of sbrk(). This function will allocate the
  621. * requested number of pages using the page allocator and map them into
  622. * consecutive virtual addresses beginning with 'brkaddr'
  623. *
  624. * NOTE: This function does not use the up_ naming standard because it
  625. * is indirectly callable from user-space code via a system trap.
  626. * Therefore, it is a system interface and follows a different naming
  627. * convention.
  628. *
  629. * Input Parameters:
  630. * brkaddr - The heap break address. The next page will be allocated and
  631. * mapped to this address. Must be page aligned. If the memory manager
  632. * has not yet been initialized and this is the first block requested for
  633. * the heap, then brkaddr should be zero. pgalloc will then assigned the
  634. * well-known virtual address of the beginning of the heap.
  635. * npages - The number of pages to allocate and map. Mapping of pages
  636. * will be contiguous beginning beginning at 'brkaddr'
  637. *
  638. * Returned Value:
  639. * The (virtual) base address of the mapped page will be returned on
  640. * success.
  641. * Normally this will be the same as the 'brkaddr' input. However, if
  642. * the 'brkaddr' input was zero, this will be the virtual address of the
  643. * beginning of the heap. Zero is returned on any failure.
  644. *
  645. ****************************************************************************/
  646. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_MM_PGALLOC) && \
  647. defined(CONFIG_ARCH_USE_MMU)
  648. uintptr_t pgalloc(uintptr_t brkaddr, unsigned int npages);
  649. #endif
  650. /****************************************************************************
  651. * Name: up_module_text_init
  652. *
  653. * Description:
  654. * Initialize the module text allocator
  655. *
  656. ****************************************************************************/
  657. #if defined(CONFIG_ARCH_USE_MODULE_TEXT)
  658. void up_module_text_init(void);
  659. #endif
  660. /****************************************************************************
  661. * Name: up_module_text_alloc
  662. *
  663. * Description:
  664. * Allocate memory for module text.
  665. *
  666. ****************************************************************************/
  667. #if defined(CONFIG_ARCH_USE_MODULE_TEXT)
  668. FAR void *up_module_text_alloc(size_t size);
  669. #endif
  670. /****************************************************************************
  671. * Name: up_module_text_free
  672. *
  673. * Description:
  674. * Free memory for module text.
  675. *
  676. ****************************************************************************/
  677. #if defined(CONFIG_ARCH_USE_MODULE_TEXT)
  678. void up_module_text_free(FAR void *p);
  679. #endif
  680. /****************************************************************************
  681. * Name: up_setpicbase and up_getpicbase
  682. *
  683. * Description:
  684. * It NXFLAT external modules (or any other binary format that requires
  685. * PIC) are supported, then these macros must defined to (1) set or get
  686. * the PIC base register value. These must be implemented with in-line
  687. * assembly.
  688. *
  689. ****************************************************************************/
  690. #ifndef CONFIG_PIC
  691. # define up_setpicbase(picbase)
  692. # define up_getpicbase(ppicbase)
  693. #endif
  694. /****************************************************************************
  695. * Address Environment Interfaces
  696. *
  697. * Low-level interfaces used in binfmt/ to instantiate tasks with address
  698. * environments. These interfaces all operate on type group_addrenv_t which
  699. * is an abstract representation of a task group's address environment and
  700. * must be defined in arch/arch.h if CONFIG_ARCH_ADDRENV is defined.
  701. *
  702. * up_addrenv_create - Create an address environment
  703. * up_addrenv_destroy - Destroy an address environment.
  704. * up_addrenv_vtext - Returns the virtual base address of the .text
  705. * address environment
  706. * up_addrenv_vdata - Returns the virtual base address of the .bss/.data
  707. * address environment
  708. * up_addrenv_heapsize - Returns the size of the initial heap allocation.
  709. * up_addrenv_select - Instantiate an address environment
  710. * up_addrenv_restore - Restore an address environment
  711. * up_addrenv_clone - Copy an address environment from one location to
  712. * another.
  713. *
  714. * Higher-level interfaces used by the tasking logic. These interfaces are
  715. * used by the functions in sched/ and all operate on the thread which whose
  716. * group been assigned an address environment by up_addrenv_clone().
  717. *
  718. * up_addrenv_attach - Clone the address environment assigned to one TCB
  719. * to another. This operation is done when a pthread
  720. * is created that share's the same address
  721. * environment.
  722. * up_addrenv_detach - Release the threads reference to an address
  723. * environment when a task/thread exits.
  724. *
  725. * CONFIG_ARCH_STACK_DYNAMIC=y indicates that the user process stack resides
  726. * in its own address space. This options is also *required* if
  727. * CONFIG_BUILD_KERNEL and CONFIG_LIBC_EXECFUNCS are selected. Why?
  728. * Because the caller's stack must be preserved in its own address space
  729. * when we instantiate the environment of the new process in order to
  730. * initialize it.
  731. *
  732. * NOTE: The naming of the CONFIG_ARCH_STACK_DYNAMIC selection implies that
  733. * dynamic stack allocation is supported. Certainly this option must be set
  734. * if dynamic stack allocation is supported by a platform. But the more
  735. * general meaning of this configuration environment is simply that the
  736. * stack has its own address space.
  737. *
  738. * If CONFIG_ARCH_STACK_DYNAMIC=y is selected then the platform specific
  739. * code must export these additional interfaces:
  740. *
  741. * up_addrenv_ustackalloc - Create a stack address environment
  742. * up_addrenv_ustackfree - Destroy a stack address environment.
  743. * up_addrenv_vustack - Returns the virtual base address of the stack
  744. * up_addrenv_ustackselect - Instantiate a stack address environment
  745. *
  746. * If CONFIG_ARCH_KERNEL_STACK is selected, then each user process will have
  747. * two stacks: (1) a large (and possibly dynamic) user stack and (2) a
  748. * smaller kernel stack. However, this option is *required* if both
  749. * CONFIG_BUILD_KERNEL and CONFIG_LIBC_EXECFUNCS are selected. Why? Because
  750. * when we instantiate and initialize the address environment of the new
  751. * user process, we will temporarily lose the address environment of the old
  752. * user process, including its stack contents. The kernel C logic will crash
  753. * immediately with no valid stack in place.
  754. *
  755. * If CONFIG_ARCH_KERNEL_STACK=y is selected then the platform specific
  756. * code must export these additional interfaces:
  757. *
  758. * up_addrenv_kstackalloc - Create a stack in the kernel address
  759. * environment
  760. * up_addrenv_kstackfree - Destroy the kernel stack.
  761. *
  762. ****************************************************************************/
  763. /****************************************************************************
  764. * Name: up_addrenv_create
  765. *
  766. * Description:
  767. * This function is called when a new task is created in order to
  768. * instantiate an address environment for the new task group.
  769. * up_addrenv_create() is essentially the allocator of the physical
  770. * memory for the new task.
  771. *
  772. * Input Parameters:
  773. * textsize - The size (in bytes) of the .text address environment needed
  774. * by the task. This region may be read/execute only.
  775. * datasize - The size (in bytes) of the .data/.bss address environment
  776. * needed by the task. This region may be read/write only. NOTE: The
  777. * actual size of the data region that is allocated will include a
  778. * OS private reserved region at the beginning. The size of the
  779. * private, reserved region is give by ARCH_DATA_RESERVE_SIZE.
  780. * heapsize - The initial size (in bytes) of the heap address environment
  781. * needed by the task. This region may be read/write only.
  782. * addrenv - The location to return the representation of the task address
  783. * environment.
  784. *
  785. * Returned Value:
  786. * Zero (OK) on success; a negated errno value on failure.
  787. *
  788. ****************************************************************************/
  789. #ifdef CONFIG_ARCH_ADDRENV
  790. int up_addrenv_create(size_t textsize, size_t datasize, size_t heapsize,
  791. FAR group_addrenv_t *addrenv);
  792. #endif
  793. /****************************************************************************
  794. * Name: up_addrenv_destroy
  795. *
  796. * Description:
  797. * This function is called when a final thread leaves the task group and
  798. * the task group is destroyed. This function then destroys the defunct
  799. * address environment, releasing the underlying physical memory.
  800. *
  801. * Input Parameters:
  802. * addrenv - The address environment to be destroyed.
  803. *
  804. * Returned Value:
  805. * Zero (OK) on success; a negated errno value on failure.
  806. *
  807. ****************************************************************************/
  808. #ifdef CONFIG_ARCH_ADDRENV
  809. int up_addrenv_destroy(FAR group_addrenv_t *addrenv);
  810. #endif
  811. /****************************************************************************
  812. * Name: up_addrenv_vtext
  813. *
  814. * Description:
  815. * Return the virtual address associated with the newly create .text
  816. * address environment. This function is used by the binary loaders in
  817. * order get an address that can be used to initialize the new task.
  818. *
  819. * Input Parameters:
  820. * addrenv - The representation of the task address environment previously
  821. * returned by up_addrenv_create.
  822. * vtext - The location to return the virtual address.
  823. *
  824. * Returned Value:
  825. * Zero (OK) on success; a negated errno value on failure.
  826. *
  827. ****************************************************************************/
  828. #ifdef CONFIG_ARCH_ADDRENV
  829. int up_addrenv_vtext(FAR group_addrenv_t *addrenv, FAR void **vtext);
  830. #endif
  831. /****************************************************************************
  832. * Name: up_addrenv_vdata
  833. *
  834. * Description:
  835. * Return the virtual address associated with the newly create .text
  836. * address environment. This function is used by the binary loaders in
  837. * order get an address that can be used to initialize the new task.
  838. *
  839. * Input Parameters:
  840. * addrenv - The representation of the task address environment previously
  841. * returned by up_addrenv_create.
  842. * textsize - For some implementations, the text and data will be saved
  843. * in the same memory region (read/write/execute) and, in this case,
  844. * the virtual address of the data just lies at this offset into the
  845. * common region.
  846. * vdata - The location to return the virtual address. NOTE that the
  847. * beginning of the data region is reserved for use by the OS. The
  848. * returned address will be at a offset from the actual allocated base
  849. * address to account for the OS private region. The size of that
  850. * offset is given by ARCH_DATA_RESERVE_SIZE
  851. *
  852. * Returned Value:
  853. * Zero (OK) on success; a negated errno value on failure.
  854. *
  855. ****************************************************************************/
  856. #ifdef CONFIG_ARCH_ADDRENV
  857. int up_addrenv_vdata(FAR group_addrenv_t *addrenv, uintptr_t textsize,
  858. FAR void **vdata);
  859. #endif
  860. /****************************************************************************
  861. * Name: up_addrenv_heapsize
  862. *
  863. * Description:
  864. * Return the initial heap allocation size. That is the amount of memory
  865. * allocated by up_addrenv_create() when the heap memory region was first
  866. * created. This may or may not differ from the heapsize parameter that
  867. * was passed to up_addrenv_create()
  868. *
  869. * Input Parameters:
  870. * addrenv - The representation of the task address environment previously
  871. * returned by up_addrenv_create.
  872. *
  873. * Returned Value:
  874. * The initial heap size allocated is returned on success; a negated
  875. * errno value on failure.
  876. *
  877. ****************************************************************************/
  878. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
  879. ssize_t up_addrenv_heapsize(FAR const group_addrenv_t *addrenv);
  880. #endif
  881. /****************************************************************************
  882. * Name: up_addrenv_select
  883. *
  884. * Description:
  885. * After an address environment has been established for a task group (via
  886. * up_addrenv_create(). This function may be called to instantiate
  887. * that address environment in the virtual address space. This might be
  888. * necessary, for example, to load the code for the task group from a file
  889. * or to access address environment private data.
  890. *
  891. * Input Parameters:
  892. * addrenv - The representation of the task address environment previously
  893. * returned by up_addrenv_create.
  894. * oldenv
  895. * The address environment that was in place before up_addrenv_select().
  896. * This may be used with up_addrenv_restore() to restore the original
  897. * address environment that was in place before up_addrenv_select() was
  898. * called. Note that this may be a task agnostic, platform-specific
  899. * representation that may or may not be different from group_addrenv_t.
  900. *
  901. * Returned Value:
  902. * Zero (OK) on success; a negated errno value on failure.
  903. *
  904. ****************************************************************************/
  905. #ifdef CONFIG_ARCH_ADDRENV
  906. int up_addrenv_select(FAR const group_addrenv_t *addrenv,
  907. FAR save_addrenv_t *oldenv);
  908. #endif
  909. /****************************************************************************
  910. * Name: up_addrenv_restore
  911. *
  912. * Description:
  913. * After an address environment has been temporarily instantiated by
  914. * up_addrenv_select(), this function may be called to restore the
  915. * original address environment.
  916. *
  917. * Input Parameters:
  918. * oldenv - The platform-specific representation of the address environment
  919. * previously returned by up_addrenv_select.
  920. *
  921. * Returned Value:
  922. * Zero (OK) on success; a negated errno value on failure.
  923. *
  924. ****************************************************************************/
  925. #ifdef CONFIG_ARCH_ADDRENV
  926. int up_addrenv_restore(FAR const save_addrenv_t *oldenv);
  927. #endif
  928. /****************************************************************************
  929. * Name: up_addrenv_coherent
  930. *
  931. * Description:
  932. * Flush D-Cache and invalidate I-Cache in preparation for a change in
  933. * address environments. This should immediately precede a call to
  934. * up_addrenv_select();
  935. *
  936. * Input Parameters:
  937. * addrenv - Describes the address environment to be made coherent.
  938. *
  939. * Returned Value:
  940. * Zero (OK) on success; a negated errno value on failure.
  941. *
  942. ****************************************************************************/
  943. #ifdef CONFIG_ARCH_ADDRENV
  944. int up_addrenv_coherent(FAR const group_addrenv_t *addrenv);
  945. #endif
  946. /****************************************************************************
  947. * Name: up_addrenv_clone
  948. *
  949. * Description:
  950. * Duplicate an address environment. This does not copy the underlying
  951. * memory, only the representation that can be used to instantiate that
  952. * memory as an address environment.
  953. *
  954. * Input Parameters:
  955. * src - The address environment to be copied.
  956. * dest - The location to receive the copied address environment.
  957. *
  958. * Returned Value:
  959. * Zero (OK) on success; a negated errno value on failure.
  960. *
  961. ****************************************************************************/
  962. #ifdef CONFIG_ARCH_ADDRENV
  963. int up_addrenv_clone(FAR const group_addrenv_t *src,
  964. FAR group_addrenv_t *dest);
  965. #endif
  966. /****************************************************************************
  967. * Name: up_addrenv_attach
  968. *
  969. * Description:
  970. * This function is called from the core scheduler logic when a thread
  971. * is created that needs to share the address environment of its task
  972. * group.
  973. *
  974. * NOTE: In some platforms, nothing will need to be done in this case.
  975. * Simply being a member of the group that has the address environment
  976. * may be sufficient.
  977. *
  978. * Input Parameters:
  979. * group - The task group to which the new thread belongs.
  980. * tcb - The TCB of the thread needing the address environment.
  981. *
  982. * Returned Value:
  983. * Zero (OK) on success; a negated errno value on failure.
  984. *
  985. ****************************************************************************/
  986. #ifdef CONFIG_ARCH_ADDRENV
  987. int up_addrenv_attach(FAR struct task_group_s *group, FAR struct tcb_s *tcb);
  988. #endif
  989. /****************************************************************************
  990. * Name: up_addrenv_detach
  991. *
  992. * Description:
  993. * This function is called when a task or thread exits in order to release
  994. * its reference to an address environment. The address environment,
  995. * however, should persist until up_addrenv_destroy() is called when the
  996. * task group is itself destroyed. Any resources unique to this thread
  997. * may be destroyed now.
  998. *
  999. * NOTE: In some platforms, nothing will need to be done in this case.
  1000. * Simply being a member of the group that has the address environment
  1001. * may be sufficient.
  1002. *
  1003. * Input Parameters:
  1004. * group - The group to which the thread belonged.
  1005. * tcb - The TCB of the task or thread whose the address environment will
  1006. * be released.
  1007. *
  1008. * Returned Value:
  1009. * Zero (OK) on success; a negated errno value on failure.
  1010. *
  1011. ****************************************************************************/
  1012. #ifdef CONFIG_ARCH_ADDRENV
  1013. int up_addrenv_detach(FAR struct task_group_s *group, FAR struct tcb_s *tcb);
  1014. #endif
  1015. /****************************************************************************
  1016. * Name: up_addrenv_ustackalloc
  1017. *
  1018. * Description:
  1019. * This function is called when a new thread is created in order to
  1020. * instantiate an address environment for the new thread's stack.
  1021. * up_addrenv_ustackalloc() is essentially the allocator of the physical
  1022. * memory for the new task's stack.
  1023. *
  1024. * Input Parameters:
  1025. * tcb - The TCB of the thread that requires the stack address environment.
  1026. * stacksize - The size (in bytes) of the initial stack address
  1027. * environment needed by the task. This region may be read/write only.
  1028. *
  1029. * Returned Value:
  1030. * Zero (OK) on success; a negated errno value on failure.
  1031. *
  1032. ****************************************************************************/
  1033. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_STACK_DYNAMIC)
  1034. int up_addrenv_ustackalloc(FAR struct tcb_s *tcb, size_t stacksize);
  1035. #endif
  1036. /****************************************************************************
  1037. * Name: up_addrenv_ustackfree
  1038. *
  1039. * Description:
  1040. * This function is called when any thread exits. This function then
  1041. * destroys the defunct address environment for the thread's stack,
  1042. * releasing the underlying physical memory.
  1043. *
  1044. * Input Parameters:
  1045. * tcb - The TCB of the thread that no longer requires the stack address
  1046. * environment.
  1047. *
  1048. * Returned Value:
  1049. * Zero (OK) on success; a negated errno value on failure.
  1050. *
  1051. ****************************************************************************/
  1052. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_STACK_DYNAMIC)
  1053. int up_addrenv_ustackfree(FAR struct tcb_s *tcb);
  1054. #endif
  1055. /****************************************************************************
  1056. * Name: up_addrenv_vustack
  1057. *
  1058. * Description:
  1059. * Return the virtual address associated with the newly create stack
  1060. * address environment.
  1061. *
  1062. * Input Parameters:
  1063. * tcb - The TCB of the thread with the stack address environment of
  1064. * interest.
  1065. * vstack - The location to return the stack virtual base address.
  1066. *
  1067. * Returned Value:
  1068. * Zero (OK) on success; a negated errno value on failure.
  1069. *
  1070. ****************************************************************************/
  1071. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_STACK_DYNAMIC)
  1072. int up_addrenv_vustack(FAR const struct tcb_s *tcb, FAR void **vstack);
  1073. #endif
  1074. /****************************************************************************
  1075. * Name: up_addrenv_ustackselect
  1076. *
  1077. * Description:
  1078. * After an address environment has been established for a task's stack
  1079. * (via up_addrenv_ustackalloc(). This function may be called to
  1080. * instantiate that address environment in the virtual address space.
  1081. * This is a necessary step before each context switch to the newly created
  1082. * thread (including the initial thread startup).
  1083. *
  1084. * Input Parameters:
  1085. * tcb - The TCB of the thread with the stack address environment to be
  1086. * instantiated.
  1087. *
  1088. * Returned Value:
  1089. * Zero (OK) on success; a negated errno value on failure.
  1090. *
  1091. ****************************************************************************/
  1092. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_STACK_DYNAMIC)
  1093. int up_addrenv_ustackselect(FAR const struct tcb_s *tcb);
  1094. #endif
  1095. /****************************************************************************
  1096. * Name: up_addrenv_kstackalloc
  1097. *
  1098. * Description:
  1099. * This function is called when a new thread is created to allocate
  1100. * the new thread's kernel stack. This function may be called for certain
  1101. * terminating threads which have no kernel stack. It must be tolerant of
  1102. * that case.
  1103. *
  1104. * Input Parameters:
  1105. * tcb - The TCB of the thread that requires the kernel stack.
  1106. * stacksize - The size (in bytes) of the kernel stack needed by the
  1107. * thread.
  1108. *
  1109. * Returned Value:
  1110. * Zero (OK) on success; a negated errno value on failure.
  1111. *
  1112. ****************************************************************************/
  1113. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK)
  1114. int up_addrenv_kstackalloc(FAR struct tcb_s *tcb);
  1115. #endif
  1116. /****************************************************************************
  1117. * Name: up_addrenv_kstackfree
  1118. *
  1119. * Description:
  1120. * This function is called when any thread exits. This function frees
  1121. * the kernel stack.
  1122. *
  1123. * Input Parameters:
  1124. * tcb - The TCB of the thread that no longer requires the kernel stack.
  1125. *
  1126. * Returned Value:
  1127. * Zero (OK) on success; a negated errno value on failure.
  1128. *
  1129. ****************************************************************************/
  1130. #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK)
  1131. int up_addrenv_kstackfree(FAR struct tcb_s *tcb);
  1132. #endif
  1133. /****************************************************************************
  1134. * Name: up_addrenv_pa_to_va
  1135. *
  1136. * Description:
  1137. * Map phy address to virtual address. Not supported by all architectures.
  1138. *
  1139. * REVISIT: Should this not then be conditional on having that
  1140. * architecture-specific support?
  1141. *
  1142. * Input Parameters:
  1143. * pa - The phy address to be mapped.
  1144. *
  1145. * Returned Value:
  1146. * Virtual address on success; NULL on failure.
  1147. *
  1148. ****************************************************************************/
  1149. FAR void *up_addrenv_pa_to_va(uintptr_t pa);
  1150. /****************************************************************************
  1151. * Name: up_addrenv_va_to_pa
  1152. *
  1153. * Description:
  1154. * Map virtual address to phy address. Not supported by all architectures.
  1155. *
  1156. * REVISIT: Should this not then be conditional on having that
  1157. * architecture-specific support?
  1158. *
  1159. * Input Parameters:
  1160. * va - The virtual address to be mapped. Not supported by all
  1161. * architectures.
  1162. *
  1163. * Returned Value:
  1164. * Phy address on success; NULL on failure.
  1165. *
  1166. ****************************************************************************/
  1167. uintptr_t up_addrenv_va_to_pa(FAR void *va);
  1168. /****************************************************************************
  1169. * Name: up_shmat
  1170. *
  1171. * Description:
  1172. * Attach, i.e, map, on shared memory region to a user virtual address
  1173. *
  1174. * Input Parameters:
  1175. * pages - A pointer to the first element in a array of physical address,
  1176. * each corresponding to one page of memory.
  1177. * npages - The number of pages in the list of physical pages to be mapped.
  1178. * vaddr - The virtual address corresponding to the beginning of the
  1179. * (contiguous) virtual address region.
  1180. *
  1181. * Returned Value:
  1182. * Zero (OK) is returned on success; a negated errno value is returned
  1183. * on failure.
  1184. *
  1185. ****************************************************************************/
  1186. #ifdef CONFIG_MM_SHM
  1187. int up_shmat(FAR uintptr_t *pages, unsigned int npages, uintptr_t vaddr);
  1188. #endif
  1189. /****************************************************************************
  1190. * Name: up_shmdt
  1191. *
  1192. * Description:
  1193. * Detach, i.e, unmap, on shared memory region from a user virtual address
  1194. *
  1195. * Input Parameters:
  1196. * vaddr - The virtual address corresponding to the beginning of the
  1197. * (contiguous) virtual address region.
  1198. * npages - The number of pages to be unmapped
  1199. *
  1200. * Returned Value:
  1201. * Zero (OK) is returned on success; a negated errno value is returned
  1202. * on failure.
  1203. *
  1204. ****************************************************************************/
  1205. #ifdef CONFIG_MM_SHM
  1206. int up_shmdt(uintptr_t vaddr, unsigned int npages);
  1207. #endif
  1208. /****************************************************************************
  1209. * Interfaces required for ELF module support
  1210. *
  1211. * up_checkarch - Perform architecture-specific ELF check
  1212. * up_relocate - Perform architecture-specific ELF relocation
  1213. * up_relocateadd - Perform architecture-specific ELF relocation
  1214. *
  1215. ****************************************************************************/
  1216. /* See prototype in include/nuttx/elf.h */
  1217. /****************************************************************************
  1218. * Name: up_irqinitialize
  1219. ****************************************************************************/
  1220. void up_irqinitialize(void);
  1221. /****************************************************************************
  1222. * Name: up_interrupt_context
  1223. *
  1224. * Description:
  1225. * Return true is we are currently executing in
  1226. * the interrupt handler context.
  1227. *
  1228. ****************************************************************************/
  1229. bool up_interrupt_context(void);
  1230. /****************************************************************************
  1231. * Name: up_enable_irq
  1232. *
  1233. * Description:
  1234. * On many architectures, there are three levels of interrupt enabling: (1)
  1235. * at the global level, (2) at the level of the interrupt controller,
  1236. * and (3) at the device level. In order to receive interrupts, they
  1237. * must be enabled at all three levels.
  1238. *
  1239. * This function implements enabling of the device specified by 'irq'
  1240. * at the interrupt controller level if supported by the architecture
  1241. * (up_irq_restore() supports the global level, the device level is
  1242. * hardware specific).
  1243. *
  1244. * Since this API is not supported on all architectures, it should be
  1245. * avoided in common implementations where possible.
  1246. *
  1247. ****************************************************************************/
  1248. #ifndef CONFIG_ARCH_NOINTC
  1249. void up_enable_irq(int irq);
  1250. #endif
  1251. /****************************************************************************
  1252. * Name: up_disable_irq
  1253. *
  1254. * Description:
  1255. * This function implements disabling of the device specified by 'irq'
  1256. * at the interrupt controller level if supported by the architecture
  1257. * (up_irq_save() supports the global level, the device level is hardware
  1258. * specific).
  1259. *
  1260. * Since this API is not supported on all architectures, it should be
  1261. * avoided in common implementations where possible.
  1262. *
  1263. ****************************************************************************/
  1264. #ifndef CONFIG_ARCH_NOINTC
  1265. void up_disable_irq(int irq);
  1266. #endif
  1267. /****************************************************************************
  1268. * Name: up_trigger_irq
  1269. *
  1270. * Description:
  1271. * Trigger an IRQ by software. May not be supported by all architectures.
  1272. *
  1273. ****************************************************************************/
  1274. #ifdef CONFIG_ARCH_HAVE_IRQTRIGGER
  1275. void up_trigger_irq(int irq);
  1276. #endif
  1277. /****************************************************************************
  1278. * Name: up_prioritize_irq
  1279. *
  1280. * Description:
  1281. * Set the priority of an IRQ.
  1282. *
  1283. * Since this API is not supported on all architectures, it should be
  1284. * avoided in common implementations where possible.
  1285. *
  1286. ****************************************************************************/
  1287. #ifdef CONFIG_ARCH_IRQPRIO
  1288. int up_prioritize_irq(int irq, int priority);
  1289. #endif
  1290. /****************************************************************************
  1291. * Function: up_timer_initialize
  1292. *
  1293. * Description:
  1294. * This function is called during start-up to initialize
  1295. * the timer hardware.
  1296. *
  1297. ****************************************************************************/
  1298. void up_timer_initialize(void);
  1299. /****************************************************************************
  1300. * Tickless OS Support.
  1301. *
  1302. * When CONFIG_SCHED_TICKLESS is enabled, all support for timer interrupts
  1303. * is suppressed and the platform specific code is expected to provide the
  1304. * following custom functions.
  1305. *
  1306. * Architecture specific timer initialization logic initializes the timer
  1307. * facilities. This happens early in the initialization sequence (via
  1308. * up_initialize()).
  1309. * int up_timer_gettime(FAR struct timespec *ts): Returns the current
  1310. * time from the platform specific time source.
  1311. *
  1312. * The tickless option can be supported either via a simple interval timer
  1313. * (plus elapsed time) or via an alarm. The interval timer allows
  1314. * programming events to occur after an interval. With the alarm, you can
  1315. * set a time in the future and get an event when that alarm goes off.
  1316. *
  1317. * int up_alarm_cancel(void): Cancel the alarm.
  1318. * int up_alarm_start(FAR const struct timespec *ts): Enable (or re-anable
  1319. * the alarm.
  1320. * #else
  1321. * int up_timer_cancel(void): Cancels the interval timer.
  1322. * int up_timer_start(FAR const struct timespec *ts): Start (or re-starts)
  1323. * the interval timer.
  1324. * #endif
  1325. *
  1326. * The RTOS will provide the following interfaces for use by the platform-
  1327. * specific interval timer implementation:
  1328. *
  1329. * #ifdef CONFIG_SCHED_TICKLESS_ALARM
  1330. * void nxsched_alarm_expiration(FAR const struct timespec *ts): Called
  1331. * by the platform-specific logic when the alarm expires.
  1332. * #else
  1333. * void nxsched_timer_expiration(void): Called by the platform-specific
  1334. * logic when the interval timer expires.
  1335. * #endif
  1336. *
  1337. ****************************************************************************/
  1338. /****************************************************************************
  1339. * Name: up_timer_gettime
  1340. *
  1341. * Description:
  1342. * Return the elapsed time since power-up (or, more correctly, since
  1343. * the archtecture-specific timer was initialized). This function is
  1344. * functionally equivalent to:
  1345. *
  1346. * int clock_gettime(clockid_t clockid, FAR struct timespec *ts);
  1347. *
  1348. * when clockid is CLOCK_MONOTONIC.
  1349. *
  1350. * This function provides the basis for reporting the current time and
  1351. * also is used to eliminate error build-up from small errors in interval
  1352. * time calculations.
  1353. *
  1354. * Provided by platform-specific code and called from the RTOS base code.
  1355. *
  1356. * Input Parameters:
  1357. * ts - Provides the location in which to return the up-time.
  1358. *
  1359. * Returned Value:
  1360. * Zero (OK) is returned on success; a negated errno value is returned on
  1361. * any failure.
  1362. *
  1363. * Assumptions:
  1364. * Called from the normal tasking context. The implementation must
  1365. * provide whatever mutual exclusion is necessary for correct operation.
  1366. * This can include disabling interrupts in order to assure atomic register
  1367. * operations.
  1368. *
  1369. ****************************************************************************/
  1370. #if defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_CLOCK_TIMEKEEPING)
  1371. int up_timer_gettime(FAR struct timespec *ts);
  1372. #endif
  1373. #ifdef CONFIG_CLOCK_TIMEKEEPING
  1374. int up_timer_getcounter(FAR uint64_t *cycles);
  1375. void up_timer_getmask(FAR uint64_t *mask);
  1376. #endif
  1377. /****************************************************************************
  1378. * Name: up_alarm_cancel
  1379. *
  1380. * Description:
  1381. * Cancel the alarm and return the time of cancellation of the alarm.
  1382. * These two steps need to be as nearly atomic as possible.
  1383. * nxsched_alarm_expiration() will not be called unless the alarm is
  1384. * restarted with up_alarm_start().
  1385. *
  1386. * If, as a race condition, the alarm has already expired when this
  1387. * function is called, then time returned is the current time.
  1388. *
  1389. * NOTE: This function may execute at a high rate with no timer running (as
  1390. * when pre-emption is enabled and disabled).
  1391. *
  1392. * Provided by platform-specific code and called from the RTOS base code.
  1393. *
  1394. * Input Parameters:
  1395. * ts - Location to return the expiration time. The current time should
  1396. * returned if the alarm is not active. ts may be NULL in which
  1397. * case the time is not returned.
  1398. *
  1399. * Returned Value:
  1400. * Zero (OK) is returned on success. A call to up_alarm_cancel() when
  1401. * the timer is not active should also return success; a negated errno
  1402. * value is returned on any failure.
  1403. *
  1404. * Assumptions:
  1405. * May be called from interrupt level handling or from the normal tasking
  1406. * level. Interrupts may need to be disabled internally to assure
  1407. * non-reentrancy.
  1408. *
  1409. ****************************************************************************/
  1410. #if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM)
  1411. int up_alarm_cancel(FAR struct timespec *ts);
  1412. #endif
  1413. /****************************************************************************
  1414. * Name: up_alarm_start
  1415. *
  1416. * Description:
  1417. * Start the alarm. nxsched_alarm_expiration() will be called when the
  1418. * alarm occurs (unless up_alaram_cancel is called to stop it).
  1419. *
  1420. * Provided by platform-specific code and called from the RTOS base code.
  1421. *
  1422. * Input Parameters:
  1423. * ts - The time in the future at the alarm is expected to occur. When
  1424. * the alarm occurs the timer logic will call
  1425. * nxsched_alarm_expiration().
  1426. *
  1427. * Returned Value:
  1428. * Zero (OK) is returned on success; a negated errno value is returned on
  1429. * any failure.
  1430. *
  1431. * Assumptions:
  1432. * May be called from interrupt level handling or from the normal tasking
  1433. * level. Interrupts may need to be disabled internally to assure
  1434. * non-reentrancy.
  1435. *
  1436. ****************************************************************************/
  1437. #if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM)
  1438. int up_alarm_start(FAR const struct timespec *ts);
  1439. #endif
  1440. /****************************************************************************
  1441. * Name: up_timer_cancel
  1442. *
  1443. * Description:
  1444. * Cancel the interval timer and return the time remaining on the timer.
  1445. * These two steps need to be as nearly atomic as possible.
  1446. * nxsched_timer_expiration() will not be called unless the timer is
  1447. * restarted with up_timer_start().
  1448. *
  1449. * If, as a race condition, the timer has already expired when this
  1450. * function is called, then that pending interrupt must be cleared so
  1451. * that up_timer_start() and the remaining time of zero should be
  1452. * returned.
  1453. *
  1454. * NOTE: This function may execute at a high rate with no timer running (as
  1455. * when pre-emption is enabled and disabled).
  1456. *
  1457. * Provided by platform-specific code and called from the RTOS base code.
  1458. *
  1459. * Input Parameters:
  1460. * ts - Location to return the remaining time. Zero should be returned
  1461. * if the timer is not active. ts may be zero in which case the
  1462. * time remaining is not returned.
  1463. *
  1464. * Returned Value:
  1465. * Zero (OK) is returned on success. A call to up_timer_cancel() when
  1466. * the timer is not active should also return success; a negated errno
  1467. * value is returned on any failure.
  1468. *
  1469. * Assumptions:
  1470. * May be called from interrupt level handling or from the normal tasking
  1471. * level. Interrupts may need to be disabled internally to assure
  1472. * non-reentrancy.
  1473. *
  1474. ****************************************************************************/
  1475. #if defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_SCHED_TICKLESS_ALARM)
  1476. int up_timer_cancel(FAR struct timespec *ts);
  1477. #endif
  1478. /****************************************************************************
  1479. * Name: up_timer_start
  1480. *
  1481. * Description:
  1482. * Start the interval timer. nxsched_timer_expiration() will be called at
  1483. * the completion of the timeout (unless up_timer_cancel is called to stop
  1484. * the timing.
  1485. *
  1486. * Provided by platform-specific code and called from the RTOS base code.
  1487. *
  1488. * Input Parameters:
  1489. * ts - Provides the time interval until nxsched_timer_expiration() is
  1490. * called.
  1491. *
  1492. * Returned Value:
  1493. * Zero (OK) is returned on success; a negated errno value is returned on
  1494. * any failure.
  1495. *
  1496. * Assumptions:
  1497. * May be called from interrupt level handling or from the normal tasking
  1498. * level. Interrupts may need to be disabled internally to assure
  1499. * non-reentrancy.
  1500. *
  1501. ****************************************************************************/
  1502. #if defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_SCHED_TICKLESS_ALARM)
  1503. int up_timer_start(FAR const struct timespec *ts);
  1504. #endif
  1505. /****************************************************************************
  1506. * TLS support
  1507. ****************************************************************************/
  1508. /****************************************************************************
  1509. * Name: up_tls_info
  1510. *
  1511. * Description:
  1512. * Return the TLS information structure for the currently executing thread.
  1513. * When TLS is enabled, up_create_stack() will align allocated stacks to
  1514. * the TLS_STACK_ALIGN value. An instance of the following structure will
  1515. * be implicitly positioned at the "lower" end of the stack. Assuming a
  1516. * "push down" stack, this is at the "far" end of the stack (and can be
  1517. * clobbered if the stack overflows).
  1518. *
  1519. * If an MCU has a "push up" then that TLS structure will lie at the top
  1520. * of the stack and stack allocation and initialization logic must take
  1521. * care to preserve this structure content.
  1522. *
  1523. * The stack memory is fully accessible to user mode threads.
  1524. *
  1525. * Input Parameters:
  1526. * None
  1527. *
  1528. * Returned Value:
  1529. * A pointer to TLS info structure at the beginning of the STACK memory
  1530. * allocation. This is essentially an application of the TLS_INFO(sp)
  1531. * macro and has a platform dependency only in the manner in which the
  1532. * stack pointer (sp) is obtained and interpreted.
  1533. *
  1534. ****************************************************************************/
  1535. /* struct tls_info_s;
  1536. * FAR struct tls_info_s *up_tls_info(void);
  1537. *
  1538. * The actual declaration or definition is provided in arch/tls.h. The
  1539. * actual implementation may be a MACRO or an inline function.
  1540. */
  1541. /****************************************************************************
  1542. * Multiple CPU support
  1543. ****************************************************************************/
  1544. /****************************************************************************
  1545. * Name: up_testset
  1546. *
  1547. * Description:
  1548. * Perform an atomic test and set operation on the provided spinlock.
  1549. *
  1550. * Input Parameters:
  1551. * lock - The address of spinlock object.
  1552. *
  1553. * Returned Value:
  1554. * The spinlock is always locked upon return. The value of previous value
  1555. * of the spinlock variable is returned, either SP_LOCKED if the spinlock
  1556. * was previously locked (meaning that the test-and-set operation failed to
  1557. * obtain the lock) or SP_UNLOCKED if the spinlock was previously unlocked
  1558. * (meaning that we successfully obtained the lock)
  1559. *
  1560. ****************************************************************************/
  1561. /* See prototype in include/nuttx/spinlock.h */
  1562. /****************************************************************************
  1563. * Name: up_fetchadd8, up_fetchadd16, and up_fetchadd32
  1564. *
  1565. * Description:
  1566. * Perform an atomic fetch add operation on the provided 8-, 16-, or 32-
  1567. * bit value.
  1568. *
  1569. * This function must be provided via the architecture-specific logic.
  1570. *
  1571. * Input Parameters:
  1572. * addr - The address of value to be incremented.
  1573. * value - The addend
  1574. *
  1575. * Returned Value:
  1576. * The incremented value (volatile!)
  1577. *
  1578. ****************************************************************************/
  1579. #ifdef CONFIG_ARCH_HAVE_FETCHADD
  1580. int32_t up_fetchadd32(FAR volatile int32_t *addr, int32_t value);
  1581. int16_t up_fetchadd16(FAR volatile int16_t *addr, int16_t value);
  1582. int8_t up_fetchadd8(FAR volatile int8_t *addr, int8_t value);
  1583. #endif
  1584. /****************************************************************************
  1585. * Name: up_fetchsub8
  1586. *
  1587. * Description:
  1588. * Perform an atomic fetch subtract operation on the provided 8-, 16-, or
  1589. * 32-bit value.
  1590. *
  1591. * This function must be provided via the architecture-specific logic.
  1592. *
  1593. * Input Parameters:
  1594. * addr - The address of value to be decremented.
  1595. * value - The subtrahend
  1596. *
  1597. * Returned Value:
  1598. * The decremented value (volatile!)
  1599. *
  1600. ****************************************************************************/
  1601. #ifdef CONFIG_ARCH_HAVE_FETCHADD
  1602. int32_t up_fetchsub32(FAR volatile int32_t *addr, int32_t value);
  1603. int16_t up_fetchsub16(FAR volatile int16_t *addr, int16_t value);
  1604. int8_t up_fetchsub8(FAR volatile int8_t *addr, int8_t value);
  1605. #endif
  1606. /****************************************************************************
  1607. * Name: up_cpu_index
  1608. *
  1609. * Description:
  1610. * Return an index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
  1611. * corresponds to the currently executing CPU.
  1612. *
  1613. * Input Parameters:
  1614. * None
  1615. *
  1616. * Returned Value:
  1617. * An integer index in the range of 0 through (CONFIG_SMP_NCPUS-1) that
  1618. * corresponds to the currently executing CPU.
  1619. *
  1620. ****************************************************************************/
  1621. #ifdef CONFIG_SMP
  1622. int up_cpu_index(void);
  1623. #else
  1624. # define up_cpu_index() (0)
  1625. #endif
  1626. /****************************************************************************
  1627. * Name: up_cpu_idlestack
  1628. *
  1629. * Description:
  1630. * Allocate a stack for the CPU[n] IDLE task (n > 0) if appropriate and
  1631. * setup up stack-related information in the IDLE task's TCB. This
  1632. * function is always called before up_cpu_start(). This function is
  1633. * only called for the CPU's initial IDLE task; up_create_task is used for
  1634. * all normal tasks, pthreads, and kernel threads for all CPUs.
  1635. *
  1636. * The initial IDLE task is a special case because the CPUs can be started
  1637. * in different wans in different environments:
  1638. *
  1639. * 1. The CPU may already have been started and waiting in a low power
  1640. * state for up_cpu_start(). In this case, the IDLE thread's stack
  1641. * has already been allocated and is already in use. Here
  1642. * up_cpu_idlestack() only has to provide information about the
  1643. * already allocated stack.
  1644. *
  1645. * 2. The CPU may be disabled but started when up_cpu_start() is called.
  1646. * In this case, a new stack will need to be created for the IDLE
  1647. * thread and this function is then equivalent to:
  1648. *
  1649. * return up_create_stack(tcb, stack_size, TCB_FLAG_TTYPE_KERNEL);
  1650. *
  1651. * The following TCB fields must be initialized by this function:
  1652. *
  1653. * - adj_stack_size: Stack size after adjustment for hardware, processor,
  1654. * etc. This value is retained only for debug purposes.
  1655. * - stack_alloc_ptr: Pointer to allocated stack
  1656. * - adj_stack_ptr: Adjusted stack_alloc_ptr for HW. The initial value of
  1657. * the stack pointer.
  1658. *
  1659. * Input Parameters:
  1660. * - cpu: CPU index that indicates which CPU the IDLE task is
  1661. * being created for.
  1662. * - tcb: The TCB of new CPU IDLE task
  1663. * - stack_size: The requested stack size for the IDLE task. At least
  1664. * this much must be allocated. This should be
  1665. * CONFIG_SMP_IDLETHREAD_STACKSIZE.
  1666. *
  1667. ****************************************************************************/
  1668. int up_cpu_idlestack(int cpu, FAR struct tcb_s *tcb, size_t stack_size);
  1669. /****************************************************************************
  1670. * Name: up_cpu_start
  1671. *
  1672. * Description:
  1673. * In an SMP configution, only one CPU is initially active (CPU 0). System
  1674. * initialization occurs on that single thread. At the completion of the
  1675. * initialization of the OS, just before beginning normal multitasking,
  1676. * the additional CPUs would be started by calling this function.
  1677. *
  1678. * Each CPU is provided the entry point to is IDLE task when started. A
  1679. * TCB for each CPU's IDLE task has been initialized and placed in the
  1680. * CPU's g_assignedtasks[cpu] list. A stack has also been allocateded and
  1681. * initialized.
  1682. *
  1683. * The OS initialization logic calls this function repeatedly until each
  1684. * CPU has been started, 1 through (CONFIG_SMP_NCPUS-1).
  1685. *
  1686. * Input Parameters:
  1687. * cpu - The index of the CPU being started. This will be a numeric
  1688. * value in the range of from one to (CONFIG_SMP_NCPUS-1). (CPU
  1689. * 0 is already active)
  1690. *
  1691. * Returned Value:
  1692. * Zero on success; a negated errno value on failure.
  1693. *
  1694. ****************************************************************************/
  1695. #ifdef CONFIG_SMP
  1696. int up_cpu_start(int cpu);
  1697. #endif
  1698. /****************************************************************************
  1699. * Name: up_cpu_pause
  1700. *
  1701. * Description:
  1702. * Save the state of the current task at the head of the
  1703. * g_assignedtasks[cpu] task list and then pause task execution on the
  1704. * CPU.
  1705. *
  1706. * This function is called by the OS when the logic executing on one CPU
  1707. * needs to modify the state of the g_assignedtasks[cpu] list for another
  1708. * CPU.
  1709. *
  1710. * Input Parameters:
  1711. * cpu - The index of the CPU to be paused.
  1712. *
  1713. * Returned Value:
  1714. * Zero on success; a negated errno value on failure.
  1715. *
  1716. * Assumptions:
  1717. * Called from within a critical section; up_cpu_resume() must be called
  1718. * later while still within the same critical section.
  1719. *
  1720. ****************************************************************************/
  1721. #ifdef CONFIG_SMP
  1722. int up_cpu_pause(int cpu);
  1723. #endif
  1724. /****************************************************************************
  1725. * Name: up_cpu_pausereq
  1726. *
  1727. * Description:
  1728. * Return true if a pause request is pending for this CPU.
  1729. *
  1730. * Input Parameters:
  1731. * cpu - The index of the CPU to be queried
  1732. *
  1733. * Returned Value:
  1734. * true = a pause request is pending.
  1735. * false = no pasue request is pending.
  1736. *
  1737. ****************************************************************************/
  1738. #ifdef CONFIG_SMP
  1739. bool up_cpu_pausereq(int cpu);
  1740. #endif
  1741. /****************************************************************************
  1742. * Name: up_cpu_paused
  1743. *
  1744. * Description:
  1745. * Handle a pause request from another CPU. Normally, this logic is
  1746. * executed from interrupt handling logic within the architecture-specific
  1747. * However, it is sometimes necessary to perform the pending pause
  1748. * operation in other contexts where the interrupt cannot be taken
  1749. * in order to avoid deadlocks.
  1750. *
  1751. * This function performs the following operations:
  1752. *
  1753. * 1. It saves the current task state at the head of the current assigned
  1754. * task list.
  1755. * 2. It waits on a spinlock, then
  1756. * 3. Returns from interrupt, restoring the state of the new task at the
  1757. * head of the ready to run list.
  1758. *
  1759. * Input Parameters:
  1760. * cpu - The index of the CPU to be paused
  1761. *
  1762. * Returned Value:
  1763. * On success, OK is returned. Otherwise, a negated errno value indicating
  1764. * the nature of the failure is returned.
  1765. *
  1766. ****************************************************************************/
  1767. #ifdef CONFIG_SMP
  1768. int up_cpu_paused(int cpu);
  1769. #endif
  1770. /****************************************************************************
  1771. * Name: up_cpu_resume
  1772. *
  1773. * Description:
  1774. * Restart the cpu after it was paused via up_cpu_pause(), restoring the
  1775. * state of the task at the head of the g_assignedtasks[cpu] list, and
  1776. * resume normal tasking.
  1777. *
  1778. * This function is called after up_cpu_pause in order ot resume operation
  1779. * of the CPU after modifying its g_assignedtasks[cpu] list.
  1780. *
  1781. * Input Parameters:
  1782. * cpu - The index of the CPU being resumed.
  1783. *
  1784. * Returned Value:
  1785. * Zero on success; a negated errno value on failure.
  1786. *
  1787. * Assumptions:
  1788. * Called from within a critical section; up_cpu_pause() must have
  1789. * previously been called within the same critical section.
  1790. *
  1791. ****************************************************************************/
  1792. #ifdef CONFIG_SMP
  1793. int up_cpu_resume(int cpu);
  1794. #endif
  1795. /****************************************************************************
  1796. * Name: up_romgetc
  1797. *
  1798. * Description:
  1799. * In Harvard architectures, data accesses and instruction accesses occur
  1800. * on different buses, perhaps concurrently. All data accesses are
  1801. * performed on the data bus unless special machine instructions are
  1802. * used to read data from the instruction address space. Also, in the
  1803. * typical MCU, the available SRAM data memory is much smaller that the
  1804. * non-volatile FLASH instruction memory. So if the application requires
  1805. * many constant strings, the only practical solution may be to store
  1806. * those constant strings in FLASH memory where they can only be accessed
  1807. * using architecture-specific machine instructions.
  1808. *
  1809. * A similar case is where strings are retained in "external" memory such
  1810. * as EEPROM or serial FLASH. This case is similar only in that again
  1811. * special operations are required to obtain the string data; it cannot
  1812. * be accessed directly from a string pointer.
  1813. *
  1814. * If CONFIG_ARCH_ROMGETC is defined, then the architecture logic must
  1815. * export the function up_romgetc(). up_romgetc() will simply read one
  1816. * byte of data from the instruction space.
  1817. *
  1818. * If CONFIG_ARCH_ROMGETC, certain C stdio functions are effected: (1)
  1819. * All format strings in printf, fprintf, sprintf, etc. are assumed to
  1820. * lie in FLASH (string arguments for %s are still assumed to reside in
  1821. * SRAM). And (2), the string argument to puts and fputs is assumed to
  1822. * reside in FLASH. Clearly, these assumptions may have to modified for
  1823. * the particular needs of your environment. There is no
  1824. * "one-size-fits-all" solution for this problem.
  1825. *
  1826. ****************************************************************************/
  1827. #ifdef CONFIG_ARCH_ROMGETC
  1828. char up_romgetc(FAR const char *ptr);
  1829. #else
  1830. # define up_romgetc(ptr) (*ptr)
  1831. #endif
  1832. /****************************************************************************
  1833. * Name: up_mdelay and up_udelay
  1834. *
  1835. * Description:
  1836. * Some device drivers may require that the plaform-specific logic
  1837. * provides these timing loops for short delays.
  1838. *
  1839. ****************************************************************************/
  1840. void up_mdelay(unsigned int milliseconds);
  1841. void up_udelay(useconds_t microseconds);
  1842. /****************************************************************************
  1843. * These are standard interfaces that are exported by the OS for use by the
  1844. * architecture specific logic.
  1845. ****************************************************************************/
  1846. /****************************************************************************
  1847. * Name: nxsched_process_timer
  1848. *
  1849. * Description:
  1850. * This function handles system timer events (only when
  1851. * CONFIG_SCHED_TICKLESS is *not* defined). The timer interrupt logic
  1852. * itself is implemented in the architecture specific code, but must call
  1853. * the following OS function periodically -- the calling interval must
  1854. * be CONFIG_USEC_PER_TICK.
  1855. *
  1856. ****************************************************************************/
  1857. #ifndef CONFIG_SCHED_TICKLESS
  1858. void nxsched_process_timer(void);
  1859. #endif
  1860. /****************************************************************************
  1861. * Name: nxsched_timer_expiration
  1862. *
  1863. * Description:
  1864. * If CONFIG_SCHED_TICKLESS is defined, then this function is provided by
  1865. * the RTOS base code and called from platform-specific code when the
  1866. * interval timer used to implement the tick-less OS expires.
  1867. *
  1868. * Input Parameters:
  1869. * None
  1870. *
  1871. * Returned Value:
  1872. * None
  1873. *
  1874. * Assumptions/Limitations:
  1875. * Base code implementation assumes that this function is called from
  1876. * interrupt handling logic with interrupts disabled.
  1877. *
  1878. ****************************************************************************/
  1879. #if defined(CONFIG_SCHED_TICKLESS) && !defined(CONFIG_SCHED_TICKLESS_ALARM)
  1880. void nxsched_timer_expiration(void);
  1881. #endif
  1882. /****************************************************************************
  1883. * Name: nxsched_alarm_expiration
  1884. *
  1885. * Description:
  1886. * if CONFIG_SCHED_TICKLESS is defined, then this function is provided by
  1887. * the RTOS base code and called from platform-specific code when the
  1888. * alarm used to implement the tick-less OS expires.
  1889. *
  1890. * Input Parameters:
  1891. * ts - The time that the alarm expired
  1892. *
  1893. * Returned Value:
  1894. * None
  1895. *
  1896. * Assumptions/Limitations:
  1897. * Base code implementation assumes that this function is called from
  1898. * interrupt handling logic with interrupts disabled.
  1899. *
  1900. ****************************************************************************/
  1901. #if defined(CONFIG_SCHED_TICKLESS) && defined(CONFIG_SCHED_TICKLESS_ALARM)
  1902. void nxsched_alarm_expiration(FAR const struct timespec *ts);
  1903. #endif
  1904. /****************************************************************************
  1905. * Name: nxsched_process_cpuload
  1906. *
  1907. * Description:
  1908. * Collect data that can be used for CPU load measurements. When
  1909. * CONFIG_SCHED_CPULOAD_EXTCLK is defined, this is an exported interface,
  1910. * use the the external clock logic. Otherwise, it is an OS internal
  1911. * interface.
  1912. *
  1913. * Input Parameters:
  1914. * None
  1915. *
  1916. * Returned Value:
  1917. * None
  1918. *
  1919. * Assumptions/Limitations:
  1920. * This function is called from a timer interrupt handler with all
  1921. * interrupts disabled.
  1922. *
  1923. ****************************************************************************/
  1924. #if defined(CONFIG_SCHED_CPULOAD) && defined(CONFIG_SCHED_CPULOAD_EXTCLK)
  1925. void weak_function nxsched_process_cpuload(void);
  1926. #endif
  1927. /****************************************************************************
  1928. * Name: irq_dispatch
  1929. *
  1930. * Description:
  1931. * This function must be called from the achitecture-specific logic in
  1932. * order to dispatch an interrupt to the appropriate, registered handling
  1933. * logic.
  1934. *
  1935. ****************************************************************************/
  1936. void irq_dispatch(int irq, FAR void *context);
  1937. /****************************************************************************
  1938. * Name: up_check_stack and friends
  1939. *
  1940. * Description:
  1941. * Determine (approximately) how much stack has been used be searching the
  1942. * stack memory for a high water mark. That is, the deepest level of the
  1943. * stack that clobbered some recognizable marker in the stack memory.
  1944. *
  1945. * Input Parameters:
  1946. * None
  1947. *
  1948. * Returned Value:
  1949. * The estimated amount of stack space used.
  1950. *
  1951. ****************************************************************************/
  1952. #ifdef CONFIG_STACK_COLORATION
  1953. struct tcb_s;
  1954. size_t up_check_tcbstack(FAR struct tcb_s *tcb);
  1955. ssize_t up_check_tcbstack_remain(FAR struct tcb_s *tcb);
  1956. size_t up_check_stack(void);
  1957. ssize_t up_check_stack_remain(void);
  1958. #if defined(CONFIG_ARCH_INTERRUPTSTACK) && CONFIG_ARCH_INTERRUPTSTACK > 3
  1959. size_t up_check_intstack(void);
  1960. size_t up_check_intstack_remain(void);
  1961. #endif
  1962. #endif
  1963. /****************************************************************************
  1964. * Name: up_rtc_initialize
  1965. *
  1966. * Description:
  1967. * Initialize the builtin, MCU hardware RTC per the selected
  1968. * configuration. This function is called once very early in the OS
  1969. * initialization sequence.
  1970. *
  1971. * NOTE that initialization of external RTC hardware that depends on the
  1972. * availability of OS resources (such as SPI or I2C) must be deferred
  1973. * until the system has fully booted. Other, RTC-specific initialization
  1974. * functions are used in that case.
  1975. *
  1976. * Input Parameters:
  1977. * None
  1978. *
  1979. * Returned Value:
  1980. * Zero (OK) on success; a negated errno on failure
  1981. *
  1982. ****************************************************************************/
  1983. #if defined(CONFIG_RTC) && !defined(CONFIG_RTC_EXTERNAL)
  1984. int up_rtc_initialize(void);
  1985. #endif
  1986. /****************************************************************************
  1987. * Name: up_rtc_time
  1988. *
  1989. * Description:
  1990. * Get the current time in seconds. This is similar to the standard time()
  1991. * function. This interface is only required if the low-resolution
  1992. * RTC/counter hardware implementation is selected. It is only used by the
  1993. * RTOS during initialization to set up the system time when CONFIG_RTC is
  1994. * set but neither CONFIG_RTC_HIRES nor CONFIG_RTC_DATETIME are set.
  1995. *
  1996. * Input Parameters:
  1997. * None
  1998. *
  1999. * Returned Value:
  2000. * The current time in seconds.
  2001. *
  2002. ****************************************************************************/
  2003. #if defined(CONFIG_RTC) && !defined(CONFIG_RTC_HIRES)
  2004. time_t up_rtc_time(void);
  2005. #endif
  2006. /****************************************************************************
  2007. * Name: up_rtc_gettime
  2008. *
  2009. * Description:
  2010. * Get the current time from the high resolution RTC clock/counter. This
  2011. * interface is only supported by the high-resolution RTC/counter hardware
  2012. * implementation.
  2013. * It is used to replace the system timer.
  2014. *
  2015. * Input Parameters:
  2016. * tp - The location to return the high resolution time value.
  2017. *
  2018. * Returned Value:
  2019. * Zero (OK) on success; a negated errno value on failure.
  2020. *
  2021. ****************************************************************************/
  2022. #if defined(CONFIG_RTC) && defined(CONFIG_RTC_HIRES)
  2023. int up_rtc_gettime(FAR struct timespec *tp);
  2024. #endif
  2025. /****************************************************************************
  2026. * Name: up_rtc_getdatetime
  2027. *
  2028. * Description:
  2029. * Get the current date and time from the date/time RTC. This interface
  2030. * is only supported by the date/time RTC hardware implementation.
  2031. * It is used to replace the system timer. It is only used by the RTOS
  2032. * during initialization to set up the system time when CONFIG_RTC and
  2033. * CONFIG_RTC_DATETIME are selected (and CONFIG_RTC_HIRES is not).
  2034. *
  2035. * NOTE: Some date/time RTC hardware is capability of sub-second accuracy.
  2036. * That sub-second accuracy is lost in this interface. However, since the
  2037. * system time is reinitialized on each power-up/reset, there will be no
  2038. * timing inaccuracy in the long run.
  2039. *
  2040. * Input Parameters:
  2041. * tp - The location to return the high resolution time value.
  2042. *
  2043. * Returned Value:
  2044. * Zero (OK) on success; a negated errno value on failure.
  2045. *
  2046. ****************************************************************************/
  2047. #if defined(CONFIG_RTC) && defined(CONFIG_RTC_DATETIME)
  2048. int up_rtc_getdatetime(FAR struct tm *tp);
  2049. #endif
  2050. /****************************************************************************
  2051. * Name: up_rtc_getdatetime_with_subseconds
  2052. *
  2053. * Description:
  2054. * Get the current date and time from the date/time RTC. This interface
  2055. * is only supported by the date/time RTC hardware implementation.
  2056. * It is used to replace the system timer. It is only used by the RTOS
  2057. * during initialization to set up the system time when CONFIG_RTC and
  2058. * CONFIG_RTC_DATETIME are selected (and CONFIG_RTC_HIRES is not).
  2059. *
  2060. * NOTE: This interface exposes sub-second accuracy capability of RTC
  2061. * hardware. This interface allow maintaining timing accuracy when system
  2062. * time needs constant resynchronization with RTC, for example on MCU with
  2063. * low-power state that stop system timer.
  2064. *
  2065. * Input Parameters:
  2066. * tp - The location to return the high resolution time value.
  2067. * nsec - The location to return the subsecond time value.
  2068. *
  2069. * Returned Value:
  2070. * Zero (OK) on success; a negated errno on failure
  2071. *
  2072. ****************************************************************************/
  2073. #if defined(CONFIG_RTC) && defined(CONFIG_RTC_DATETIME) && \
  2074. defined(CONFIG_ARCH_HAVE_RTC_SUBSECONDS)
  2075. int up_rtc_getdatetime_with_subseconds(FAR struct tm *tp, FAR long *nsec);
  2076. #endif
  2077. /****************************************************************************
  2078. * Name: up_rtc_settime
  2079. *
  2080. * Description:
  2081. * Set the RTC to the provided time. All RTC implementations must be able
  2082. * to set their time based on a standard timespec.
  2083. *
  2084. * Input Parameters:
  2085. * tp - the time to use
  2086. *
  2087. * Returned Value:
  2088. * Zero (OK) on success; a negated errno value on failure.
  2089. *
  2090. ****************************************************************************/
  2091. #ifdef CONFIG_RTC
  2092. int up_rtc_settime(FAR const struct timespec *tp);
  2093. #endif
  2094. /****************************************************************************
  2095. * Name: arch_phy_irq
  2096. *
  2097. * Description:
  2098. * This function may be called to register an interrupt handler that will
  2099. * be called when a PHY interrupt occurs. This function both attaches
  2100. * the interrupt handler and enables the interrupt if 'handler' is non-
  2101. * NULL. If handler is NULL, then the interrupt is detached and disabled
  2102. * instead.
  2103. *
  2104. * The PHY interrupt is always disabled upon return. The caller must
  2105. * call back through the enable function point to control the state of
  2106. * the interrupt.
  2107. *
  2108. * This interrupt may or may not be available on a given platform depending
  2109. * on how the network hardware architecture is implemented. In a typical
  2110. * case, the PHY interrupt is provided to board-level logic as a GPIO
  2111. * interrupt (in which case this is a board-specific interface and really
  2112. * should be called board_phy_irq()); In other cases, the PHY interrupt
  2113. * may be cause by the chip's MAC logic (in which case arch_phy_irq()) is
  2114. * an appropriate name. Other other boards, there may be no PHY interrupts
  2115. * available at all. If client attachable PHY interrupts are available
  2116. * from the board or from the chip, then CONFIG_ARCH_PHY_INTERRUPT should
  2117. * be defined to indicate that fact.
  2118. *
  2119. * Typical usage:
  2120. * a. OS service logic (not application logic*) attaches to the PHY
  2121. * PHY interrupt and enables the PHY interrupt.
  2122. * b. When the PHY interrupt occurs: (1) the interrupt should be
  2123. * disabled and () work should be scheduled on the worker thread (or
  2124. * perhaps a dedicated application thread).
  2125. * c. That worker thread should use the SIOCGMIIPHY, SIOCGMIIREG,
  2126. * and SIOCSMIIREG ioctl calls** to communicate with the PHY,
  2127. * determine what network event took place (Link Up/Down?), and
  2128. * take the appropriate actions.
  2129. * d. It should then interact the PHY to clear any pending
  2130. * interrupts, then re-enable the PHY interrupt.
  2131. *
  2132. * * This is an OS internal interface and should not be used from
  2133. * application space. Rather applications should use the SIOCMIISIG
  2134. * ioctl to receive a signal when a PHY event occurs.
  2135. * ** This interrupt is really of no use if the Ethernet MAC driver
  2136. * does not support these ioctl calls.
  2137. *
  2138. * Input Parameters:
  2139. * intf - Identifies the network interface. For example "eth0". Only
  2140. * useful on platforms that support multiple Ethernet interfaces
  2141. * and, hence, multiple PHYs and PHY interrupts.
  2142. * handler - The client interrupt handler to be invoked when the PHY
  2143. * asserts an interrupt. Must reside in OS space, but can
  2144. * signal tasks in user space. A value of NULL can be passed
  2145. * in order to detach and disable the PHY interrupt.
  2146. * arg - The argument that will accompany the interrupt
  2147. * enable - A function pointer that be unused to enable or disable the
  2148. * PHY interrupt.
  2149. *
  2150. * Returned Value:
  2151. * Zero (OK) returned on success; a negated errno value is returned on
  2152. * failure.
  2153. *
  2154. ****************************************************************************/
  2155. #ifdef CONFIG_ARCH_PHY_INTERRUPT
  2156. int arch_phy_irq(FAR const char *intf, xcpt_t handler, void *arg,
  2157. phy_enable_t *enable);
  2158. #endif
  2159. /****************************************************************************
  2160. * Debug interfaces exported by the architecture-specific logic
  2161. ****************************************************************************/
  2162. /****************************************************************************
  2163. * Name: up_putc
  2164. *
  2165. * Description:
  2166. * Output one character on the console
  2167. *
  2168. ****************************************************************************/
  2169. int up_putc(int ch);
  2170. /****************************************************************************
  2171. * Name: up_puts
  2172. *
  2173. * Description:
  2174. * Output a string on the console
  2175. *
  2176. ****************************************************************************/
  2177. void up_puts(FAR const char *str);
  2178. /****************************************************************************
  2179. * Name: arch_sporadic_*
  2180. *
  2181. * Description:
  2182. * Hooks that can be enabled to monitor the behavior of the sporadic
  2183. * scheduler. These are call outs from the OS and must be provided by
  2184. * architecture-specific logic.
  2185. *
  2186. * Input Parameters:
  2187. * tcb - The TCB of the thread to be restarted.
  2188. *
  2189. * Returned Value:
  2190. * None
  2191. *
  2192. ****************************************************************************/
  2193. #ifdef CONFIG_SPORADIC_INSTRUMENTATION
  2194. void arch_sporadic_start(FAR struct tcb_s *tcb);
  2195. void arch_sporadic_lowpriority(FAR struct tcb_s *tcb);
  2196. void arch_sporadic_suspend(FAR struct tcb_s *tcb);
  2197. void arch_sporadic_resume(FAR struct tcb_s *tcb);
  2198. #endif
  2199. /****************************************************************************
  2200. * Name: up_critmon_*
  2201. *
  2202. * Description:
  2203. * The first interface simply provides the current time value in unknown
  2204. * units. NOTE: This function may be called early before the timer has
  2205. * been initialized. In that event, the function should just return a
  2206. * start time of zero.
  2207. *
  2208. * Nothing is assumed about the units of this time value. The following
  2209. * are assumed, however: (1) The time is an unsigned integer value, (2)
  2210. * the time is monotonically increasing, and (3) the elapsed time (also
  2211. * in unknown units) can be obtained by subtracting a start time from
  2212. * the current time.
  2213. *
  2214. * The second interface simple converts an elapsed time into well known
  2215. * units.
  2216. ****************************************************************************/
  2217. #ifdef CONFIG_SCHED_CRITMONITOR
  2218. uint32_t up_critmon_gettime(void);
  2219. void up_critmon_convert(uint32_t elapsed, FAR struct timespec *ts);
  2220. #endif
  2221. #undef EXTERN
  2222. #if defined(__cplusplus)
  2223. }
  2224. #endif
  2225. #endif /* __INCLUDE_NUTTX_ARCH_H */