From Java4c





OS-independent programming

Some programmers work for their project. It may be running on a special hardware with a special operation system, mostly a RTOS (Real Time Operation System). The tests are executed at the target hardware - reality tests. Thus the thought is C is not C, any target system needs its own slang (dialect).

What is missing? Compilation of the sources with a proper Integrated Development Environment (IDE). On the PCs, there are some good IDEs, such as Eclipse, Microsoft Visual Studio etc. Mostly, the IDEs for a special hardware are good, but not so good like PC-platform-tools.

What is also missing? Functional testing the algorithm. It isn't a real-time test. But it may be essential.

What is the effort? The algorithm in C need to compile in a PC-environment. It should be able to test, not in real-time, maybe only in one thread or more. For this reason the OS-functionality should be able to use at the test-environment.

What is the result:

  • Well functional tested algorithms
  • Faster writing, reorganization, optimizing and gardening of sources, because the PC-platform

is able to use for faster work.

  • Better sources.

The tests on the target-platform are reduced to test the real platform problems, not to test the algorithm basically.

Need of special Operation System capabilities

Most of the Operation Systems are similar in a large way of thinking. All of these support multi-threading, with mutex etc. Most of them have a file system in a adequate kind etc.

The differences are: They should be support the hardware platform with different processors, different equipment in RAM, ROM, different I/O. But the user programming shouldn't consider all of them so far. The user programming should be realized in a more abstract shell. This means the RTOS should be proper for the hardware, but it should not have to much special features for the user programming. It may be useful only for driver or interrupt-level-programming.

Conclusion: The user programming should use unified interfaces to the operation system.

OSAL-Level in the CRuntimeJavalike

Programming in Java is OS-independent in the first way. In that mind, the CRuntimeJavalike needs a Operation System Adaption Level (OSAL).

The given OSAL is layered closed to a not-only Java-like-programming. It supports standard C functionality. The typical Java-like functions like ThreadJc based on this OSAL-interface.

A first idea in the past was to introduce the OSAL-level in the OS-oriented classes like ThreadJc, ObjectJc with its synchronized_ObjectJc-methods etc. But a Java-independent definition of the OSAL-interface provides some use-cases for the non-java-like-oriented programming, too. So it is implemented independently from Java-like-C-classes.

Simple-C in OSAL

The OSAL-component contains Headerfiles and Implementations, which contain simple C-functionality. They are independent of compiler, platform and operation systems. That header are contained in the CRuntimeJavalike-package (see [launchpad.net/zbnf/srcjava.zbnf]) in the subdir include/Fwc/*.h:

  • [include/Fwc/fw_Exception.h]: Exception handling for C and C++ inclusive Stacktrace-Mechanism. In C a longjmp is used to throw. (longjmp.h is defined in the old Standards of C and in C99 too).
  • [include/Fwc/fw_Formatter.h]: Declaration of methods for formatting Strings. It include time-formattings. It is similar to sprintf.
  • [include/Fwc/fw_MemC.h]: Definition of a struct MemC with pointer and its size. Some macros to handle with pointer. Some function prototypes for MemC-handling.
  • [include/Fwc/fw_Readline.h]: Support of reading lines from a file. A line can be terminated with 0d, 0a or any combination (Windows, Unix, Mac-conventions all in one). The os_file.h is used as interface to read a file.
  • [include/Fwc/fw_SimpleC.h]: Some basicly simple macros and function declarations.
  • [include/Fwc/fw_String.h]: Basic functions for String storing in a struct StringJc. It is the alternative to zero-terminated C-Strings. The pointer and the length is stored. The basic functions are a bridge between 0-terminated C-strings and StringJc-referenced strings.
  • [include/Fwc/fw_ThreadContext.h]: The ThreadContext is managed in the OSAL, but its struct is defined here.
  • [include/Fwc/fw_timeconversions.h]: struct and funtion declarations for time conversions: A timestamp should be stored internally in form of currently seconds and microseconds after a start time. The conversion to a human readable time should be done only for presentation. The routines support the conversion.
  • [include/Fwc/fw_Va_list.h]: An appreciation to the < stdarg.h> concept. The value as new: Any argument-type of a variable argument list is described with one char in a char*-string with one char. With the knowledge of the correct type any users function can be use the variable argument more correctly. Usual any other information should be necessary, for example the format-String of sprintf. This header and functions are used in fw_formatter.h

The C-files are named adequate to the header files. They are located in the same component CRuntimeJavalike in the directory source/Fwc. This base routines can be used for implementation of special os-adaption. Nevertheless for example the exception handling should not be used for the osal-level, because usage of exception handling is a decision of applications. It is offered here, but not used. The OSAL-adaption should be written simple and easy.

Common headers

The os-adaption contain C-files, which are special written for the appropriate operation system. But the headerfiles are identical over all mostly. It describes the OSAL-interface.

An interface in C-language is established in header-files. Most of compiler-tool-associated header-files declare the same things, but in their own files in a maybe different form. So the risk of little differences are given.

Instead all OS-interface-functions should be declared in the same header-files, independent of the current used operation system. The implementation of the OSAL should use this files and adapt their OS-functions.

All of those OS-independent common header files for OSAL-functions are declared in the folder CRuntimeJavalike/OSAL/inc. The current file list is:


The OSAL-Implementation can use some basicly C-routines, which are offered for common usage with a OSAL-library too. That headers files are contained in CRuntimeJavalike/Fwc:


Different headers

  • One Headerfile, which contains some depending definitions which should be adapted to the platform, os and compiler. It is the os_types_def.h.

Some things should be declared or defined in a OS-specific way. The same things should be defined in a different kind, appropriate to the operation system and the compiler properties.

The most important file doing this is the ,,os_types_def.h,,. The same file-name is used in different directories, all specific for OS and compiler. It defines the same things in a different way.

The most noticeable property is the definition of the OS- and compiler-depending definition of fix-size-integer types. The C99-standard suggests the usage of ,,int32_t,, etc. But most of the programmers had created their own standard before or simultaneous to the C99-Standard. These types are present in many sources. They are defined in some special headers like ,,standard.h,,, which is anytime ,,mystandard.h,,. These types are defined in the ,,os_types_def.h,,.

There are some things defined there in addition:

  • little/big endian defines, processors are different.
  • C++-keyword for C-usage, especially ,,bool,,, ,,true,,, ,,false,,.
  • The macro METHOD_C which maybe ,,extern "C",, or not.
  • A ,,MemUnit,,-type. It is the type which describes one element in the address spaces.

It is not a ,,char,, anytime, not in Signal-processors.


There are some things, which may defined in a good C-design able to use for the OSAL-level too. This C-basics are provided OS-independently in the following files (definition and implementation):


This so-named framework-level is independent from the OSAL-adaption and it is ready to use for the OS-adaption.

OS-adaption for threads

see ,,os_thread.h,,

Your Ad Here
Personal tools