Posix HAL

This port makes a posix system look like real hardware to TiROS.

TiROS runs within a posix process. This port provides the context switching and time functions to TiROS. It simulates interrupts using posix signals. The posix port does not use kernel traps (They work on Linux but do not work reliably on Cygwin). The signal implementation under Cygwin is such that storing and restoring a context within a signal handler does not work properly. So we bypass this for the Cygwin environment and use direct Win32 api calls. This port has been tested on Linux 2.6.x kernel series/Glibc and on Cygwin 5.1. This port does not work on Mac OS X (as of 10.4), because the needed posix functions are not implemented.

This port does not allow the time to be set.

Currently, this port does not use the user provided stack memory for the task stack. This port stores the context on the user provided memory. For the task stack, it allocates new memory (memory size defined by TIROS_POSIX_STKSZ)

Configuration Options:

PORT_TIMER_TYPE :
Options are 1 or 2. Setting PORT_TIMER_TYPE to 1 uses the system real time. Setting PORT_TIMER_TYPE to 2, uses the process time. This option is irrelevant to Cygwin as only real time is available.
TIROS_POSIX_STKSZ :
The stack size allocated to each task. When os_task_create is called, the stack location and stack size for the task are passed along to the port. The Posix port stores the context at this provided stack location. The context size is fixed based on the registers etc. The rest of this provided stack is unused. The stack for the task is allocated separately using a mmap. By default, this stack is 16384 bytes. This was done because sometimes simple calls like printf on a posix system will easily overrun a small stack (tens of bytes) that might be specified for an embedded system. Allocating a larger stack on a posix system might help in running the code on both platforms without modification. Override the default by specifying TIROS_POSIX_STKSZ.

Writing ISRs for the Posix port

The posix port uses unix/posix signals to fake interrupts. Interrupt handlers are thus signal handlers. The posix port does not use kernel traps (for compatibility). So the form of the ISR must be as follows.

 extern int halint_kernel_trap_flagged;  // Flag in hal
 extern uint8_t os_isr_nesting;
 void signal_handler(int sig)
 { 
   OS_ISR_BEGIN();
   halint_kernel_trap_flagged = 0;
   // Perform actions
   xxx();
   
     // Re-enable interrupts if desired
   if (os_isr_nesting  < TIROS_MAX_ISR_NESTING) {
      OS_INT_ENABLE();
      yyy();
   } 
   zzz();
   // End actions
   OS_ISR_END();
   if (halint_kernel_trap_flagged) {
      hal_ctxt_switch();
   }
 }

TiROS User Manual: Last Updated on Fri Jul 20 10:52:24 2007