傻大方


首页 > 知识库 > >

移植|移植μCOSII中英文翻译资料( 五 )


按关键词阅读: 移植 COSII 资料 翻译 中英文



38、ts*/ #define OS_STK_GROWTH 1 /* Define stack growth: 1 = Down, 0 = Up*/ (4)#define OS_TASK_SW() ? OS_CPU.H, Compiler Specific Data Types Because different microprocessors have different word length, the port of C/OS-II includes a series of type definitions that ensures portability. Specifically, C/O 。

39、S-IIs code never makes use of Cs short, int and, long data types because they are inherently non-portable. Instead, I defined integer data types that are both portable and intuitive The INT16U data type, for example, always represents a 16-bit unsigned integer. C/OS-II and your application code can。

40、now assume that the range of values for variables declared with this type is from 0 to 65535. A C/OS-II port to a 32-bit processor could mean that an INT16U is actually declared as an unsigned short instead of an unsigned int. Where C/OS-II is concerned, however, it still deals with an INT16U.You mu 。

41、st tell C/OS-II the data type of a tasks stack. This is done by declaring the proper C data type for OS_STK. If stack elements on your processor are 32-bit and your compiler documentation specify that an int is 32-bit then, you would declare OS_STK as being of type unsigned int. All task stacks MUST 。

42、 be declared using OS_STK as its data type.All you have to do is to consult the compilers manual and find the standard C data types that corresponds to the types expected by C/OS-II.OS_CPU.H, OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL()C/OS-II like all real-time kernels need to disable interrupts in o 。

43、rder to access critical sections of code, and re-enable interrupts when done. This allows C/OS-II to protect critical code from being entered simultaneously from either multiple tasks or Interrupt Service Routines (ISRS). Every processor generally provide instructions to disable/enable interrupts an 。

44、d your C compiler must have a mechanism to perform these operations directly from C. Some compilers will allow you to insert in-line assembly language statements in your C source code. This makes it quite easy to insert processor instructions to enable and disable interrupts. Other compilers will ac 。

45、tually contain language extensions to enable and disable interrupts directly from C. To hide the implementation method chosen by the compiler manufacturer, C/OS-II defines two macros to disable and enable interrupts: OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL(), respectivelyT1.C/OS-IIs critical sectio 。

46、ns are wrapped with OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() as shown below:C/OS-II Service FunctionOS_ENTER_CRITICAL();
/* C/OS-II critical code section */OS_EXIT_CRITICAL();
T1Method #1:.The first and simplest way to implement these two macros is to invoke the processor instruction to disable int 。

47、errupts for OS_ENTER_CRITICAL() and the enable interrupts instruction for OS_EXIT_CRITICAL(). There is, however, a little problem with this scenario. If you called the C/OS-II function with interrupts disabled then, upon return from C/OS-II, interrupts would be enabled! If you had interrupts disable 。

48、d, you may have wanted them to be disabled upon return from the C/OS-II function. In this case, the above implementation would not be adequate.Method #2:The second way to implement OS_ENTER_CRITICAL() is to save the interrupt disable status onto the stack and then, disable interrupts. OS_EXIT_CRITIC 。

49、AL() would simply be implemented by restoring the interrupt status from the stack. Using this scheme, if you called a C/OS-II service with either interrupts enabled or disabled then, the status would be preserved across the call.Your application can use OS_ENTER_CRITICAL()and OS_EXIT_CRITICAL() to a 。

50、lso protect critical sections of code. Be careful, however, because your application will crash if you have interrupts disabled before calling a service such as OSTimeDly(). This will happen because the task will be suspended until time expires but, because interrupts are disabled, you would never s 。

51、ervice the tick interrupt! Obviously, all the PEND calls are also subject to this problem so, be careful. As a general rule, you should always call C/OS-II services with interrupts enabled! OS_CPU.H, OS_STK_GROWTHThe stack on most microprocessors and microcontrollers grows from high-memory to low-me 。

52、mory. There are, however, some processors that work the other way around. C/OS-II has been designed to be able to handle either flavor. This is accomplished by specifying to C/OS-II which way the stack grows through the configuration constant OS_STK_GROWTH as shown below:Set OS_STK_GROWTH to 0 for L 。

53、ow to High memory stack growth.Set OS_STK_GROWTH to 1 for High to Low memory stack growth. OS_CPU.H, OS_TASK_SW()OS_TASK_SW() is a macro that is invoked when C/OS-II switches from a low-priority task to the highest-priority task. OS_TASK_SW() is always called from task level code. Another mechanism, 。


来源:(未知)

【学习资料】网址:/a/2021/0406/0021864430.html

标题:移植|移植μCOSII中英文翻译资料( 五 )


上一篇:2021|2021年公司办公室文员办公室实习报告范文

下一篇:农村信用社|某农村信用社信息科技风险管理经验交流