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