aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32/multi/PAL
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2017-08-31 14:04:24 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2017-08-31 14:04:24 +0000
commit424f88606831bf8645716b9cfce831b468cfca75 (patch)
treea9ec0ecab43e2ca267176cdd35d77134be33c6aa /testhal/STM32/multi/PAL
parentf400137e6fb5992253f884faf59e39e831766b0e (diff)
downloadChibiOS-424f88606831bf8645716b9cfce831b468cfca75.tar.gz
ChibiOS-424f88606831bf8645716b9cfce831b468cfca75.tar.bz2
ChibiOS-424f88606831bf8645716b9cfce831b468cfca75.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10514 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32/multi/PAL')
-rw-r--r--testhal/STM32/multi/PAL/.project5
-rw-r--r--testhal/STM32/multi/PAL/cfg-stm32l476_discovery/portab.h6
-rw-r--r--testhal/STM32/multi/PAL/main.c52
3 files changed, 47 insertions, 16 deletions
diff --git a/testhal/STM32/multi/PAL/.project b/testhal/STM32/multi/PAL/.project
index a50e94f93..f08c2332f 100644
--- a/testhal/STM32/multi/PAL/.project
+++ b/testhal/STM32/multi/PAL/.project
@@ -77,11 +77,6 @@
</natures>
<linkedResources>
<link>
- <name>board</name>
- <type>2</type>
- <locationURI>CHIBIOS/os/hal/boards/ST_STM32L476_DISCOVERY</locationURI>
- </link>
- <link>
<name>os</name>
<type>2</type>
<locationURI>CHIBIOS/os</locationURI>
diff --git a/testhal/STM32/multi/PAL/cfg-stm32l476_discovery/portab.h b/testhal/STM32/multi/PAL/cfg-stm32l476_discovery/portab.h
index b5d68b86b..a887e3190 100644
--- a/testhal/STM32/multi/PAL/cfg-stm32l476_discovery/portab.h
+++ b/testhal/STM32/multi/PAL/cfg-stm32l476_discovery/portab.h
@@ -29,9 +29,9 @@
/* Module constants. */
/*===========================================================================*/
-#define PORTAB_BLINK_LED1 LINE_LED_GREEN
-#define PORTAB_BLINK_LED2 LINE_LED_RED
-#define PORTAB_BLINK_BUTTON LINE_JOY_DOWN
+#define PORTAB_LINE_LED1 LINE_LED_GREEN
+#define PORTAB_LINE_LED2 LINE_LED_RED
+#define PORTAB_LINE_BUTTON LINE_JOY_CENTER
/*===========================================================================*/
/* Module pre-compile time settings. */
diff --git a/testhal/STM32/multi/PAL/main.c b/testhal/STM32/multi/PAL/main.c
index c57a75f02..81d520cc5 100644
--- a/testhal/STM32/multi/PAL/main.c
+++ b/testhal/STM32/multi/PAL/main.c
@@ -22,28 +22,46 @@
/* Generic code. */
/*===========================================================================*/
-#if defined(PORTAB_BLINK_LED2)
+#if defined(PORTAB_LINE_LED2)
/*
* LED blinker thread, times are in milliseconds.
*/
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {
-
(void)arg;
chRegSetThreadName("blinker");
while (true) {
- palClearLine(PORTAB_BLINK_LED2);
- chThdSleepMilliseconds(500);
- palSetLine(PORTAB_BLINK_LED2);
- chThdSleepMilliseconds(500);
+ systime_t time = palReadLine(PORTAB_LINE_BUTTON) == PAL_LOW ? 500 : 250;
+ palClearLine(PORTAB_LINE_LED2);
+ chThdSleepMilliseconds(time);
+ palSetLine(PORTAB_LINE_LED2);
+ chThdSleepMilliseconds(time);
}
}
#endif
+event_source_t button_pressed_event;
+event_source_t button_released_event;
+
+static void button_cb(void *arg) {
+
+ (void)arg;
+
+ chSysLockFromISR();
+ if (palReadLine(PORTAB_LINE_BUTTON) == PAL_LOW) {
+ chEvtBroadcastI(&button_released_event);
+ }
+ else {
+ chEvtBroadcastI(&button_pressed_event);
+ }
+ chSysUnlockFromISR();
+}
+
/*
* Application entry point.
*/
int main(void) {
+ event_listener_t el0, el1;
/*
* System initializations.
@@ -55,17 +73,35 @@ int main(void) {
halInit();
chSysInit();
-#if defined(PORTAB_BLINK_LED2)
+ /* Events initialization and registration.*/
+ chEvtObjectInit(&button_pressed_event);
+ chEvtObjectInit(&button_released_event);
+ chEvtRegister(&button_pressed_event, &el0, 0);
+ chEvtRegister(&button_released_event, &el1, 1);
+
+#if defined(PORTAB_LINE_LED2)
/*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
#endif
+ /* Enabling callback on both edges of the button line.*/
+ palLineEnableEvent(PORTAB_LINE_BUTTON, PAL_EVENT_MODE_BOTH_EDGES,
+ button_cb, NULL);
+
/*
* Normal main() thread activity.
*/
while (true) {
- chThdSleepMilliseconds(1000);
+ eventmask_t events;
+
+ events = chEvtWaitOne(EVENT_MASK(0) | EVENT_MASK(1));
+ if (events & EVENT_MASK(0)) {
+ palSetLine(PORTAB_LINE_LED1);
+ }
+ if (events & EVENT_MASK(1)) {
+ palClearLine(PORTAB_LINE_LED1);
+ }
}
}