Write to Peripheral Registers

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Write to Peripheral Registers

867件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Andreas Richter on Thu Jan 31 23:59:13 MST 2013
Hello,

I'm rather new in the ARM-Cortex World, and I have a general Qustion for accessing Peripherals. Is it save to write to the same Peripheral register e.g. LPC_TIM0->MCR from both, an ISR and the Main program (both accessing different Bits of course). It would not be safe if the Compiler translates the modify instruction into:
- fetch value into register
- modify register
- write back register
I don't know if the ARM has the capability to mofify a memory value directly.
In that case it would be safe.

Regards Andreas
0 件の賞賛
返信
2 返答(返信)

849件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Andreas Richter on Fri Feb 01 01:46:56 MST 2013
gbm, Thanks for response. I will surround the register manipulation by __disable_irq()/__enable_irq(). Bit banding could work, I have to change one bit only (MRxI in T0MCR).

My idea is to use the Match-Registers as an on-time event. As soon the Interrupt has fired I want to disable the Match-Register in the ISR. If a new Task is pending in Main-Program I will re-activate the Match-Register again. I try to port the application from an 8051 project. There this scenario has worked very well with the Capture-Compare unit. Do you think it would be better to let the Match register active the whole time? Than I could use an external flag to remember if the unit is active or not.

Regards
0 件の賞賛
返信

849件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Fri Feb 01 01:14:04 MST 2013
1. In general, this will take 3 or 4 operations, so you definitely should put these accesses in a critical section.

2. Itąs not a good idea to design the main thread so that it changes some bits in timer config while the timer is running. The only thing to change while timer is running should be the value of match reg.

3. Sometimes the registers can be accessed using bit-banding. This will be safe but it's not always available and easy to achieve.
0 件の賞賛
返信