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@40:53666b1a5848, 2018-12-04 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Dec 04 12:26:27 2018 +0000
- Revision:
- 40:53666b1a5848
- Parent:
- 39:5b594b1b6a0a
Renamed timer to hrtimer; added clktimer to handle utc based times.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 35:ba9f575aa3c6 | 1 | The clock library provides a number of separate functions: |
| andrewboyson | 40:53666b1a5848 | 2 | * "hrtimer" An unsigned 32bit high resolution timer which wraps around every 44 seconds from which all the time is derived. |
| andrewboyson | 40:53666b1a5848 | 3 | * "mstimer" An unsigned 32bit low resolution timer which wraps around every 49 days |
| andrewboyson | 40:53666b1a5848 | 4 | * "clktimer" A signed 64bit utc linked timer which doesn't wrap (or not until 2242 when clock time breaks) |
| andrewboyson | 40:53666b1a5848 | 5 | * "scan" Calculates the max, min and average scan times. |
| andrewboyson | 40:53666b1a5848 | 6 | * "rtc" A real time clock to provide backup |
| andrewboyson | 40:53666b1a5848 | 7 | * "tm" Routines to manipulate struct tm local and utc times |
| andrewboyson | 40:53666b1a5848 | 8 | * "clock" A clock which is synchronised to an external source |
| andrewboyson | 35:ba9f575aa3c6 | 9 | |
| andrewboyson | 35:ba9f575aa3c6 | 10 | High resolution timer |
| andrewboyson | 35:ba9f575aa3c6 | 11 | ===================== |
| andrewboyson | 40:53666b1a5848 | 12 | hrtimer.c uses TIM0 as a 32bit timer which counts at the cpu frequency 96MHz and rolls over after about 44s. |
| andrewboyson | 35:ba9f575aa3c6 | 13 | It has an init routine called from ClockInit to start it, thereafter it free runs. |
| andrewboyson | 35:ba9f575aa3c6 | 14 | No dependancies. |
| andrewboyson | 35:ba9f575aa3c6 | 15 | |
| andrewboyson | 40:53666b1a5848 | 16 | Millisecond timer |
| andrewboyson | 40:53666b1a5848 | 17 | ================= |
| andrewboyson | 38:25b2a3c494aa | 18 | 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. |
| andrewboyson | 35:ba9f575aa3c6 | 19 | It has a main routine called from ClockMain. |
| andrewboyson | 35:ba9f575aa3c6 | 20 | Depends on timer. |
| andrewboyson | 35:ba9f575aa3c6 | 21 | |
| andrewboyson | 40:53666b1a5848 | 22 | Clock timer |
| andrewboyson | 40:53666b1a5848 | 23 | =========== |
| andrewboyson | 40:53666b1a5848 | 24 | clktimer.h uses the signed 64 bit clock time. |
| andrewboyson | 40:53666b1a5848 | 25 | Depends on clock and hence hrtimer. |
| andrewboyson | 40:53666b1a5848 | 26 | |
| andrewboyson | 36:6a8a8e1951d4 | 27 | Scan times |
| andrewboyson | 36:6a8a8e1951d4 | 28 | ========== |
| andrewboyson | 36:6a8a8e1951d4 | 29 | scan.c uses the high resolution timer to calculate the max, min and average scan times. |
| andrewboyson | 36:6a8a8e1951d4 | 30 | It has a main routine called from ClockMain. |
| andrewboyson | 40:53666b1a5848 | 31 | Depends on hrtimer. |
| andrewboyson | 36:6a8a8e1951d4 | 32 | |
| andrewboyson | 35:ba9f575aa3c6 | 33 | Real time clock |
| andrewboyson | 35:ba9f575aa3c6 | 34 | =============== |
| andrewboyson | 35:ba9f575aa3c6 | 35 | rtc.c contains routines to save and restore the time in the battery backed real time clock. |
| andrewboyson | 35:ba9f575aa3c6 | 36 | It speaks struct tm. |
| andrewboyson | 35:ba9f575aa3c6 | 37 | No dependancies. |
| andrewboyson | 35:ba9f575aa3c6 | 38 | |
| andrewboyson | 35:ba9f575aa3c6 | 39 | Local and UTC manipulation |
| andrewboyson | 35:ba9f575aa3c6 | 40 | ========================== |
| andrewboyson | 38:25b2a3c494aa | 41 | tm.c contains a number of functions for manipulating 64 bit seconds since 1970 and struct tm times. |
| andrewboyson | 38:25b2a3c494aa | 42 | It contains nothing for clock time or the high resolution count. |
| andrewboyson | 38:25b2a3c494aa | 43 | 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 |
| andrewboyson | 35:ba9f575aa3c6 | 44 | No dependancies. |
| andrewboyson | 35:ba9f575aa3c6 | 45 | |
| andrewboyson | 31:f6ff7fdb9c67 | 46 | Clock |
| andrewboyson | 31:f6ff7fdb9c67 | 47 | ===== |
| andrewboyson | 31:f6ff7fdb9c67 | 48 | clock.c contains |
| andrewboyson | 31:f6ff7fdb9c67 | 49 | * settings |
| andrewboyson | 31:f6ff7fdb9c67 | 50 | * functions to save and restore the time to the RTC. |
| andrewboyson | 35:ba9f575aa3c6 | 51 | Depends on timer, rtc and tm. |
| andrewboyson | 10:19ed22b94c99 | 52 | |
| andrewboyson | 33:b9e3c06e7dab | 53 | clkstate.c contains state (ppb and slew) and settings (changes to the defaulsts are set up in the main program) |
| andrewboyson | 33:b9e3c06e7dab | 54 | PPB is stored in GPREG0 whenever it is set and retrieved during initialisation. |
| andrewboyson | 33:b9e3c06e7dab | 55 | |
| andrewboyson | 33:b9e3c06e7dab | 56 | 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). |
| andrewboyson | 33:b9e3c06e7dab | 57 | 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. |
| andrewboyson | 33:b9e3c06e7dab | 58 | See time-formats.text for the clock time format. |
| andrewboyson | 31:f6ff7fdb9c67 | 59 | |
| andrewboyson | 35:ba9f575aa3c6 | 60 | clksync.c takes external time from either: |
| andrewboyson | 31:f6ff7fdb9c67 | 61 | * a long term source such as NTP |
| andrewboyson | 31:f6ff7fdb9c67 | 62 | * a pulse per second (PPS) |
| andrewboyson | 33:b9e3c06e7dab | 63 | It adjusts the ppb and slew to synchronise the external source and the clock time. |
| andrewboyson | 23:07b19cd5f6d0 | 64 | |
| andrewboyson | 35:ba9f575aa3c6 | 65 | clkntp.c converts clock time to NTP time and vice versa. |
| andrewboyson | 31:f6ff7fdb9c67 | 66 | |
| andrewboyson | 38:25b2a3c494aa | 67 | clktm.c converts clock time to struct tm and vice versa |
| andrewboyson | 38:25b2a3c494aa | 68 |