aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-12 18:27:00 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-12 18:27:00 +0000
commit3db4f2d2353f7f87f5112fb8d152e87733bd9ae0 (patch)
treecbc282949c8ed7e930b26ca49f316c074cd6b288
parentd3e15bccfc41af4e4d3972003ff06b69de2225bc (diff)
downloadChibiOS-3db4f2d2353f7f87f5112fb8d152e87733bd9ae0.tar.gz
ChibiOS-3db4f2d2353f7f87f5112fb8d152e87733bd9ae0.tar.bz2
ChibiOS-3db4f2d2353f7f87f5112fb8d152e87733bd9ae0.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3311 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--testhal/STM32F1xx/EXT/main.c83
1 files changed, 60 insertions, 23 deletions
diff --git a/testhal/STM32F1xx/EXT/main.c b/testhal/STM32F1xx/EXT/main.c
index ce21c1fd8..a438c3035 100644
--- a/testhal/STM32F1xx/EXT/main.c
+++ b/testhal/STM32F1xx/EXT/main.c
@@ -21,29 +21,71 @@
#include "ch.h"
#include "hal.h"
-static const EXTConfig extcfg = {
- {
- {EXT_CH_MODE_DISABLED, NULL},
- },
- EXT_MODE_EXTI(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
-};
+static VirtualTimer vt;
-/*
- * Red LED blinker thread, times are in milliseconds.
- */
-static WORKING_AREA(waThread1, 128);
-static msg_t Thread1(void *arg) {
+/* LED set to OFF after 200mS.*/
+static void ledoff(void *arg) {
(void)arg;
- chRegSetThreadName("blinker");
- while (TRUE) {
- palClearPad(GPIOC, GPIOC_LED);
- chThdSleepMilliseconds(500);
- palSetPad(GPIOC, GPIOC_LED);
- chThdSleepMilliseconds(500);
- }
+ palSetPad(GPIOC, GPIOC_LED);
+}
+
+/* Triggered when the button is pressed or released. The LED is set to ON.*/
+static void extcb1(EXTDriver *extp, expchannel_t channel) {
+
+ (void)extp;
+ (void)channel;
+ palClearPad(GPIOC, GPIOC_LED);
+ chSysLockFromIsr();
+ if (!chVTIsArmedI(&vt))
+ chVTSetI(&vt, MS2ST(200), ledoff, NULL);
+ chSysUnlockFromIsr();
+}
+
+/* Triggered when the LED goes OFF.*/
+static void extcb2(EXTDriver *extp, expchannel_t channel) {
+
+ (void)extp;
+ (void)channel;
}
+static const EXTConfig extcfg = {
+ {
+ {EXT_CH_MODE_BOTH_EDGES, extcb1},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_RISING_EDGE, extcb2},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ {EXT_CH_MODE_DISABLED, NULL},
+ },
+ EXT_MODE_EXTI(EXT_MODE_GPIOA,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ EXT_MODE_GPIOC,
+ 0,
+ 0,
+ 0)
+};
+
/*
* Application entry point.
*/
@@ -65,11 +107,6 @@ int main(void) {
extStart(&EXTD1, &extcfg);
/*
- * Creates the blinker thread.
- */
- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
-
- /*
* Normal main() thread activity, in this demo it does nothing except
* sleeping in a loop and check the button state.
*/