aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32/STM32F1xx/RTC/main.c
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-11-01 13:20:46 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-11-01 13:20:46 +0000
commit55f399caf7e95a657a956e8ecc6110f9be306682 (patch)
treeffd8972815f85736d832fedc891ad5e1fc0015ab /testhal/STM32/STM32F1xx/RTC/main.c
parent8642d175f167e12fae087696cc5760aa2f81fa3c (diff)
downloadChibiOS-55f399caf7e95a657a956e8ecc6110f9be306682.tar.gz
ChibiOS-55f399caf7e95a657a956e8ecc6110f9be306682.tar.bz2
ChibiOS-55f399caf7e95a657a956e8ecc6110f9be306682.zip
RTCv1. Added testhal application.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7441 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32/STM32F1xx/RTC/main.c')
-rw-r--r--testhal/STM32/STM32F1xx/RTC/main.c160
1 files changed, 160 insertions, 0 deletions
diff --git a/testhal/STM32/STM32F1xx/RTC/main.c b/testhal/STM32/STM32F1xx/RTC/main.c
new file mode 100644
index 000000000..cbaded0c1
--- /dev/null
+++ b/testhal/STM32/STM32F1xx/RTC/main.c
@@ -0,0 +1,160 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "ch.h"
+#include "hal.h"
+
+RTCDateTime timespec;
+RTCAlarm alarmspec;
+
+#define TEST_ALARM_WAKEUP FALSE
+
+#if TEST_ALARM_WAKEUP
+
+/*
+ * Running indicator thread.
+ */
+static THD_WORKING_AREA(blinkWA, 128);
+static THD_FUNCTION(blink_thd, arg) {
+ (void)arg;
+ while (TRUE) {
+ chThdSleepMilliseconds(100);
+ palTogglePad(GPIOC, GPIOC_LED);
+ }
+ return 0;
+}
+
+/*
+ *
+ */
+int main(void) {
+
+ uint32_t tv_sec;
+
+ halInit();
+ chSysInit();
+
+ chThdCreateStatic(blinkWA, sizeof(blinkWA), NORMALPRIO, blink_thd, NULL);
+
+ /* compile ability test */
+ rtcGetTime(&RTCD1, &timespec);
+
+ /* set alarm in near future */
+ rtcSTM32GetSecMsec(&RTCD1, &tv_sec, NULL);
+ alarmspec.tv_sec = tv_sec + 20;
+ rtcSetAlarm(&RTCD1, 0, &alarmspec);
+
+ while (TRUE){
+ chThdSleepSeconds(10);
+
+ /* going to anabiosis*/
+ chSysLock();
+ PWR->CR |= PWR_CR_CWUF | PWR_CR_CSBF;
+ PWR->CR |= PWR_CR_PDDS | PWR_CR_LPDS;
+ SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
+ __WFI();
+ }
+ return 0;
+}
+
+#else /* TEST_ALARM_WAKEUP */
+
+/*
+ * Test alarm period.
+ */
+#define RTC_ALARMPERIOD 10
+
+binary_semaphore_t alarm_sem;
+
+/*
+ * Alarm callback.
+ */
+static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
+
+ (void)rtcp;
+
+ switch (event) {
+ case RTC_EVENT_OVERFLOW:
+ palTogglePad(GPIOC, GPIOC_LED);
+ break;
+ case RTC_EVENT_SECOND:
+ //palTogglePad(GPIOC, GPIOC_LED);
+ break;
+ case RTC_EVENT_ALARM:
+ palTogglePad(GPIOC, GPIOC_LED);
+ osalSysLockFromISR();
+ chBSemSignalI(&alarm_sem);
+ osalSysUnlockFromISR();
+ break;
+ }
+}
+
+static time_measurement_t sett, gett;
+
+int main(void) {
+
+ msg_t status = MSG_TIMEOUT;
+ uint32_t tv_sec;
+
+ halInit();
+ chSysInit();
+ chBSemObjectInit(&alarm_sem, TRUE);
+ chTMObjectInit(&sett);
+ chTMObjectInit(&gett);
+
+ /* compile ability test */
+ chTMStartMeasurementX(&gett);
+ rtcGetTime(&RTCD1, &timespec);
+ chTMStopMeasurementX(&gett);
+
+ rtcSTM32SetSec(&RTCD1, 1414845464);
+ osalThreadSleepMilliseconds(10);
+ rtcGetTime(&RTCD1, &timespec);
+ timespec.month -= 1;
+
+ chTMStartMeasurementX(&sett);
+ rtcSetTime(&RTCD1, &timespec);
+ chTMStopMeasurementX(&sett);
+ osalThreadSleepMilliseconds(10);
+
+ rtcGetTime(&RTCD1, &timespec);
+
+ rtcSTM32GetSecMsec(&RTCD1, &tv_sec, NULL);
+ alarmspec.tv_sec = tv_sec + RTC_ALARMPERIOD;
+ rtcSetAlarm(&RTCD1, 0, &alarmspec);
+
+ rtcSetCallback(&RTCD1, my_cb);
+
+ while (TRUE){
+
+ /* Wait until alarm callback signaled semaphore.*/
+ status = chBSemWaitTimeout(&alarm_sem, S2ST(RTC_ALARMPERIOD + 5));
+
+ if (status == MSG_TIMEOUT){
+ osalSysHalt("time is out");
+ }
+ else{
+ rtcSTM32GetSecMsec(&RTCD1, &tv_sec, NULL);
+ alarmspec.tv_sec = tv_sec + RTC_ALARMPERIOD;
+ rtcSetAlarm(&RTCD1, 0, &alarmspec);
+ }
+ }
+ return 0;
+}
+
+#endif /* TEST_ALARM_WAKEUP */
+
+