Porting Embedded Rapid Prototyper Run-Time Libraries : Target Dependent Areas in the RTL : Files and Libraries : INTRINSICS Library

INTRINSICS Library
OS_FLAGS.H file defines the flags for target platform. The flags for the new target should be defined here.
OS_INCLUDE.H file contains the mapping of the common-named macros on the target-dependent functions to their calls. To understand which routines execute the same function in different target OS, compare the same macro for different OS. For instance, OS_wake_main_task macro is mapped to the vx_wake_main_task for VxWorks and it does not exist under Windows and Unix. Write a similar function <new_target>_wake_main_task, place it into the <new_target>_timer.c file and declare the proper macro in the OS_INCLUDE.H file as shown:

 

#Ifdef <new_target>

#Define OS_wake_main_task <new_target>_wake_main_task

#Endif <new_target>

 

This file contains target dependent macro definitions, declarations, and constants. Create the new #ifdef-#endif section for the new target platform.

OS_create_task is the macro definition, which allows creating target-oriented task. It has the following parameter
\
OS_CTRLC_handler sets the SIGINT handler function and contains a single parameter, which is the function name.
OS_stderr_redirect redirects STDERR to a temporary file since some OS can give an error message in when opening of the. pdbrc file if it does not exist.
OS_stderr_return returns the previous STDERR file descriptor.

The couple of macros, mentioned above, is used for run-time debugger (PDB) only.
OS_exit sets the operator that should be called when the program is finished. Different OS may need different exit command (e.g., VxWorks needs the return () command instead of the exit () function call in Unix).
OS_getuid macro is used in the TCP/IP protocol implementation. See the get_default_port_number function in the gba and the rpgertl libraries.
OS_main is the main program name including parameters and the “{” character.
OS_pause allows to replace the pause () function call by some other OS service call, existing in the target OS.
OS_pr_pause sets the implementation of the Rational Statemate pause “adapter,” which allows the exit from WAIT state and monitors the CTRLC or other external event.
OS_reset_CTRLC_handler resets the SIGINT/CTRLC handler if it is needed; otherwise it is an empty definition.

Some operating systems need to forbid the new SIGINT event appearing via its handling. In this case the macro OS_disable_signal is called.

The next group of macros concerns the semaphore implementation. Their names explain their functions: OS_sem_create, OS_sem_delete, OS_sem_give and OS_sem_take. All of them have single parameter – the semaphore descriptor name. Its type is OS_sem_id and it is defined in the OS_INCLUDE.H file too.

The task synchronization is done using the OS_synchronize macro call. It has one parameter – time delay.

All active tasks should be deleted when the program is finishing. It should be done using the OS_terminate_tasks macro.

It is necessary to call the timer handler every step if the timer is implemented using separate thread/task. In other cases it is not needed. So this call is implemented by the macro OS_timer_call_handler, which should be defined properly for the target OS.
OS_timer_handler_p is either NULL or the function that is called every step in the main function in order to check whether the next time-out event occurs or not.
OS_timer_start_p is either NULL or the function that starts the timer.
OS_timer_stop_p is either NULL or the function that starts the timer.

If the generated code is running under the PDB debugger, it is necessary to exit from the timer. This can be achieved using the OS_timer_exit call.

If the behavioral module is in a stable state, it can be awakened. It is needed if some external event happened. The awakening mechanism is platform dependent, so the OS_wake_main_task macro is used in addition to the sched_resume function call. See the try_to_wake_main_task function in the intrinsics library.