diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2018-11-25 10:20:09 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2018-11-25 10:20:09 +0000 |
commit | 7a0857aa5d161a27128622b0d9f61867dc7520ae (patch) | |
tree | 760371b2a169e11c5f24c904f52fa68d23d2405e /testhal/STM32/multi/RTC/main.c | |
parent | e9fbae0881b5c4aa4302ff2629efe06360e34fa5 (diff) | |
download | ChibiOS-7a0857aa5d161a27128622b0d9f61867dc7520ae.tar.gz ChibiOS-7a0857aa5d161a27128622b0d9f61867dc7520ae.tar.bz2 ChibiOS-7a0857aa5d161a27128622b0d9f61867dc7520ae.zip |
RTC callbacks now working.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12437 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'testhal/STM32/multi/RTC/main.c')
-rw-r--r-- | testhal/STM32/multi/RTC/main.c | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/testhal/STM32/multi/RTC/main.c b/testhal/STM32/multi/RTC/main.c index be90b57a5..3c273c238 100644 --- a/testhal/STM32/multi/RTC/main.c +++ b/testhal/STM32/multi/RTC/main.c @@ -29,6 +29,7 @@ #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
static void cmd_date(BaseSequentialStream *chp, int argc, char *argv[]) {
+ RTCDateTime timespec;
(void)argv;
@@ -36,6 +37,16 @@ static void cmd_date(BaseSequentialStream *chp, int argc, char *argv[]) { chprintf(chp, "Usage: date\r\n");
return;
}
+
+ rtcGetTime(&RTCD1, ×pec);
+ chprintf(chp, "%02d:%02d:%02d (%02d) - %02d-%02d-%04d\r\n",
+ timespec.millisecond / 3600000U,
+ (timespec.millisecond % 3600000U) / 60000U,
+ (timespec.millisecond % 60000U) / 1000U,
+ timespec.millisecond % 1000U,
+ timespec.month,
+ timespec.day,
+ timespec.year + 1980U);
}
static const ShellCommand commands[] = {
@@ -52,6 +63,8 @@ static const ShellConfig shell_cfg1 = { /* Generic code. */
/*===========================================================================*/
+static sysinterval_t interval = TIME_MS2I(500);
+
/*
* LED blinker thread, times are in milliseconds.
*/
@@ -62,9 +75,24 @@ static THD_FUNCTION(Thread1, arg) { chRegSetThreadName("blinker");
while (true) {
palToggleLine(PORTAB_LINE_LED1);
- chThdSleepMilliseconds(500);
+ chThdSleep(interval);
palToggleLine(PORTAB_LINE_LED1);
- chThdSleepMilliseconds(500);
+ chThdSleep(interval);
+ }
+}
+
+/*
+ * RTC callback.
+ */
+static void alarmcb(RTCDriver *rtcp, rtcevent_t event) {
+
+ (void)rtcp;
+
+ if (event == RTC_EVENT_ALARM_A) {
+ interval = TIME_MS2I(500);
+ }
+ else if (event == RTC_EVENT_ALARM_B) {
+ interval = TIME_MS2I(50);
}
}
@@ -72,6 +100,20 @@ static THD_FUNCTION(Thread1, arg) { * Application entry point.
*/
int main(void) {
+ static const RTCAlarm alarm1 = {
+ RTC_ALRM_MSK4 | /* No month/week day match. */
+ RTC_ALRM_MSK3 | /* No hour match. */
+ RTC_ALRM_MSK2 | /* No minutes match. */
+ RTC_ALRM_ST(0) |
+ RTC_ALRM_SU(0) /* Match minute start. */
+ };
+ static const RTCAlarm alarm2 = {
+ RTC_ALRM_MSK4 | /* No month/week day match. */
+ RTC_ALRM_MSK3 | /* No hour match. */
+ RTC_ALRM_MSK2 | /* No minutes match. */
+ RTC_ALRM_ST(3) |
+ RTC_ALRM_SU(0) /* Match minute half. */
+ };
/*
* System initializations.
@@ -95,6 +137,10 @@ int main(void) { /* Creates the blinker thread.*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+ rtcSetAlarm(&RTCD1, 0, &alarm1);
+ rtcSetAlarm(&RTCD1, 1, &alarm2);
+ rtcSetCallback(&RTCD1, alarmcb);
+
/* Normal main() thread activity, spawning shells.*/
while (true) {
thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
|