pybrtc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2013, 2014 Damien P. George
  7. * Copyright (c) 2015 Daniel Campora
  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. #include "py/mpconfig.h"
  28. #include "py/obj.h"
  29. #include "py/runtime.h"
  30. #include "py/mperrno.h"
  31. #include "lib/timeutils/timeutils.h"
  32. #include "inc/hw_types.h"
  33. #include "inc/hw_ints.h"
  34. #include "inc/hw_memmap.h"
  35. #include "rom_map.h"
  36. #include "prcm.h"
  37. #include "pybrtc.h"
  38. #include "mpirq.h"
  39. #include "pybsleep.h"
  40. #include "simplelink.h"
  41. #include "modnetwork.h"
  42. #include "modwlan.h"
  43. #include "mpexception.h"
  44. /// \moduleref pyb
  45. /// \class RTC - real time clock
  46. /******************************************************************************
  47. DECLARE PRIVATE DATA
  48. ******************************************************************************/
  49. STATIC const mp_irq_methods_t pyb_rtc_irq_methods;
  50. STATIC pyb_rtc_obj_t pyb_rtc_obj;
  51. /******************************************************************************
  52. FUNCTION-LIKE MACROS
  53. ******************************************************************************/
  54. #define RTC_U16MS_CYCLES(msec) ((msec * 1024) / 1000)
  55. #define RTC_CYCLES_U16MS(cycles) ((cycles * 1000) / 1024)
  56. /******************************************************************************
  57. DECLARE PRIVATE FUNCTIONS
  58. ******************************************************************************/
  59. STATIC void pyb_rtc_set_time (uint32_t secs, uint16_t msecs);
  60. STATIC uint32_t pyb_rtc_reset (void);
  61. STATIC void pyb_rtc_disable_interupt (void);
  62. STATIC void pyb_rtc_irq_enable (mp_obj_t self_in);
  63. STATIC void pyb_rtc_irq_disable (mp_obj_t self_in);
  64. STATIC int pyb_rtc_irq_flags (mp_obj_t self_in);
  65. STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds);
  66. STATIC mp_obj_t pyb_rtc_datetime(mp_obj_t self, const mp_obj_t datetime);
  67. STATIC void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds);
  68. STATIC void rtc_msec_add(uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2);
  69. /******************************************************************************
  70. DECLARE PUBLIC FUNCTIONS
  71. ******************************************************************************/
  72. __attribute__ ((section (".boot")))
  73. void pyb_rtc_pre_init(void) {
  74. // only if comming out of a power-on reset
  75. if (MAP_PRCMSysResetCauseGet() == PRCM_POWER_ON) {
  76. // Mark the RTC in use first
  77. MAP_PRCMRTCInUseSet();
  78. // reset the time and date
  79. pyb_rtc_reset();
  80. }
  81. }
  82. void pyb_rtc_get_time (uint32_t *secs, uint16_t *msecs) {
  83. uint16_t cycles;
  84. MAP_PRCMRTCGet (secs, &cycles);
  85. *msecs = RTC_CYCLES_U16MS(cycles);
  86. }
  87. uint32_t pyb_rtc_get_seconds (void) {
  88. uint32_t seconds;
  89. uint16_t mseconds;
  90. pyb_rtc_get_time(&seconds, &mseconds);
  91. return seconds;
  92. }
  93. void pyb_rtc_calc_future_time (uint32_t a_mseconds, uint32_t *f_seconds, uint16_t *f_mseconds) {
  94. uint32_t c_seconds;
  95. uint16_t c_mseconds;
  96. // get the current time
  97. pyb_rtc_get_time(&c_seconds, &c_mseconds);
  98. // calculate the future seconds
  99. *f_seconds = c_seconds + (a_mseconds / 1000);
  100. // calculate the "remaining" future mseconds
  101. *f_mseconds = a_mseconds % 1000;
  102. // add the current milliseconds
  103. rtc_msec_add (c_mseconds, f_seconds, f_mseconds);
  104. }
  105. void pyb_rtc_repeat_alarm (pyb_rtc_obj_t *self) {
  106. if (self->repeat) {
  107. uint32_t f_seconds, c_seconds;
  108. uint16_t f_mseconds, c_mseconds;
  109. pyb_rtc_get_time(&c_seconds, &c_mseconds);
  110. // substract the time elapsed between waking up and setting up the alarm again
  111. int32_t wake_ms = ((c_seconds * 1000) + c_mseconds) - ((self->alarm_time_s * 1000) + self->alarm_time_ms);
  112. int32_t next_alarm = self->alarm_ms - wake_ms;
  113. next_alarm = next_alarm > 0 ? next_alarm : PYB_RTC_MIN_ALARM_TIME_MS;
  114. pyb_rtc_calc_future_time (next_alarm, &f_seconds, &f_mseconds);
  115. // now configure the alarm
  116. pyb_rtc_set_alarm (self, f_seconds, f_mseconds);
  117. }
  118. }
  119. void pyb_rtc_disable_alarm (void) {
  120. pyb_rtc_obj.alarmset = false;
  121. pyb_rtc_disable_interupt();
  122. }
  123. /******************************************************************************
  124. DECLARE PRIVATE FUNCTIONS
  125. ******************************************************************************/
  126. STATIC void pyb_rtc_set_time (uint32_t secs, uint16_t msecs) {
  127. // add the RTC access time
  128. rtc_msec_add(RTC_ACCESS_TIME_MSEC, &secs, &msecs);
  129. // convert from mseconds to cycles
  130. msecs = RTC_U16MS_CYCLES(msecs);
  131. // now set the time
  132. MAP_PRCMRTCSet(secs, msecs);
  133. }
  134. STATIC uint32_t pyb_rtc_reset (void) {
  135. // fresh reset; configure the RTC Calendar
  136. // set the date to 1st Jan 2015
  137. // set the time to 00:00:00
  138. uint32_t seconds = timeutils_seconds_since_2000(2015, 1, 1, 0, 0, 0);
  139. // disable any running alarm
  140. pyb_rtc_disable_alarm();
  141. // Now set the RTC calendar time
  142. pyb_rtc_set_time(seconds, 0);
  143. return seconds;
  144. }
  145. STATIC void pyb_rtc_disable_interupt (void) {
  146. uint primsk = disable_irq();
  147. MAP_PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR);
  148. (void)MAP_PRCMIntStatus();
  149. enable_irq(primsk);
  150. }
  151. STATIC void pyb_rtc_irq_enable (mp_obj_t self_in) {
  152. pyb_rtc_obj_t *self = self_in;
  153. // we always need interrupts if repeat is enabled
  154. if ((self->pwrmode & PYB_PWR_MODE_ACTIVE) || self->repeat) {
  155. MAP_PRCMIntEnable(PRCM_INT_SLOW_CLK_CTR);
  156. } else { // just in case it was already enabled before
  157. MAP_PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR);
  158. }
  159. self->irq_enabled = true;
  160. }
  161. STATIC void pyb_rtc_irq_disable (mp_obj_t self_in) {
  162. pyb_rtc_obj_t *self = self_in;
  163. self->irq_enabled = false;
  164. if (!self->repeat) { // we always need interrupts if repeat is enabled
  165. pyb_rtc_disable_interupt();
  166. }
  167. }
  168. STATIC int pyb_rtc_irq_flags (mp_obj_t self_in) {
  169. pyb_rtc_obj_t *self = self_in;
  170. return self->irq_flags;
  171. }
  172. STATIC uint pyb_rtc_datetime_s_us(const mp_obj_t datetime, uint32_t *seconds) {
  173. timeutils_struct_time_t tm;
  174. uint32_t useconds;
  175. // set date and time
  176. mp_obj_t *items;
  177. size_t len;
  178. mp_obj_get_array(datetime, &len, &items);
  179. // verify the tuple
  180. if (len < 3 || len > 8) {
  181. mp_raise_ValueError(mpexception_value_invalid_arguments);
  182. }
  183. tm.tm_year = mp_obj_get_int(items[0]);
  184. tm.tm_mon = mp_obj_get_int(items[1]);
  185. tm.tm_mday = mp_obj_get_int(items[2]);
  186. if (len < 7) {
  187. useconds = 0;
  188. } else {
  189. useconds = mp_obj_get_int(items[6]);
  190. }
  191. if (len < 6) {
  192. tm.tm_sec = 0;
  193. } else {
  194. tm.tm_sec = mp_obj_get_int(items[5]);
  195. }
  196. if (len < 5) {
  197. tm.tm_min = 0;
  198. } else {
  199. tm.tm_min = mp_obj_get_int(items[4]);
  200. }
  201. if (len < 4) {
  202. tm.tm_hour = 0;
  203. } else {
  204. tm.tm_hour = mp_obj_get_int(items[3]);
  205. }
  206. *seconds = timeutils_seconds_since_2000(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  207. return useconds;
  208. }
  209. /// The 8-tuple has the same format as CPython's datetime object:
  210. ///
  211. /// (year, month, day, hours, minutes, seconds, milliseconds, tzinfo=None)
  212. ///
  213. STATIC mp_obj_t pyb_rtc_datetime(mp_obj_t self_in, const mp_obj_t datetime) {
  214. uint32_t seconds;
  215. uint32_t useconds;
  216. if (datetime != MP_OBJ_NULL) {
  217. useconds = pyb_rtc_datetime_s_us(datetime, &seconds);
  218. pyb_rtc_set_time (seconds, useconds / 1000);
  219. } else {
  220. seconds = pyb_rtc_reset();
  221. }
  222. // set WLAN time and date, this is needed to verify certificates
  223. wlan_set_current_time(seconds);
  224. return mp_const_none;
  225. }
  226. STATIC void pyb_rtc_set_alarm (pyb_rtc_obj_t *self, uint32_t seconds, uint16_t mseconds) {
  227. // disable the interrupt before updating anything
  228. if (self->irq_enabled) {
  229. MAP_PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR);
  230. }
  231. // set the match value
  232. MAP_PRCMRTCMatchSet(seconds, RTC_U16MS_CYCLES(mseconds));
  233. self->alarmset = true;
  234. self->alarm_time_s = seconds;
  235. self->alarm_time_ms = mseconds;
  236. // enabled the interrupts again if applicable
  237. if (self->irq_enabled || self->repeat) {
  238. MAP_PRCMIntEnable(PRCM_INT_SLOW_CLK_CTR);
  239. }
  240. }
  241. STATIC void rtc_msec_add (uint16_t msecs_1, uint32_t *secs, uint16_t *msecs_2) {
  242. if (msecs_1 + *msecs_2 >= 1000) { // larger than one second
  243. *msecs_2 = (msecs_1 + *msecs_2) - 1000;
  244. *secs += 1; // carry flag
  245. } else {
  246. // simply add the mseconds
  247. *msecs_2 = msecs_1 + *msecs_2;
  248. }
  249. }
  250. /******************************************************************************/
  251. // MicroPython bindings
  252. STATIC const mp_arg_t pyb_rtc_init_args[] = {
  253. { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
  254. { MP_QSTR_datetime, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
  255. };
  256. STATIC mp_obj_t pyb_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
  257. // parse args
  258. mp_map_t kw_args;
  259. mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
  260. mp_arg_val_t args[MP_ARRAY_SIZE(pyb_rtc_init_args)];
  261. mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(args), pyb_rtc_init_args, args);
  262. // check the peripheral id
  263. if (args[0].u_int != 0) {
  264. mp_raise_OSError(MP_ENODEV);
  265. }
  266. // setup the object
  267. pyb_rtc_obj_t *self = &pyb_rtc_obj;
  268. self->base.type = &pyb_rtc_type;
  269. // set the time and date
  270. pyb_rtc_datetime((mp_obj_t)&pyb_rtc_obj, args[1].u_obj);
  271. // pass it to the sleep module
  272. pyb_sleep_set_rtc_obj (self);
  273. // return constant object
  274. return (mp_obj_t)&pyb_rtc_obj;
  275. }
  276. STATIC mp_obj_t pyb_rtc_init(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
  277. // parse args
  278. mp_arg_val_t args[MP_ARRAY_SIZE(pyb_rtc_init_args) - 1];
  279. mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), &pyb_rtc_init_args[1], args);
  280. return pyb_rtc_datetime(pos_args[0], args[0].u_obj);
  281. }
  282. STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_init_obj, 1, pyb_rtc_init);
  283. STATIC mp_obj_t pyb_rtc_now (mp_obj_t self_in) {
  284. timeutils_struct_time_t tm;
  285. uint32_t seconds;
  286. uint16_t mseconds;
  287. // get the time from the RTC
  288. pyb_rtc_get_time(&seconds, &mseconds);
  289. timeutils_seconds_since_2000_to_struct_time(seconds, &tm);
  290. mp_obj_t tuple[8] = {
  291. mp_obj_new_int(tm.tm_year),
  292. mp_obj_new_int(tm.tm_mon),
  293. mp_obj_new_int(tm.tm_mday),
  294. mp_obj_new_int(tm.tm_hour),
  295. mp_obj_new_int(tm.tm_min),
  296. mp_obj_new_int(tm.tm_sec),
  297. mp_obj_new_int(mseconds * 1000),
  298. mp_const_none
  299. };
  300. return mp_obj_new_tuple(8, tuple);
  301. }
  302. STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_now_obj, pyb_rtc_now);
  303. STATIC mp_obj_t pyb_rtc_deinit (mp_obj_t self_in) {
  304. pyb_rtc_reset();
  305. return mp_const_none;
  306. }
  307. STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_rtc_deinit_obj, pyb_rtc_deinit);
  308. STATIC mp_obj_t pyb_rtc_alarm(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
  309. STATIC const mp_arg_t allowed_args[] = {
  310. { MP_QSTR_id, MP_ARG_INT, {.u_int = 0} },
  311. { MP_QSTR_time, MP_ARG_OBJ, {.u_obj = mp_const_none} },
  312. { MP_QSTR_repeat, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
  313. };
  314. // parse args
  315. pyb_rtc_obj_t *self = pos_args[0];
  316. mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
  317. mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(args), allowed_args, args);
  318. // check the alarm id
  319. if (args[0].u_int != 0) {
  320. mp_raise_OSError(MP_ENODEV);
  321. }
  322. uint32_t f_seconds;
  323. uint16_t f_mseconds;
  324. bool repeat = args[2].u_bool;
  325. if (MP_OBJ_IS_TYPE(args[1].u_obj, &mp_type_tuple)) { // datetime tuple given
  326. // repeat cannot be used with a datetime tuple
  327. if (repeat) {
  328. mp_raise_ValueError(mpexception_value_invalid_arguments);
  329. }
  330. f_mseconds = pyb_rtc_datetime_s_us (args[1].u_obj, &f_seconds) / 1000;
  331. } else { // then it must be an integer
  332. self->alarm_ms = mp_obj_get_int(args[1].u_obj);
  333. pyb_rtc_calc_future_time (self->alarm_ms, &f_seconds, &f_mseconds);
  334. }
  335. // store the repepat flag
  336. self->repeat = repeat;
  337. // now configure the alarm
  338. pyb_rtc_set_alarm (self, f_seconds, f_mseconds);
  339. return mp_const_none;
  340. }
  341. STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_alarm_obj, 1, pyb_rtc_alarm);
  342. STATIC mp_obj_t pyb_rtc_alarm_left(size_t n_args, const mp_obj_t *args) {
  343. pyb_rtc_obj_t *self = args[0];
  344. int32_t ms_left;
  345. uint32_t c_seconds;
  346. uint16_t c_mseconds;
  347. // only alarm id 0 is available
  348. if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
  349. mp_raise_OSError(MP_ENODEV);
  350. }
  351. // get the current time
  352. pyb_rtc_get_time(&c_seconds, &c_mseconds);
  353. // calculate the ms left
  354. ms_left = ((self->alarm_time_s * 1000) + self->alarm_time_ms) - ((c_seconds * 1000) + c_mseconds);
  355. if (!self->alarmset || ms_left < 0) {
  356. ms_left = 0;
  357. }
  358. return mp_obj_new_int(ms_left);
  359. }
  360. STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_left_obj, 1, 2, pyb_rtc_alarm_left);
  361. STATIC mp_obj_t pyb_rtc_alarm_cancel(size_t n_args, const mp_obj_t *args) {
  362. // only alarm id 0 is available
  363. if (n_args > 1 && mp_obj_get_int(args[1]) != 0) {
  364. mp_raise_OSError(MP_ENODEV);
  365. }
  366. // disable the alarm
  367. pyb_rtc_disable_alarm();
  368. return mp_const_none;
  369. }
  370. STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_rtc_alarm_cancel_obj, 1, 2, pyb_rtc_alarm_cancel);
  371. /// \method irq(trigger, priority, handler, wake)
  372. STATIC mp_obj_t pyb_rtc_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
  373. mp_arg_val_t args[mp_irq_INIT_NUM_ARGS];
  374. mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, mp_irq_INIT_NUM_ARGS, mp_irq_init_args, args);
  375. pyb_rtc_obj_t *self = pos_args[0];
  376. // save the power mode data for later
  377. uint8_t pwrmode = (args[3].u_obj == mp_const_none) ? PYB_PWR_MODE_ACTIVE : mp_obj_get_int(args[3].u_obj);
  378. if (pwrmode > (PYB_PWR_MODE_ACTIVE | PYB_PWR_MODE_LPDS | PYB_PWR_MODE_HIBERNATE)) {
  379. goto invalid_args;
  380. }
  381. // check the trigger
  382. if (mp_obj_get_int(args[0].u_obj) == PYB_RTC_ALARM0) {
  383. self->pwrmode = pwrmode;
  384. pyb_rtc_irq_enable((mp_obj_t)self);
  385. } else {
  386. goto invalid_args;
  387. }
  388. // the interrupt priority is ignored since it's already set to to highest level by the sleep module
  389. // to make sure that the wakeup irqs are always called first when resuming from sleep
  390. // create the callback
  391. mp_obj_t _irq = mp_irq_new ((mp_obj_t)self, args[2].u_obj, &pyb_rtc_irq_methods);
  392. self->irq_obj = _irq;
  393. return _irq;
  394. invalid_args:
  395. mp_raise_ValueError(mpexception_value_invalid_arguments);
  396. }
  397. STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_rtc_irq_obj, 1, pyb_rtc_irq);
  398. STATIC const mp_rom_map_elem_t pyb_rtc_locals_dict_table[] = {
  399. { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&pyb_rtc_init_obj) },
  400. { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pyb_rtc_deinit_obj) },
  401. { MP_ROM_QSTR(MP_QSTR_now), MP_ROM_PTR(&pyb_rtc_now_obj) },
  402. { MP_ROM_QSTR(MP_QSTR_alarm), MP_ROM_PTR(&pyb_rtc_alarm_obj) },
  403. { MP_ROM_QSTR(MP_QSTR_alarm_left), MP_ROM_PTR(&pyb_rtc_alarm_left_obj) },
  404. { MP_ROM_QSTR(MP_QSTR_alarm_cancel), MP_ROM_PTR(&pyb_rtc_alarm_cancel_obj) },
  405. { MP_ROM_QSTR(MP_QSTR_irq), MP_ROM_PTR(&pyb_rtc_irq_obj) },
  406. // class constants
  407. { MP_ROM_QSTR(MP_QSTR_ALARM0), MP_ROM_INT(PYB_RTC_ALARM0) },
  408. };
  409. STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
  410. const mp_obj_type_t pyb_rtc_type = {
  411. { &mp_type_type },
  412. .name = MP_QSTR_RTC,
  413. .make_new = pyb_rtc_make_new,
  414. .locals_dict = (mp_obj_t)&pyb_rtc_locals_dict,
  415. };
  416. STATIC const mp_irq_methods_t pyb_rtc_irq_methods = {
  417. .init = pyb_rtc_irq,
  418. .enable = pyb_rtc_irq_enable,
  419. .disable = pyb_rtc_irq_disable,
  420. .flags = pyb_rtc_irq_flags
  421. };