SAMA5 ADC: If running from SDRAM, BOARD_MCK_FREQUENCY is not a constant and cannot be used in pre-processor conditionals

This commit is contained in:
Gregory Nutt 2014-04-16 09:42:07 -06:00
parent e21212f2b4
commit 1b46ebc7f4
4 changed files with 46 additions and 21 deletions

View File

@ -7171,3 +7171,7 @@
also reset the camera module. Noted by David Sidrane (2014-4-11).
* arch/arm/src/stm32/stm32_usbhost.c/.h and stm32_otgfshost.c: USB host
tracing added by Leo (2014-4-12).
* arch/arm/src/sama5/sam_adc.c: If running from SDRAM, then BOARD_MCK_FREQUENCY
is not a constand and cannot be used in condititional comilation
(2014-4-16).

View File

@ -217,7 +217,7 @@ config SAMA5_PWM
select PWM
config SAMA5_ADC
bool "Touch Screen ADC Controller (ADC)"
bool "Touch Screen / ADC Controller (ADC)"
default n
select ANALOG
select ADC

View File

@ -370,24 +370,6 @@
#define SAMA5_ADC_SAMPLES (CONFIG_SAMA5_ADC_DMASAMPLES * SAMA5_NCHANNELS)
/* Clocking */
#if BOARD_MCK_FREQUENCY <= SAM_ADC_MAXPERCLK
# define ADC_FREQUENCY BOARD_MCK_FREQUENCY
# define ADC_PCR_DIV PMC_PCR_DIV1
#elif (BOARD_MCK_FREQUENCY >> 1) <= SAM_ADC_MAXPERCLK
# define ADC_FREQUENCY (BOARD_MCK_FREQUENCY >> 1)
# define ADC_PCR_DIV PMC_PCR_DIV2
#elif (BOARD_MCK_FREQUENCY >> 2) <= SAM_ADC_MAXPERCLK
# define ADC_FREQUENCY (BOARD_MCK_FREQUENCY >> 2)
# define ADC_PCR_DIV PMC_PCR_DIV4
#elif (BOARD_MCK_FREQUENCY >> 3) <= SAM_ADC_MAXPERCLK
# define ADC_FREQUENCY (BOARD_MCK_FREQUENCY >> 3)
# define ADC_PCR_DIV PMC_PCR_DIV8
#else
# error Cannot realize ADC input frequency
#endif
/****************************************************************************
* Private Types
****************************************************************************/
@ -398,6 +380,7 @@ struct sam_adc_s
{
sem_t exclsem; /* Supports exclusive access to the ADC interface */
bool initialized; /* The ADC driver is already initialized */
uint32_t frequency; /* ADC clock frequency */
#ifdef SAMA5_ADC_HAVE_CHANNELS
#ifdef CONFIG_SAMA5_ADC_DMA
@ -701,6 +684,7 @@ static void sam_adc_dmadone(void *arg)
*
****************************************************************************/
#ifdef CONFIG_SAMA5_ADC_DMA
static void sam_adc_dmastart(struct sam_adc_s *priv)
{
/* Make sure that the worker is available and that DMA is not disabled */
@ -712,6 +696,7 @@ static void sam_adc_dmastart(struct sam_adc_s *priv)
SAMA5_ADC_SAMPLES * sizeof(uint16_t));
}
}
#endif
/****************************************************************************
* Name: sam_adc_dmacallback
@ -980,7 +965,9 @@ static int sam_adc_interrupt(int irq, void *context)
static void sam_adc_reset(struct adc_dev_s *dev)
{
#ifdef CONFIG_SAMA5_ADC_DMA
struct sam_adc_s *priv = (struct sam_adc_s *)dev->ad_priv;
#endif
uint32_t regval;
avdbg("Resetting..\n");
@ -1120,7 +1107,9 @@ static int sam_adc_setup(struct adc_dev_s *dev)
static void sam_adc_shutdown(struct adc_dev_s *dev)
{
#ifdef CONFIG_SAMA5_ADC_DMA
struct sam_adc_s *priv = (struct sam_adc_s *)dev->ad_priv;
#endif
avdbg("Shutdown\n");
@ -1147,7 +1136,9 @@ static void sam_adc_shutdown(struct adc_dev_s *dev)
static void sam_adc_rxint(struct adc_dev_s *dev, bool enable)
{
#ifdef CONFIG_SAMA5_ADC_DMA
struct sam_adc_s *priv = (struct sam_adc_s *)dev->ad_priv;
#endif
avdbg("enable=%d\n", enable);
@ -1916,6 +1907,7 @@ struct adc_dev_s *sam_adc_initialize(void)
{
struct sam_adc_s *priv = &g_adcpriv;
uint32_t regval;
uint32_t mck;
int ret;
/* Have we already been initialzed? If yes, than just hand out the
@ -1990,9 +1982,38 @@ struct adc_dev_s *sam_adc_initialize(void)
DEBUGASSERT(priv->dma);
#endif
/* Determine the maximum ADC peripheral clock frequency */
mck = BOARD_MCK_FREQUENCY;
if (mck <= SAM_ADC_MAXPERCLK)
{
priv->frequency = mck;
regval = PMC_PCR_DIV1;
}
else if ((mck >> 1) <= SAM_ADC_MAXPERCLK)
{
priv->frequency = (mck >> 1);
regval = PMC_PCR_DIV2;
}
else if ((mck >> 2) <= SAM_ADC_MAXPERCLK)
{
priv->frequency = (mck >> 2);
regval = PMC_PCR_DIV4;
}
else if ((mck >> 3) <= SAM_ADC_MAXPERCLK)
{
priv->frequency = (mck >> 3);
regval = PMC_PCR_DIV8;
}
else
{
adbg("ERROR: Cannot realize ADC input frequency\n");
return NULL;
}
/* Set the maximum ADC peripheral clock frequency */
regval = PMC_PCR_PID(SAM_PID_ADC) | PMC_PCR_CMD | ADC_PCR_DIV | PMC_PCR_EN;
regval |= PMC_PCR_PID(SAM_PID_ADC) | PMC_PCR_CMD | PMC_PCR_EN;
sam_adc_putreg(priv, SAM_PMC_PCR, regval);
/* Enable the ADC peripheral clock*/

View File

@ -83,7 +83,7 @@ extern "C"
*
****************************************************************************/
void sam_clockconfig(void);
void __ramfunc__ sam_clockconfig(void);
/****************************************************************************
* Name: board_norflash_config