Generic ARM port

This port serves as a template enabling the porting of Sirius RTOS and other products to ARM microprocessors.

Source files

All port files for this architecture are listed in the table below:

File nameExtensionDescription
AR_APIHPort API File
AR_TypesHType declarations file
AR_ARMCPort source file
AR_ARMaSPort assembly file
AR_ARMHooksC, HCPU-specific functions

General description

The internal timer must be configured to generate interrupts for preemption. It is generally configured to provide an interval between 0.1 and 1 millisecond.

A secondary timer should track the number of "ticks" elapsed since startup. This value is returned by the arGetTickCount function to provide system time.

The arLock and arRestore functions perform preemption disabling and re-enabling by modifying the standard interrupt (IRQ) enable state.

The arYield function performs a context switch without utilizing an additional software interrupt.

All tasks execute in Supervisor Mode. When the operating system calls the port-specific arSetPreemptiveHandler function, it does not allocate a new stack or task context for the operating system scheduler. This is because the scheduler executes in IRQ Mode, which possesses its own distinct stack and register set.

Most ARM processors support switching to an idle mode. The arSavePower function is utilized by the operating system to reduce power consumption when no tasks are executing.

Architecture specific code

To run Sirius RTOS and other SpaceShadow products on a specific ARM microprocessor, the following five CPU-specific functions must be implemented:

  • arARMInitHook
  • arARMDeinitHook
  • arGetTickCountHook
  • arIRQHandlerHook
  • arSavePowerHook

The arARMInitHook function must implement platform initialization and enable the timer. This timer must periodically execute the callback function passed as a parameter to realize preemption.

The arARMDeinitHook function is executed during platform deinitialization. This implementation may be skipped if the feature is not required.

The arGetTickCountHook function must return the total number of clock "ticks" elapsed since system startup. To properly manage system time, the number of clock "ticks" per second must be defined in the AR_TICKS_PER_SECOND constant. Using one-millisecond intervals is recommended.

The arIRQHandlerHook function is executed every time preemption occurs. It is used to acknowledge the interrupt (End of Interrupt).

The arSavePowerHook function is called whenever the CPU is idle (not processing any task). It allows switching the CPU to a power-save mode, which resumes execution upon any interrupt. This is often performed by an architecture-specific instruction (e.g., HLT on i386 or HALT on Motorola 68k). If the processor does not provide a method for halting execution, the body of this function should remain empty.

Task context

The task context contains all information required to resume the execution of a preempted task. The table below details the 64-byte task context structure for ARM processors:

OffsetSizeDescription
00004R15 (PC) register - Task startup procedure
00044R14 register, original Link Register value
00084R12 register
000C4R11 register
00104R10 register
00144R9 register
00184R8 register
001C4R7 register
00204R6 register
00244R5 register
00284R4 register
002C4R3 register
00304R2 register
00344R1 register
00384R0 register
003C4CPSR (Flags) register

SpaceShadow documentation