##############################################################################
#                                                                            #
# IAR ARM ANSI C/C++ Compiler V4.11A/W32               20/Jul/2004  18:58:47 #
# Copyright 1999-2004 IAR Systems. All rights reserved.                      #
#                                                                            #
#    Cpu mode        =  arm                                                  #
#    Endian          =  little                                               #
#    Stack alignment =  4                                                    #
#    Source file     =  C:\medusa\timer0.c                                   #
#    Command line    =  -I "C:\Program Files\IAR Systems\Embedded Workbench  #
#                       4.0\ARM\INC\" -lc C:\medusa\Debug\List\ -la          #
#                       C:\medusa\Debug\List\ -o C:\medusa\Debug\Obj\ -s2    #
#                       --no_cse --no_unroll --no_inline --no_code_motion    #
#                       --no_tbaa --no_clustering --no_scheduling --debug    #
#                       --cpu_mode arm --endian little --cpu ARM7TDMI-S      #
#                       --stack_align 4 -e --fpu None                        #
#                       "-D_DLIB_CONFIG_FILE=C:\Program Files\IAR            #
#                       Systems\Embedded Workbench                           #
#                       4.0\ARM\LIB\dl4tpannl8n.h" C:\medusa\timer0.c        #
#    List file       =  C:\medusa\Debug\List\timer0.lst                      #
#    Object file     =  C:\medusa\Debug\Obj\timer0.r79                       #
#                                                                            #
#                                                                            #
##############################################################################

C:\medusa\timer0.c
      1          #include "archinc.h"
      2          #include "board.h"
      3          #include "pll.h"
      4          #include "timer0.h"
      5          
      6          static unsigned int tickCounter = 0;
      7          static unsigned int isrEntry = 0;
      8          static unsigned int delayTicks = 0;
      9          
     10          /* 
     11           * ISR declaration
     12           */
     13          
     14          DECLARE_ISR(timer0Match0Isr);
     15          
     16          int timer0Init(void) 
     17          {
     18            int retStat;
     19            unsigned int periphDivider = pllGetPeriphDivider();
     20          
     21            /* Disable the timer */
     22            T0TCR = (lpc210x_reg)0;
     23          
     24            /* Reset the timer */
     25            T0TC = (lpc210x_reg)0;
     26            T0PC = (lpc210x_reg)0;
     27          
     28            /* Set the timer prescale counter */
     29            // T0PR = (lpc210x_reg)2500;
     30            // FIXME: retrieve the PLL multipler and make this more intelligent
     31            // Medusa: 60MHz/4 = 15 MHz
     32            // Medusa: 60MHz/1 = 60 MHz
     33            T0PR = (lpc210x_reg)(60000 / periphDivider);
     34          
     35            /* Set match register */
     36            T0MR0 = (lpc210x_reg)100;
     37          
     38            /* Generate interrupt and reset counter on match */
     39            T0MCR = (lpc210x_reg)3;
     40          
     41            // connect the interrupt vector
     42            if ((retStat = armvicIntConnect(LPC210X_IRQVEC_TIMER0, timer0Match0Isr)) != 0)
     43              return retStat;
     44          
     45            // enable the interrupt
     46            if ((retStat = armvicIntEnable(LPC210X_IRQVEC_TIMER0)) != 0)
     47              return retStat;
     48          
     49            /* Start the timer */
     50            T0TCR = (lpc210x_reg)1;
     51          
     52            return 0;
     53          }
     54          
     55          ISR_FUNCTION(timer0Match0Isr)
     56          {
     57            ISR_ENTER()
     58          
     59            isrEntry++;
     60          
     61            /* clear the interrupt */
     62            T0IR = (lpc210x_reg)0xff;
     63          
     64            if (delayTicks != 0)
     65              delayTicks--;
     66          
     67            // each tick is 100 millisecond(s), so let's setup on=500ms, off=500ms or 500 ticks ea.
     68            if (++tickCounter == 5) {
     69              boardTimerLedToggle();
     70              tickCounter = 0;
     71              }
     72          
     73            VICIrqDone;
     74          
     75            ISR_LEAVE()
     76          }
     77          
     78          // this is a simple-minded delay that doesn't take rollover into account
     79          void timer0Delay(unsigned int timerTicks)
     80          {
     81            lpc210x_reg target;
     82          
     83            if (timerTicks < 1)
     84              return;
     85          
     86            target = T0TC + timerTicks;
     87          
     88            while(T0TC != target)
                                       ^
Warning[Pa082]: undefined behavior: the order of volatile accesses is
          undefined in this statement
     89              ;
     90          }

   Maximum stack usage in bytes:

     Function        CSTACK CSTACK IRQSTACK
     --------        ------ ------ --------
     timer0Delay         4      0        0
     timer0Init         12      0        0
     timer0Match0Isr     0     20        0


   Segment part sizes:

     Function/Label  Bytes
     --------------  -----
     tickCounter        4
     isrEntry           4
     delayTicks         4
     timer0Init       208
     timer0Match0Isr  208
     timer0Delay       64
      Others           72

 
 540 bytes in segment CODE
  12 bytes in segment DATA_Z
  12 bytes in segment INITTAB
 
 480 bytes of CODE memory (+ 72 bytes shared)
  12 bytes of DATA memory

Errors: none
Warnings: 1
