Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
clock.txt
- Committer:
- andrewboyson
- Date:
- 2018-12-04
- Revision:
- 40:53666b1a5848
- Parent:
- 39:5b594b1b6a0a
File content as of revision 40:53666b1a5848:
The clock library provides a number of separate functions:
* "hrtimer" An unsigned 32bit high resolution timer which wraps around every 44 seconds from which all the time is derived.
* "mstimer" An unsigned 32bit low resolution timer which wraps around every 49 days
* "clktimer" A signed 64bit utc linked timer which doesn't wrap (or not until 2242 when clock time breaks)
* "scan" Calculates the max, min and average scan times.
* "rtc" A real time clock to provide backup
* "tm" Routines to manipulate struct tm local and utc times
* "clock" A clock which is synchronised to an external source
High resolution timer
=====================
hrtimer.c uses TIM0 as a 32bit timer which counts at the cpu frequency 96MHz and rolls over after about 44s.
It has an init routine called from ClockInit to start it, thereafter it free runs.
No dependancies.
Millisecond timer
=================
mstimer.c uses the high resolution timer to count the number of ms since power up. Its unsigned 32bit count rolls over after about 49 days.
It has a main routine called from ClockMain.
Depends on timer.
Clock timer
===========
clktimer.h uses the signed 64 bit clock time.
Depends on clock and hence hrtimer.
Scan times
==========
scan.c uses the high resolution timer to calculate the max, min and average scan times.
It has a main routine called from ClockMain.
Depends on hrtimer.
Real time clock
===============
rtc.c contains routines to save and restore the time in the battery backed real time clock.
It speaks struct tm.
No dependancies.
Local and UTC manipulation
==========================
tm.c contains a number of functions for manipulating 64 bit seconds since 1970 and struct tm times.
It contains nothing for clock time or the high resolution count.
time_t is used in the expectation that it will become 64 bit before 2038; if not then replace time_t with int64_t and replace TimeT with Secs1970
No dependancies.
Clock
=====
clock.c contains
* settings
* functions to save and restore the time to the RTC.
Depends on timer, rtc and tm.
clkstate.c contains state (ppb and slew) and settings (changes to the defaulsts are set up in the main program)
PPB is stored in GPREG0 whenever it is set and retrieved during initialisation.
clktime.c increments by 1 each second via clock.c from timer.c. It increments the clock time using the ppb and slew (set by sync.c).
When the clock time is requested it uses its count and a proportion of the elapsed second from the high resolution timer to calculate the exact time.
See time-formats.text for the clock time format.
clksync.c takes external time from either:
* a long term source such as NTP
* a pulse per second (PPS)
It adjusts the ppb and slew to synchronise the external source and the clock time.
clkntp.c converts clock time to NTP time and vice versa.
clktm.c converts clock time to struct tm and vice versa