git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5336 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2013-02-27 10:42:09 +00:00
parent f8f56be6c5
commit e089716749
16 changed files with 434 additions and 14 deletions

View File

@ -0,0 +1,152 @@
/*
* Licensed under ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* 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.
*/
/**
* @file SPC5xx/EQADC_v1/adc_lld.c
* @brief SPC5xx low level ADC driver code.
*
* @addtogroup ADC
* @{
*/
#include "ch.h"
#include "hal.h"
#if HAL_USE_ADC || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/**
* @brief ADCD1 driver identifier.
*/
#if SPC5_ADC_USE_EQADC1_Q0 || defined(__DOXYGEN__)
ADCDriver ADCD10;
#endif
/**
* @brief ADCD20 driver identifier.
*/
#if SPC5_ADC_USE_EQADC2_Q0 || defined(__DOXYGEN__)
ADCDriver ADCD20;
#endif
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver exported functions. */
/*===========================================================================*/
/**
* @brief Low level ADC driver initialization.
*
* @notapi
*/
void adc_lld_init(void) {
#if SPC5_ADC_USE_EQADC1_Q0
/* Driver initialization.*/
adcObjectInit(&ADCD10);
#endif /* SPC5_ADC_USE_EQADC1_Q0 */
#if SPC5_ADC_USE_EQADC2_Q0
/* Driver initialization.*/
adcObjectInit(&ADCD20);
#endif /* SPC5_ADC_USE_EQADC2_Q0 */
}
/**
* @brief Configures and activates the ADC peripheral.
*
* @param[in] adcp pointer to the @p ADCDriver object
*
* @notapi
*/
void adc_lld_start(ADCDriver *adcp) {
if (adcp->state == ADC_STOP) {
/* Enables the peripheral.*/
#if SPC5_ADC_USE_EQADC1_Q0
if (&ADCD10 == adcp) {
}
#endif /* SPC5_ADC_USE_EQADC1_Q0 */
}
/* Configures the peripheral.*/
}
/**
* @brief Deactivates the ADC peripheral.
*
* @param[in] adcp pointer to the @p ADCDriver object
*
* @notapi
*/
void adc_lld_stop(ADCDriver *adcp) {
if (adcp->state == ADC_READY) {
/* Resets the peripheral.*/
/* Disables the peripheral.*/
#if SPC5_ADC_USE_EQADC1_Q0
if (&ADCD1 == adcp) {
}
#endif /* SPC5_ADC_USE_EQADC1_Q0 */
}
}
/**
* @brief Starts an ADC conversion.
*
* @param[in] adcp pointer to the @p ADCDriver object
*
* @notapi
*/
void adc_lld_start_conversion(ADCDriver *adcp) {
(void)adcp;
}
/**
* @brief Stops an ongoing conversion.
*
* @param[in] adcp pointer to the @p ADCDriver object
*
* @notapi
*/
void adc_lld_stop_conversion(ADCDriver *adcp) {
(void)adcp;
}
#endif /* HAL_USE_ADC */
/** @} */

View File

@ -0,0 +1,268 @@
/*
* Licensed under ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* 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.
*/
/**
* @file SPC5xx/EQADC_v1/adc_lld.c
* @brief SPC5xx low level ADC driver header.
*
* @addtogroup ADC
* @{
*/
#ifndef _ADC_LLD_H_
#define _ADC_LLD_H_
#if HAL_USE_ADC || defined(__DOXYGEN__)
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/**
* @name CFIFO commands
* @{
*/
#define ADC_CFIFO_CHANNEL_MASK (0xFFU << 8)/**< @brief Channel number mask.*/
#define ADC_CFIFO_CHANNEL(n) ((n) << 8) /**< @brief Channel number. */
#define ADC_CFIFO_FMT_RJU (0U << 16) /**< @brief Unsigned samples. */
#define ADC_CFIFO_FMT_RJS (1U << 16) /**< @brief Signed samples. */
#define ADC_CFIFO_TSR (1U << 17) /**< @brief Time stamp request. */
#define ADC_CFIFO_LST_MASK (3U << 18) /**< @brief Sample time. */
#define ADC_CFIFO_LST_2 (0U << 18) /**< @brief 2 clock cycles. */
#define ADC_CFIFO_LST_8 (1U << 18) /**< @brief 8 clock cycles. */
#define ADC_CFIFO_LST_64 (2U << 18) /**< @brief 64 clock cycles. */
#define ADC_CFIFO_LST_128 (3U << 18) /**< @brief 128 clock cycles. */
#define ADC_CFIFO_MSG_MASK (15U << 20) /**< @brief Message mask. */
#define ADC_CFIFO_MSG_RFIFO(n) ((n) << 20) /**< @brief Result in RFIFO0..5.*/
#define ADC_CFIFO_MSG_NULL (6U << 20) /**< @brief Null message. */
#define ADC_CFIFO_CAL (1U << 24) /**< @brief Calibrated result. */
#define ADC_CFIFO_BN_MASK (1U << 25) /**< @brief Buffer number mask. */
#define ADC_CFIFO_BN(n) ((n) << 25) /**< @brief Buffer number. */
#define ADC_CFIFO_REP (1U << 29) /**< @brief Repeat loop flag. */
#define ADC_CFIFO_PAUSE (1U << 30) /**< @brief Pause flag. */
#define ADC_CFIFO_EOQ (1U << 31) /**< @brief End of queue flag. */
/** @} */
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/**
* @name Configuration options
* @{
*/
/**
* @brief ADCD10 driver enable switch.
* @details If set to @p TRUE the support for EQADC1 queue 0 is included.
* @note The default is @p FALSE.
*/
#if !defined(SPC5_ADC_USE_EQADC1_Q0) || defined(__DOXYGEN__)
#define SPC5_ADC_USE_EQADC1_Q0 FALSE
#endif
/**
* @brief ADCD20 driver enable switch.
* @details If set to @p TRUE the support for EQADC2 queue 0 is included.
* @note The default is @p FALSE.
*/
#if !defined(SPC5_ADC_USE_EQADC2_Q0) || defined(__DOXYGEN__)
#define SPC5_ADC_USE_EQADC2_Q0 FALSE
#endif
/** @} */
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/**
* @brief ADC command data type.
*/
typedef uint32_t adccommand_t;
/**
* @brief ADC sample data type.
*/
typedef uint16_t adcsample_t;
/**
* @brief Channels number in a conversion group.
*/
typedef uint16_t adc_channels_num_t;
/**
* @brief Possible ADC failure causes.
* @note Error codes are architecture dependent and should not relied
* upon.
*/
typedef enum {
ADC_ERR_DMAFAILURE = 0, /**< DMA operations failure. */
ADC_ERR_OVERFLOW = 1 /**< ADC overflow condition. */
} adcerror_t;
/**
* @brief Type of a structure representing an ADC driver.
*/
typedef struct ADCDriver ADCDriver;
/**
* @brief ADC notification callback type.
*
* @param[in] adcp pointer to the @p ADCDriver object triggering the
* callback
* @param[in] buffer pointer to the most recent samples data
* @param[in] n number of buffer rows available starting from @p buffer
*/
typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n);
/**
* @brief ADC error callback type.
*
* @param[in] adcp pointer to the @p ADCDriver object triggering the
* callback
* @param[in] err ADC error code
*/
typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err);
/**
* @brief Conversion group configuration structure.
* @details This implementation-dependent structure describes a conversion
* operation.
* @note Implementations may extend this structure to contain more,
* architecture dependent, fields.
*/
typedef struct {
/**
* @brief Enables the circular buffer mode for the group.
*/
bool_t circular;
/**
* @brief Number of the analog channels belonging to the conversion group.
*/
adc_channels_num_t num_channels;
/**
* @brief Callback function associated to the group or @p NULL.
*/
adccallback_t end_cb;
/**
* @brief Error callback or @p NULL.
*/
adcerrorcallback_t error_cb;
/* End of the mandatory fields.*/
/**
* @brief Number of command iterations stored in @p commands.
* @note The total number of array elements must be @p num_channels *
* @p num_iterations.
* @note This fields is the upper limit of the parameter @p n that can
* be passed to the functions @p adcConvert() and
* @p adcStartConversion().
*/
uint32_t num_iterations;
/**
* @brief Pointer to an array of low level EQADC commands to be pushed
* into the CFIFO during a conversion.
*/
const adccommand_t *commands;
} ADCConversionGroup;
/**
* @brief Driver configuration structure.
* @note It could be empty on some architectures.
*/
typedef struct {
uint32_t dummy;
} ADCConfig;
/**
* @brief Structure representing an ADC driver.
*/
struct ADCDriver {
/**
* @brief Driver state.
*/
adcstate_t state;
/**
* @brief Current configuration data.
*/
const ADCConfig *config;
/**
* @brief Current samples buffer pointer or @p NULL.
*/
adcsample_t *samples;
/**
* @brief Current samples buffer depth or @p 0.
*/
size_t depth;
/**
* @brief Current conversion group pointer or @p NULL.
*/
const ADCConversionGroup *grpp;
#if ADC_USE_WAIT || defined(__DOXYGEN__)
/**
* @brief Waiting thread.
*/
Thread *thread;
#endif
#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
#if CH_USE_MUTEXES || defined(__DOXYGEN__)
/**
* @brief Mutex protecting the peripheral.
*/
Mutex mutex;
#elif CH_USE_SEMAPHORES
Semaphore semaphore;
#endif
#endif /* ADC_USE_MUTUAL_EXCLUSION */
#if defined(ADC_DRIVER_EXT_FIELDS)
ADC_DRIVER_EXT_FIELDS
#endif
/* End of the mandatory fields.*/
};
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#if SPC5_ADC_USE_EQADC1_Q0 && !defined(__DOXYGEN__)
extern ADCDriver ADCD10;
#endif
#if SPC5_ADC_USE_EQADC2_Q0 && !defined(__DOXYGEN__)
extern ADCDriver ADCD20;
#endif
#ifdef __cplusplus
extern "C" {
#endif
void adc_lld_init(void);
void adc_lld_start(ADCDriver *adcp);
void adc_lld_stop(ADCDriver *adcp);
void adc_lld_start_conversion(ADCDriver *adcp);
void adc_lld_stop_conversion(ADCDriver *adcp);
#ifdef __cplusplus
}
#endif
#endif /* HAL_USE_ADC */
#endif /* _ADC_LLD_H_ */
/** @} */

