aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/AVR
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-25 15:18:18 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-09-25 15:18:18 +0000
commitbede8d6781661d679475d2b60d87fb7f43cc5e8e (patch)
tree37247a6cae23580d0705204ee432fce56261f037 /os/hal/platforms/AVR
parentaba41323fcc5ac96be23e8e498527397c66b5a71 (diff)
downloadChibiOS-bede8d6781661d679475d2b60d87fb7f43cc5e8e.tar.gz
ChibiOS-bede8d6781661d679475d2b60d87fb7f43cc5e8e.tar.bz2
ChibiOS-bede8d6781661d679475d2b60d87fb7f43cc5e8e.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3410 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms/AVR')
-rw-r--r--os/hal/platforms/AVR/pal_lld.c134
-rw-r--r--os/hal/platforms/AVR/pal_lld.h265
-rw-r--r--os/hal/platforms/AVR/platform.dox14
-rw-r--r--os/hal/platforms/AVR/platform.mk1
4 files changed, 414 insertions, 0 deletions
diff --git a/os/hal/platforms/AVR/pal_lld.c b/os/hal/platforms/AVR/pal_lld.c
new file mode 100644
index 000000000..4bfd7bd04
--- /dev/null
+++ b/os/hal/platforms/AVR/pal_lld.c
@@ -0,0 +1,134 @@
+/*
+ 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 AVR/pal_lld.c
+ * @brief AVR GPIO low level driver code.
+ *
+ * @addtogroup PAL
+ * @{
+ */
+
+#include "ch.h"
+#include "hal.h"
+
+#if HAL_USE_PAL || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
+/**
+ * @brief AVR GPIO ports configuration.
+ * @details GPIO registers initialization.
+ *
+ * @param[in] config the AVR ports configuration
+ *
+ * @notapi
+ */
+void _pal_lld_init(const PALConfig *config) {
+
+#if defined(PORTA) || defined(__DOXYGEN__)
+ PORTA = config->porta.out;
+ DDRA = config->porta.dir;
+#endif
+
+#if defined(PORTB) || defined(__DOXYGEN__)
+ PORTB = config->portb.out;
+ DDRB = config->portb.dir;
+#endif
+
+#if defined(PORTC) || defined(__DOXYGEN__)
+ PORTC = config->portc.out;
+ DDRC = config->portc.dir;
+#endif
+
+#if defined(PORTD) || defined(__DOXYGEN__)
+ PORTD = config->portd.out;
+ DDRD = config->portd.dir;
+#endif
+
+#if defined(PORTE) || defined(__DOXYGEN__)
+ PORTE = config->porte.out;
+ DDRE = config->porte.dir;
+#endif
+}
+
+/**
+ * @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_UNCONNECTED is implemented as output as recommended by
+ * the AVR Family User's Guide. Unconnected pads are set to input
+ * with pull-up by default.
+ *
+ * @notapi
+ *
+ * TODO: check PAL_MODE_UNCONNECTED mode recommended for AVR
+ */
+void _pal_lld_setgroupmode(ioportid_t port,
+ ioportmask_t mask,
+ iomode_t mode) {
+
+ switch (mode) {
+ case PAL_MODE_RESET:
+ case PAL_MODE_INPUT:
+ port->dir &= ~mask;
+ break;
+ case PAL_MODE_INPUT_ANALOG:
+ port->dir &= ~mask;
+ port->out &= ~mask;
+ break;
+ case PAL_MODE_UNCONNECTED:
+ case PAL_MODE_INPUT_PULLUP:
+ port->dir &= ~mask;
+ port->out |= mask;
+ case PAL_MODE_OUTPUT_PUSHPULL:
+ port->dir |= mask;
+ break;
+ }
+}
+
+#endif /* HAL_USE_PAL */
+
+/** @} */
diff --git a/os/hal/platforms/AVR/pal_lld.h b/os/hal/platforms/AVR/pal_lld.h
new file mode 100644
index 000000000..a2d1f8714
--- /dev/null
+++ b/os/hal/platforms/AVR/pal_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 AVR/pal_lld.h
+ * @brief AVR GPIO low level driver header.
+ *
+ * @addtogroup PAL
+ * @{
+ */
+
+#ifndef _PAL_LLD_H_
+#define _PAL_LLD_H_
+
+#if HAL_USE_PAL || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Unsupported modes and specific modes */
+/*===========================================================================*/
+
+#undef PAL_MODE_INPUT_PULLDOWN
+#undef PAL_MODE_OUTPUT_OPENDRAIN
+
+/*===========================================================================*/
+/* I/O Ports Types and constants. */
+/*===========================================================================*/
+
+/**
+ * @brief Width, in bits, of an I/O port.
+ */
+#define PAL_IOPORTS_WIDTH 8
+
+/**
+ * @brief Whole port mask.
+ * @brief This macro specifies all the valid bits into a port.
+ */
+#define PAL_WHOLE_PORT ((ioportmask_t)0xFF)
+
+/**
+ * @brief AVR setup registers.
+ */
+typedef struct {
+ uint8_t out;
+ uint8_t dir;
+} avr_gpio_setup_t;
+
+typedef struct {
+ volatile uint8_t in;
+ volatile uint8_t dir;
+ volatile uint8_t out;
+} avr_gpio_registers_t;
+
+/**
+ * @brief Generic I/O ports 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 {
+#if defined(PORTA) || defined(__DOXYGEN__)
+ avr_gpio_setup_t porta;
+#endif
+#if defined(PORTB) || defined(__DOXYGEN__)
+ avr_gpio_setup_t portb;
+#endif
+#if defined(PORTC) || defined(__DOXYGEN__)
+ avr_gpio_setup_t portc;
+#endif
+#if defined(PORTD) || defined(__DOXYGEN__)
+ avr_gpio_setup_t portd;
+#endif
+#if defined(PORTE) || defined(__DOXYGEN__)
+ avr_gpio_setup_t porte;
+#endif
+} PALConfig;
+
+/**
+ * @brief Digital I/O port sized unsigned type.
+ */
+typedef uint8_t ioportmask_t;
+
+/**
+ * @brief Digital I/O modes.
+ */
+typedef uint8_t iomode_t;
+
+/**
+ * @brief Port Identifier.
+ * @details This type can be a scalar or some kind of pointer, do not make
+ * any assumption about it, use the provided macros when populating
+ * variables of this type.
+ */
+typedef avr_gpio_registers_t *ioportid_t;
+
+/*===========================================================================*/
+/* I/O Ports Identifiers. */
+/*===========================================================================*/
+
+#if defined(PORTA) || defined(__DOXYGEN__)
+/**
+ * @brief GPIO port A identifier.
+ */
+#define IOPORT1 ((volatile avr_gpio_registers_t *)&PINA)
+#endif
+
+#if defined(PORTB) || defined(__DOXYGEN__)
+/**
+ * @brief GPIO port B identifier.
+ */
+#define IOPORT2 ((volatile avr_gpio_registers_t *)&PINB)
+#endif
+
+#if defined(PORTC) || defined(__DOXYGEN__)
+/**
+ * @brief GPIO port C identifier.
+ */
+#define IOPORT3 ((volatile avr_gpio_registers_t *)&PINC)
+#endif
+
+#if defined(PORTD) || defined(__DOXYGEN__)
+/**
+ * @brief GPIO port D identifier.
+ */
+#define IOPORT4 ((volatile avr_gpio_registers_t *)&PIND)
+#endif
+
+#if defined(PORTE) || defined(__DOXYGEN__)
+/**
+ * @brief GPIO port E identifier.
+ */
+#define IOPORT5 ((volatile avr_gpio_registers_t *)&PINE)
+#endif
+
+/*===========================================================================*/
+/* Implementation, some of the following macros could be implemented as */
+/* functions, if so please put them in pal_lld.c. */
+/*===========================================================================*/
+
+/**
+ * @brief Low level PAL subsystem initialization.
+ *
+ * @param[in] config the architecture-dependent ports configuration
+ *
+ * @notapi
+ */
+#define pal_lld_init(config) _pal_lld_init(config)
+
+/**
+ * @brief Reads the physical I/O port states.
+ *
+ * @param[in] port the port identifier
+ * @return The port bits.
+ *
+ * @notapi
+ */
+#define pal_lld_readport(port) ((port)->in)
+
+/**
+ * @brief Reads the output latch.
+ * @details The purpose of this function is to read back the latched output
+ * value.
+ *
+ * @param[in] port the port identifier
+ * @return The latched logical states.
+ *
+ * @notapi
+ */
+#define pal_lld_readlatch(port) ((port)->out)
+
+/**
+ * @brief Writes a bits mask on a I/O port.
+ *
+ * @param[in] port the port identifier
+ * @param[in] bits the bits to be written on the specified port
+ *
+ * @notapi
+ */
+#define pal_lld_writeport(port, bits) ((port)->out = bits)
+
+/**
+ * @brief Pads group mode setup.
+ * @details This function programs a pads group belonging to the same port
+ * with the specified mode.
+ * @note Programming an unknown or unsupported mode is silently ignored.
+ *
+ * @param[in] port the port identifier
+ * @param[in] mask the group mask
+ * @param[in] mode the mode
+ *
+ * @notapi
+ */
+#define pal_lld_setgroupmode(port, mask, mode) _pal_lld_setgroupmode(port, mask, mode)
+
+/**
+ * @brief Sets a pad logical state to @p PAL_HIGH.
+ *
+ * @param[in] port the port identifier
+ * @param[in] pad the pad number within the port
+ *
+ * @notapi
+ */
+#define pal_lld_setpad(port, pad) \
+__asm__ __volatile__ \
+( \
+ "sbi %0,%1\n\t" \
+ : \
+ : "I" (_SFR_IO_ADDR(port->out)), \
+ "I" (pad) \
+ \
+)
+
+/**
+ * @brief Clears a pad logical state to @p PAL_LOW.
+ *
+ * @param[in] port the port identifier
+ * @param[in] pad the pad number within the port
+ *
+ * @notapi
+ */
+#define pal_lld_clearpad(port, pad) \
+__asm__ __volatile__ \
+( \
+ "cbi %0,%1\n\t" \
+ : \
+ : "I" (_SFR_IO_ADDR(port->out)), \
+ "I" (pad) \
+ \
+)
+
+extern ROMCONST PALConfig pal_default_config;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void _pal_lld_init(const PALConfig *config);
+ void _pal_lld_setgroupmode(ioportid_t port,
+ ioportmask_t mask,
+ iomode_t mode);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HAL_USE_PAL */
+
+#endif /* _PAL_LLD_H_ */
+
+/** @} */
diff --git a/os/hal/platforms/AVR/platform.dox b/os/hal/platforms/AVR/platform.dox
index bc29954b6..2ac2256b9 100644
--- a/os/hal/platforms/AVR/platform.dox
+++ b/os/hal/platforms/AVR/platform.dox
@@ -36,6 +36,20 @@
*/
/**
+ * @defgroup AVR_PAL AVR PAL Support
+ * @details The AVR PAL driver uses the GPIO peripherals.
+ *
+ * @section avr_pal_1 Supported HW resources
+ * - GPIOA.
+ * - GPIOB.
+ * - GPIOC.
+ * - GPIOD.
+ * - GPIOE.
+ * .
+ * @ingroup AVR_DRIVERS
+ */
+
+/**
* @defgroup AVR_SERIAL AVR Serial Support
* @details The AVR Serial driver uses the USART peripherals in a
* buffered, interrupt driven, implementation.
diff --git a/os/hal/platforms/AVR/platform.mk b/os/hal/platforms/AVR/platform.mk
index fdc5390bb..e31413c79 100644
--- a/os/hal/platforms/AVR/platform.mk
+++ b/os/hal/platforms/AVR/platform.mk
@@ -1,5 +1,6 @@
# List of all the AVR platform files.
PLATFORMSRC = ${CHIBIOS}/os/hal/platforms/AVR/hal_lld.c \
+ ${CHIBIOS}/os/hal/platforms/AVR/pal_lld.c \
${CHIBIOS}/os/hal/platforms/AVR/serial_lld.c
# Required include directories