Changeset 2894


Ignore:
Timestamp:
Mar 16, 2012, 2:02:28 AM (3 years ago)
Author:
wmb
Message:

ARM MMP2 timer driver - improved the code that reads the timer values. The technique I was using to ensure a self-consistent read was bogus, and the hardware documentation is extremely unclear. It turns out that you need to use different techniques for the different timers - careful write/read synchronization for the fast one, and read-until-match for the slower ones.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpu/arm/mmp2/timer.fth

    r2629 r2894  
    2222; 
    2323 
    24 [ifdef] arm-assembler 
     24\ The first ldr usually returns stale data; the second one returns good data. 
     25\ Empirically, draining the write buffer does not help. 
     26\ Read-until-match doesn't work with the fast clock because it never matches. 
    2527code timer0@  ( -- n )  \ 6.5 MHz 
    2628   psh  tos,sp 
     
    2830   mov  r0,#1 
    2931   str  r0,[r1,#0xa4] 
    30    mov  r0,r0 
    31    ldr  tos,[r1,#0x28] 
     32   ldr  tos,[r1,#0xa4] 
     33   ldr  tos,[r1,#0xa4] 
    3234c; 
    3335 
     36\ For the slower timers, we use the read-until-match technique. 
     37\ Apparently the freeze register doesn't update until the next 
     38\ clock tick, so using it doesn't work well for the slow clocks. 
    3439code timer1@  ( -- n )  \ 32.768 kHz 
    3540   psh  tos,sp 
    3641   set  r1,`h# 014000 +io #` 
    37    mov  r0,#1 
    38    str  r0,[r1,#0xa8] 
    39    mov  r0,r0 
    4042   ldr  tos,[r1,#0x2c] 
     43   begin 
     44      mov  r0,tos 
     45      ldr  tos,[r1,#0x2c] 
     46      cmps tos,r0 
     47   = until 
    4148c; 
    4249 
     
    4451   psh  tos,sp 
    4552   set  r1,`h# 014000 +io #` 
    46    mov  r0,#1 
    47    str  r0,[r1,#0xac] 
    48    mov  r0,r0 
    4953   ldr  tos,[r1,#0x30] 
     54   begin 
     55      mov  r0,tos 
     56      ldr  tos,[r1,#0x30] 
     57      cmps tos,r0 
     58   = until 
    5059c; 
    5160[else] 
    52 : timer0@  ( -- n )  1 h# 0140a4 io!  h# 014028 io@  ; 
    53 : timer1@  ( -- n )  1 h# 0140a8 io!  h# 01402c io@  ; 
    54 : timer2@  ( -- n )  1 h# 0140ac io!  h# 014030 io@  ; 
     61: timer0@  ( -- n )  1 h# 0140a4 io!  h# 0140a4 io@ drop h# 0140a4 io@  ; 
     62: timer1@  ( -- n )  1 h# 0140a8 io!  h# 0140a8 io@ drop h# 0140a8 io@  ; 
     63: timer2@  ( -- n )  1 h# 0140ac io!  h# 0140ac io@ drop h# 0140ac io@  ; 
    5564[then] 
    5665 
Note: See TracChangeset for help on using the changeset viewer.