bare metal - How do I add a delay of 150 cycles on ARM? -



bare metal - How do I add a delay of 150 cycles on ARM? -

changing pull up/down resistors gpio pins on raspberry pi requires waiting 150 cycles after enabling , disbaling clock signal according specs. doing bit longer doesn't wound using timer wait longer magnitudes don't want that. have simple busy loop:

for (int = 0; < 150; ++i) { asm volatile (""); } 0: e3a03096 mov r3, #150 ; 0x96 4: e2533001 subs r3, r3, #1 8: 1afffffd bne 4 <foo+0x4>

that loops 150 times, executing 300 instructions. without instruction caching , without branch prediction more 150 cycles. 1 time turned on loop runs way faster, faster 150 cycles think.

so how wait close 150 cycles or without instruction caches , branch prediction enabled? note: worst case 2 functions, delay_no_cache() , delay_cache()

this not duplicate of how delay arm cortex m0+ n cycles, without timer? since instruction cache , branch prediction completly throws of timing. timing differs between raspberry pi (armv6) , raspberry pi2 (armv7).

does know execution timings (with , without cache) if 1 insert dmb, dsb (i guess nops since not ram accessed) or isb instruction loop? prevent run-away effect when caches enabled?

you may need utilize repeat macro function delay. using loop in run time, there optimization, , loop costs time too. iterate macro of nop 150 times. there no optimization , no redundant cycles.

here's repeated-macro template:

#define macro_cmb( , b) a##b #define m_rpt(__n, __macro) macro_cmb(m_rpt, __n)(__macro) #define m_rpt0(__macro) #define m_rpt1(__macro) m_rpt0(__macro) __macro(0) #define m_rpt2(__macro) m_rpt1(__macro) __macro(1) #define m_rpt3(__macro) m_rpt2(__macro) __macro(2) ... #define m_rpt256(__macro) m_rpt255(__macro) __macro(255)

you can define nop instruction this:

#define my_nop(__n) __asm ("nop"); // or sth "mov r0,r0"

then can repeat instruction 150 times calling this:

m_rpt(150, my_nop);

it executed 150 times.

hope helped.

arm bare-metal

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -