diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-09-13 12:40:42 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-09-13 12:40:42 +0000 |
commit | fbac4d253d67cc5b1ec39166ce1abb8124b1e3a8 (patch) | |
tree | 23300615d3484cef1515fba815a7218f1118d377 /os/hal | |
parent | b86e5efeeb17af6937319d0fd874fc64b0c1ccb4 (diff) | |
download | ChibiOS-fbac4d253d67cc5b1ec39166ce1abb8124b1e3a8.tar.gz ChibiOS-fbac4d253d67cc5b1ec39166ce1abb8124b1e3a8.tar.bz2 ChibiOS-fbac4d253d67cc5b1ec39166ce1abb8124b1e3a8.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3314 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal')
-rw-r--r-- | os/hal/include/ext.h | 30 | ||||
-rw-r--r-- | os/hal/platforms/STM32/ext_lld.c | 51 | ||||
-rw-r--r-- | os/hal/platforms/STM32/ext_lld.h | 2 | ||||
-rw-r--r-- | os/hal/src/ext.c | 46 | ||||
-rw-r--r-- | os/hal/templates/ext_lld.c | 24 | ||||
-rw-r--r-- | os/hal/templates/ext_lld.h | 2 |
6 files changed, 146 insertions, 9 deletions
diff --git a/os/hal/include/ext.h b/os/hal/include/ext.h index 83191b030..5d904cf4e 100644 --- a/os/hal/include/ext.h +++ b/os/hal/include/ext.h @@ -39,12 +39,14 @@ * @name EXT channels modes
* @{
*/
+#define EXT_CH_MODE_EDGES_MASK 3 /**< @brief Mask of edges field. */
#define EXT_CH_MODE_DISABLED 0 /**< @brief Channel disabled. */
#define EXT_CH_MODE_RISING_EDGE 1 /**< @brief Rising edge callback. */
#define EXT_CH_MODE_FALLING_EDGE 2 /**< @brief Falling edge callback. */
-/** @brief Both edges callback.*/
-#define EXT_CH_MODE_BOTH_EDGES (EXT_CH_MODE_RISING_EDGE | \
- EXT_CH_MODE_FALLING_EDGE)
+#define EXT_CH_MODE_BOTH_EDGES 3 /**< @brief Both edges callback. */
+
+#define EXT_CH_MODE_AUTOSTART 4 /**< @brief Channel started
+ automatically on driver start. */
/** @} */
/*===========================================================================*/
@@ -79,6 +81,26 @@ typedef struct EXTDriver EXTDriver; /* Driver macros. */
/*===========================================================================*/
+/**
+ * @brief Enables an EXT channel.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ * @param[in] channel channel to be enabled
+ *
+ * @iclass
+ */
+#define extChannelEnableI(extp, channel) ext_lld_channel_enable(extp, channel)
+
+/**
+ * @brief Disables an EXT channel.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ * @param[in] channel channel to be disabled
+ *
+ * @iclass
+ */
+#define extChannelDisableI(extp, channel) ext_lld_channel_disable(extp, channel)
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@@ -90,6 +112,8 @@ extern "C" { void extObjectInit(EXTDriver *extp);
void extStart(EXTDriver *extp, const EXTConfig *config);
void extStop(EXTDriver *extp);
+ void extChannelEnable(EXTDriver *extp, expchannel_t channel);
+ void extChannelDisable(EXTDriver *extp, expchannel_t channel);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/platforms/STM32/ext_lld.c b/os/hal/platforms/STM32/ext_lld.c index fc203fa60..712ed5a39 100644 --- a/os/hal/platforms/STM32/ext_lld.c +++ b/os/hal/platforms/STM32/ext_lld.c @@ -328,7 +328,7 @@ void ext_lld_start(EXTDriver *extp) { /* Configuration.*/
imr = emr = rtsr = ftsr = 0;
for (i = 0; i < EXT_MAX_CHANNELS; i++) {
- if (extp->config->channels[i].mode != EXT_CH_MODE_DISABLED) {
+ if (extp->config->channels[i].mode & EXT_CH_MODE_AUTOSTART) {
if (extp->config->channels[i].cb != NULL)
imr |= (1 << i);
else
@@ -344,11 +344,11 @@ void ext_lld_start(EXTDriver *extp) { AFIO->EXTICR[2] = extp->config->exti[2];
AFIO->EXTICR[3] = extp->config->exti[3];
EXTI->SWIER = 0;
- EXTI->RTSR = rtsr;
- EXTI->FTSR = ftsr;
- EXTI->PR = EXT_CHANNELS_MASK;
- EXTI->EMR = emr;
- EXTI->IMR = imr;
+ EXTI->RTSR = rtsr;
+ EXTI->FTSR = ftsr;
+ EXTI->PR = EXT_CHANNELS_MASK;
+ EXTI->EMR = emr;
+ EXTI->IMR = imr;
}
/**
@@ -385,6 +385,45 @@ void ext_lld_stop(EXTDriver *extp) { EXTI->PR = EXT_CHANNELS_MASK;
}
+/**
+ * @brief Enables an EXT channel.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ * @param[in] channel channel to be enabled
+ *
+ * @notapi
+ */
+void ext_lld_channel_enable(EXTDriver *extp, expchannel_t channel) {
+
+ if (extp->config->channels[channel].cb != NULL)
+ EXTI->IMR |= (1 << channel);
+ else
+ EXTI->EMR |= (1 << channel);
+ if (extp->config->channels[channel].mode & EXT_CH_MODE_RISING_EDGE)
+ EXTI->RTSR |= (1 << channel);
+ if (extp->config->channels[channel].mode & EXT_CH_MODE_FALLING_EDGE)
+ EXTI->FTSR |= (1 << channel);
+}
+
+/**
+ * @brief Disables an EXT channel.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ * @param[in] channel channel to be disabled
+ *
+ * @notapi
+ */
+void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel) {
+
+ (void)extp;
+
+ EXTI->IMR &= ~(1 << channel);
+ EXTI->EMR &= ~(1 << channel);
+ EXTI->RTSR &= ~(1 << channel);
+ EXTI->FTSR &= ~(1 << channel);
+ EXTI->PR = (1 << channel);
+}
+
#endif /* HAL_USE_EXT */
/** @} */
diff --git a/os/hal/platforms/STM32/ext_lld.h b/os/hal/platforms/STM32/ext_lld.h index 45e863d9c..17ea09fb8 100644 --- a/os/hal/platforms/STM32/ext_lld.h +++ b/os/hal/platforms/STM32/ext_lld.h @@ -254,6 +254,8 @@ extern "C" { void ext_lld_init(void);
void ext_lld_start(EXTDriver *extp);
void ext_lld_stop(EXTDriver *extp);
+ void ext_lld_channel_enable(EXTDriver *extp, expchannel_t channel);
+ void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c index d68758684..1c83cd2e6 100644 --- a/os/hal/src/ext.c +++ b/os/hal/src/ext.c @@ -78,6 +78,8 @@ void extObjectInit(EXTDriver *extp) { /**
* @brief Configures and activates the EXT peripheral.
+ * @post After activation all EXT channels are in the disabled state,
+ * use @p extChannelEnable() in order to activate them.
*
* @param[in] extp pointer to the @p EXTDriver object
* @param[in] config pointer to the @p EXTConfig object
@@ -116,6 +118,50 @@ void extStop(EXTDriver *extp) { chSysUnlock();
}
+/**
+ * @brief Enables an EXT channel.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ * @param[in] channel channel to be enabled
+ *
+ * @api
+ */
+void extChannelEnable(EXTDriver *extp, expchannel_t channel) {
+
+ chDbgCheck((extp != NULL) &&
+ (channel < EXT_MAX_CHANNELS) &&
+ (extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED),
+ "extChannelEnable");
+
+ chSysLock();
+ chDbgAssert(extp->state == EXT_ACTIVE,
+ "extChannelEnable(), #1", "invalid state");
+ extChannelEnableI(extp, channel);
+ chSysUnlock();
+}
+
+/**
+ * @brief Disables an EXT channel.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ * @param[in] channel channel to be disabled
+ *
+ * @api
+ */
+void extChannelDisable(EXTDriver *extp, expchannel_t channel) {
+
+ chDbgCheck((extp != NULL) &&
+ (channel < EXT_MAX_CHANNELS) &&
+ (extp->config->channels[channel].mode != EXT_CH_MODE_DISABLED),
+ "extChannelDisable");
+
+ chSysLock();
+ chDbgAssert(extp->state == EXT_ACTIVE,
+ "extChannelDisable(), #1", "invalid state");
+ extChannelDisableI(extp, channel);
+ chSysUnlock();
+}
+
#endif /* HAL_USE_EXT */
/** @} */
diff --git a/os/hal/templates/ext_lld.c b/os/hal/templates/ext_lld.c index 1aa9477a6..45bc1c3dc 100644 --- a/os/hal/templates/ext_lld.c +++ b/os/hal/templates/ext_lld.c @@ -94,6 +94,30 @@ void ext_lld_stop(EXTDriver *extp) { }
}
+/**
+ * @brief Enables an EXT channel.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ * @param[in] channel channel to be enabled
+ *
+ * @notapi
+ */
+void ext_lld_channel_enable(EXTDriver *extp, expchannel_t channel) {
+
+}
+
+/**
+ * @brief Disables an EXT channel.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ * @param[in] channel channel to be disabled
+ *
+ * @notapi
+ */
+void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel) {
+
+}
+
#endif /* HAL_USE_EXT */
/** @} */
diff --git a/os/hal/templates/ext_lld.h b/os/hal/templates/ext_lld.h index eb5a624a4..494cef1b9 100644 --- a/os/hal/templates/ext_lld.h +++ b/os/hal/templates/ext_lld.h @@ -114,6 +114,8 @@ extern "C" { void ext_lld_init(void);
void ext_lld_start(EXTDriver *extp);
void ext_lld_stop(EXTDriver *extp);
+ void ext_lld_channel_enable(EXTDriver *extp, expchannel_t channel);
+ void ext_lld_channel_disable(EXTDriver *extp, expchannel_t channel);
#ifdef __cplusplus
}
#endif
|