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

periph_drivers: Proposal for a minimal RTC interface #1020

Merged
merged 1 commit into from
Aug 21, 2014

Conversation

thomaseichinger
Copy link
Member

This is a proposal for a low-level RTC driver. (now for real)
It tries to follow the principles of @haukepetersen's low-level driver interfaces and is open for discussion.

* @arg RTC_IRQ_PERIODIC
* @param[in] callback The ISR to use for specified *irq_type*.
*/
void rtc_install_isr(rtc_irq_t irq_type, void (*callback)(int));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like an explicit typedef void (rtc_alarm_callback_t *)(int irq_type); better.

@Kijewski
Copy link
Contributor

IMO all functions should return an error if the access was successful.

/**
* @brief Resets set alarms
*/
void rtc_reset_alarm(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the plural in the name, too.

@haukepetersen
Copy link
Contributor

I seem to have some trouble to understand the specific usage of this interface. I would imagine and interface for the RTC maybe as this:

int rtc_init()
time_t rtc_get_time()
int rtc_set_time(time_t time)
int rtc_set_alarm(time_t time, void (*some_callback)(void)) 
int rtc_clear_alarm(int id)

I am not quite sure that the IRQ masks and types are i) portable enough and ii) needed for a clean and easy interface?!

@thomaseichinger
Copy link
Member Author

@haukepetersen Well most platforms I checked provide alarm/time registers in their RTC module someone can write seconds minutes and hours to. So someone could say "alarm in 2 months" or "alarm in 87840 seconds". Using time_t would need a conversion in the driver implementation. Because of this I decided to use tm.

@haukepetersen
Copy link
Contributor

oh, actually the time_t in my pseudo-code was rather meant as placeholder for 'some-struct-that-defines-time'... tm is fine with me...

@OlegHahm OlegHahm removed this from the Release NEXT MAJOR milestone Jun 3, 2014
@thomaseichinger
Copy link
Member Author

updated addressing @Kijewski's and @haukepetersen's comments

@@ -0,0 +1,74 @@
/*
* Copyright (C) 2013 Thomas Eichinger <[email protected]>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2014

@OlegHahm
Copy link
Member

ACK

@haukepetersen
Copy link
Contributor

Now that i look at this again, I have some remarks which I didn't think of before:

  • would it make sense to include a function like rtc_remove_alarm(struct tm *time)?
  • for power management, rtc_poweron() and rtc_poweroff() functions as in proposed drivers: Initial import of SPI low-level driver IF #1311 would be useful?!
  • we should synchronize on the usage of specific vs. general types (int vs int32_t) in low-level drivers -> should we open an issue for this?
  • the existing drivers register callbacks in their init functions. We should also try to synchronize this design decision for all low-level drivers...

@LudwigKnuepfer
Copy link
Member

I'd say use int instead of int8_t for the return values.

@LudwigKnuepfer
Copy link
Member

I'm not sure registering an alarm callback on init makes sense.

Edit: yes it does (these devices tend not to have several alarm registers, so that functionality would need to be implemented in a high-level driver anyway).

@LudwigKnuepfer
Copy link
Member

Can RTC's be turned on and off at all? If so, I'm in favor of functions like @haukepetersen proposed.

Edit: yes they can

@LudwigKnuepfer
Copy link
Member

Other than that I'd rather like to see this merged asap, the current interface is not so great.

@LudwigKnuepfer
Copy link
Member

-> ACK when types changed, anything else can come later.

@LudwigKnuepfer
Copy link
Member

One last remark: it might make sense to explicitly specify the format expected in the struct tm *time parameters.
The old interface apparently expects offsets to the year 1900 and 0 as the first month. In my opinion this should be handled by the driver implementation even if this is a common characteristic of RTCs.
In any case - specify what the driver expects to avoid confusion.

Edit: aha, the old driver actually complied with the specification.. http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html

@thomaseichinger
Copy link
Member Author

updated addressing @LudwigOrtmann's comments and rebased

* @brief Set an alarm for RTC to the specified value.
*
* The expects values in `tm` that comply to the Gregorian calendar
* format and calculates those to the hardware's specific format.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 * The values in `tm` are expected to conform to the `struct tm` specification.
 * Compare: http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html

?

@thomaseichinger
Copy link
Member Author

Updated addressing @haukepetersen's offline comments.

@haukepetersen
Copy link
Contributor

Looking nice! ACK when squashed, merge at will

@thomaseichinger
Copy link
Member Author

squashed and go

thomaseichinger added a commit that referenced this pull request Aug 21, 2014
periph_drivers: Introduce a minimal RTC interface
@thomaseichinger thomaseichinger merged commit 57cbaef into RIOT-OS:master Aug 21, 2014
@thomaseichinger thomaseichinger deleted the real_rtc_interface branch August 21, 2014 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants