Add ADC bind method to the Tiva ADC drivers

This commit is contained in:
Gregory Nutt 2016-05-26 12:39:22 -06:00
parent 8f2a660c8b
commit aa05767a00
2 changed files with 70 additions and 25 deletions

View File

@ -125,32 +125,32 @@
struct tiva_adc_step_cfg_s
{
uint8_t adc; /* Parent peripheral */
uint8_t sse; /* Parent sample sequencer (SSE) */
uint8_t step; /* Which step in the sequencer */
uint8_t shold; /* Sample and hold time */
uint8_t flags; /* Last step? Interrupt enabled?
* Internal temperature sensor? */
uint8_t ain; /* Which analog input */
uint8_t adc; /* Parent peripheral */
uint8_t sse; /* Parent sample sequencer (SSE) */
uint8_t step; /* Which step in the sequencer */
uint8_t shold; /* Sample and hold time */
uint8_t flags; /* Last step? Interrupt enabled?
* Internal temperature sensor? */
uint8_t ain; /* Which analog input */
};
/* Sample Sequencer configuration options */
struct tiva_adc_sse_cfg_s
{
uint8_t priority; /* Conversion priority, 0-3 no duplicates */
uint8_t trigger; /* Trigger source */
uint8_t priority; /* Conversion priority, 0-3 no duplicates */
uint8_t trigger; /* Trigger source */
};
/* ADC peripheral configuration options */
struct tiva_adc_cfg_s
{
uint8_t adc; /* ADC peripheral number */
bool sse[4]; /* active SSEs in a bitmask */
struct tiva_adc_sse_cfg_s ssecfg[4]; /* SSE configuration */
uint8_t steps; /* Size of the stepcfg array */
struct tiva_adc_step_cfg_s *stepcfg; /* Step configuration array */
uint8_t adc; /* ADC peripheral number */
bool sse[4]; /* active SSEs in a bitmask */
struct tiva_adc_sse_cfg_s ssecfg[4]; /* SSE configuration */
uint8_t steps; /* Size of the stepcfg array */
struct tiva_adc_step_cfg_s *stepcfg; /* Step configuration array */
};
/****************************************************************************

View File

@ -1,8 +1,10 @@
/****************************************************************************
* arch/arm/src/tiva/tiva_adclow.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2015 TRD2 Inc. All rights reserved.
* Author: Calvin Maguranis <calvin.maguranis@trd2inc.com>
* Gregory Nutt <gnutt@nuttx.org>
*
* References:
*
@ -67,8 +69,8 @@
#include <stdbool.h>
#include <semaphore.h>
#include <errno.h>
#include <debug.h>
#include <assert.h>
#include <debug.h>
#include <arch/board/board.h>
@ -135,6 +137,8 @@
/* Upper level ADC driver ***************************************************/
static int tiva_adc_bind(FAR struct adc_dev_s *dev,
FAR const struct adc_callback_s *callback);
static void tiva_adc_reset(struct adc_dev_s *dev);
static int tiva_adc_setup(struct adc_dev_s *dev);
static void tiva_adc_shutdown(struct adc_dev_s *dev);
@ -149,6 +153,7 @@ static int tiva_adc_ioctl(struct adc_dev_s *dev, int cmd, unsigned long arg);
static const struct adc_ops_s g_adcops =
{
.ao_bind = tiva_adc_bind,
.ao_reset = tiva_adc_reset,
.ao_setup = tiva_adc_setup,
.ao_shutdown = tiva_adc_shutdown,
@ -163,6 +168,7 @@ static const struct adc_ops_s g_adcops =
struct tiva_adc_s
{
struct adc_dev_s *dev;
const struct adc_callback_s *cb;
bool cfg; /* Configuration state */
bool ena; /* Operation state */
uint8_t devno; /* ADC device number */
@ -373,6 +379,25 @@ static void tiva_adc_irqinitialize(struct tiva_adc_cfg_s *cfg)
#endif
}
/****************************************************************************
* Name: tiva_adc_bind
*
* Description:
* Bind the upper-half driver callbacks to the lower-half implementation. This
* must be called early in order to receive ADC event notifications.
*
****************************************************************************/
static int tiva_adc_bind(FAR struct adc_dev_s *dev,
FAR const struct adc_callback_s *callback)
{
struct tiva_adc_s *priv = (struct tiva_adc_s *)dev->ad_priv;
DEBUGASSERT(priv != NULL);
priv->cb = callback;
return OK;
}
/****************************************************************************
* Name: tiva_adc_reset
*
@ -559,11 +584,20 @@ static int tiva_adc_ioctl(struct adc_dev_s *dev, int cmd, unsigned long arg)
fifo_count = tiva_adc_sse_data(priv->devno, sse, buf);
for (i = 0; i < fifo_count; ++i)
/* Verify that the upper-half driver has bound its callback functions */
if (priv->cb != NULL)
{
(void)adc_receive(dev,
tiva_adc_get_ain(priv->devno, sse, i),
buf[i]);
DEBUGASSERT(priv->cb->au_receive != NULL);
for (i = 0; i < fifo_count; ++i)
{
/* Perform the data received callback */
priv->cb->au_receive(dev,
tiva_adc_get_ain(priv->devno, sse, i),
buf[i]);
}
}
/* Release our lock on the ADC structure */
@ -651,18 +685,28 @@ static void tiva_adc_read(void *arg)
/* This is a serious error: indicates invalid pointer indirection
* and should cause a full system stop.
*/
alldbg("PANIC!!! Invalid ADC device number given %d\n", sse->adc);
PANIC();
return;
}
for (i = 0; i < fifo_count; ++i)
/* Verify that the upper-half driver has bound its callback functions */
if (priv->cb != NULL)
{
(void)adc_receive(dev,
tiva_adc_get_ain(sse->adc, sse->num, i),
buf[i]);
avdbg("AIN%d=0x%04x\n",
tiva_adc_get_ain(sse->adc, sse->num, i), buf[i]);
DEBUGASSERT(priv->cb->au_receive != NULL);
for (i = 0; i < fifo_count; ++i)
{
/* Perform the data received callback */
priv->cb->au_receive(dev,
tiva_adc_get_ain(sse->adc, sse->num, i),
buf[i]);
avdbg("AIN%d = 0x%04x\n",
tiva_adc_get_ain(sse->adc, sse->num, i), buf[i]);
}
}
/* Exit, re-enabling ADC interrupts */
@ -858,6 +902,7 @@ int tiva_adc_initialize(const char *devpath, struct tiva_adc_cfg_s *cfg,
/* Now we are initialized */
adc->ena = true;
adc->cb = NULL;
#ifdef CONFIG_DEBUG_ANALOG
tiva_adc_runtimeobj_vals();