RTI Connext Micro  Version 2.4.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
osapi_porting.h
Go to the documentation of this file.
1 /*
2  * FILE: osapi_porting.h - Porting Guide
3  *
4  * Copyright 2012-2014 Real-Time Innovations, Inc.
5  *
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  *
11  * Modification History
12  * --------------------
13  * 22mar14,tk Written
14  * 12mar12,tk Written
15  */
16 #ifndef osapi_porting_h
17 #define osapi_porting_h
18 
19 /*e \file
20  * \brief Porting Guide
21  */
22 /*e \addtogroup OSAPIUserManuals_PortingModule
23  */
24 
25 /*e \defgroup OSAPIPortingIntroClass Introduction
26  \ingroup OSAPIUserManuals_PortingModule
27 
28  \details
29 
30  \rtime has been engineered for reasonable portability to platforms and
31  environments which RTI does not have access to. This porting
32  guide describes the features required by \rtime to run.
33 
34  The source tree shipped with \rtime is identical to the development tree
35  used by RTI. However, the internal file structure has been modified to
36  make it easier to import and compile the source as part of a project.
37 
38  \rtime uses an abstraction layer to support running on a number
39  of platforms. The abstraction layer, OSAPI, is an abstraction of
40  functionality typically found in one or more of the following
41  libraries and services:
42 
43  <ul>
44  <li> Operating System calls
45  <li> Device drivers
46  <li> Standard C library
47  </ul>
48 
49  The OSAPI module is designed to be relatively easy to move to a new
50  platform. All functionality, with the exception of NETIO (which must be
51  ported) is contained within this single module, even though the functionality
52  typically spans different libraries. It should be noted that although
53  some functions may not seem relevant on a particular platform, they must
54  still be implemented, as they are used by other modules. For example,
55  the port running on Stellaris with no OS support still needs to implement
56  a threading model.
57 
58  Please note that the OSAPI module is not designed to be a general purpose
59  abstraction layer; its sole purpose is to support the execution of \rtime.
60 
61  Before porting the OSAPI module, you are expected to be familiar with
62  general OS concepts, the standard C library, and embedded systems. This
63  guide covers the following topics:
64 
65  <ul>
66  <li> \ref OSAPIPortingConfigClass
67  <li> \ref OSAPIModuleHeap
68  <li> \ref OSAPIPortingMutexClass
69  <li> \ref OSAPIPortingSemaphoreClass
70  <li> \ref OSAPIPortingProcessClass
71  <li> \ref OSAPIPortingStdioClass
72  <li> \ref OSAPIPortingSystemClass
73  <li> \ref OSAPIPortingThreadClass
74  </ul>
75 
76  The directory structure for the OS API module is as follows:
77 
78  <ul>
79  <li> include/osapi/
80  <li> srcC/osapi/common/
81  <ul>
82  <li>/<platform>/<file>.c
83  </ul>
84  </ul>
85 
86  The 'include' directory contains the external interfaces, those that are
87  assumed by other modules. The only files that may need modification in the
88  include directory are files ending in _impl.h and config.h.
89 
90  The srcC directory contains a sub-directory `common` which contains source
91  code that is independent of any specific OS, but depends on functions
92  implemented by exactly one of the other sub-modules, such as posix or
93  windows.
94 
95  NOTE: It is <em> not </em> recommended to modify source files shipped with
96  \rtime. Instead if it is desired to start with code supplied by RTI
97  it is recommended to <em> copy </em> the corresponding sub-directory,
98  for example posix, and rename it. This way it is easier to upgrade \rtime
99  while keeping existing ports.
100  */
101 
102 /*e \defgroup OSAPIPortingConfigClass Configuration files
103  \ingroup OSAPIUserManuals_PortingModule
104 
105  The include/osapi/osapi_config.h file contains platform-specific settings
106  used by OSAPI and other modules. A new platform needs its settings defined
107  there. Please refer to the existing file for details.
108 
109  It should be noted that \rtime does not currently use auto-detection
110  programs to detect the host and target build environment. \rtime relies
111  on predefined macros to determine the target environment. If \rtime
112  cannot determine the target environment it is necessary to manually
113  configure the target environment in osapi_config.
114 */
115 
116 /*e \defgroup OSAPIModuleHeap Heap Porting Guide
117  * \ingroup OSAPIUserManuals_PortingModule
118  *
119  * \details
120  *
121  * \rtime uses the heap to allocate memory for internal data-structures. With
122  * a few exceptions, \rtime does _not_ return memory to the heap. Instead,
123  * \rtime uses internal pools to quickly allocate and free memory for specific
124  * types. Only the initial memory is allocated directly from the heap.
125  * The following functions must be ported:
126  *
127  * <ul>
128  * <li> \ref OSAPI_Heap_allocate
129  * <li> \ref OSAPI_Heap_free
130  * </ul>
131  *
132  * Please refer to the \ref OSAPI_HeapClass API for definition of the behavior.
133  * The available source code contains implementation in the file:
134  *
135  * srcC/osapi/<platform>/Heap.c
136  *
137  */
138 
139  /*e \defgroup OSAPIPortingMutexClass Mutex Porting Guide
140  * \ingroup OSAPIUserManuals_PortingModule
141  *
142  * \details
143  *
144  * \rtime relies on mutex support to protect internal data-structures from
145  * corruption when accessed from multiple threads.
146  *
147  * The following functions must be ported:
148  *
149  * <ul>
150  * <li> \ref OSAPI_Mutex_new
151  * <li> \ref OSAPI_Mutex_delete
152  * <li> \ref OSAPI_Mutex_take
153  * <li> \ref OSAPI_Mutex_give
154  * </ul>
155  *
156  * Please refer to the \ref OSAPI_MutexClass API for definition of the behavior.
157  * The available source code contains implementation in the file:
158  *
159  * srcC/osapi/<platform>/Mutex.c
160  */
161 
162  /*e \defgroup OSAPIPortingSemaphoreClass Semaphore Porting Guide
163  * \ingroup OSAPIUserManuals_PortingModule
164  *
165  * \details
166  *
167  * \rtime relies on semaphore support for thread control. If \rtime is running
168  * on a non pre-emptive operating system with no support for IPC and
169  * thread synchronization, it is possible to implement these functions as
170  * no-ops. Please refer to \ref OSAPIPortingThreadClass for details regarding
171  * threading.
172  *
173  * The following functions must be ported:
174  *
175  * <ul>
176  * <li> \ref OSAPI_Semaphore_new
177  * <li> \ref OSAPI_Semaphore_delete
178  * <li> \ref OSAPI_Semaphore_take
179  * <li> \ref OSAPI_Semaphore_give
180  * </ul>
181  *
182  * Please refer to the \ref OSAPI_SemaphoreClass API for definition of the
183  * behavior. The available source code contains implementation in the file:
184  *
185  * srcC/osapi/<platform>/Semaphore.c
186  */
187 
188  /*e \defgroup OSAPIPortingProcessClass Process Porting Guide
189  * \ingroup OSAPIUserManuals_PortingModule
190  *
191  * \details
192  *
193  * \rtime only uses the process API to retrieve a unique ID for the
194  * applications.
195  *
196  * The following functions must be ported:
197  *
198  * <ul>
199  * <li> \ref OSAPI_Process_getpid
200  * </ul>
201  *
202  * Please refer to the \ref OSAPI_Process_getpid API for definition of the
203  * behavior. The available source code contains implementation in the file:
204  *
205  * srcC/osapi/<platform>/Process.c
206  */
207 
208  /*e \defgroup OSAPIPortingStdioClass Stdio Porting Guide
209  * \ingroup OSAPIUserManuals_PortingModule
210  *
211  * \details
212  *
213  * \rtime uses the stdio functions for logging purposes.
214  *
215  * The following functions must be ported:
216  *
217  * <ul>
218  * <li> \ref OSAPI_Stdio_puts
219  * <li> \ref OSAPI_Stdio_printf
220  * <li> \ref OSAPI_Stdio_snprintf
221  * <li> \ref OSAPI_Stdio_vsnprintf
222  * </ul>
223  */
224 
225  /*e \defgroup OSAPIPortingSystemClass System Porting Guide
226  * \ingroup OSAPIUserManuals_PortingModule
227  *
228  * \details
229  *
230  * The system API consists of functions which are more related to the
231  * hardware on which \rtime is running than on the operating system. As of
232  * \rtime 2.3.1 the system API is implemented as an interface as opposed
233  * to the previous pure function implementation. This change makes it easier
234  * to adapt \rtime to different hardware platforms without having to write a
235  * new port.
236  *
237  * The system interface is defined in OSAPI_SystemI, and a port must implement
238  * all the methods in this structure. In addition, the function
239  * \ref OSAPI_System_get_native_interface must be implemented. This function
240  * must return the system interface for the port (called the native system
241  * interface).
242  *
243  * The semantics for the methods in the interface are exactly as defined
244  * by the corresponding system function. For example, the method
245  * \ref OSAPI_SystemI::get_time must behave exactly as that described by
246  * OSAPI_System_get_time.
247  *
248  * The following system interface methods must be implemented in the
249  * OSAPI_SystemI structure:
250  *
251  * <ul>
252  * <li> \ref OSAPI_SystemI::get_timer_resolution
253  * <li> \ref OSAPI_SystemI::get_time
254  * <li> \ref OSAPI_SystemI::start_timer
255  * <li> \ref OSAPI_SystemI::stop_timer
256  * <li> \ref OSAPI_SystemI::generate_uuid
257  * <li> \ref OSAPI_SystemI::get_hostname
258  * <li> \ref OSAPI_SystemI::initialize
259  * <li> \ref OSAPI_SystemI::finalize
260  * </ul>
261  *
262  *
263  * Please refer to the \ref OSAPI_SystemClass API for definition of the
264  * behavior. The available source code contains implementation in the file:
265  *
266  * srcC/osapi/<platform>/System.c
267  *
268  * \defgroup OSAPIPortingSystemClassUpgrade Migrating a 2.2.x port to 2.3.x
269  * \ingroup OSAPIPortingSystemClass
270 
271  In \rtime 2.3.x changes where made to how the system API is
272  implemented. Because of these changes existing ports must be updated, and
273  this section describes how to make a \rtime 2.2.x port compatible with \rtime
274  2.3.x.
275 
276  If you have ported \rtime 2.2.x the following steps will make it compatible
277  with version 2.3.x:
278 
279  <ul>
280  <li> Rename the following functions and make them private to your
281  source code. For example, rename OSAPI_System_get_time
282  to OSAPI_MyPortSystem_get_time etc.
283  <ul>
284  <li> \ref OSAPI_System_get_time
285  <li> \ref OSAPI_System_get_timer_resolution
286  <li> \ref OSAPI_System_start_timer
287  <li> \ref OSAPI_System_stop_timer
288  <li> \ref OSAPI_System_generate_uuid
289  </ul>
290  <li> Implement the following new methods.
291  <ul>
292  <li> \ref OSAPI_SystemI::get_hostname
293  <li> \ref OSAPI_SystemI::initialize
294  <li> \ref OSAPI_SystemI::finalize
295  </ul>
296  <li> Create a system structure for your port using the following
297  template:
298  \code
299  struct OSAPI_MyPortSystem
300  {
301  struct OSAPI_System _parent;
302 
303  Your system variable
304  };
305 
306  static struct OSAPI_MyPortSystem OSAPI_System_g;
307 
308  /* OSAPI_System_gv_system is a global system variable used by the
309  * generic system API. Thus, the name must be exactly as
310  * shown here.
311  */
312  struct OSAPI_System * OSAPI_System_gv_system = &OSAPI_System_g._parent;
313 
314  \endcode
315  <li> Implement \ref OSAPI_System_get_native_interface method and fill
316  the OSAPI_SystemI structure with all the system methods.
317  </ul>
318 */
319 
320  /*e \defgroup OSAPIPortingThreadClass Thread Porting Guide
321  * \ingroup OSAPIUserManuals_PortingModule
322  *
323  * \details
324  *
325  * The thread API is used by \rtime to create threads. Currently only the
326  * UDP transport uses threads and it is a goal to keep the generic \rtime
327  * core library free of threads. Thus, if \rtime is ported to an environment
328  * with no thread support the thread API can be stubbed out. However, note that
329  * the UDP transport must be ported accordingly in this case; that is all
330  * thread code must be removed and replaced with code appropriate for the
331  * environment.
332  *
333  * The following functions must be ported:
334  *
335  * <ul>
336  * <li> \ref OSAPI_Thread_create
337  * <li> \ref OSAPI_Thread_sleep
338  * </ul>
339  *
340  * Please refer to the \ref OSAPI_ThreadClass API for definition of the
341  * behavior. The available source code contains implementation in the file:
342  *
343  * srcC/osapi/<platform>/Thread.c
344  */
345 
346 #endif /* osapi_porting_h */

RTI Connext Micro Version 2.4.1.0 Copyright © Thu Nov 20 2014 Real-Time Innovations, Inc