aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-12 13:40:44 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-12 13:40:44 +0000
commit7148a664b5c73138a504cd61a1882cfb91ba3b7a (patch)
treea53dae25c3193d92d3a940adf479816f0aa96ecf /os
parentcf7747f0407db08d59ecb0570dd66f867a07063e (diff)
downloadChibiOS-7148a664b5c73138a504cd61a1882cfb91ba3b7a.tar.gz
ChibiOS-7148a664b5c73138a504cd61a1882cfb91ba3b7a.tar.bz2
ChibiOS-7148a664b5c73138a504cd61a1882cfb91ba3b7a.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3309 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/dox/ext.dox84
-rw-r--r--os/hal/hal.mk1
-rw-r--r--os/hal/include/ext.h101
-rw-r--r--os/hal/include/hal.h1
-rw-r--r--os/hal/platforms/STM32/ext_lld.c390
-rw-r--r--os/hal/platforms/STM32/ext_lld.h265
-rw-r--r--os/hal/platforms/STM32F1xx/platform.mk1
-rw-r--r--os/hal/src/ext.c121
-rw-r--r--os/hal/src/hal.c3
-rw-r--r--os/hal/templates/ext_lld.c99
-rw-r--r--os/hal/templates/ext_lld.h125
11 files changed, 1191 insertions, 0 deletions
diff --git a/os/hal/dox/ext.dox b/os/hal/dox/ext.dox
new file mode 100644
index 000000000..5a66830e9
--- /dev/null
+++ b/os/hal/dox/ext.dox
@@ -0,0 +1,84 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @defgroup EXT EXT Driver
+ * @brief Generic EXT Driver.
+ * @details This module implements a generic EXT (EXTernal) driver.
+ * @pre In order to use the EXT driver the @p HAL_USE_EXT option
+ * must be enabled in @p halconf.h.
+ *
+ * @section ext_1 Driver State Machine
+ * The driver implements a state machine internally, not all the driver
+ * functionalities can be used in any moment, any transition not explicitly
+ * shown in the following diagram has to be considered an error and shall
+ * be captured by an assertion (if enabled).
+ * @if LATEX_PDF
+ * @dot
+ digraph example {
+ size="5, 7";
+ rankdir="LR";
+
+ node [shape=circle, fontname=Sans, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
+ edge [fontname=Sans, fontsize=8];
+
+ uninit [label="EXT_UNINIT", style="bold"];
+ stop [label="EXT_STOP\nLow Power"];
+ active [label="EXT_ACTIVE"];
+
+ uninit -> stop [label="extInit()"];
+ stop -> stop [label="\nextStop()"];
+ stop -> active [label="\nextStart()"];
+ active -> stop [label="\nextStop()"];
+ active -> active [label="\nextStart()"];
+ }
+ * @enddot
+ * @else
+ * @dot
+ digraph example {
+ rankdir="LR";
+
+ node [shape=circle, fontname=Sans, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
+ edge [fontname=Sans, fontsize=8];
+
+ uninit [label="EXT_UNINIT", style="bold"];
+ stop [label="EXT_STOP\nLow Power"];
+ active [label="EXT_ACTIVE"];
+
+ uninit -> stop [label="extInit()"];
+ stop -> stop [label="\nextStop()"];
+ stop -> active [label="\nextStart()"];
+ active -> stop [label="\nextStop()"];
+ active -> active [label="\nextStart()"];
+ }
+ * @enddot
+ * @endif
+ *
+ * @section ext_2 EXT Operations.
+ * This driver abstracts generic external interrupt sources, a callback
+ * is invoked when a programmable transition is detected on one of the
+ * configured channels. Several channel modes are possible.
+ * - <b>EXT_CH_MODE_DISABLED</b>, channel not used.
+ * - <b>EXT_CH_MODE_RISING_EDGE</b>, callback on a rising edge.
+ * - <b>EXT_CH_MODE_FALLING_EDGE</b>, callback on a falling edge.
+ * - <b>EXT_CH_MODE_BOTH_EDGES</b>, callback on a both edges.
+ * .
+ * @ingroup IO
+ */
diff --git a/os/hal/hal.mk b/os/hal/hal.mk
index 87a3c6dc3..dddb73f85 100644
--- a/os/hal/hal.mk
+++ b/os/hal/hal.mk
@@ -3,6 +3,7 @@
HALSRC = ${CHIBIOS}/os/hal/src/hal.c \
${CHIBIOS}/os/hal/src/adc.c \
${CHIBIOS}/os/hal/src/can.c \
+ ${CHIBIOS}/os/hal/src/ext.c \
${CHIBIOS}/os/hal/src/gpt.c \
${CHIBIOS}/os/hal/src/i2c.c \
${CHIBIOS}/os/hal/src/icu.c \
diff --git a/os/hal/include/ext.h b/os/hal/include/ext.h
new file mode 100644
index 000000000..83191b030
--- /dev/null
+++ b/os/hal/include/ext.h
@@ -0,0 +1,101 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file ext.h
+ * @brief EXT Driver macros and structures.
+ *
+ * @addtogroup EXT
+ * @{
+ */
+
+#ifndef _EXT_H_
+#define _EXT_H_
+
+#if HAL_USE_EXT || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @name EXT channels modes
+ * @{
+ */
+#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)
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Driver state machine possible states.
+ */
+typedef enum {
+ EXT_UNINIT = 0, /**< Not initialized. */
+ EXT_STOP = 1, /**< Stopped. */
+ EXT_ACTIVE = 2, /**< Active. */
+} extstate_t;
+
+/**
+ * @brief Type of a structure representing a EXT driver.
+ */
+typedef struct EXTDriver EXTDriver;
+
+#include "ext_lld.h"
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void extInit(void);
+ void extObjectInit(EXTDriver *extp);
+ void extStart(EXTDriver *extp, const EXTConfig *config);
+ void extStop(EXTDriver *extp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_EXT */
+
+#endif /* _EXT_H_ */
+
+/** @} */
diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h
index b92789b02..8d7214325 100644
--- a/os/hal/include/hal.h
+++ b/os/hal/include/hal.h
@@ -37,6 +37,7 @@
#include "pal.h"
#include "adc.h"
#include "can.h"
+#include "ext.h"
#include "gpt.h"
#include "i2c.h"
#include "icu.h"
diff --git a/os/hal/platforms/STM32/ext_lld.c b/os/hal/platforms/STM32/ext_lld.c
new file mode 100644
index 000000000..fc203fa60
--- /dev/null
+++ b/os/hal/platforms/STM32/ext_lld.c
@@ -0,0 +1,390 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file STM32/ext_lld.c
+ * @brief STM32 EXT subsystem low level driver source.
+ *
+ * @addtogroup EXT
+ * @{
+ */
+
+#include "ch.h"
+#include "hal.h"
+
+#if HAL_USE_EXT || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/**
+ * @brief EXTD1 driver identifier.
+ */
+EXTDriver EXTD1;
+
+/*===========================================================================*/
+/* Driver local variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/**
+ * @brief EXTI[0] interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(EXTI0_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 0);
+ EXTD1.config->channels[0].cb(&EXTD1, 0);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief EXTI[1] interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(EXTI1_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 1);
+ EXTD1.config->channels[1].cb(&EXTD1, 1);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief EXTI[2] interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(EXTI2_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 2);
+ EXTD1.config->channels[2].cb(&EXTD1, 2);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief EXTI[3] interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(EXTI3_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 3);
+ EXTD1.config->channels[3].cb(&EXTD1, 3);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief EXTI[4] interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(EXTI4_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 4);
+ EXTD1.config->channels[4].cb(&EXTD1, 4);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief EXTI[5]...EXTI[9] interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(EXTI9_5_IRQHandler) {
+ uint32_t pr;
+
+ CH_IRQ_PROLOGUE();
+
+ pr = EXTI->PR;
+ EXTI->PR = pr;
+ if (pr & (1 << 5))
+ EXTD1.config->channels[5].cb(&EXTD1, 5);
+ if (pr & (1 << 6))
+ EXTD1.config->channels[6].cb(&EXTD1, 6);
+ if (pr & (1 << 7))
+ EXTD1.config->channels[7].cb(&EXTD1, 7);
+ if (pr & (1 << 8))
+ EXTD1.config->channels[8].cb(&EXTD1, 8);
+ if (pr & (1 << 9))
+ EXTD1.config->channels[9].cb(&EXTD1, 9);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief EXTI[10]...EXTI[15] interrupt handler.
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(EXTI15_10_IRQHandler) {
+ uint32_t pr;
+
+ CH_IRQ_PROLOGUE();
+
+ pr = EXTI->PR;
+ EXTI->PR = pr;
+ if (pr & (1 << 10))
+ EXTD1.config->channels[10].cb(&EXTD1, 10);
+ if (pr & (1 << 11))
+ EXTD1.config->channels[11].cb(&EXTD1, 11);
+ if (pr & (1 << 12))
+ EXTD1.config->channels[12].cb(&EXTD1, 12);
+ if (pr & (1 << 13))
+ EXTD1.config->channels[13].cb(&EXTD1, 13);
+ if (pr & (1 << 14))
+ EXTD1.config->channels[14].cb(&EXTD1, 14);
+ if (pr & (1 << 15))
+ EXTD1.config->channels[15].cb(&EXTD1, 15);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief EXTI[16] interrupt handler (PVD).
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(PVD_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 16);
+ EXTD1.config->channels[16].cb(&EXTD1, 16);
+
+ CH_IRQ_EPILOGUE();
+}
+
+/**
+ * @brief EXTI[17] interrupt handler (RTC).
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(RTCAlarm_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 17);
+ EXTD1.config->channels[17].cb(&EXTD1, 17);
+
+ CH_IRQ_EPILOGUE();
+}
+
+#if STM32_HAS_USB || defined(__DOXYGEN__)
+/**
+ * @brief EXTI[18] interrupt handler (USB).
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(USBWakeUp_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 18);
+ EXTD1.config->channels[18].cb(&EXTD1, 18);
+
+ CH_IRQ_EPILOGUE();
+}
+#endif /* STM32_HAS_USB */
+
+#if STM32_HAS_OTG1 || defined(__DOXYGEN__)
+/**
+ * @brief EXTI[18] interrupt handler (OTG1).
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(OTG_FS_WKUP_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 18);
+ EXTD1.config->channels[18].cb(&EXTD1, 18);
+
+ CH_IRQ_EPILOGUE();
+}
+#endif /* STM32_HAS_OTG1 */
+
+#if STM32_HAS_ETH || defined(__DOXYGEN__)
+/**
+ * @brief EXTI[19] interrupt handler (ETH).
+ *
+ * @isr
+ */
+CH_IRQ_HANDLER(ETH_WKUP_IRQHandler) {
+
+ CH_IRQ_PROLOGUE();
+
+ EXTI->PR = (1 << 19);
+ EXTD1.config->channels[19].cb(&EXTD1, 19);
+
+ CH_IRQ_EPILOGUE();
+}
+#endif /* STM32_HAS_ETH */
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * @brief Low level EXT driver initialization.
+ *
+ * @notapi
+ */
+void ext_lld_init(void) {
+
+ /* Driver initialization.*/
+ extObjectInit(&EXTD1);
+}
+
+/**
+ * @brief Configures and activates the EXT peripheral.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ *
+ * @notapi
+ */
+void ext_lld_start(EXTDriver *extp) {
+ unsigned i;
+ uint32_t imr, emr, rtsr, ftsr;
+
+ if (extp->state == EXT_STOP) {
+ /* Clock activation.*/
+ NVICEnableVector(EXTI0_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI0_IRQ_PRIORITY));
+ NVICEnableVector(EXTI1_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI1_IRQ_PRIORITY));
+ NVICEnableVector(EXTI2_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI2_IRQ_PRIORITY));
+ NVICEnableVector(EXTI3_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI3_IRQ_PRIORITY));
+ NVICEnableVector(EXTI4_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI4_IRQ_PRIORITY));
+ NVICEnableVector(EXTI9_5_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI5_9_IRQ_PRIORITY));
+ NVICEnableVector(EXTI15_10_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI10_15_IRQ_PRIORITY));
+ NVICEnableVector(PVD_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI16_IRQ_PRIORITY));
+ NVICEnableVector(RTCAlarm_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI17_IRQ_PRIORITY));
+#if STM32_HAS_USB
+ NVICEnableVector(USBWakeUp_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI18_IRQ_PRIORITY));
+#endif
+#if STM32_HAS_OTG1
+ NVICEnableVector(OTG_FS_WKUP_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI18_IRQ_PRIORITY));
+#endif
+#if STM32_HAS_ETH
+ NVICEnableVector(ETH_WKUP_IRQn,
+ CORTEX_PRIORITY_MASK(STM32_EXT_EXTI19_IRQ_PRIORITY));
+#endif
+ }
+ /* 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].cb != NULL)
+ imr |= (1 << i);
+ else
+ emr |= (1 << i);
+ if (extp->config->channels[i].mode & EXT_CH_MODE_RISING_EDGE)
+ rtsr |= (1 << i);
+ if (extp->config->channels[i].mode & EXT_CH_MODE_FALLING_EDGE)
+ ftsr |= (1 << i);
+ }
+ }
+ AFIO->EXTICR[0] = extp->config->exti[0];
+ AFIO->EXTICR[1] = extp->config->exti[1];
+ 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;
+}
+
+/**
+ * @brief Deactivates the EXT peripheral.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ *
+ * @notapi
+ */
+void ext_lld_stop(EXTDriver *extp) {
+
+ if (extp->state == EXT_ACTIVE) {
+ NVICDisableVector(EXTI0_IRQn);
+ NVICDisableVector(EXTI1_IRQn);
+ NVICDisableVector(EXTI2_IRQn);
+ NVICDisableVector(EXTI3_IRQn);
+ NVICDisableVector(EXTI4_IRQn);
+ NVICDisableVector(EXTI9_5_IRQn);
+ NVICDisableVector(EXTI15_10_IRQn);
+ NVICDisableVector(PVD_IRQn);
+ NVICDisableVector(RTCAlarm_IRQn);
+#if STM32_HAS_USB
+ NVICDisableVector(USBWakeUp_IRQn);
+#endif
+#if STM32_HAS_OTG1
+ NVICDisableVector(OTG_FS_WKUP_IRQn);
+#endif
+#if STM32_HAS_ETH
+ NVICDisableVector(ETH_WKUP_IRQn);
+#endif
+ }
+ EXTI->EMR = 0;
+ EXTI->IMR = 0;
+ EXTI->PR = EXT_CHANNELS_MASK;
+}
+
+#endif /* HAL_USE_EXT */
+
+/** @} */
diff --git a/os/hal/platforms/STM32/ext_lld.h b/os/hal/platforms/STM32/ext_lld.h
new file mode 100644
index 000000000..45e863d9c
--- /dev/null
+++ b/os/hal/platforms/STM32/ext_lld.h
@@ -0,0 +1,265 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file STM32/ext_lld.h
+ * @brief STM32 EXT subsystem low level driver header.
+ *
+ * @addtogroup EXT
+ * @{
+ */
+
+#ifndef _EXT_LLD_H_
+#define _EXT_LLD_H_
+
+#if HAL_USE_EXT || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @brief Available number of EXT channels.
+ * @note The number of available channels varies depending on the STM32
+ * subfamily:
+ * - STM32F10X_CL, 20 channels.
+ * - STM32F2XX, 23 channels.
+ * - STM32L1XX_MD, 23 channels.
+ * - All other STM32F10X_xx, 19 channels.
+ * .
+ */
+#if defined(STM32F10X_CL) || defined(__DOXYGEN__)
+#define EXT_MAX_CHANNELS 20
+#elif defined(STM32F2XX)
+#define EXT_MAX_CHANNELS 23
+#else
+#define EXT_MAX_CHANNELS 19
+#endif
+
+/**
+ * @brief Mask of the available channels.
+ */
+#define EXT_CHANNELS_MASK (EXT_MAX_CHANNELS - 1)
+
+/**
+ * @name EXTI configuration helpers
+ * @{
+ */
+/**
+ * @brief EXTI-GPIO association macro.
+ * @details Helper macro to associate a GPIO to each of the Mx EXTI inputs.
+ */
+#define EXT_MODE_EXTI(m0, m1, m2, m3, m4, m5, m6, m7, \
+ m8, m9, m10, m11, m12, m13, m14, m15) \
+ { \
+ ((m0) << 0) | ((m1) << 4) | ((m2) << 8) | ((m3) << 12), \
+ ((m4) << 0) | ((m5) << 4) | ((m6) << 8) | ((m7) << 12), \
+ ((m8) << 0) | ((m9) << 4) | ((m10) << 8) | ((m11) << 12), \
+ ((m12) << 0) | ((m13) << 4) | ((m14) << 8) | ((m15) << 12) \
+ }
+
+#define EXT_MODE_GPIOA 0 /**< @brief GPIOA identifier. */
+#define EXT_MODE_GPIOB 1 /**< @brief GPIOB identifier. */
+#define EXT_MODE_GPIOC 2 /**< @brief GPIOC identifier. */
+#define EXT_MODE_GPIOD 3 /**< @brief GPIOD identifier. */
+#define EXT_MODE_GPIOE 4 /**< @brief GPIOE identifier. */
+#define EXT_MODE_GPIOF 5 /**< @brief GPIOF identifier. */
+#define EXT_MODE_GPIOG 6 /**< @brief GPIOG identifier. */
+#define EXT_MODE_GPIOH 7 /**< @brief GPIOH identifier. */
+#define EXT_MODE_GPIOI 8 /**< @brief GPIOI identifier. */
+/** @} */
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/**
+ * @brief EXTI0 interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI0_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI0_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI1 interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI1_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI1_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI2 interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI2_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI2_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI3 interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI3_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI3_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI4 interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI4_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI4_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI9..5 interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI5_9_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI5_9_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI15..10 interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI10_15_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI10_15_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI16 (PVD) interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI16_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI16_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI17 (RTC) interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI17_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI17_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI18 (USB) interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI18_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI18_IRQ_PRIORITY 6
+#endif
+
+/**
+ * @brief EXTI19 (ETH) interrupt priority level setting.
+ */
+#if !defined(STM32_EXT_EXTI19_IRQ_PRIORITY) || defined(__DOXYGEN__)
+#define STM32_EXT_EXTI19_IRQ_PRIORITY 6
+#endif
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief EXT channel identifier.
+ */
+typedef uint32_t expchannel_t;
+
+/**
+ * @brief Type of an EXT generic notification callback.
+ *
+ * @param[in] extp pointer to the @p EXPDriver object triggering the
+ * callback
+ */
+typedef void (*extcallback_t)(EXTDriver *extp, expchannel_t channel);
+
+/**
+ * @brief Channel configuration structure.
+ */
+typedef struct {
+ /**
+ * @brief Channel mode.
+ */
+ uint32_t mode;
+ /**
+ * @brief Channel callback.
+ * @details In the STM32 implementation a @p NULL callback pointer is
+ * valid and configures the channel as an event sources instead
+ * of an interrupt source.
+ */
+ extcallback_t cb;
+} EXTChannelConfig;
+
+/**
+ * @brief Driver configuration structure.
+ * @note It could be empty on some architectures.
+ */
+typedef struct {
+ /**
+ * @brief Channel configurations.
+ */
+ EXTChannelConfig channels[EXT_MAX_CHANNELS];
+ /* End of the mandatory fields.*/
+ /**
+ * @brief Initialization values for EXTICRx registers.
+ */
+ uint16_t exti[4];
+} EXTConfig;
+
+/**
+ * @brief Structure representing an EXT driver.
+ */
+struct EXTDriver {
+ /**
+ * @brief Driver state.
+ */
+ extstate_t state;
+ /**
+ * @brief Current configuration data.
+ */
+ const EXTConfig *config;
+ /* End of the mandatory fields.*/
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#if !defined(__DOXYGEN__)
+extern EXTDriver EXTD1;
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void ext_lld_init(void);
+ void ext_lld_start(EXTDriver *extp);
+ void ext_lld_stop(EXTDriver *extp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_EXT */
+
+#endif /* _EXT_LLD_H_ */
+
+/** @} */
diff --git a/os/hal/platforms/STM32F1xx/platform.mk b/os/hal/platforms/STM32F1xx/platform.mk
index 26f13cd81..89179f65f 100644
--- a/os/hal/platforms/STM32F1xx/platform.mk
+++ b/os/hal/platforms/STM32F1xx/platform.mk
@@ -2,6 +2,7 @@
PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/STM32F1xx/hal_lld.c \
${CHIBIOS}/os/hal/platforms/STM32F1xx/adc_lld.c \
${CHIBIOS}/os/hal/platforms/STM32/can_lld.c \
+ ${CHIBIOS}/os/hal/platforms/STM32/ext_lld.c \
${CHIBIOS}/os/hal/platforms/STM32/gpt_lld.c \
${CHIBIOS}/os/hal/platforms/STM32/icu_lld.c \
${CHIBIOS}/os/hal/platforms/STM32/i2c_lld.c \
diff --git a/os/hal/src/ext.c b/os/hal/src/ext.c
new file mode 100644
index 000000000..d68758684
--- /dev/null
+++ b/os/hal/src/ext.c
@@ -0,0 +1,121 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file ext.c
+ * @brief EXT Driver code.
+ *
+ * @addtogroup EXT
+ * @{
+ */
+
+#include "ch.h"
+#include "hal.h"
+
+#if HAL_USE_EXT || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * @brief EXT Driver initialization.
+ * @note This function is implicitly invoked by @p halInit(), there is
+ * no need to explicitly initialize the driver.
+ *
+ * @init
+ */
+void extInit(void) {
+
+ ext_lld_init();
+}
+
+/**
+ * @brief Initializes the standard part of a @p EXTDriver structure.
+ *
+ * @param[out] extp pointer to the @p EXTDriver object
+ *
+ * @init
+ */
+void extObjectInit(EXTDriver *extp) {
+
+ extp->state = EXT_STOP;
+ extp->config = NULL;
+}
+
+/**
+ * @brief Configures and activates the EXT peripheral.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ * @param[in] config pointer to the @p EXTConfig object
+ *
+ * @api
+ */
+void extStart(EXTDriver *extp, const EXTConfig *config) {
+
+ chDbgCheck((extp != NULL) && (config != NULL), "extStart");
+
+ chSysLock();
+ chDbgAssert((extp->state == EXT_STOP) || (extp->state == EXT_ACTIVE),
+ "extStart(), #1", "invalid state");
+ extp->config = config;
+ ext_lld_start(extp);
+ extp->state = EXT_ACTIVE;
+ chSysUnlock();
+}
+
+/**
+ * @brief Deactivates the EXT peripheral.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ *
+ * @api
+ */
+void extStop(EXTDriver *extp) {
+
+ chDbgCheck(extp != NULL, "extStop");
+
+ chSysLock();
+ chDbgAssert((extp->state == EXT_STOP) || (extp->state == EXT_ACTIVE),
+ "extStop(), #1", "invalid state");
+ ext_lld_stop(extp);
+ extp->state = EXT_STOP;
+ chSysUnlock();
+}
+
+#endif /* HAL_USE_EXT */
+
+/** @} */
diff --git a/os/hal/src/hal.c b/os/hal/src/hal.c
index 3c8fb2fe6..d5a8082e9 100644
--- a/os/hal/src/hal.c
+++ b/os/hal/src/hal.c
@@ -71,6 +71,9 @@ void halInit(void) {
#if HAL_USE_CAN || defined(__DOXYGEN__)
canInit();
#endif
+#if HAL_USE_EXT || defined(__DOXYGEN__)
+ extInit();
+#endif
#if HAL_USE_GPT || defined(__DOXYGEN__)
gptInit();
#endif
diff --git a/os/hal/templates/ext_lld.c b/os/hal/templates/ext_lld.c
new file mode 100644
index 000000000..1aa9477a6
--- /dev/null
+++ b/os/hal/templates/ext_lld.c
@@ -0,0 +1,99 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file templates/ext_lld.c
+ * @brief EXT Driver subsystem low level driver source template.
+ *
+ * @addtogroup EXT
+ * @{
+ */
+
+#include "ch.h"
+#include "hal.h"
+
+#if HAL_USE_EXT || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * @brief Low level EXT driver initialization.
+ *
+ * @notapi
+ */
+void ext_lld_init(void) {
+
+}
+
+/**
+ * @brief Configures and activates the EXT peripheral.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ *
+ * @notapi
+ */
+void ext_lld_start(EXTDriver *extp) {
+
+ if (extp->state == EXT_STOP) {
+ /* Clock activation.*/
+ }
+ /* Configuration.*/
+}
+
+/**
+ * @brief Deactivates the EXT peripheral.
+ *
+ * @param[in] extp pointer to the @p EXTDriver object
+ *
+ * @notapi
+ */
+void ext_lld_stop(EXTDriver *extp) {
+
+ if (extp->state == EXT_ACTIVE) {
+ /* Clock deactivation.*/
+
+ }
+}
+
+#endif /* HAL_USE_EXT */
+
+/** @} */
diff --git a/os/hal/templates/ext_lld.h b/os/hal/templates/ext_lld.h
new file mode 100644
index 000000000..eb5a624a4
--- /dev/null
+++ b/os/hal/templates/ext_lld.h
@@ -0,0 +1,125 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file templates/ext_lld.h
+ * @brief EXT Driver subsystem low level driver header template.
+ *
+ * @addtogroup EXT
+ * @{
+ */
+
+#ifndef _EXT_LLD_H_
+#define _EXT_LLD_H_
+
+#if HAL_USE_EXT || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver constants. */
+/*===========================================================================*/
+
+/**
+ * @brief Available number of EXT channels.
+ */
+#define EXT_MAX_CHANNELS 20
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief EXT channel identifier.
+ */
+typedef uint32_t expchannel_t;
+
+/**
+ * @brief Type of an EXT generic notification callback.
+ *
+ * @param[in] extp pointer to the @p EXPDriver object triggering the
+ * callback
+ */
+typedef void (*extcallback_t)(EXTDriver *extp);
+
+/**
+ * @brief Channel configuration structure.
+ */
+typedef struct {
+ uint32_t mode; /**< @brief Channel mode. */
+ extcallback_t cb; /**< @brief Channel callback. */
+} EXTChannelConfig;
+
+/**
+ * @brief Driver configuration structure.
+ * @note It could be empty on some architectures.
+ */
+typedef struct {
+ /**
+ * @brief Channel configurations.
+ */
+ EXTChannelConfig channels[EXT_MAX_CHANNELS];
+ /* End of the mandatory fields.*/
+} EXTConfig;
+
+/**
+ * @brief Structure representing an EXT driver.
+ */
+struct EXTDriver {
+ /**
+ * @brief Driver state.
+ */
+ extstate_t state;
+ /**
+ * @brief Current configuration data.
+ */
+ const EXTConfig *config;
+ /* End of the mandatory fields.*/
+};
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void ext_lld_init(void);
+ void ext_lld_start(EXTDriver *extp);
+ void ext_lld_stop(EXTDriver *extp);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_EXT */
+
+#endif /* _EXT_LLD_H_ */
+
+/** @} */