]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/RTOS2/src/cmsis_os2_MigrationGuide.txt
CMSIS-Core(A): Enhanced documentation for cache access maintenance.
[cmsis] / CMSIS / DoxyGen / RTOS2 / src / cmsis_os2_MigrationGuide.txt
1
2
3 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
4 /**
5 \page os2MigrationGuide RTX Migration Guide
6
7 RTX5 supplies both API layers: CMSIS-RTOS v1 and CMSIS-RTOS v2. This allows a gradient transition from version 1 to 2. A
8 modified v1 header and a special v1 compatibility module enable existing code to run on a v2 implementation with almost no
9 modifications.
10
11 Only a few incompatibilities and limitations exist:
12 - Kernel startup\n
13   The function \c osKernelRunning has been deprecated. "main" was usually a running thread in v1 implementations, which is
14   not the case in v2 anymore. It was also possible to not even initialize and start the Kernel, but just to assume that
15   "main" was a running thread. Portable code would typically initialize the Kernel (\ref osKernelInitialize) and then start
16   the Kernel (\ref osKernelStart) or skip that part if \c osKernelRunning indicated that it is already running.\n
17   The example code below shows how to overcome this situation.
18 - The function \c osWait is deprecated.
19 - Error code incompatibility\n
20   CMSIS-RTOS v1 used two different error codes for invalid parameters: \c osErrorParameter and \c osErrorValue. The new
21   version only uses a common \ref osErrorParameter code. Therefore, code relying on osErrorValue is not compatible. The
22   following functions are affected:
23   - \ref osThreadSetPriority returns \ref osErrorParameter instead of osErrorValue when priority is out of range
24   - \ref osMemoryPoolFree (previously \c osPoolFree) returns \ref osErrorParameter instead of osErrorValue when block to be
25     returned is invalid
26 - The \ref osDelay return code has changed from osErrorTimeout to \ref osOK.
27
28 The level of migration depends on the project's phase in its life cycle:
29 - The \ref MigL1 "first level" of migration is to migrate to RTX5 without changing the API level.
30 - The \ref MigL2 "second level" in the transition is to use v2 API functions and v1 API functions in mixed variation.
31 - The \ref MigL3 "third level" is the full transition to the API v2. It is non-trivial and requires some additional
32   development effort to migrate all API v1 calls to v2.
33
34
35 \section MigL1 Level 1 Migration - Upgrade to RTX5 on API v1
36
37 Upgrade to RTX Version 5 from any 4.x version using the API v1 compatibility layer. Configure an existing project as follows:
38
39 - Open \b Manage \b Run-Time \b Environment window
40 - Expand \b CMSIS software component.
41 - Expand \b RTOS \b (API), uncheck \b Keil \b RTX, and select \b Keil \b RTX5.
42 - Expand \b RTOS2 \b (API) and select \b Keil \b RTX5.
43 - Resolve missing components.
44
45 \image html "RTX5_Migrate1.PNG" "Component Selection for RTX5"
46
47 - Click OK.
48 - Expand \b CMSIS group in the \b Project window:
49 - Open \b %RTX_Config.h and adapt the configuration to suit the application including (refer to \ref config_rtx5):
50   - System Configuration->Global Dynamic Memory size
51   - Kernel Tick Frequency
52   - Thread Configuration->Default Thread Stack size
53 - Rename function <tt>int main (void)</tt> to <tt>void app_main (void *arg)</tt>.
54 - Create a new function <tt>int main (void)</tt> which implements at least:
55   - System initialization and configuration
56   - Update SystemCoreClock
57   - Initialize CMSIS-RTOS kernel
58   - Creates new thread app_main
59   - Start RTOS scheduler                       
60
61 <b>Example - Application Main Thread</b>
62 \code
63 /* Renamed main() function */
64 void app_main (void const *argument) {
65   // contents of old "main"
66 }
67  
68 osThreadDef(app_main, osPriorityNormal, 1, 0);
69  
70 int main (void) {
71   // System Initialization
72   SystemCoreClockUpdate();
73   // ...
74   osKernelInitialize();
75   osThreadCreate(osThread(app_main), NULL);
76   osKernelStart();
77   for (;;);
78 }
79 \endcode
80
81 \note In RTOS API v1 all timings were specified in milliseconds. RTX5 defines all times in kernel ticks.
82 To match both it is recommended to set the Kernel Tick Frequency to 1000 Hz in the \ref systemConfig.
83
84 To validate the correct operation of your RTOS after migration you can temporarily integrate the \ref rtosValidation
85 component into your project.
86
87
88 \section MigL2 Level 2 Migration - Use API v2 and v1 alongside in RTX5
89
90 Implementing new features in your project is ideally done using the new API. Both API versions are offered in RTX5 and can
91 exist along-side.
92  
93 The component selection is identical to Migration Level 1.
94
95 Include "cmsis_os2.h" in all modules where access to API v2 functions is required.
96
97 \code
98 #include "cmsis_os.h"                   // ARM::CMSIS:RTOS:Keil RTX5
99 #include "cmsis_os2.h"                  // ARM::CMSIS:RTOS2:Keil RTX5
100 \endcode
101
102 The following snippet shows how threads - created with both API versions - live along-side:
103
104 \code
105 /*----------------------------------------------------------------------------
106  *      Thread 4 'phaseD': Phase D output   - API v2 thread
107  *---------------------------------------------------------------------------*/
108 void phaseD (void *argument) {
109   for (;;) {
110     osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever);    /* wait for an event flag 0x0001 */
111     Switch_On (LED_D);
112     signal_func(tid_phaseA);                                     /* call common signal function   */
113     Switch_Off(LED_D);
114   }
115 }
116  
117 /*----------------------------------------------------------------------------
118  *      Thread 5 'clock': Signal Clock  - API v1 thread
119  *---------------------------------------------------------------------------*/
120 void clock (void const *argument) {
121   for (;;) {
122     osSignalWait(0x0100, osWaitForever);    /*  Wait for event send by API v2 function osThreadFlagsSet() */
123     Switch_On (LED_CLK);
124     osDelay(80);                            /* delay ticks                    */
125     Switch_Off(LED_CLK);
126   }
127 }
128  
129 /* Define the API v1 thread */
130 osThreadDef(clock,  osPriorityNormal, 1, 0);
131  
132 /*----------------------------------------------------------------------------
133  *      Main: Initialize and start RTX Kernel
134  *---------------------------------------------------------------------------*/
135 void app_main (void *argument) {
136
137   ; //...
138   /* Create the API v2 thread */
139   tid_phaseD = osThreadNew(phaseD, NULL, NULL);
140   /* Create the API v1 thread */
141   tid_clock  = osThreadCreate(osThread(clock),  NULL);
142  
143   osThreadFlagsSet(tid_phaseA, 0x0001);          /* set signal to phaseA thread   */
144  
145   osDelay(osWaitForever);
146   while(1);
147 }
148 \endcode
149  
150 The full example "RTX5 Migration" is part of the CMSIS5 pack and available from the pack installer.
151
152
153 \section MigL3 Level 3 Migration - Full transition to API v2
154 Migrating fully to APIv2 reduces the overhead of the translation layer and simplifies the project.
155 There is some effort to replace and re-test all API Version 1 calls.
156 The following steps are recommended as a rough guide-line:
157 - Open Manage Run-Time Environment window:
158 - Expand CMSIS Software Component:
159 - Expand RTOS (API) Software Component and de-select Keil RTX5
160 - Click OK
161 - Exchange all occurrences of
162   \code
163   #include "cmsis_os.h"  
164   \endcode
165   with
166   \code
167   #include "cmsis_os2.h"  
168   \endcode
169 - Identify all references to the API v1 and replace with the appropriate calls in v2. You might want to use the Error List
170   window in uVision to identify the related code passages quickly. 
171
172 \note See \ref os2MigrationFunctions for details in differences.
173
174 Generally there are no longer os*Def macros to declare OS objects. 
175
176 \note
177 - Signal Events have been replaced. Use the functions listed under Thread Flags and Event Flags instead. 
178 - The Mail Queue RTOS v1 functions have been deprecated. Use the functionality of the Message Queue instead. Differences are
179   listed under \ref mig_msgQueue.
180 */
181