2009-11-29 08:50:13 +00:00
|
|
|
/*
|
2013-03-30 10:32:37 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-10-04 17:16:18 +00:00
|
|
|
* @file AT91SAM7/pal_lld.c
|
|
|
|
* @brief AT91SAM7 PIO low level driver code.
|
|
|
|
*
|
2010-10-25 20:34:08 +00:00
|
|
|
* @addtogroup PAL
|
2009-11-29 08:50:13 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2009-11-29 13:37:19 +00:00
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2009-12-29 11:40:09 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported variables. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2013-02-28 16:23:19 +00:00
|
|
|
/* Driver local variables and types. */
|
2009-12-29 11:40:09 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver local functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver interrupt handlers. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2010-10-04 17:16:18 +00:00
|
|
|
* @brief AT91SAM7 I/O ports configuration.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details PIO registers initialization.
|
|
|
|
*
|
2010-10-04 17:16:18 +00:00
|
|
|
* @param[in] config the AT91SAM7 ports configuration
|
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-05-14 10:46:26 +00:00
|
|
|
void _pal_lld_init(const PALConfig *config) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2009-11-29 13:37:19 +00:00
|
|
|
uint32_t ports = (1 << AT91C_ID_PIOA);
|
2009-11-29 10:50:14 +00:00
|
|
|
#if (SAM7_PLATFORM == SAM7X128) || (SAM7_PLATFORM == SAM7X256) || \
|
2012-11-08 07:29:55 +00:00
|
|
|
(SAM7_PLATFORM == SAM7X512) || (SAM7_PLATFORM == SAM7A3)
|
2009-11-29 08:50:13 +00:00
|
|
|
ports |= (1 << AT91C_ID_PIOB);
|
|
|
|
#endif
|
|
|
|
AT91C_BASE_PMC->PMC_PCER = ports;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PIOA setup.
|
|
|
|
*/
|
|
|
|
AT91C_BASE_PIOA->PIO_PPUER = config->P0Data.pusr; /* Pull-up as spec.*/
|
|
|
|
AT91C_BASE_PIOA->PIO_PPUDR = ~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.
|
|
|
|
*/
|
2009-11-29 10:50:14 +00:00
|
|
|
#if (SAM7_PLATFORM == SAM7X128) || (SAM7_PLATFORM == SAM7X256) || \
|
2012-11-08 07:29:55 +00:00
|
|
|
(SAM7_PLATFORM == SAM7X512) || (SAM7_PLATFORM == SAM7A3)
|
2009-11-29 08:50:13 +00:00
|
|
|
AT91C_BASE_PIOB->PIO_PPUER = config->P1Data.pusr; /* Pull-up as spec.*/
|
|
|
|
AT91C_BASE_PIOB->PIO_PPUDR = ~config->P1Data.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.*/
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-04 17:16:18 +00:00
|
|
|
* @brief Pads mode setup.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This function programs a pads group belonging to the same port
|
|
|
|
* with the specified mode.
|
2010-10-04 17:16:18 +00:00
|
|
|
* @note This function is not meant to be invoked directly from 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.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2010-10-04 17:16:18 +00:00
|
|
|
* @param[in] port the port identifier
|
|
|
|
* @param[in] mask the group mask
|
|
|
|
* @param[in] mode the mode
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2010-10-04 17:16:18 +00:00
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
void _pal_lld_setgroupmode(ioportid_t port,
|
|
|
|
ioportmask_t mask,
|
2011-07-17 13:07:16 +00:00
|
|
|
iomode_t mode) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2011-06-20 19:03:17 +00:00
|
|
|
switch (mode) {
|
2009-11-29 08:50:13 +00:00
|
|
|
case PAL_MODE_RESET:
|
|
|
|
case PAL_MODE_INPUT_PULLUP:
|
|
|
|
port->PIO_PPUER = mask;
|
|
|
|
port->PIO_ODR = mask;
|
|
|
|
break;
|
|
|
|
case PAL_MODE_INPUT:
|
|
|
|
case PAL_MODE_INPUT_ANALOG:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#endif /* HAL_USE_PAL */
|
2009-11-29 13:37:19 +00:00
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/** @} */
|