Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf846fa1

Browse files
committed
enable NRFX RTCadafruit#1046
1 parentf88f9fd commitf846fa1

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

‎ports/nrf/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ SRC_NRFX = $(addprefix nrfx/,\
140140
drivers/src/nrfx_twim.c \
141141
drivers/src/nrfx_uarte.c \
142142
drivers/src/nrfx_gpiote.c \
143+
drivers/src/nrfx_rtc.c \
143144
)
144145

145146
ifdefEXTERNAL_FLASH_DEVICES

‎ports/nrf/common-hal/rtc/RTC.c‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,44 @@
3333
#include"supervisor/shared/translate.h"
3434

3535
#include"nrfx_rtc.h"
36+
#include"nrf_clock.h"
3637

37-
staticuint32_t_rtc_seconds=0;
38+
#defineRTC_CLOCK_HZ (8)
3839

39-
voidrtc_handler(nrfx_rtc_int_type_tint_type) {
40+
staticuint32_trtc_offset=0;
41+
42+
constnrfx_rtc_trtc_instance=NRFX_RTC_INSTANCE(0);
4043

44+
constnrfx_rtc_config_trtc_config= {
45+
.prescaler=RTC_FREQ_TO_PRESCALER(RTC_CLOCK_HZ),
46+
.reliable=0,
47+
.tick_latency=0,
48+
.interrupt_priority=6
49+
};
50+
51+
voidrtc_handler(nrfx_rtc_int_type_tint_type) {
52+
// do nothing
4153
}
4254

4355
voidrtc_init(void) {
56+
if (!nrf_clock_lf_is_running()) {
57+
nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART);
58+
}
59+
nrfx_rtc_counter_clear(&rtc_instance);
60+
nrfx_rtc_init(&rtc_instance,&rtc_config,rtc_handler);
61+
nrfx_rtc_enable(&rtc_instance);
4462
}
4563

4664
voidcommon_hal_rtc_get_time(timeutils_struct_time_t*tm) {
47-
timeutils_seconds_since_2000_to_struct_time(_rtc_seconds,tm);
65+
uint32_tt=rtc_offset+ (nrfx_rtc_counter_get(&rtc_instance) /RTC_CLOCK_HZ );
66+
timeutils_seconds_since_2000_to_struct_time(t,tm);
4867
}
4968

5069
voidcommon_hal_rtc_set_time(timeutils_struct_time_t*tm) {
51-
_rtc_seconds=timeutils_seconds_since_2000(
70+
rtc_offset=timeutils_seconds_since_2000(
5271
tm->tm_year,tm->tm_mon,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec
5372
);
73+
nrfx_rtc_counter_clear(&rtc_instance);
5474
}
5575

5676
// A positive value speeds up the clock by removing clock cycles.

‎ports/nrf/nrfx_config.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
#defineNRFX_PWM3_ENABLED 0
7171
#endif
7272

73+
#defineNRFX_RTC_ENABLED 1
74+
#defineNRFX_RTC0_ENABLED 1
75+
7376
// TIMERS
7477
#defineNRFX_TIMER_ENABLED 1
7578
// Don't enable TIMER0: it's used by the SoftDevice.

‎shared-bindings/rtc/RTC.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include"shared-bindings/time/__init__.h"
3737
#include"supervisor/shared/translate.h"
3838

39+
/*
3940
void MP_WEAK common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
4041
mp_raise_NotImplementedError(translate("RTC is not supported on this board"));
4142
}
@@ -51,6 +52,7 @@ int MP_WEAK common_hal_rtc_get_calibration(void) {
5152
void MP_WEAK common_hal_rtc_set_calibration(int calibration) {
5253
mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board"));
5354
}
55+
*/
5456

5557
constrtc_rtc_obj_trtc_rtc_obj= {{&rtc_rtc_type}};
5658

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp