An attempt to provide a Real Time Clock for the nRF51-DK. This code provides rtc.time and rtc.set_time replacements for the similarly named C standard methods (unimplemented for nRF51-DK last I checked). Not very well tested, but it seems to work for simple applications.
Dependents: nRF51_rtc_example LoRa_PIR BLE_Lightning_sensor BLE_AlarmWatch ... more
nrf51_rtc.h@0:3677a016109b, 2015-02-08 (annotated)
- Committer:
- fxschumacher
- Date:
- Sun Feb 08 01:28:47 2015 +0000
- Revision:
- 0:3677a016109b
Initial revision -- library to implement Real Time Clock (time and set_time) for nRF51-DK.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fxschumacher | 0:3677a016109b | 1 | #ifndef NRF51_RTC_H |
fxschumacher | 0:3677a016109b | 2 | #define NRF51_RTC_H |
fxschumacher | 0:3677a016109b | 3 | |
fxschumacher | 0:3677a016109b | 4 | #include "mbed.h" |
fxschumacher | 0:3677a016109b | 5 | |
fxschumacher | 0:3677a016109b | 6 | static class nrf51_rtc { |
fxschumacher | 0:3677a016109b | 7 | // class to create equivalent of time() and set_time() |
fxschumacher | 0:3677a016109b | 8 | // ...depends upon RTC1 to be running and to never stop -- a byproduct of instantiation of mbed library's "ticker" |
fxschumacher | 0:3677a016109b | 9 | public: |
fxschumacher | 0:3677a016109b | 10 | nrf51_rtc(); |
fxschumacher | 0:3677a016109b | 11 | time_t time(); |
fxschumacher | 0:3677a016109b | 12 | int set_time(time_t rawtime); |
fxschumacher | 0:3677a016109b | 13 | |
fxschumacher | 0:3677a016109b | 14 | // these should be private |
fxschumacher | 0:3677a016109b | 15 | private: |
fxschumacher | 0:3677a016109b | 16 | time_t time_base; |
fxschumacher | 0:3677a016109b | 17 | unsigned int rtc_previous; |
fxschumacher | 0:3677a016109b | 18 | unsigned int ticks_per_second, counter_size_in_seconds; |
fxschumacher | 0:3677a016109b | 19 | void update_rtc(); // similar to "time" but doesn't return the value, just updates underlying variables |
fxschumacher | 0:3677a016109b | 20 | |
fxschumacher | 0:3677a016109b | 21 | } rtc; |
fxschumacher | 0:3677a016109b | 22 | #endif |