Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/periph_common: problems with starting RTC early #8914

Closed
ZetaR60 opened this issue Apr 10, 2018 · 6 comments
Closed

drivers/periph_common: problems with starting RTC early #8914

ZetaR60 opened this issue Apr 10, 2018 · 6 comments

Comments

@ZetaR60
Copy link
Contributor

ZetaR60 commented Apr 10, 2018

In #8842 I have had trouble with race conditions when using xtimer. This is solved by removing rtc_init from drivers/periph_common/init.c and moving it to the application (tests/periph_rtc). It seems that code in drivers/periph_common/init.c is executed before xtimer_init, which is in sys/auto_init/auto_init.c

Steps to reproduce: use xtimer_usleep in rtc_init

Expected results: xtimer functions normally

Actual results: xtimer hangs the system prior to kernel_init

Versions:

  • avr-gcc: avr-gcc (Fedora 7.2.0-1.fc27) 7.2.0
  • avr-libc: "2.0.0" ("20150208")
  • git: git version 2.14.2
@jnohlgard
Copy link
Member

I think this would benefit from a more dynamic approach to auto_init, which could be possible using xfa (under development in #7523). That said, I think your rtc driver design is flawed if you need xtimer for controlling the on CPU RTC. The periph drivers are the lowest level interface drivers toward the hardware, all other drivers depend on them for hardware interfaces, therefore it makes sense to initialize them first. Why do you need xtimer in your rtc driver?

@ZetaR60
Copy link
Contributor Author

ZetaR60 commented Apr 11, 2018

Strictly speaking, it does not require xtimer. On the ATmega, safe access to several registers controlling the asynchronous timer is not guaranteed. There is a register that has busy flags that you have to wait on before you can safely write them (and for one register, even reading it requires waiting on a flag). This wait can be up to two cycles of the RTC timer, each of which is around 30ms. xtimer is useful because it allows the system to be doing other things rather than just spinning while waiting.

I think it is odd that the RTC is initialized where it is, while other low-level drivers (such as the RTT) are not automatically initialized anywhere except in code for specific boards. I propose that the RTC should be considered similarly to how the RTT is handled: if a specific board or cpu needs it initialized very early, it can be added to the code specific to that board or cpu.

@jnohlgard
Copy link
Member

We are working towards moving the periph initialization to periph_init which is called from the board init. This reduces the amount of code that has to be maintained for each individual board.

@ZetaR60
Copy link
Contributor Author

ZetaR60 commented Apr 11, 2018

Should I just make the system spin while waiting on those flags? Even thread_yield won't really be useful because periph_init is called before kernel_init.

@jnohlgard
Copy link
Member

Let's continue this discussion in the proper PR

@ZetaR60
Copy link
Contributor Author

ZetaR60 commented Apr 11, 2018

Closing. I asked my question in #8842.

@ZetaR60 ZetaR60 closed this as completed Apr 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants