rtos.rst 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. .. _design_rtos:
  2. RTOS
  3. ====
  4. .. _design_rtos_overview:
  5. Overview
  6. --------
  7. In Nuclei SDK, we have support four most-used RTOSes in the world,
  8. **FreeRTOS**, **UCOSII**, **ThreadX** and **RT-Thread from China**.
  9. Our RTOS port require Nuclei ECLIC interrupt controller, please make sure
  10. your Nuclei CPU is configured with ECLIC present.
  11. If you want to use RTOS in your application, you can choose one
  12. of the supported RTOSes.
  13. .. note::
  14. When you want to develop RTOS application in Nuclei SDK, please
  15. don't reconfigure ``SysTimer`` and ``SysTimer Software Interrupt``,
  16. since it is already used by RTOS portable code.
  17. .. _design_rtos_freertos:
  18. FreeRTOS
  19. --------
  20. `FreeRTOS`_ is a market-leading real-time operating system (RTOS) for
  21. microcontrollers and small microprocessors.
  22. In our FreeRTOS portable code, we are using ``SysTimer Interrupt`` as RTOS SysTick
  23. Interrupt, and using ``SysTimer Software Interrupt`` to do task switch.
  24. These two interrupts are kept as lowest level, and ``SysTimer Interrupt``
  25. is initialized as non-vector interrupt, and ``SysTimer Software Interrupt``
  26. is initialized as vector interrupt and interrupt handler implemented using asm code.
  27. In our FreeRTOS porting, we also allow FreeRTOS configuration variable
  28. ``configMAX_SYSCALL_INTERRUPT_PRIORITY`` which can be find in https://www.freertos.org/a00110.html.
  29. The ``configMAX_SYSCALL_INTERRUPT_PRIORITY`` should be set to be a
  30. absolute interrupt level range from 1 to (2^lvlbits-1) while ``lvlbits = min(nlbits, CLICINTCTLBITS)``.
  31. If you set configMAX_SYSCALL_INTERRUPT_PRIORITY to value above the accepted
  32. value range, it will use the max value.
  33. If you want to learn about how to use FreeRTOS APIs, you need to go to
  34. its website to learn the FreeRTOS documentation in its website.
  35. In Nuclei SDK, if you want to use **FreeRTOS** in your application, you need
  36. to add ``RTOS = FreeRTOS`` in your application Makefile.
  37. And in your application code, you need to do the following things:
  38. * Add FreeRTOS configuration file -> ``FreeRTOSConfig.h``
  39. * Include FreeRTOS header files
  40. Now we also support FreeRTOS SMP version, about SMP version, please refer to
  41. https://www.freertos.org/symmetric-multiprocessing-introduction.html , and we also
  42. provide freertos smpdemo example in our SDK, you can find it in
  43. ``application\freertos\smpdemo``.
  44. To use FreeRTOS SMP version for 2 Core SMP CPU, you need to add ``SMP = 2`` in your application Makefile.
  45. And also you need to make sure your application code is placed and run on shared memory which can be
  46. accessed by both CPUs. When ``SMP=2`` is specified, it will define extra requried macro called ``configNUMBER_OF_CORES``,
  47. for details, please check ``OS/FreeRTOS/build.mk``.
  48. .. note::
  49. * You can check the ``application\freertos\`` for freertos application reference
  50. * From Nuclei SDK 0.6.0, we introduced FreeRTOS SMP support, both Nuclei RV32 and RV64 processors are supported.
  51. * Current version of FreeRTOS used in Nuclei SDK is ``V11.1.0``
  52. * If you want to change the OS ticks per seconds, you can change the ``configTICK_RATE_HZ``
  53. defined in ``FreeRTOSConfig.h``
  54. More information about FreeRTOS get started, please click
  55. https://www.freertos.org/FreeRTOS-quick-start-guide.html
  56. .. _design_rtos_ucosii:
  57. UCOSII
  58. ------
  59. `UCOSII`_ a priority-based preemptive real-time kernel for microprocessors,
  60. written mostly in the programming language C. It is intended for use in embedded systems.
  61. In our UCOSII portable code, we are using ``SysTimer Interrupt`` as RTOS SysTick
  62. Interrupt, and using ``SysTimer Software Interrupt`` to do task switch.
  63. If you want to learn about ``UCOSII``, please click https://www.micrium.com/books/ucosii/
  64. We are using the opensource version of UC-OS2 source code from https://github.com/SiliconLabs/uC-OS2,
  65. with optimized code for Nuclei RISC-V processors.
  66. In Nuclei SDK, if you want to use **UCOSII** in your application, you need
  67. to add ``RTOS = UCOSII`` in your application Makefile.
  68. And in your application code, you need to do the following things:
  69. * Add UCOSII application configuration header file -> ``app_cfg.h`` and ``os_cfg.h``
  70. * Add application hook source file -> ``app_hooks.c``
  71. * Include UCOSII header files
  72. .. note::
  73. * You can check the ``application\ucosii\`` for ucosii application reference
  74. * The UCOS-II application configuration template files can also be found in
  75. https://github.com/SiliconLabs/uC-OS2/tree/master/Cfg/Template
  76. * Current version of UCOSII used in Nuclei SDK is ``V2.93.00``
  77. * If you want to change the OS ticks per seconds, you can change the ``OS_TICKS_PER_SEC``
  78. defined in ``os_cfg.h``
  79. .. warning::
  80. * For Nuclei SDK release > v0.2.2, the UCOSII source code is replaced using the
  81. version from https://github.com/SiliconLabs/uC-OS2/, and application development
  82. for UCOSII is also changed, the ``app_cfg.h``, ``os_cfg.h`` and ``app_hooks.c`` files
  83. are required in application source code.
  84. .. _design_rtos_rtthread:
  85. RT-Thread
  86. ---------
  87. `RT-Thread`_ was born in 2006, it is an open source, neutral,
  88. and community-based real-time operating system (RTOS).
  89. RT-Thread is mainly written in C language, easy to understand and easy
  90. to port(can be quickly port to a wide range of mainstream MCUs and module chips).
  91. It applies object-oriented programming methods to real-time system design,
  92. making the code elegant, structured, modular, and very tailorable.
  93. In our support for RT-Thread, we get the source code of RT-Thread from a project
  94. called `RT-Thread Nano`_, which only provide kernel code of RT-Thread, which is easy
  95. to be integrated with Nuclei SDK.
  96. In our RT-Thread portable code, we are using ``SysTimer Interrupt`` as RTOS SysTick
  97. Interrupt, and using ``SysTimer Software Interrupt`` to do task switch.
  98. And also the ``rt_hw_board_init`` function is implemented in our portable code.
  99. If you want to learn about ``RT-Thread``, please click:
  100. * For Chinese version, click https://www.rt-thread.org/document/site/
  101. * For English version, click https://github.com/RT-Thread/rt-thread#documentation
  102. In Nuclei SDK, if you want to use **RT-Thread** in your application, you need
  103. to add ``RTOS = RTThread`` in your application Makefile.
  104. And in your application code, you need to do the following things:
  105. * Add RT-Thread application configuration header file -> ``rtconfig.h``
  106. * Include RT-Thread header files
  107. * If you want to enable RT-Thread MSH feature, just add ``RTTHREAD_MSH := 1`` in
  108. your application Makefile.
  109. .. note::
  110. * You can check the ``application\rtthread\`` for rtthread application reference
  111. * In RT-Thread, the ``main`` function is created as a RT-Thread thread,
  112. so you don't need to do any OS initialization work, it is done before ``main``
  113. * We also provide good support directly through RT-Thread official repo,
  114. you can check Nuclei processor support for RT-Thread in `RT-Thread BSP For Nuclei`_.
  115. .. _design_rtos_threadx:
  116. ThreadX
  117. -------
  118. `Eclipse ThreadX`_ offers a vendor-neutral, open source, safety certified OS for real-time applications,
  119. all under a permissive license. It stands alone as the first and only RTOS with this unique blend of
  120. attributes to meet a wide range of needs that will benefit industry adopters, developers and end users alike.
  121. Microsoft has contributed the Azure RTOS technology to the Eclipse Foundation.
  122. With the Eclipse Foundation as its new home, Azure RTOS now becomes Eclipse ThreadX – an advanced embedded
  123. development suite including a small but powerful operating system that provides reliable, ultra-fast performance
  124. for resource-constrained devices.
  125. ThreadX is IEC 61508, IEC 62304, ISO 26262, and EN 50128 conformance certified by SGS-TÜV Saar.
  126. ThreadX has also achieved EAL4+ Common Criteria security certification.
  127. These certifications are a big differentiator, and are unprecedented in the industry.
  128. They are a game changer, as there are currently no open source RTOS's which have them.
  129. In our ThreadX portable code, we are using ``SysTimer Interrupt`` as RTOS SysTick
  130. Interrupt, and using ``SysTimer Software Interrupt`` to do task switch.
  131. If you want to learn about ``Eclipse ThreadX``, please click:
  132. * For introduction of Eclipse ThreadX, click https://eclipse-foundation.blog/2023/11/21/introducing-eclipse-threadx/
  133. * For ThreadX documentation, click https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/threadx/index.md
  134. In Nuclei SDK, if you want to use **ThreadX** in your application, you need
  135. to add ``RTOS = ThreadX`` in your application Makefile.
  136. And in your application code, you need to do the following things:
  137. * Add ThreadX application configuration header file -> ``tx_user.h``
  138. * Include ThreadX header files
  139. .. note::
  140. * You can check the ``application\threadx\`` for threadx application reference
  141. * Currently we only support single core version, the SMP version is not yet supported.
  142. .. _FreeRTOS: https://www.freertos.org/
  143. .. _UCOSII: https://www.micrium.com/
  144. .. _RT_Thread: https://www.rt-thread.org/
  145. .. _RT-Thread Nano: https://github.com/RT-Thread/rtthread-nano
  146. .. _Eclipse ThreadX: https://github.com/eclipse-threadx/threadx
  147. .. _RT-Thread BSP For Nuclei: https://github.com/RT-Thread/rt-thread/tree/master/bsp/nuclei/