Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

237 rindas
10 KiB

  1. /*
  2. *********************************************************************************************************
  3. * uC/OS-II
  4. * The Real-Time Kernel
  5. *
  6. * Copyright 1992-2021 Silicon Laboratories Inc. www.silabs.com
  7. *
  8. * SPDX-License-Identifier: APACHE-2.0
  9. *
  10. * This software is subject to an open source license and is distributed by
  11. * Silicon Laboratories Inc. pursuant to the terms of the Apache License,
  12. * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0.
  13. *
  14. *********************************************************************************************************
  15. */
  16. /*
  17. *********************************************************************************************************
  18. *
  19. * ARMv7-M Port
  20. *
  21. * Filename : os_cpu.h
  22. * Version : V2.93.01
  23. *********************************************************************************************************
  24. * For : ARMv7-M Cortex-M
  25. * Mode : Thumb-2 ISA
  26. * Toolchain : IAR EWARM
  27. *********************************************************************************************************
  28. * Note(s) : (1) This port supports the ARM Cortex-M3, Cortex-M4 and Cortex-M7 architectures.
  29. * (2) It has been tested with the following Hardware Floating Point Unit.
  30. * (a) Single-precision: FPv4-SP-D16-M and FPv5-SP-D16-M
  31. * (b) Double-precision: FPv5-D16-M
  32. *********************************************************************************************************
  33. */
  34. #ifndef OS_CPU_H
  35. #define OS_CPU_H
  36. #ifdef OS_CPU_GLOBALS
  37. #define OS_CPU_EXT
  38. #else
  39. #define OS_CPU_EXT extern
  40. #endif
  41. /*
  42. *********************************************************************************************************
  43. * EXTERNAL C LANGUAGE LINKAGE
  44. *
  45. * Note(s) : (1) C++ compilers MUST 'extern'ally declare ALL C function prototypes & variable/object
  46. * declarations for correct C language linkage.
  47. *********************************************************************************************************
  48. */
  49. #ifdef __cplusplus
  50. extern "C" { /* See Note #1. */
  51. #endif
  52. /*
  53. *********************************************************************************************************
  54. * DEFINES
  55. *
  56. * Note(s) : (1) If using uC/CPU then 'cpu_cfg.h' has already this define in its template. The user will
  57. * only need to include 'cpu_cfg.h' in 'app_cfg.h'; otherwise, define CPU_CFG_KA_IPL_BOUNDARY
  58. * and CPU_CFG_NVIC_PRIO_BITS in 'app_cfg.h'
  59. *
  60. * (2) Since the port is using BASEPRI to separate kernel vs non-kernel aware ISR, please make sure
  61. * your external interrupt priorities are set accordingly. For example, if CPU_CFG_KA_IPL_BOUNDARY
  62. * is set to 4 then external interrupt priorities 4-15 will be kernel aware while priorities
  63. * 0-3 will be use as non-kernel aware.
  64. *
  65. * (3) Determines the interrupt programmable priority levels. This is normally specified in the
  66. * Microcontroller reference manual. 4-bits gives us 16 programmable priority levels.
  67. *
  68. * NVIC_IPRx
  69. * 7 0
  70. * +------------------+
  71. * | PRIO |
  72. * +------------------+
  73. *
  74. * Bits[7:4] Priority mask bits
  75. * Bits[3:0] Reserved
  76. *
  77. * In this example our CPU_CFG_NVIC_PRIO_BITS define should be set to 4 due to the processor
  78. * implementing only bits[7:4].
  79. *********************************************************************************************************
  80. */
  81. #ifndef OS_CPU_EXCEPT_STK_SIZE
  82. #define OS_CPU_EXCEPT_STK_SIZE 256u /* Default exception stack size is 256 OS_STK entries */
  83. #endif
  84. #ifdef __ARMVFP__
  85. #define OS_CPU_ARM_FP_EN 1u
  86. #else
  87. #define OS_CPU_ARM_FP_EN 0u
  88. #endif
  89. #ifndef CPU_CFG_KA_IPL_BOUNDARY
  90. #error "CPU_CFG_KA_IPL_BOUNDARY not #define'd in 'app_cfg.h' " /* See Note # 1 & 2 */
  91. #else
  92. #if (CPU_CFG_KA_IPL_BOUNDARY == 0u)
  93. #error "CPU_CFG_KA_IPL_BOUNDARY should be > 0 "
  94. #endif
  95. #endif
  96. #ifndef CPU_CFG_NVIC_PRIO_BITS
  97. #error "CPU_CFG_NVIC_PRIO_BITS not #define'd in 'app_cfg.h' " /* See Note # 3 */
  98. #else
  99. #if (CPU_CFG_KA_IPL_BOUNDARY >= (1u << CPU_CFG_NVIC_PRIO_BITS))
  100. #error "CPU_CFG_KA_IPL_BOUNDARY should not be set to higher than max programable priority level "
  101. #endif
  102. #endif
  103. /*
  104. *********************************************************************************************************
  105. * DATA TYPES
  106. * (Compiler Specific)
  107. *********************************************************************************************************
  108. */
  109. typedef unsigned char BOOLEAN;
  110. typedef unsigned char INT8U; /* Unsigned 8 bit quantity */
  111. typedef signed char INT8S; /* Signed 8 bit quantity */
  112. typedef unsigned short INT16U; /* Unsigned 16 bit quantity */
  113. typedef signed short INT16S; /* Signed 16 bit quantity */
  114. typedef unsigned int INT32U; /* Unsigned 32 bit quantity */
  115. typedef signed int INT32S; /* Signed 32 bit quantity */
  116. typedef float FP32; /* Single precision floating point */
  117. typedef double FP64; /* Double precision floating point */
  118. typedef unsigned int OS_STK; /* Each stack entry is 32-bit wide */
  119. typedef unsigned int OS_CPU_SR; /* Define size of CPU status register (PSR = 32 bits) */
  120. /*
  121. *********************************************************************************************************
  122. * Cortex-M
  123. * Critical Section Management
  124. *
  125. * Method #1: Disable/Enable interrupts using simple instructions. After critical section, interrupts
  126. * will be enabled even if they were disabled before entering the critical section.
  127. * NOT IMPLEMENTED
  128. *
  129. * Method #2: Disable/Enable interrupts by preserving the state of interrupts. In other words, if
  130. * interrupts were disabled before entering the critical section, they will be disabled when
  131. * leaving the critical section.
  132. * NOT IMPLEMENTED
  133. *
  134. * Method #3: Disable/Enable interrupts by preserving the state of interrupts. Generally speaking you
  135. * would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then
  136. * disable interrupts. 'cpu_sr' is allocated in all of uC/OS-II's functions that need to
  137. * disable interrupts. You would restore the interrupt disable state by copying back 'cpu_sr'
  138. * into the CPU's status register.
  139. *********************************************************************************************************
  140. */
  141. #define OS_CRITICAL_METHOD 3u
  142. #if OS_CRITICAL_METHOD == 3u
  143. /* Save current BASEPRI priority lvl for exception... */
  144. /* .. and set BASEPRI to CPU_CFG_KA_IPL_BOUNDARY */
  145. #define OS_ENTER_CRITICAL() do { cpu_sr = OS_CPU_SR_Save(CPU_CFG_KA_IPL_BOUNDARY << (8u - CPU_CFG_NVIC_PRIO_BITS));} while (0)
  146. /* Restore CPU BASEPRI priority level. */
  147. #define OS_EXIT_CRITICAL() do { OS_CPU_SR_Restore(cpu_sr);} while (0)
  148. #endif
  149. /*
  150. *********************************************************************************************************
  151. * Cortex-M Miscellaneous
  152. *********************************************************************************************************
  153. */
  154. #define OS_STK_GROWTH 1u /* Stack grows from HIGH to LOW memory on ARM */
  155. #define OS_TASK_SW() OSCtxSw()
  156. /*
  157. *********************************************************************************************************
  158. * GLOBAL VARIABLES
  159. *********************************************************************************************************
  160. */
  161. OS_CPU_EXT OS_STK OS_CPU_ExceptStk[OS_CPU_EXCEPT_STK_SIZE];
  162. OS_CPU_EXT OS_STK *OS_CPU_ExceptStkBase;
  163. /*
  164. *********************************************************************************************************
  165. * FUNCTION PROTOTYPES
  166. *********************************************************************************************************
  167. */
  168. #if OS_CRITICAL_METHOD == 3u /* See OS_CPU_A.ASM */
  169. OS_CPU_SR OS_CPU_SR_Save (OS_CPU_SR new_basepri);
  170. void OS_CPU_SR_Restore (OS_CPU_SR cpu_sr);
  171. #endif
  172. void OSCtxSw (void);
  173. void OSIntCtxSw (void);
  174. void OSStartHighRdy (void);
  175. /* See OS_CPU_C.C */
  176. void OS_CPU_SysTickInit (INT32U cnts);
  177. void OS_CPU_SysTickInitFreq (INT32U cpu_freq);
  178. void OS_CPU_SysTickHandler (void);
  179. void OS_CPU_PendSVHandler (void);
  180. #if (OS_CPU_ARM_FP_EN > 0u)
  181. void OS_CPU_FP_Reg_Push (OS_STK *stkPtr);
  182. void OS_CPU_FP_Reg_Pop (OS_STK *stkPtr);
  183. #endif
  184. /*
  185. *********************************************************************************************************
  186. * EXTERNAL C LANGUAGE LINKAGE END
  187. *********************************************************************************************************
  188. */
  189. #ifdef __cplusplus
  190. } /* End of 'extern'al C lang linkage. */
  191. #endif
  192. /*
  193. *********************************************************************************************************
  194. * MODULE END
  195. *********************************************************************************************************
  196. */
  197. #endif