diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-07-11 14:36:20 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-07-11 14:36:20 +0000 |
commit | 43def70685c2b8cfc998a4a906d6b209aeb974ac (patch) | |
tree | b36f52e65d8ff611bd00de8cda3c89bede2a0a4c /ports | |
parent | 2b5e0544c8285976d94abe21268342698c94dd85 (diff) | |
download | ChibiOS-43def70685c2b8cfc998a4a906d6b209aeb974ac.tar.gz ChibiOS-43def70685c2b8cfc998a4a906d6b209aeb974ac.tar.bz2 ChibiOS-43def70685c2b8cfc998a4a906d6b209aeb974ac.zip |
Completed PAL support for AT91SAM7X.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1057 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'ports')
-rw-r--r-- | ports/ARM7-AT91SAM7X/pal_lld.c | 116 | ||||
-rw-r--r-- | ports/ARM7-AT91SAM7X/pal_lld.h | 76 | ||||
-rw-r--r-- | ports/ARM7-AT91SAM7X/port.dox | 15 |
3 files changed, 192 insertions, 15 deletions
diff --git a/ports/ARM7-AT91SAM7X/pal_lld.c b/ports/ARM7-AT91SAM7X/pal_lld.c new file mode 100644 index 000000000..266bdb38d --- /dev/null +++ b/ports/ARM7-AT91SAM7X/pal_lld.c @@ -0,0 +1,116 @@ +/*
+ ChibiOS/RT - Copyright (C) 2006-2007 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 ports/ARM7-AT91SAM7X/pal_lld.c
+ * @brief AT91SAM7X PIO low level driver code
+ * @addtogroup AT91SAM7X_PAL
+ * @{
+ */
+
+#include <ch.h>
+#include <pal.h>
+
+/**
+ * @brief AT91SAM7X I/O ports configuration.
+ * @details PIO registers initialization.
+ *
+ * @param[in] config the AT91SAM7X ports configuration
+ */
+void _pal_lld_init(const AT91SAM7XPIOConfig *config) {
+
+ AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA) | (1 << AT91C_ID_PIOB);
+
+ /*
+ * PIOA setup. + */
+ AT91C_BASE_PIOA->PIO_OER = config->P0Data.pusr; /* Pull-up as spec.*/
+ AT91C_BASE_PIOA->PIO_ODR = ~config->P0Data.pusr;
+ AT91C_BASE_PIOA->PIO_PER = 0xFFFFFFFF; /* PIO enabled.*/
+ AT91C_BASE_PIOA->PIO_ODSR = config->P0Data.odsr; /* Data as specified.*/
+ AT91C_BASE_PIOA->PIO_OER = config->P0Data.osr; /* Dir. as specified.*/
+ AT91C_BASE_PIOA->PIO_ODR = ~config->P0Data.osr;
+ AT91C_BASE_PIOA->PIO_IFDR = 0xFFFFFFFF; /* Filter disabled.*/
+ AT91C_BASE_PIOA->PIO_IDR = 0xFFFFFFFF; /* Int. disabled.*/
+ AT91C_BASE_PIOA->PIO_MDDR = 0xFFFFFFFF; /* Push Pull drive.*/
+ AT91C_BASE_PIOA->PIO_ASR = 0xFFFFFFFF; /* Peripheral A.*/
+ AT91C_BASE_PIOA->PIO_OWER = 0xFFFFFFFF; /* Write enabled.*/
+
+ /*
+ * PIOB setup. + */
+ AT91C_BASE_PIOB->PIO_OER = config->P0Data.pusr; /* Pull-up as spec.*/
+ AT91C_BASE_PIOB->PIO_ODR = ~config->P0Data.pusr;
+ AT91C_BASE_PIOB->PIO_PER = 0xFFFFFFFF; /* PIO enabled.*/
+ AT91C_BASE_PIOB->PIO_ODSR = config->P1Data.odsr; /* Data as specified.*/
+ AT91C_BASE_PIOB->PIO_OER = config->P1Data.osr; /* Dir. as specified.*/
+ AT91C_BASE_PIOB->PIO_ODR = ~config->P1Data.osr;
+ AT91C_BASE_PIOB->PIO_IFDR = 0xFFFFFFFF; /* Filter disabled.*/
+ AT91C_BASE_PIOB->PIO_IDR = 0xFFFFFFFF; /* Int. disabled.*/
+ AT91C_BASE_PIOB->PIO_MDDR = 0xFFFFFFFF; /* Push Pull drive.*/
+ AT91C_BASE_PIOB->PIO_ASR = 0xFFFFFFFF; /* Peripheral A.*/
+ AT91C_BASE_PIOB->PIO_OWER = 0xFFFFFFFF; /* Write enabled.*/
+}
+
+/**
+ * @brief Pads mode setup.
+ * @details This function programs a pads group belonging to the same port
+ * with the specified mode.
+ *
+ * @param[in] port the port identifier
+ * @param[in] mask the group mask
+ * @param[in] mode the mode
+ *
+ * @note This function is not meant to be invoked directly by the application
+ * code.
+ * @note @p PAL_MODE_RESET is implemented as input with pull-up.
+ * @note @p PAL_MODE_UNCONNECTED is implemented as push pull output with high
+ * state.
+ * @note @p PAL_MODE_OUTPUT_OPENDRAIN also enables the pull-up resistor.
+ */
+void _pal_lld_setgroupmode(ioportid_t port,
+ ioportmask_t mask,
+ uint_fast8_t mode) {
+
+ switch (mode & PAL_MODE_MASK) {
+ case PAL_MODE_RESET:
+ case PAL_MODE_INPUT_PULLUP:
+ port->PIO_PPUER = mask;
+ port->PIO_ODR = mask;
+ break;
+ case PAL_MODE_INPUT:
+ port->PIO_PPUDR = mask;
+ port->PIO_ODR = mask;
+ break;
+ case PAL_MODE_UNCONNECTED:
+ port->PIO_SODR = mask;
+ /* Falls in */
+ case PAL_MODE_OUTPUT_PUSHPULL:
+ port->PIO_PPUDR = mask;
+ port->PIO_OER = mask;
+ port->PIO_MDDR = mask;
+ break;
+ case PAL_MODE_OUTPUT_OPENDRAIN:
+ port->PIO_PPUER = mask;
+ port->PIO_OER = mask;
+ port->PIO_MDER = mask;
+ }
+}
+
+/** @} */
diff --git a/ports/ARM7-AT91SAM7X/pal_lld.h b/ports/ARM7-AT91SAM7X/pal_lld.h index 37088a4cc..b403fc2cc 100644 --- a/ports/ARM7-AT91SAM7X/pal_lld.h +++ b/ports/ARM7-AT91SAM7X/pal_lld.h @@ -19,7 +19,7 @@ /**
* @file ports/ARM7-AT91SAM7X/pal_lld.h
- * @brief AT91SAM7X PIO low level driver
+ * @brief AT91SAM7X PIO low level driver header
* @addtogroup AT91SAM7X_PAL
* @{
*/
@@ -27,15 +27,45 @@ #ifndef _PAL_LLD_H_
#define _PAL_LLD_H_
-#ifndef AT91SAM7X256_H
#include "at91lib/AT91SAM7X256.h"
-#endif
+
+/*===========================================================================*/
+/* Unsupported modes and specific modes */
+/*===========================================================================*/
+
+#undef PAL_MODE_INPUT_PULLDOWN
/*===========================================================================*/
/* I/O Ports Types and constants. */
/*===========================================================================*/
/**
+ * @brief PIO port setup info.
+ */
+typedef struct {
+ /** Initial value for ODSR register (data).*/
+ uint32_t odsr;
+ /** Initial value for OSR register (direction).*/
+ uint32_t osr;
+ /** Initial value for PUSR register (Pull-ups).*/
+ uint32_t pusr;
+} at91sam7x_pio_setup_t;
+
+/**
+ * @brief AT91SAM7X PIO static initializer.
+ * @details An instance of this structure must be passed to @p palInit() at
+ * system startup time in order to initialized the digital I/O
+ * subsystem. This represents only the initial setup, specific pads
+ * or whole ports can be reprogrammed at later time.
+ */
+typedef struct {
+ /** @brief Port 0 setup data.*/
+ at91sam7x_pio_setup_t P0Data;
+ /** @brief Port 1 setup data.*/
+ at91sam7x_pio_setup_t P1Data;
+} AT91SAM7XPIOConfig;
+
+/**
* @brief Width, in bits, of an I/O port. */
#define PAL_IOPORTS_WIDTH 32
@@ -74,18 +104,8 @@ typedef AT91PS_PIO ioportid_t; /**
* @brief Low level PAL subsystem initialization.
- * @details Clocks are enabled and both PIO ports are reset to a known state
- * and all pads are enabled a digital I/Os.
- *
- * @note The other PIO registers are not modified, the PIOs are supposed to
- * have just been reset. The PIO_PSR is cleared because its status
- * after the reset is not very clear in the documentation.
*/
-#define pal_lld_init() { \
- AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA) | (1 << AT91C_ID_PIOB); \
- AT91C_BASE_PIOA->PIO_PER = 0xFFFFFFFF; \
- AT91C_BASE_PIOB->PIO_PER = 0xFFFFFFFF; \
-}
+#define pal_lld_init(config) _pal_lld_init(config)
/**
* @brief Reads the physical I/O port states.
@@ -181,6 +201,23 @@ typedef AT91PS_PIO ioportid_t; }
/**
+ * @brief Pads group mode setup.
+ * @details This function programs a pads group belonging to the same port
+ * with the specified mode.
+ *
+ * @param[in] port the port identifier
+ * @param[in] mask the group mask
+ * @param[in] mode the mode
+ *
+ * @note This function is not meant to be invoked directly by the application
+ * code.
+ * @note @p PAL_MODE_UNCONNECTED is implemented as push pull output with high
+ * state.
+ */
+#define pal_lld_setgroupmode(port, mask, mode) \
+ _pal_lld_setgroupmode(port, mask, mode)
+
+/**
* @brief Writes a logical state on an output pad.
*
* @param[in] port the port identifier
@@ -192,6 +229,17 @@ typedef AT91PS_PIO ioportid_t; */
#define pal_lld_writepad(port, pad, bit) pal_lld_writegroup(port, 1, pad, bit)
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void _pal_lld_init(const AT91SAM7XPIOConfig *config);
+ void _pal_lld_setgroupmode(ioportid_t port,
+ ioportmask_t mask,
+ uint_fast8_t mode);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _PAL_LLD_H_ */
/** @} */
diff --git a/ports/ARM7-AT91SAM7X/port.dox b/ports/ARM7-AT91SAM7X/port.dox index 245c4b4bc..dac6ed181 100644 --- a/ports/ARM7-AT91SAM7X/port.dox +++ b/ports/ARM7-AT91SAM7X/port.dox @@ -39,8 +39,21 @@ * - Output latched regardless of the pad setting.
* - Direct read of input pads regardless of the pad setting.
* .
- * The only non atomic operations are bit toggling and bus/group writing.
+ * <h2>Supported Setup Modes</h2>
+ * - @p PAL_MODE_RESET.
+ * - @p PAL_MODE_UNCONNECTED.
+ * - @p PAL_MODE_INPUT.
+ * - @p PAL_MODE_INPUT_PULLUP.
+ * - @p PAL_MODE_OUTPUT_PUSHPULL.
+ * - @p PAL_MODE_OUTPUT_OPENDRAIN.
+ * .
+ * Any attempt to setup an invalid mode is ignored.
*
+ * <h2>Suboptimal Behavior</h2>
+ * Some PIO features are less than optimal:
+ * - Pad/port toggling operations are not atomic.
+ * - Pad/group mode setup is not atomic.
+ * .
* @ingroup AT91SAM7X
*/
|