Keil Logo

Configuration Macros

All hardware related configuration options are described with configuration macros. Some of the macros (for example OS_TID_ and OS_TIM_) are used only to simplify the code. They are not used in all of the configuration files. Using configuration macros allows easy customization of the configuration for the different peripheral timers supported by an ARM device.

The following configuration macros are introduced:
(examples are for NXP LPC21xx devices - Timer 0)

  • OS_TRV macro specifies the timer reload value for the peripheral timer. Peripheral timer counts up to a reload value, then then overflows to 0, and then generates a tick interrupt. The reload value should be calculated to generate the desired interval length (for example 10 ms).
    #define OS_TRV      ((U32)(((double)OS_CLOCK*(double)OS_TICK)/1E6)-1)
    
  • OS_TVAL macro is used to read the current timer value for a count-up timer. The RTX kernel uses it to check whether a timer interrupt is a periodic timer interrupt or a software forced interrupt.
    #define OS_TVAL     T0TC              /* Timer Value */
    
    For a countdown timer, you must convert the return value. This is an example for a 16-bit count-down timer:
    #define OS_TVAL     (0xFFFF - T0VAL)  /* Timer Value */
    
  • OS_TOVF specifies a timer overflow flag. The RTX kernel uses it together with the OS_TVAL macro to differentiate between the periodic timer interrupts and forced timer interrupts.
    #define OS_TOVF     (T0IR & 1)        /* Overflow Flag */
    
  • OS_TREL() macro specifies a code sequence to reload a peripheral timer on overflow. When a peripheral timer has an auto-reload functionality, this macro is left empty.
    #define OS_TREL()  ;                  /* Timer Reload */
    
  • OS_TFIRQ() specifies a code sequence to force a timer interrupt. This must be a software triggered interrupt if the peripheral timer does not allow manual setting of an overflow flag. If manual setting is possible, this macro should set a peripheral timer overflow flag, which will cause a timer interrupt.
    #define OS_TFIRQ()  VICSoftInt = OS_TIM_;  /* Force Interrupt */
    
  • OS_TIACK() is used to acknowledge an interrupt from the timer interrupt function to release the timer interrupt logic.
    #define OS_TIACK()  T0IR = 1;            /* Interrupt Ack */  \ 
                        VICSoftIntClr = OS_TIM_;                  \ 
                        VICVectAddr   = 0;
    
  • OS_TINIT() macro is used to initialize the peripheral timer/counter, setup a timer mode, and set a timer reload. Timer interrupts are also activated here by enabling a peripheral timer interrupt. This code is executed from the os_sys_init() function.
    #define OS_TINIT()  T0MR0 = OS_TRV;     /* Initialization */  \ 
                        T0MCR = 3;                                \ 
                        T0TCR = 1;                                \ 
                        VICDefVectAddr = (U32)os_def_interrupt;   \ 
                        VICVectAddr15  = (U32)os_clock_interrupt; \ 
                        VICVectCntl15  = 0x20 | OS_TID_;
    
  • OS_LOCK() macro disables timer tick interrupts. It is used to avoid interrupting the system task scheduler. This macro should disable both the periodic timer interrupts and the forced interrupts. This code is executed from the tsk_lock() function.
    #define OS_LOCK()   VICIntEnClr = OS_TIM_;    /* Task Lock */
    
  • OS_UNLOCK() macro enables the timer tick interrupts. The code sequence specified here should enable the periodic timer interrupts and the forced interrupts. This code is executed from tsk_unlock() function.
    #define OS_UNLOCK() VICIntEnable = OS_TIM_;  /* Task Unlock */
    
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.