硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2958|回复: 1
收起左侧

[ThreadX全家桶] ThreadX的OSEK封装层发布,方便汽车系统软件开发

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106938
QQ
发表于 2021-6-3 13:25:30 | 显示全部楼层 |阅读模式
threadx/utility/rtos_compatibility_layers/OSEK at master · azure-rtos/threadx (github.com)

1.png

  1. Azure RTOS' OSEK compatibility layer for ThreadX

  2. 1. Installation

  3. The OSEK compatibility layer for ThreadX is comprised of two files tx_osek.c and os.h
  4. which should be copied at a suitable location for inclusion into a ThreadX project. Refer
  5. to the ThreadX readme file for installation instructions for ThreadX.


  6. 2. Building

  7. Building the OSEK layer should be as simple as including the tx_osek.c and os.h file to
  8. an existing ThreadX project, making sure that the location of the os.h header is in the
  9. include paths. The OSEK layer requires that the ThreadX headers such as tx_api.h are
  10. reachable in the include paths as well.


  11. 3. Initialization

  12. The OSEK layer initialization can be performed either from the tx_application_define()
  13. during the ThreadX initialization or from a running ThreadX thread. It is strongly
  14. recommended to initialize and start the OSEK layer as soon as possible. Once started
  15. other ThreadX tasks and API call should not be used to prevent resource conflicts with
  16. OSEK.

  17. The OSEK initialization has three phases. First the osek internal initialization which
  18. must be performed before calling any other OSEK API functions, by calling
  19. osek_initialize() passing it a pointer to the OSEK memory and the application structure.
  20. The size of the memory region passed to osek_initialize() must be set at compile time
  21. by adjusting the OSEK_MEMORY_SIZE define in osek_uart.h.

  22. After having initialized the OSEK internally, the application can now create OSEK objects
  23. and link or assigned them as needed. See below for a list of object creation functions.

  24. Finally, after all the objects are created and configured the OSEK layer can be started
  25. using StartOS(). Once started it is no longer possible to create or change any OSEK
  26. objects.


  27. 4. OSEK shutdown and restart

  28. The OSEK layer can be shutdown using the standard OSEK API ShutdownOS(). As an extension
  29. to the OSEK layer offers an osek_cleanup() function which can be used to cleanup and
  30. reset the OSEK layer allowing a subsequent restart without having to reset the CPU. This
  31. is primarily intended for testing.


  32. 5. Hooks

  33. The various hook routines available within OSEK can be set during initialization by
  34. setting the various handler members of the APPLICATION_INFO structure passed to
  35. osek_initialize(). See the OSEK documentation for the signature of those hook functions.

  36. For example:

  37.     app.error_hook_handler = ErrorHook;
  38.     app.startup_hook_handler = StartupHook;
  39.     app.shutdown_hook_handler = ShutdownHook;
  40.     app.pretask_hook_handler = PreTaskHook;
  41.     app.posttask_hook_handler = PostTaskHook;


  42. 6. Interrupts

  43. As per the OSEK specification, category 1 ISRs are not affected by the OSEK layer
  44. execution and are not allowed to call any of the OSEK API. Those ISR are configured and
  45. processed just like any other interrupts under ThreadX. Category 2 ISR have to be
  46. created using CreateISR() as well as being registered and enable like a category 1 ISR.
  47. In the body of the low level ISR process_ISR2() must be called with the return value of
  48. the corresponding CreateISR() in argument. This will instruct the OSEK layer to schedule
  49. the category 2 ISR as soon as possible.

  50. A category 2 ISR is made of two handlers, the one that process the hardware interrupt
  51. and the OSEK ISR body.

  52. To define a category 2 ISR body use the standard ISR() macro as follows:


  53. ISRType DemoISR; /* ISR declaration. */

  54. /* ISR body definition. */
  55. ISR(DemoISR)
  56. {
  57.     /* ISR body. */
  58. }


  59. This ISR should be created during system initialization:


  60. DemoISR = CreateISR("Demo ISR", ISREntry(DemoISR), CATEGORY2, 1024);


  61. Once properly initialized the ISR can be triggered by calling process_ISR2 with the ISR
  62. name in argument from within the hardware ISR handler.


  63. void demo_isr_hardware_handler(void)
  64. {
  65.     /* Call OSEK to process the ISR. */
  66.     process_ISR2(DemoISR);
  67. }


  68. 7. Implementation specific information

  69. Since OSEK requires a static allocation methodology, the number of available OSEK object
  70. has to be limited at compile time. By default the following limits apply:

  71. Maximum number of tasks: 32
  72. Maximum number of internal resources: 8
  73. Maximum number of external resources: 16
  74. Maximum number of alarms: 16
  75. Maximum number of counters: 16
  76. Maximum number of events: 32
  77. Maximum number of category 2 ISRs: 8
  78. Minimum OSEK task priority: 0
  79. Maximum OSEK task priority: 23
  80. Maximum alarm counter value: 0x7FFFFFFFUL
  81. Maximum task activation count: 8

  82. 8. Supported OSEK API

  83. The ThreadX OSEK layer supports all the mandatory APIs specified in version 2.2.3 of
  84. the OSEK/VDK Operating System Specification.

  85. Summary of the supported API, see the OSEK specification and tx_osek.c for the full
  86. details of each API.

  87. TASK MANAGEMENT

  88. DeclareTask
  89. ActivateTask
  90. TerminateTask
  91. ChainTask
  92. Schedule
  93. GetTaskID
  94. GetTaskState

  95. INTERRUPT HANDLING

  96. EnableAllInterrupts
  97. DisableAllInterrupts
  98. ResumeAllInterrupts
  99. SuspendAllInterrupts
  100. ResumeOSInterrupts
  101. SuspendOSInterrupts

  102. RESOURCE MANAGEMENT

  103. DeclareResource
  104. GetResource
  105. ReleaseResource

  106. EVENT CONTROL

  107. DeclareEvent
  108. SetEvent
  109. ClearEvent
  110. GetEvent
  111. WaitEvent

  112. ALARMS

  113. DeclareAlarm
  114. GetAlarmBase
  115. GetAlarm
  116. SetRelAlarm
  117. SetAbsAlarm
  118. CancelAlarm

  119. EXECUTION CONTROL

  120. GetActiveApplicationMode
  121. StartOS
  122. ShutdownOS

  123. Hook Routines

  124. ErrorHook
  125. PreTaskHook
  126. PostTaskHook
  127. StartupHook
  128. ShutdownHook

  129. 9. Object creation API

  130. The various object creation and registration functions are as follows. See tx_osek.c for a
  131. detailed description of each function.

  132. ----
  133. CreateTask – Creates an OSEK task, the task is returned if successful.

  134.     TaskType CreateTask(CHAR *name,
  135.                         void(*entry_function)(),
  136.                         UINT priority,
  137.                         UINT max_activation,
  138.                         ULONG stack_size,
  139.                         SCHEDULE policy,
  140.                         AUTOSTART start,
  141.                         UINT type,
  142.                         AppModeType mode);


  143. ----
  144. CreateResource - Creates an OSEK resource, the resource is returned if successful.

  145.     ResourceType CreateResource(const CHAR *name,
  146.                                 StatusType type,
  147.                                 ResourceType linked_res);


  148. ----
  149. RegisterTasktoResource - Registers a task to a resource. The resource will be accessible
  150. by the registered task.

  151.     StatusType RegisterTasktoResource(ResourceType Resource,
  152.                                       TaskType TaskID);


  153. ----
  154. CreateEvent - Creates an event, the created event is returned if successful. Note that
  155. per the OSEK specification an absolute maximum of 32 events can be created.

  156.     EventMaskType CreateEvent(void);


  157. ----
  158. RegisterEventtoTask - Register an event to a task. The event is now usable from that
  159. task. Note that an event can only be registered to a single task.

  160.     StatusType RegisterEventtoTask(EventType eventid,
  161.                                    TaskType TaskID);


  162. ----
  163. CreateISR - Creates an ISR.

  164.     ISRType CreateISR(const CHAR *name,
  165.                       void(*entry_function)(),
  166.                       UINT category,
  167.                       ULONG stack_size);


  168. ----
  169. RegisterISRtoResource - Register an ISR to a resource. Note that ISR cannot be registered
  170. to category 1 ISRS.

  171.     StatusType RegisterISRtoResource(ResourceType Resource,
  172.                                      ISRType ISRID);


  173. ----
  174. CreateCounter - Creates a new counter.

  175.     CounterType CreateCounter(CHAR *name,
  176.                               TickType max_allowed_value,
  177.                               TickType ticks_per_base,
  178.                               TickType min_cycle,
  179.                               TickType start_value);

  180. ----
  181. DefineSystemCounter - Assign a counter to be used as the system counter.

  182.     StatusType DefineSystemCounter(CounterType cntr);

  183. ---
  184. CreateAlarm - Creates an alarm.

  185. AlarmType CreateAlarm(CHAR *name,
  186.                       CounterType cntr,
  187.                       UINT action,
  188.                       ULONG events,
  189.                       TaskType task,
  190.                       void (*callback)(),
  191.                       UINT Startup, TickType Alarmtime,
  192.                       TickType Cycle);
复制代码


回复

使用道具 举报

6

主题

640

回帖

658

积分

金牌会员

积分
658
QQ
发表于 2021-6-3 16:30:58 | 显示全部楼层
跟着大佬一起学习
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-11 05:26 , Processed in 0.248123 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表