View File

@ -14,7 +14,7 @@
/**
* @file SPC5xx/ESCI_v1/serial_lld.c
* @brief SPC5xx low level serial driver code.
* @brief SPC5xx low level serial driver header.
*
* @addtogroup SERIAL
* @{

View File

@ -85,7 +85,7 @@ void adc_lld_init(void) {
void adc_lld_start(ADCDriver *adcp) {
if (adcp->state == ADC_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_ADC_USE_ADC1
if (&ADCD1 == adcp) {

View File

@ -85,7 +85,7 @@ void can_lld_init(void) {
void can_lld_start(CANDriver *canp) {
if (canp->state == CAN_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_CAN_USE_CAN1
if (&CAND1 == canp) {

View File

@ -85,7 +85,7 @@ void ext_lld_init(void) {
void ext_lld_start(EXTDriver *extp) {
if (extp->state == EXT_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_EXT_USE_EXT1
if (&EXTD1 == extp) {

View File

@ -85,7 +85,7 @@ void gpt_lld_init(void) {
void gpt_lld_start(GPTDriver *gptp) {
if (gptp->state == GPT_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_GPT_USE_GPT1
if (&GPTD1 == gptp) {

View File

@ -84,7 +84,7 @@ void i2c_lld_init(void) {
void i2c_lld_start(I2CDriver *i2cp) {
if (i2cp->state == I2C_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_I2C_USE_I2C1
if (&I2CD1 == i2cp) {

View File

@ -85,7 +85,7 @@ void icu_lld_init(void) {
void icu_lld_start(ICUDriver *icup) {
if (icup->state == ICU_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_ICU_USE_ICU1
if (&ICUD1 == icup) {

View File

@ -88,7 +88,7 @@ void mac_lld_init(void) {
void mac_lld_start(MACDriver *macp) {
if (macp->state == MAC_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_MAC_USE_MAC1
if (&MACD1 == macp) {

View File

@ -85,7 +85,7 @@ void xxx_lld_init(void) {
void xxx_lld_start(XXXDriver *xxxp) {
if (xxxp->state == XXX_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_XXX_USE_XXX1
if (&XXXD1 == xxxp) {

View File

@ -85,7 +85,7 @@ void pwm_lld_init(void) {
void pwm_lld_start(PWMDriver *pwmp) {
if (pwmp->state == PWM_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_PWM_USE_PWM1
if (&PWMD1 == pwmp) {

View File

@ -98,7 +98,7 @@ void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
config = &default_config;
if (sdp->state == SD_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_SERIAL_USE_SD1
if (&SD1 == sdp) {

View File

@ -85,7 +85,7 @@ void spi_lld_init(void) {
void spi_lld_start(SPIDriver *spip) {
if (spip->state == SPI_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_SPI_USE_SPI1
if (&SPID1 == spip) {

View File

@ -85,7 +85,7 @@ void uart_lld_init(void) {
void uart_lld_start(UARTDriver *uartp) {
if (uartp->state == UART_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_UART_USE_UART1
if (&UARTD1 == uartp) {

View File

@ -119,7 +119,7 @@ void usb_lld_init(void) {
void usb_lld_start(USBDriver *usbp) {
if (usbp->state == USB_STOP) {
/* Enables the pehipheral.*/
/* Enables the peripheral.*/
#if PLATFORM_USB_USE_USB1
if (&USBD1 == usbp) {