View: 11440|Reply: 5

[Bare metal] Reading the 64-bit counter

[Copy link]

2

threads

3

posts

10

credits

Novice

Rank: 1

credits
10
Published in 2018-6-15 19:20:29 | Show all floors |Read mode
Edited by rpidmx512 at 2018-6-15 12:23

Example for how to read the 64-bit counter

  1. .macro FUNC name
  2. .text
  3. .code 32
  4. .global \name
  5. \name:
  6. .endm

  7. FUNC h3_read_cnt64
  8.         mov        r2, #0x1e00
  9.         mov r0, #2
  10.         movt r2, #0x1f0
  11.         str r0, [r2,#0x80]
  12. 1:
  13.         ldr r3, [r2,#0x80]
  14.         tst r3, #2
  15.         bne 1b
  16.         ldrd r0,r1,[r2,#0x84]
  17.         bx lr
Copy code

9

threads

27

posts

286

credits

Intermediate member

Rank: 3Rank: 3

credits
286
Published in 2018-6-30 14:12:12 | Show all floors
dmx512 replied at 2018-6-27 00:58
What is this code used for ?

It's used for reading the 64 bit counter.

I was using the memory mapped register method for a system timer until I realised that just using the coprocessor interface for it was far simpler.
That single line I provided reads the 64 bit counter via the coprocessor interface instead of the memory mapped interface. That's all. It grabs the whole 64 bits at once and puts them into two registers. My example uses a1 and a2, or if you like R0 and R1. Same thing. I believe they cn be any general purpose registers though.


9

threads

27

posts

286

credits

Intermediate member

Rank: 3Rank: 3

credits
286
Published in 2018-6-23 09:45:36 | Show all floors
Edited by ImmortanJoe at 2018-6-23 09:48

    MRRC   p15, 0, a1, a2, c14

copypasted from my code. a1 is low word. a2 is high word.
e:This is for the H3. It'd probably be similar on other SoCs.

27

threads

58

posts

2229

credits

Gold member

Rank: 6Rank: 6

credits
2229
Published in 2018-6-27 00:58:46 | Show all floors
  1. MRRC   p15, 0, a1, a2, c14
Copy code

What is this code used for ?

9

threads

27

posts

286

credits

Intermediate member

Rank: 3Rank: 3

credits
286
Published in 2018-7-1 10:51:28 | Show all floors
Edited by ImmortanJoe at 2018-7-1 10:59

Besides the H3 datasheet, the following documents are extremely useful regarding working with the H3:

* ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition
* Cortex -A7 MPCore Technical Reference Manual
* CoreLink GIC-400 Generic Interrupt Controller Technical Reference Manual
* Allwinner DE2.0 Specification
* Enhanced Host Controller Interface Specification for Universal Serial Bus
* i.MX 6Dual/6Quad Applications Processor Reference Manual (for the graphics hardware)
e: Forgot to say before the MPCore TRM is where a lot of useful things are like coprocessor interface information. The H3 core doesn't really seem to have been altered from the A7 MPCore design in any significant way.

27

threads

58

posts

2229

credits

Gold member

Rank: 6Rank: 6

credits
2229
Published in 2018-7-12 03:18:20 | Show all floors
ImmortanJoe replied at 2018-6-30 07:12
It's used for reading the 64 bit counter.

I was using the memory mapped register method for a sys ...

This is great information. Thank you!
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list