readme_xtensa.txt 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. FreeRTOS Port for Xtensa Configurable and Diamond Processors
  2. ============================================================
  3. FreeRTOS Kernel Version 10.0.0
  4. Introduction
  5. ------------
  6. This document describes the Xtensa port for FreeRTOS multitasking RTOS.
  7. For an introduction to FreeRTOS itself, please refer to FreeRTOS
  8. documentation.
  9. This port currently works with FreeRTOS kernel version 10.0.0.
  10. Xtensa Configuration Requirements and Restrictions
  11. --------------------------------------------------
  12. The Xtensa configurable architecture supports a vast space of processor
  13. features. This port supports all of them, including custom processor
  14. extensions defined in the TIE language, with certain minimum
  15. requirements. You must use Xtensa Tools to compile and link FreeRTOS and
  16. your application for your Xtensa configuration. The port uses the Xtensa
  17. Hardware Abstraction Layer (HAL) to adapt to your Xtensa configuration.
  18. NOTE: It may be possible to build and run this with the open-source
  19. xtensa-linux tools provided you have the correct overlay for your Xtensa
  20. configuration. However, this has not been tested and is currently not
  21. supported by Cadence.
  22. This port includes optional reentrancy support for the 'newlib' and
  23. 'xclib' C runtime libraries distributed with Xtensa Tools, providing
  24. thread-safety on a per task basis (for use in tasks only, not interrupt
  25. handlers).
  26. NOTE: At this time only 'newlib' and 'xclib' C libraries are supported
  27. for thread safety. The 'uclibc' library is not reentrant and does not
  28. provide thread safety at this time. However, if you are not concerned
  29. with reentrancy then you can use any of these libraries.
  30. This port also includes a simple example application that may run on
  31. a supported board or the Xtensa instruction set simulator (ISS). There
  32. are also a couple of test programs used in maintaining the port, which
  33. serve as additional examples.
  34. FreeRTOS for Xtensa configurable processors requires the following minimum
  35. processor configuration options:
  36. - Timer interrupt option with at least one interruptible timer.
  37. - Interrupt option (implied by the timer interrupt option).
  38. - Exception Architecture 2 (XEA2). Please note that XEA1 is NOT supported.
  39. All 'Diamond', 'Xtensa 6', 'Xtensa LX' and 'Xtensa LX2' processors and
  40. most 'Xtensa T1050' processors are configured with XEA2.
  41. All Diamond processor cores meet these requirements and are supported.
  42. Minimal support for certain evaluation boards is provided via a board
  43. independent XTBSP API implemented by a board specific library distributed
  44. with the Xtensa Tools. This provides the board clock frequency and basic
  45. polled drivers for the display and console device. Note that XTBSP
  46. is not a tradtional RTOS "board support package" with RTOS specific
  47. interrupt-driven drivers - it is not specific to any RTOS. Note that
  48. FreeRTOS can run on any Xtensa or Diamond board without this board support
  49. (a "raw" platform), but you will have to provide the clock frequency
  50. and drivers for any on-board devices you want to use.
  51. Installation
  52. ------------
  53. The Xtensa port of FreeRTOS is available at this location:
  54. https://github.com/foss-xtensa/amazon-freertos
  55. This download includes the core FreeRTOS source and include files needed
  56. to build the port. You can also download the official release of FreeRTOS
  57. version 1.0.0 or later from this location:
  58. https://github.com/aws/amazon-freertos
  59. The Xtensa port files are currently not included in the official package.
  60. All source is provided along with a Makefile that works for any host
  61. platform supported by Xtensa Tools (Windows, Linux). These instructions
  62. are written for Windows users, but can easily be understood and adapted
  63. to other host platforms.
  64. First install the FreeRTOS common package in a directory of your choosing.
  65. The structure of that package will look like this:
  66. <install directory>
  67. |-- demos
  68. | `-- cadence
  69. | `-- sim
  70. | |-- common
  71. | | |-- application_code
  72. | | | `-- cadence_code
  73. | | `-- config_files
  74. | `-- xplorer
  75. `-- lib
  76. |-- FreeRTOS
  77. | `-- portable
  78. | |-- Common
  79. | |-- MemMang
  80. | `-- XCC
  81. | `-- Xtensa
  82. `-- include
  83. `-- private
  84. The Xtensa Tools are available from Cadence as part of a processor
  85. license. Be sure you have installed the Xtensa Tools and your processor
  86. configuration.
  87. Building FreeRTOS for Xtensa
  88. ----------------------------
  89. To build the FreeRTOS library and the example programs, go into the
  90. directory 'demos/cadence/sim' and use the makefile in that directory.
  91. "make all" will build all the examples. There is another makefile in
  92. the 'lib/FreeRTOS/portable/XCC/Xtensa' directory that builds just the
  93. FreeRTOS library.
  94. By default, you will build for the Xtensa instruction set simulator. If
  95. you have a supported emulation board, you can build to run on that. You
  96. can also build to run on a raw Xtensa core with no board support, a
  97. good starting point for supporting your own target platform. Cadence
  98. recommends doing functional development on the simulator because it
  99. is easier to debug with, then move to a board if/when you need to test
  100. hardware drivers or real-time performance.
  101. The provided makefile simplifies building FreeRTOS and the example
  102. for your Xtensa configuration and platform (ISS, board, etc.). There
  103. are detailed instructions in the comments at the top of the makefile.
  104. The makefiles work on Windows and Linux and support incremental builds.
  105. The build for each Xtensa configuration and target platform is placed in
  106. a subdirectory so several core and platform builds can co-exist even with
  107. incremental rebuilds. You may specify the root of the build area (if tou
  108. want it to be elsewhere than under the source tree) by defining BLDROOT
  109. either in the make command or your shell environment.
  110. Building the FreeRTOS Library
  111. -----------------------------
  112. First, be sure you have installed Xtensa Tools and your processor
  113. configuration, and be sure that Xtensa Tools are in your search path.
  114. You can use xt-make, which comes with the Xtensa Tools, to run the
  115. makefiles.
  116. Change directories to the Xtensa port directory:
  117. > cd lib/FreeRTOS/portable/XCC/Xtensa
  118. Now build the FreeRTOS RTOS as a library (libfreertos.a) as follows:
  119. > xt-make
  120. which by default builds for the simulator (TARGET=sim), or:
  121. > xt-make TARGET=board
  122. which builds for a supported board. Note that the board type does not
  123. need to be specified when building the FreeRTOS library.
  124. If you are building for an Xtensa processor configuration that is not the
  125. default you selected when you installed Xtensa Tools, you need to define the
  126. environment variable XTENSA_CORE. If your configuration is not in the
  127. default registry you selected when you installed Xtensa Tools, you also
  128. need to define the environment variable XTENSA_SYSTEM. See tools manuals.
  129. You can avoid defining these in your environment if you pass the variables
  130. you need to redefine into xt-make as follows:
  131. > xt-make XTENSA_CORE=<your_config_name> XTENSA_SYSTEM=<your_registry> ...
  132. There are more details about build options in the comment in the Makefile.
  133. After the library has been built, you must link your application with this
  134. library in order to use FreeRTOS.
  135. Building the FreeRTOS Examples
  136. ------------------------------
  137. The provided examples are designed to run on the Xtensa instruction set
  138. simulator (ISS) or a supported evaluation board programmed with your
  139. Xtensa processor configuration.
  140. To build the examples for the default platform (simulator):
  141. > cd demos/cadence/sim
  142. > xt-make all
  143. which is the same as
  144. > xt-make all TARGET=sim
  145. The boards currently supported are the Xilinx ML605 and KC705 FPGA
  146. development boards. To target these boards, type
  147. > xt-make all TARGET=ml605
  148. or
  149. > xt-make all TARGET=kc705
  150. To build in a location other than the default, specify the new location
  151. using the BLDROOT variable. Note that this makefile will invoke the
  152. FreeRTOS library build makefile automatically, passing on the relevant
  153. parameters based on what you specified.
  154. You can override the default compilation options by specifying the new
  155. options via CFLAGS. For example:
  156. > xt-make all TARGET=sim CFLAGS="-O2 -Os -g"
  157. This compiles the examples and links them with the FreeRTOS library
  158. libfreertos.a and the appropriate linker-support package (LSP) for your
  159. target platform (you can override the LSP by adding LSP=<lsp> to the
  160. xt-make command line). The resulting ELF files can be downloaded and
  161. executed on the target. The example binaries appear in the platform
  162. specific subdirectory described earlier.
  163. To build your application with thread-safe C library support, you
  164. need to make certain modifications to the application to plug in and
  165. invoke the reentrancy support. This allows each task to use the library
  166. without interference with other tasks (it is not safe for interrupt
  167. handlers to call the C library).
  168. First, you must define
  169. XT_USE_THREAD_SAFE_CLIB
  170. to a nonzero value either in xtensa_config.h or on the compiler's command
  171. line. Note that the default xtensa_config.h provided with this port does
  172. define this to 1 if either newlib or xclib is detected.
  173. Then, you must also make sure to allocate extra space on the stack for
  174. each task that will use the C library reentrant functions. This extra
  175. space is to be allocated over and above the actual stack space required
  176. by the task itself. The define
  177. XT_STACK_EXTRA_CLIB
  178. specifies the amount of extra space to be added on to the stack to allow
  179. saving the context for the C library as well as the coprocessors if any.
  180. E.g. if your task requires 2000 bytes of stack space, you must allocate
  181. (2000 + XT_STACK_EXTRA_CLIB) bytes for the stack.
  182. IMPORTANT NOTE
  183. --------------
  184. The header file FreeRTOS.h, which is a part of the core FreeRTOS sources,
  185. includes <reent.h> if thread safety for the C libraries is enabled. For
  186. xclib, this file exists in <sys/reent.h> and so is reported as missing.
  187. To work around this, the makefiles supplied with this port will copy the
  188. reent.h header into the build directory during the build process. If you
  189. use a different build process, then you must make sure to copy this file
  190. to a location that is included in the list of include paths. This can be
  191. the build directory or the directory that contains the Xtensa port source
  192. files.
  193. Running or Debugging an Application
  194. -----------------------------------
  195. To execute the example application on the simulator:
  196. > xt-run [--turbo] example.exe
  197. The option --turbo provides much faster, but non-cycle-accurate simulation
  198. (the --turbo option is only available with Xtensa Tools version 7 or later).
  199. To execute on the simulator using the Xplorer GUI based debugger:
  200. > xplorer --debug example.exe
  201. To execute on a supported evaluation board, download example.exe per
  202. instructions in the tools manuals. Be sure the board has been programmed
  203. with the correct configuration and is set up to boot from RAM and debug
  204. a downloaded program! Optionally you may connect a terminal or terminal
  205. emulator to the serial port on the board with settings as described in
  206. the board user manual, and see the output of printf on the terminal.
  207. To obtain I/O on a "raw" platform such as an unsupported board, you need
  208. to provide low level I/O drivers (eg. inbyte() and outbyte() for character
  209. I/O if you want to use printf etc.). You can run "raw" executables on
  210. any Xtensa platform, including simulator and any board, but you will not
  211. see any behavior specific to the platform (eg. display, printed output,
  212. stopping simulation at end of program). You can, while debugging, use a
  213. debugger mechanism called GDBIO to obtain basic I/O. To use GDBIO, link
  214. with the gdbio LSP. Refer to Xtensa tools documentation for details.
  215. Task Stack Sizes
  216. ----------------
  217. The application must ensure that every task has enough space for its
  218. stack. Each task needs enough space for its own use, its own interrupt
  219. stack frame (defined in xtensa_context.h) and space to save coprocessor
  220. state, if any. Several factors influence the size of the stack required,
  221. including the compiler optimization level and the use of the C library.
  222. Calls to standard output functions such as printf() can use up a lot of
  223. stack space. The tool xt-stack-usage is helpful in determining safe stack
  224. sizes for your application.
  225. Some macros are provided in xtensa_config.h to help determine the stack
  226. size for tasks that do and do not use the C library. Use these as the
  227. basis for each task's stack size. They are minimum requirements taking
  228. into account your configuration and use of the C library. In particular,
  229. the define
  230. XT_STACK_MIN_SIZE
  231. defines the minimum stack size for any task. Be very careful if you try
  232. to use a stack size smaller than this minimum. Stack overruns can cause
  233. all kinds of hard-to-debug errors. It is recommended that you enable the
  234. FreeRTOS stack checking features during development.
  235. WARNING: The newlib printf() function uses a lot of stack space. Be very
  236. careful in using it. Optionally you can use the 'libxtutil' library for
  237. output - it implements a subset of printf() that has smaller code size
  238. and uses far less stack space. More information about this library is in
  239. the Xtensa Tools documentation.
  240. Interrupt Stack
  241. ---------------
  242. Beginning with port version 1.2, the port uses a separate interrupt stack
  243. for handling interrupts. Thus, it is no longer necessary for each task to
  244. reserve space on its stack to handle interrupts. The size of the interrupt
  245. stack is controlled by the parameter "configISR_STACK_SIZE" defined in
  246. FreeRTOSConfig.h. Define this carefully to match your system requirements.
  247. Assembler / Compiler Switches
  248. -----------------------------
  249. The following are compiler switches are used by the provided
  250. Makefile in building the FreeRTOS library and example application.
  251. These can be modified by editing the Makefile or by overriding the
  252. CFLAGS variable in the make command line, for example:
  253. > xt-make CFLAGS="-O2 -DXT_USE_THREAD_SAFE_CLIB"
  254. -g Specifies debug information.
  255. -c Specifies object code generation.
  256. -On Sets compiler optimization level n (default -O0).
  257. -mlongcalls Allows assembler and linker to convert call
  258. instructions to longer indirect call sequences
  259. when target is out of range.
  260. -x assembler-with-cpp Passes .s and .S files through C preprocessor.
  261. -Dmacro Define a preprocessor macro with no value.
  262. -Dmacro=value Define a preprocessor macro with a value.
  263. See the compiler / linker documentation for a full list of switches and
  264. their use.
  265. Many definitions can be provided at compile-time via the -D option
  266. without editing the source code. Here are some of the more useful ones:
  267. XT_USE_THREAD_SAFE_CLIB Enable support for the reentrancy to provide
  268. thread-safety for the newlib and xclib libraries
  269. supplied with Xtensa Tools. Default ON.
  270. Note, the follwing defines are unique to the Xtensa port so have names
  271. beginning with "XT_".
  272. XT_SIMULATOR Set this if building to run on the simulator.
  273. Takes advantage of certain simulator control
  274. and reporting facilities, and adjusts timing
  275. of periodic tick to provide a more acceptable
  276. performance in simulation (see XT_CLOCK_FREQ).
  277. Set by default unless PLATFORM is overridden.
  278. XT_BOARD Set this if building for a supported board.
  279. Be sure to specify the correct LSP for the
  280. board. See the example makefile for usage.
  281. XT_CLOCK_FREQ=freq Specifies the target processor's clock
  282. frequency in Hz. Used primarily to set the
  283. timer that generates the periodic interrupt.
  284. Defaults are provided and may be edited in
  285. xtensa_timer.h (see comments there also).
  286. Default for simulator provides more acceptable
  287. performance, but cannot provide real-time
  288. performance due to variation in simulation
  289. speed per host platform and insufficient
  290. cycles between interrupts to process them.
  291. Supported board platforms by default leave
  292. this undefined and compute the clock frequency
  293. at initialization unless this is explicitly
  294. defined.
  295. XT_TICK_PER_SEC=n Specifies the frequency of the periodic tick.
  296. XT_TIMER_INDEX=n Specifies which timer to use for periodic tick.
  297. Set this if your Xtensa processor configuration
  298. provides more than one suitable timer and you
  299. want to override the default. See xtensa_timer.h .
  300. XT_INTEXC_HOOKS Enables hooks in interrupt vector handlers
  301. to support dynamic installation of exception
  302. and interrupt handlers. Disabled by default.
  303. XT_USE_OVLY Enable code overlay support. It uses a mutex,
  304. hence configUSE_MUTEX must be enabled. This
  305. option is currently unsupported.
  306. XT_USE_SWPRI Enable software prioritization of interrupts.
  307. Enabling this will prioritize interrupts with
  308. higher bit numbers over those with lower bit
  309. numbers at the same level. This works only for
  310. low and medium priority interrupts that can be
  311. dispatched to C handlers.
  312. Register Usage and Stack Frames
  313. -------------------------------
  314. The Xtensa architecture specifies two ABIs that determine how the general
  315. purpose registers a0-a15 are used: the standard windowed ABI use with
  316. the Xtensa windowed register file architecture, and the optional and
  317. more conventional Call0 ABI (required for Xtensa configurations without
  318. a windowed register file).
  319. Xtensa processors may have other special registers (including co-processor
  320. registers and other TIE "states") that are independent of this choice
  321. of ABI. See Xtensa documentation for more details.
  322. In the windowed ABI the registers of the current window are used as follows:
  323. a0 = return address
  324. a1 = stack pointer (alias sp)
  325. a2 = first argument and result of call (in simple cases)
  326. a3-7 = second through sixth arguments of call (in simple cases).
  327. Note that complex or large arguments are passed on the
  328. stack. Details are in the Xtensa Tools manuals.
  329. a8-a15 = available for use as temporaries.
  330. There are no callee-save registers. The windowed hardware automatically
  331. saves registers a0-a3 on a call4, a0-a8 on a call8, a0-a12 on a call12,
  332. by rotating the register window. Hardware triggers window overflow and
  333. underflow exceptions as necessary when registers outside the current
  334. window need to be spilled to preallocated space in the stack frame, or
  335. restored. Complete details are in the Xtensa manuals. The entire windowed
  336. register file is saved and restored on interrupt or task context switch.
  337. The Call0 ABI does not make use of register windows, relying instead
  338. on a fixed set of 16 registers without window rotation.
  339. The Call0 ABI is more conventional and uses registers as follows:
  340. a0 = return address
  341. a1 = stack pointer (alias sp)
  342. a2 = first argument and result of call (in simple cases)
  343. a3-7 = second through sixth arguments of call (in simple cases).
  344. Note that complex or large arguments are passed on the
  345. stack. Details are in the Xtensa Tools manuals.
  346. a8-a11 = scratch.
  347. a12-a15 = callee-save (a function must preserve these for its caller).
  348. On a FreeRTOS API call, callee-save registers are saved only when a task
  349. context switch occurs, and other registers are not saved at all (the caller
  350. does not expect them to be preserved). On an interrupt, callee-saved
  351. registers might only be saved and restored when a task context-switch
  352. occurs, but all other registers are always saved and restored.
  353. An Xtensa processor has other special registers independent of the ABI,
  354. depending on the configuration (including co-processor registers and other
  355. TIE state) that are part of the task context. FreeRTOS preserves all such
  356. registers over an unsolicited context-switch triggered by an interrupt.
  357. However it does NOT preserve these over a solicited context-switch during
  358. a FreeRTOS API call. This bears some explanation. These special registers
  359. are either ignored by the compiler or treated as caller-saved, meaning
  360. that if kept "live" over a function call (ie. need to be preserved)
  361. they must be saved and restored by the caller. Since solicited entry to
  362. FreeRTOS is always made by a function call, FreeRTOS assumes the caller
  363. has saved any of these registers that are "live". FreeRTOS avoids a lot
  364. of overhead by not having to save and restore every special register
  365. (there can be many) on every solicited context switch.
  366. As a consequence, the application developer should NOT assume that special
  367. registers are preserved over a FreeRTOS API call such as vTaskDelay().
  368. If multiple tasks use a register, the caller must save and restore it.
  369. The saved context stack frames for context switches that occur as
  370. a result of interrupt handling (interrupt frame) or from task-level
  371. API calls (solicited frame) are described in human readable form in
  372. xtensa_context.h . All suspended tasks have one of these two types
  373. of stack frames. The top of the suspended task's stack is pointed to
  374. by pxCurrentTCB->pxTopOfStack. A special location common to both stack
  375. frames differentiates solicited and interrupt stack frames.
  376. Improving Performance, Footprint, or Ease of Debugging
  377. ------------------------------------------------------
  378. By default FreeRTOS for Xtensa is built with debug (-g) and without
  379. compiler optimizations (-O0). This makes debugging easier. Of course,
  380. -O0 costs performance and usually also increases stack usage. To make
  381. FreeRTOS run faster you can change the Makefile to enable the desired
  382. optimizations or set a predefined optimization level (-O<level>) .
  383. Maximum performance is achieved with -O3 -ipa, but that might increase
  384. the footprint substantially. A good compromise is -O2. See the compiler
  385. manual for details.
  386. Minimal footprint is achieved by optimizing for space with -Os, at the
  387. cost of some performance. See the compiler manual for details.
  388. The Xtensa architecture port-specific assembly files are coded with no
  389. file-scope labels inside functions (all labels inside functions begin with
  390. ".L"). This allows a profiler to accurately associate an address with a
  391. function, and also allows the debugger's stack trace to show the correct
  392. function wherever the program counter is within that function. However
  393. there are some tradeoffs in debugging. Local (".L") labels are not
  394. visible to the debugger, so the following limitations may be observed
  395. during debugging:
  396. - You cannot set a breakpoint on a local label inside a function.
  397. - Disassembly will show the entire function, but will get out of sync and
  398. show incorrect opcodes if it crosses any padding before an aligned local
  399. branch target (".L" label, not ".Ln"). Restart disassembly specifying an
  400. address range explicitly between points where there is padding.
  401. Since FreeRTOS is provided in source form, it is not difficult to remove
  402. the ".L" and ".Ln" prefixes from local labels if you want them visible.
  403. They can also be made visible by passing the '-L' option to the assembler
  404. and linker (see the assembler and linker manuals for details).
  405. Interrupt and Exception Handling
  406. --------------------------------
  407. FreeRTOS provides a complete set of efficient exception and first-level
  408. interrupt handlers installed at the appropriate exception and interrupt
  409. vector locations. The Xtensa architecture supports several different
  410. classes of exceptions and interrupts. Being a configurable architecture,
  411. many of these are optional, and the vector locations are determined by
  412. your processor configuration. (Note that Diamond cores are pre-configured
  413. with specific vector locations.) The handlers provided use conditional
  414. compilation to adapt to your processor configuration and include only
  415. the code that is needed.
  416. Xtensa vector locations may reside almost anywhere, including in ROM.
  417. The amount of code space available at each of these locations is
  418. often very small (e.g. due to following vectors). A small stub of
  419. code installed at the vector jumps to the corresponding handler,
  420. usually in RAM. The exception and interrupt handlers are defined in
  421. xtensa_vectors.S. They are not specific to FreeRTOS, but call into
  422. FreeRTOS where appropriate via macros defined in xtensa_rtos.h .
  423. The handlers provided for low and medium priority interrupts are just
  424. dispatchers that save relevant state and call user-definable handlers.
  425. See the files xtensa_vectors.S and xtensa_api.h for more details of how
  426. to create and install application-specific user interrupt handlers.
  427. Similarly, user-defined handlers can be installed for exceptions (other
  428. than a few which are always handled by the OS).
  429. The high priority interrupt handlers provided may be considered templates
  430. into which the application adds code to service specific interrupts.
  431. The places where application handlers should be inserted are tagged with
  432. the comment "USER_EDIT" in xtensa_vectors.S.
  433. This FreeRTOS port supports strict priority-based nesting of interrupts.
  434. An interrupt may only nest on top of one of strictly lower priority.
  435. Equal priority interrupts concurrently pending are handled in an
  436. application-defined sequence before any lower priority interrupts
  437. are handled. During interrupt and exception handling, the processor's
  438. interrupt level (PS.INTLEVEL) is used to control the interrupt priority
  439. level that can be accepted; interrupt sources are not controlled
  440. individually by FreeRTOS (the application is free to access the INTENABLE
  441. register directly to enable/disable individual interrupts, eg. using
  442. Xtensa HAL services). This approach provides the most deterministic
  443. bounds on interrupt latency (for a given priority) and stack depth.
  444. Software prioritization of interrupts at the same priority is controlled
  445. by the definition of XT_USE_SWPRI. See above for a description of this
  446. parameter.
  447. The following subsections describe the handling of each class of exception
  448. and interrupt in more detail. Many have nothing to do with FreeRTOS but
  449. are mentioned because there is code to handle them in xtensa_vectors.S.
  450. User Exception and Interrupt Handler (Low/Medium Priority):
  451. All Xtensa 'general exceptions' come to the user, kernel, or double
  452. exception vector. The exception type is identified by the EXCCAUSE
  453. special register (level 1 interrupts are one particular cause of a
  454. general exception). This port sets up PS to direct all such exceptions
  455. to the user vector. Exceptions taken at the other two vectors usually
  456. indicate a kernel or application bug.
  457. Level 1 interrupts are identified at the beginning of the handler
  458. and are dispatched to a dedicated handler. Then, syscall and alloca
  459. exceptions are identified and dispatched to special handlers described
  460. below. After this, coprocessor exceptions are identified and dispatched
  461. to the coprocessor handler.
  462. Any remaining exceptions are processed as follows:
  463. Having allocated the exception stack frame, the user exception handler
  464. saves the current task state and sets up a C environment and enables
  465. the high-priority class of interrupts (which do not interact with
  466. FreeRTOS), then reads EXCCAUSE and uses the cause (number) to index
  467. into a table of user-specified handlers. The correct handler is then
  468. called. If the handler returns, the context is restored and control is
  469. returned to the code that caused the exception. The user-defined handler
  470. may alter the saved context, or any other system state, that allows the
  471. faulting instruction to be retried.
  472. If the cause is a level 1 (low-priority) or medium-priority interrupt,
  473. the handler enables all interrupts above that priority level after
  474. saving the task context. It then sets up the environment for C code
  475. and then calls the handler (found in the handler table) for the
  476. interrupt number. If the user has not specified a handler, then the
  477. default handler will be called, which will terminate the program.
  478. If the interrupt is for the system timer, it calls a special interrupt
  479. handler for the system timer tick, which calls _frxt_timer_int then
  480. clears its bit from the mask. This interrupt cannot be hooked by the
  481. user-defined handler.
  482. Finally, the handler calls _frxt_int_exit to allow FreeRTOS to perform
  483. any scheduling necessary and return either to the interrupted task
  484. or another.
  485. If software prioritization is enabled, the handler will re-enable all
  486. interrupts at the same level that are numerically higher than the current
  487. one, before calling the user handler. This allows a higher priority
  488. interrupt to pre-empt the lower priority handler.
  489. Medium Priority Interrupt Handlers:
  490. Medium priority interrupts are those at levels 2 up to XCHAL_EXCM_LEVEL,
  491. a configuration-specific maximum interrupt level affected by the global
  492. 'exception mode' bit in the processor status word (PS.EXCM).
  493. Interrupt levels above XCHAL_EXCM_LEVEL are of the high-priority class.
  494. The Xtensa hardware documentation considers medium priority interrupts
  495. to be a special case of high-priority interrupts, but from a software
  496. perspective they are very different.
  497. Dispatch of medium-priority interrupts is discussed in the section
  498. above.
  499. High Priority Interrupt Handlers:
  500. High priority interrupts are those strictly above XCHAL_EXCM_LEVEL,
  501. a configuration-specific maximum interrupt level affected by the
  502. global 'exception mode' bit in the processor status word (PS.EXCM).
  503. High priority handlers may not directly interact with FreeRTOS at all,
  504. and are described here only for the sake of completeness. They must
  505. be coded in assembler (may not be coded in C) and are intended to be
  506. used for handling extremely high frequency hardware events that need
  507. to be handled in only a few cycles. A high priority interrupt handler
  508. may trigger a software interrupt at a medium or low priority level to
  509. occasionally signal FreeRTOS. Please see Xtensa documentation.
  510. There is a separate vector and a few special registers for each high
  511. priority interrupt, providing for fast dispatch and efficient nesting
  512. on top of lower priority interrupts. Handlers are templates included
  513. only for the vectors that exist in your Xtensa processor configuration.
  514. These templates are written for only one interrupt per high priority
  515. level to minimize latency servicing very fast time-critical interrupts.
  516. The vector code jumps to the corresponding first-level interrupt handler,
  517. which then executes application-provided assembler code before returning
  518. quickly to the interrupted task or lower priority handler.
  519. Kernel Exception Handler:
  520. Kernel mode is not used in this port of FreeRTOS, and therefore kernel
  521. exceptions should not happen. A stub is provided for the vector that
  522. triggers the debugger (if connected) or calls _xt_panic to freeze the
  523. processor should a kernel exception occur.
  524. Alloca Exception Handler:
  525. Alloca exceptions are generated by the 'movsp' instruction, which
  526. is used only in the windowed ABI. Its purpose is to allocate some
  527. space on top of the stack. Because the window hardware may have
  528. spilled some registers to the 16 byte "base save" area below the
  529. stack pointer, it is necessary to protect those values. The alloca
  530. handler accomplishes this quickly without setting up an interrupt
  531. frame or entering FreeRTOS, by emulating a register underflow and
  532. re-executing 'movsp'.
  533. Syscall Exception Handler:
  534. Syscall exceptions are generated by a 'syscall' instruction.
  535. The windowed ABI specifies that executing this instruction with
  536. a value of zero in register a2 must spill any unsaved registers
  537. in the windowed register file to their pre-determined locations
  538. on the caller's stack. The handler does exactly that, and skips
  539. over the 'syscall' instruction before returning to the caller.
  540. If a2 is non-zero, the handler returns a2 == -1 to the caller.
  541. Co-Processor Exception Handler:
  542. A co-processor exception is generated when a task accesses a
  543. co-processor that it does not "own". Ownership represents which
  544. task's state is currently in the co-processor. Co-processors are
  545. context-switched "lazily" (on demand) only when a non-owning task
  546. uses a co-processor instruction, otherwise a task retains ownership
  547. even when it is preempted from the main processor. The co-processor
  548. exception handler performs the context-switch and manages ownership.
  549. Co-processors may not be used by any code outside the context of a
  550. task. A co-processor exception triggered by code that is not part
  551. of a running task is a fatal error and FreeRTOS for Xtensa will panic.
  552. This restriction is intended to reduce the overhead of saving and
  553. restoring co-processor state (which can be quite large) and in
  554. particular remove that overhead from interrupt handlers.
  555. Debug Exception Handler:
  556. A debug exception is caused as a result of running code, such as by
  557. a 'break' instruction or hardware breakpoints and watchpoints, or
  558. as a result of an external debug interrupt, such as from an OCD based
  559. debugger or multiprocessor debug events ("breakin/breakout"). If the
  560. processor is running in OCD mode under control of an OCD-based debugger,
  561. the trigger event immediately halts the processor and gives control to
  562. the OCD debugger. Otherwise control is transferred to the debug vector.
  563. The debug vector handler calls the simulator if running on the ISS,
  564. which then takes control and interacts with any attached debugger.
  565. If running on hardware and not in OCD mode, debug exceptions are not
  566. expected, so the debug handler calls _xt_panic to freeze the processor.
  567. Double Exception Handler:
  568. A double exception is a general exception that happens while the
  569. processor is in exception mode (PS.EXCM set), and thus indicates a
  570. bug in kernel code. The double exception vector handler triggers
  571. the debugger (if connected) or calls _xt_panic to freeze the
  572. processor.
  573. Window Overflow and Underflow Exception Handlers:
  574. Window overflow and underflow handlers are required for use of the
  575. windowed ABI. Each has its own dedicated vector and highly optimized
  576. code that is independent of OS. See Xtensa documentation for details.
  577. Hooks for Dynamic Installation of Handlers:
  578. Optional hooks are provided in the user exception and low level
  579. interrupt handler and all medium and high priority interrupt handlers,
  580. to dynamically install a handler function (which may be coded in C,
  581. unless in a high-priority interrupt handler). These hooks are enabled
  582. and used by automatic regression tests, they are not part of a normal
  583. FreeRTOS build. However an application is free to take advantage of
  584. them. The interrupt/exception hooks are described in xtensa_rtos.h .
  585. It is recommended that the application not make use of these hooks, but
  586. rather use xt_set_interrupt_handler() and xt_set_exception_handler()
  587. to install application-specific handlers. This method is more convenient
  588. and allows arguments to be passed to the handlers. Software prioritization
  589. of interrupts works only with this method. See xtensa_api.h for details.
  590. Overlay Support
  591. Code overlays are currently not supported for FreeRTOS. This will be
  592. supported in a future release. Make sure that the option XT_USE_OVLY is
  593. never defined when building.
  594. -End-