diff options
Diffstat (limited to 'testhal/ATSAMA5D2/RTC/main.c')
-rw-r--r-- | testhal/ATSAMA5D2/RTC/main.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/testhal/ATSAMA5D2/RTC/main.c b/testhal/ATSAMA5D2/RTC/main.c index 49865e6d3..d75ed1caa 100644 --- a/testhal/ATSAMA5D2/RTC/main.c +++ b/testhal/ATSAMA5D2/RTC/main.c @@ -20,15 +20,18 @@ #include "string.h"
#include <time.h>
+/* This macro converts from decimal to BCD */
+#define decimal2BCD(nt, nu) ((nt << 4) | (nu))
+
#define SIZE 30
RTCDateTime cfg_time = {
38,
- 2,
+ 4,
0,
1,
- 26,
- 46824000
+ 9,
+ 66840000
};
RTCDateTime now_DateTime;
@@ -36,6 +39,35 @@ struct tm now_tm; char buffer[SIZE];
+/*
+ * Alarm configuration.
+ * Fields are in BCD format
+ */
+RTCAlarm alarmspec = {
+ RTC_TIMALR_HOUREN | RTC_TIMALR_HOUR(decimal2BCD(1,8)) |
+ RTC_TIMALR_MINEN | RTC_TIMALR_MIN(decimal2BCD(3,5)) , /* timalarm */
+ 0 /* calalarm */
+};
+
+/*
+ * Alarm callback.
+ */
+static void alarm_cb(RTCDriver *rtcp, rtcevent_t event) {
+
+ (void)rtcp;
+
+ switch (event) {
+ case RTC_EVENT_SECOND:
+ /* Toggle Led green very second */
+ palToggleLine(LINE_LED_GREEN);
+ break;
+ case RTC_EVENT_ALARM:
+ /* Led red on alarm */
+ palClearLine(LINE_LED_RED);
+ break;
+ }
+}
+
static const SerialConfig sdcfg = {
115200,
0,
@@ -83,6 +115,8 @@ int main(void) { * Configures date
*/
rtcSetTime(&RTCD0, &cfg_time);
+ rtcSetAlarm(&RTCD0, 0, &alarmspec);
+ rtcSetCallback(&RTCD0, alarm_cb);
while (true) {
if(!palReadPad(PIOB, PIOB_USER_PB)) {
|