; generated by Component: ARM Compiler 5.06 update 1 (build 61) Tool: ArmCC [4d35ad]
; commandline ArmCC [--list --debug -c --asm --interleave -o.\obj\timer.o --asm_dir=.\Obj\ --list_dir=.\Obj\ --depend=.\obj\timer.d --cpu=Cortex-M3 --apcs=interwork -O0 --diag_suppress=9931 -I. -I.\Core_CM3 -ID:\work\arm\lpc1769_eth_bootloader\RTE -I"C:\Program Files\Keil\ARM\PACK\Keil\LPC1700_DFP\2.2.0\Device\Include" -I"C:\Program Files\Keil\ARM\CMSIS\Include" -D__UVISION_VERSION=517 -DLPC175x_6x --omf_browse=.\obj\timer.crf timer\timer.c]
                          THUMB

                          AREA ||.text||, CODE, READONLY, ALIGN=2

                  Timer_init PROC
;;;21     // initialize timer 0 to count milliseconds
;;;22     void Timer_init(void) {
000000  4824              LDR      r0,|L1.148|
;;;23       // timer 0 clocked with CCLK/1
;;;24       LPC_SC->PCLKSEL0 &= (0x3UL << 2);
000002  6800              LDR      r0,[r0,#0]
000004  f000000c          AND      r0,r0,#0xc
000008  4923              LDR      r1,|L1.152|
00000a  f8c101a8          STR      r0,[r1,#0x1a8]
;;;25       LPC_SC->PCLKSEL0 |= (0x1UL << 2);
00000e  4608              MOV      r0,r1
000010  f8d001a8          LDR      r0,[r0,#0x1a8]
000014  f0400004          ORR      r0,r0,#4
000018  491e              LDR      r1,|L1.148|
00001a  6008              STR      r0,[r1,#0]
;;;26     
;;;27       // use timer 0 as timer (pclk = 64MHz)
;;;28       LPC_TIM0->CTCR = 0x00;
00001c  2000              MOVS     r0,#0
00001e  f04f2140          MOV      r1,#0x40004000
000022  6708              STR      r0,[r1,#0x70]
;;;29       // prescaler - count at 1kHz
;;;30       LPC_TIM0->PR = 64000-1;
000024  f64f10ff          MOV      r0,#0xf9ff
000028  60c8              STR      r0,[r1,#0xc]
;;;31       // no matches or interrupts
;;;32       LPC_TIM0->MCR = 0x0000;
00002a  2000              MOVS     r0,#0
00002c  6148              STR      r0,[r1,#0x14]
;;;33       // enable
;;;34       LPC_TIM0->TCR = 0x01;
00002e  2001              MOVS     r0,#1
000030  6048              STR      r0,[r1,#4]
;;;35     }
000032  4770              BX       lr
;;;36     
                          ENDP

                  Timer_DeInit PROC
;;;39     // the state of the registers
;;;40     void Timer_DeInit(void) {
000034  2000              MOVS     r0,#0
;;;41       // disable
;;;42       LPC_TIM0->TCR  = 0x00;
000036  f04f2140          MOV      r1,#0x40004000
00003a  6048              STR      r0,[r1,#4]
;;;43       LPC_TIM0->CTCR = 0x00;
00003c  6708              STR      r0,[r1,#0x70]
;;;44       LPC_TIM0->PR   = 0;
00003e  60c8              STR      r0,[r1,#0xc]
;;;45       LPC_TIM0->MCR  = 0x0000;
000040  6148              STR      r0,[r1,#0x14]
;;;46       LPC_TIM0->TC   = 0;
000042  6088              STR      r0,[r1,#8]
;;;47       LPC_TIM0->PC   = 0;
000044  6108              STR      r0,[r1,#0x10]
;;;48     }
000046  4770              BX       lr
;;;49     
                          ENDP

                  Timer_GetTimestamp PROC
;;;50     // get the current timer 0 count
;;;51     unsigned long Timer_GetTimestamp(void) {
000048  f04f2040          MOV      r0,#0x40004000
;;;52       return LPC_TIM0->TC;
00004c  6880              LDR      r0,[r0,#8]
;;;53     }
00004e  4770              BX       lr
;;;54     
                          ENDP

                  Timer_HasTimestampExpired PROC
;;;56     // returns 1 if in the past, 0 if not
;;;57     int Timer_HasTimestampExpired(unsigned long timestamp) {
000050  4601              MOV      r1,r0
;;;58       unsigned long now = LPC_TIM0->TC;
000052  f04f2040          MOV      r0,#0x40004000
000056  6882              LDR      r2,[r0,#8]
;;;59     
;;;60       if (now > timestamp)
000058  428a              CMP      r2,r1
00005a  d907              BLS      |L1.108|
;;;61       {
;;;62         if ((now - timestamp) < 0x80000000)
00005c  1a50              SUBS     r0,r2,r1
00005e  f1b04f00          CMP      r0,#0x80000000
000062  d201              BCS      |L1.104|
;;;63           return 1;
000064  2001              MOVS     r0,#1
                  |L1.102|
;;;64         else
;;;65           return 0;
;;;66       }
;;;67       else
;;;68       {
;;;69         if ((timestamp - now) >= 0x80000000)
;;;70           return 1;
;;;71         else
;;;72           return 0;
;;;73       }
;;;74     }
000066  4770              BX       lr
                  |L1.104|
000068  2000              MOVS     r0,#0                 ;65
00006a  e7fc              B        |L1.102|
                  |L1.108|
00006c  1a88              SUBS     r0,r1,r2              ;69
00006e  f1b04f00          CMP      r0,#0x80000000        ;69
000072  d301              BCC      |L1.120|
000074  2001              MOVS     r0,#1                 ;70
000076  e7f6              B        |L1.102|
                  |L1.120|
000078  2000              MOVS     r0,#0                 ;72
00007a  e7f4              B        |L1.102|
;;;75     
                          ENDP

                  Timer_Delay PROC
;;;76     // pause for a specific number of milliseconds
;;;77     void Timer_Delay(unsigned long milliseconds) {
00007c  b510              PUSH     {r4,lr}
00007e  4603              MOV      r3,r0
;;;78       unsigned long timestamp = Timer_GetTimestamp() + milliseconds;
000080  f7fffffe          BL       Timer_GetTimestamp
000084  18c4              ADDS     r4,r0,r3
;;;79       while (!Timer_HasTimestampExpired(timestamp));
000086  bf00              NOP      
                  |L1.136|
000088  4620              MOV      r0,r4
00008a  f7fffffe          BL       Timer_HasTimestampExpired
00008e  2800              CMP      r0,#0
000090  d0fa              BEQ      |L1.136|
;;;80     }
000092  bd10              POP      {r4,pc}
                          ENDP

                  |L1.148|
                          DCD      0x400fc1a8
                  |L1.152|
                          DCD      0x400fc000
