Skip to content

Commit f56a6a9

Browse files
authored
Merge pull request #7474 from RetiredWizard/broadcomRTC
Broadcom port: Add 'fake' RTC support
2 parents 74a3ec5 + ecde857 commit f56a6a9

File tree

5 files changed

+92
-2
lines changed

5 files changed

+92
-2
lines changed

ports/broadcom/common-hal/rtc/RTC.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Nick Moore for Adafruit Industries
7+
* Copyright (c) 2019 Artur Pacholec
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include <stdlib.h>
29+
30+
#include "py/obj.h"
31+
#include "py/runtime.h"
32+
#include "shared/timeutils/timeutils.h"
33+
#include "supervisor/port.h"
34+
35+
// This is the time in seconds since 2000 that the RTC was started.
36+
// TODO: Change the offset to ticks so that it can be a subsecond adjustment.
37+
static uint32_t rtc_offset = 0;
38+
39+
void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
40+
uint64_t ticks_s = port_get_raw_ticks(NULL) / 1024;
41+
timeutils_seconds_since_2000_to_struct_time(rtc_offset + ticks_s, tm);
42+
}
43+
44+
void common_hal_rtc_set_time(timeutils_struct_time_t *tm) {
45+
uint64_t ticks_s = port_get_raw_ticks(NULL) / 1024;
46+
uint32_t epoch_s = timeutils_seconds_since_2000(
47+
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec
48+
);
49+
rtc_offset = epoch_s - ticks_s;
50+
}
51+
52+
int common_hal_rtc_get_calibration(void) {
53+
return 0;
54+
}
55+
56+
void common_hal_rtc_set_calibration(int calibration) {
57+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_calibration);
58+
}

ports/broadcom/common-hal/rtc/RTC.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Noralf Trønnes
7+
* Copyright (c) 2019 Artur Pacholec
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#ifndef MICROPY_INCLUDED_BROADCOM_COMMON_HAL_RTC_RTC_H
29+
#define MICROPY_INCLUDED_BROADCOM_COMMON_HAL_RTC_RTC_H
30+
31+
extern void rtc_reset(void);
32+
33+
#endif // MICROPY_INCLUDED_BROADCOM_COMMON_HAL_RTC_RTC_H

ports/broadcom/common-hal/rtc/__init__.c

Whitespace-only changes.

ports/broadcom/mpconfigport.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ CIRCUITPY_PARALLELDISPLAY = 0
1515
CIRCUITPY_PULSEIO = 0
1616
CIRCUITPY_PWMIO = 0
1717
CIRCUITPY_ROTARYIO = 0
18-
CIRCUITPY_RTC = 0
1918

2019
CIRCUITPY_SDIOIO = 1
2120
CIRCUITPY_VIDEOCORE = 1

ports/broadcom/supervisor/port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#include "genhdr/mpversion.h"
3434

35-
// #include "common-hal/rtc/RTC.h"
35+
#include "common-hal/rtc/RTC.h"
3636
#include "common-hal/busio/I2C.h"
3737
#include "common-hal/busio/SPI.h"
3838
#include "common-hal/busio/UART.h"

0 commit comments

Comments
 (0)