aboutsummaryrefslogtreecommitdiffstats
path: root/testhal
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-11 20:07:19 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-11 20:07:19 +0000
commit7f333ab4563c75d4e32f86c01db51a75fe07ed65 (patch)
treea832aa1701dd91170cf0b93c5966ba5f4cad281f /testhal
parentbff048984efe45bcdb0a072598d0e9ef6f32a6d5 (diff)
downloadChibiOS-7f333ab4563c75d4e32f86c01db51a75fe07ed65.tar.gz
ChibiOS-7f333ab4563c75d4e32f86c01db51a75fe07ed65.tar.bz2
ChibiOS-7f333ab4563c75d4e32f86c01db51a75fe07ed65.zip
RTC. Fixed some bugs and added locks into write functions. Haltest updated.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3790 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal')
-rw-r--r--testhal/STM32F1xx/RTC/main.c58
-rw-r--r--testhal/STM32F1xx/RTC/mcuconf.h4
2 files changed, 44 insertions, 18 deletions
diff --git a/testhal/STM32F1xx/RTC/main.c b/testhal/STM32F1xx/RTC/main.c
index 84df3c109..2b3bb7be8 100644
--- a/testhal/STM32F1xx/RTC/main.c
+++ b/testhal/STM32F1xx/RTC/main.c
@@ -24,17 +24,23 @@
RTCTime timespec;
RTCAlarm alarmspec;
-#define TEST_ALARM_WAKEUP FALSE
+#define TEST_ALARM_WAKEUP TRUE
#if TEST_ALARM_WAKEUP
+static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
+ (void)rtcp;
+ (void)event;
+ return;
+}
+
/* sleep indicator thread */
static WORKING_AREA(blinkWA, 128);
static msg_t blink_thd(void *arg){
(void)arg;
while (TRUE) {
chThdSleepMilliseconds(100);
- palTogglePad(IOPORT3, GPIOC_LED);
+ palTogglePad(GPIOC, GPIOC_LED);
}
return 0;
}
@@ -45,24 +51,32 @@ int main(void) {
chThdCreateStatic(blinkWA, sizeof(blinkWA), NORMALPRIO, blink_thd, NULL);
/* set alarm in near future */
- rtcGetTime(&timespec);
- alarmspec.tv_sec = timespec.tv_sec + 60;
- rtcSetAlarm(&alarmspec);
+ rtcGetTime(&RTCD1, &timespec);
+ alarmspec.tv_sec = timespec.tv_sec + 30;
+ rtcSetAlarm(&RTCD1, 0, &alarmspec);
+
+ /* Needed just to switch interrupts on.*/
+ rtcSetCallback(&RTCD1, my_cb);
while (TRUE){
- chThdSleepSeconds(10);
- chSysLock();
+ chThdSleepSeconds(10);
+ chSysLock();
- /* going to anabiosis*/
- PWR->CR |= (PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
- SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
- __WFI();
+ /* going to anabiosis*/
+ PWR->CR |= (PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_CSBF | PWR_CR_CWUF);
+ SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
+ __WFI();
}
return 0;
}
#else /* TEST_ALARM_WAKEUP */
+/* Manually reloaded test alarm period.*/
+#define RTC_ALARMPERIOD 10
+
+BinarySemaphore alarm_sem;
+
static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
(void)rtcp;
@@ -76,24 +90,36 @@ static void my_cb(RTCDriver *rtcp, rtcevent_t event) {
break;
case RTC_EVENT_ALARM:
palTogglePad(GPIOC, GPIOC_LED);
- rtcGetTime(&RTCD1, &timespec);
- alarmspec.tv_sec = timespec.tv_sec + 10;
- rtcSetAlarm(&RTCD1, 0, &alarmspec);
+ chBSemSignalI(&alarm_sem);
break;
}
}
int main(void) {
+ msg_t status = RDY_TIMEOUT;
+
halInit();
chSysInit();
+ chBSemInit(&alarm_sem, TRUE);
rtcGetTime(&RTCD1, &timespec);
- alarmspec.tv_sec = timespec.tv_sec + 10;
+ alarmspec.tv_sec = timespec.tv_sec + RTC_ALARMPERIOD;
rtcSetAlarm(&RTCD1, 0, &alarmspec);
rtcSetCallback(&RTCD1, my_cb);
while (TRUE){
- chThdSleepMilliseconds(500);
+
+ /* Wait until alarm callback signaled semaphore.*/
+ status = chBSemWaitTimeout(&alarm_sem, S2ST(RTC_ALARMPERIOD + 5));
+
+ if (status == RDY_TIMEOUT){
+ chSysHalt();
+ }
+ else{
+ rtcGetTime(&RTCD1, &timespec);
+ alarmspec.tv_sec = timespec.tv_sec + RTC_ALARMPERIOD;
+ rtcSetAlarm(&RTCD1, 0, &alarmspec);
+ }
}
return 0;
}
diff --git a/testhal/STM32F1xx/RTC/mcuconf.h b/testhal/STM32F1xx/RTC/mcuconf.h
index 1a38f9876..e43e31d12 100644
--- a/testhal/STM32F1xx/RTC/mcuconf.h
+++ b/testhal/STM32F1xx/RTC/mcuconf.h
@@ -38,7 +38,7 @@
#define STM32_HSI_ENABLED TRUE
#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED TRUE
-#define STM32_LSE_ENABLED FALSE
+#define STM32_LSE_ENABLED TRUE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PLLXTPRE STM32_PLLXTPRE_DIV1
@@ -50,7 +50,7 @@
#define STM32_USB_CLOCK_REQUIRED TRUE
#define STM32_USBPRE STM32_USBPRE_DIV1P5
#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK
-#define STM32_RTCSEL STM32_RTCSEL_HSEDIV
+#define STM32_RTCSEL STM32_RTCSEL_LSE
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0