SAM D21/R21 Lightweight Mesh - Register addressing

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Regarding SAMR21:

alexru wrote:
I don't know much about ASF ... I have not seen any problems with standalone projects. Just to see something work you can try Lightweight Mesh v1.2.1 projects.

https://www.avrfreaks.net/index.p...

https://www.avrfreaks.net/index.p...

So I have been looking at Lightweight Mesh v1.2.1; eg,

Lightweight Mesh v1.2.1, in halTimer.c, wrote:

void HAL_TimerInit(void)
{
  halTimerIrqCount = 0;

  PM->APBCMASK.reg |= PM_APBCMASK_TC4;

  GCLK->CLKCTRL.reg =   GCLK_CLKCTRL_ID(TC4_GCLK_ID) |
                        GCLK_CLKCTRL_CLKEN           | 
                        GCLK_CLKCTRL_GEN(0);

  TC4->COUNT16.CTRLA.reg = 
      TC_CTRLA_MODE     (TC_CTRLA_MODE_COUNT16_Val)     |
      TC_CTRLA_WAVEGEN  (TC_CTRLA_WAVEGEN_MFRQ_Val)     |
      TC_CTRLA_PRESCALER(TC_CTRLA_PRESCALER_DIV8_Val)   |
      TC_CTRLA_PRESCSYNC(TC_CTRLA_PRESCSYNC_PRESC_Val);
  halTimerSync();

  TC4->COUNT16.COUNT.reg = 0;
  halTimerSync();

  TC4->COUNT16.CC[0].reg = TIMER_TOP;
  halTimerSync();

  TC4->COUNT16.CTRLA.reg |= TC_CTRLA_ENABLE;
  halTimerSync();

  TC4->COUNT16.INTENSET.reg = TC_INTENSET_MC0;
  NVIC_EnableIRQ(TC4_IRQn);
}

In particular:

TC4->COUNT16.CTRLA.reg |= TC_CTRLA_ENABLE;

And:

TC4->COUNT16.INTENSET.reg = TC_INTENSET_MC0;

Is there any particular reason why it always uses the .reg variant rather than .bit :?:

eg, why not:

TC4->COUNT16.CTRLA.bit.ENABLE = true;

And:

TC4->COUNT16.INTENSET.bit.MC0 = true;

:?:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Oct 16, 2015 - 01:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Because for registers that need synchronization manipulating individual bits is risky and you can't do multiple bits in a row without synchronizing each and every of them. And that's just silly.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, there is INTENSET and INTENCLR specifically so that you won't have to manipulate individual bits, which is kind of nice.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I get that for manipulating multiple bits in a register - but when you are accessing just one bit...?

Or is it just a matter of consistency: if it's best to use the whole registers sometimes, then just do it that way always :?:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pretty much it.

I'd really rather have just ".reg" versions without ".reg" suffix, like in AVRs.

Plus you might decide to change another bit later and you will either have to rewrite the code or forget to synchronize and have fun time debugging.

NOTE: I no longer actively read this forum. Please ask your question on www.eevblog.com/forum if you want my answer.