diff options
Diffstat (limited to 'src/gadc/driver.h')
-rw-r--r-- | src/gadc/driver.h | 93 |
1 files changed, 37 insertions, 56 deletions
diff --git a/src/gadc/driver.h b/src/gadc/driver.h index 4427f4f0..6e935576 100644 --- a/src/gadc/driver.h +++ b/src/gadc/driver.h @@ -32,9 +32,9 @@ * @{ */ typedef struct GadcLldTimerData_t { - uint32_t physdev; /* @< A value passed to describe which physical ADC devices/channels to use. */ - adcsample_t *buffer; /* @< The static buffer to put the ADC samples into. */ - size_t count; /* @< The number of conversions to do before doing a callback and stopping the ADC. */ + uint32_t physdev; /* @< Which physical ADC devices/channels to use. Filled in by High Level Code */ + uint32_t frequency; /* @< The conversion frequency. Filled in by High Level Code */ + GDataBuffer *pdata; /* @< The buffer to put the ADC samples into. */ bool_t now; /* @< Trigger the first conversion now rather than waiting for the first timer interrupt (if possible) */ } GadcLldTimerData; /* @} */ @@ -52,30 +52,6 @@ typedef struct GadcLldNonTimerData_t { /* @} */ /** - * @brief These routines are the callbacks that the driver uses. - * @details Defined in the high level GADC code. - * - * @notapi - * @{ - */ - -/** - * @param[in] adcp The ADC driver - * @param[in] buffer The sample buffer - * @param[in] n The amount of samples - */ -extern void GADC_ISR_CompleteI(ADCDriver *adcp, adcsample_t *buffer, size_t n); - -/** - * @param[in] adcp The ADC driver - * @param[in] err ADC error - */ -extern void GADC_ISR_ErrorI(ADCDriver *adcp, adcerror_t err); -/** - * @} - */ - -/** * @brief This can be incremented by the low level driver if a timer interrupt is missed. * @details Defined in the high level GADC code. * @@ -92,70 +68,75 @@ extern "C" { #endif /** - * @brief Initialise the driver + * @brief These routines are the callbacks that the driver uses. + * @details Defined in the high level GADC code. * - * @api + * @notapi + * @{ + */ + /** + * @brief The last conversion requested is now complete + */ + void gadcDataReadyI(void); + + /** + * @brief The last conversion requested failed + */ + void gadcDataFailI(void); +/** + * @} */ -void gadc_lld_init(void); /** - * @brief Get the number of samples in a conversion. - * @details Calculates and returns the number of samples per conversion for the specified physdev. - * - * @note A physdev describing a mono device would return 1, a stereo device would return 2. - * For most ADC's physdev is a bitmap so it is only a matter of counting the bits. - * - * @param[in] physdev A value passed to describe which physical ADC devices/channels to use. + * @brief Initialise the driver * - * @return Number of samples of the convesion * @api */ -size_t gadc_lld_samples_per_conversion(uint32_t physdev); +void gadc_lld_init(void); /** * @brief Start a periodic timer for high frequency conversions. * - * @param[in] physdev A value passed to describe which physical ADC devices/channels to use. - * @param[in] frequency The frequency to create ADC conversions + * @param[in] pgtd The structure containing the sample frequency and physical device to use. * * @note The exact meaning of physdev is hardware dependent. It describes the channels * the will be used later on when a "timer" conversion is actually scheduled. * @note It is assumed that the timer is capable of free-running even when the ADC * is stopped or doing something else. - * @details When a timer interrupt occurs a conversion should start if these is a "timer" conversion + * @details When a timer interrupt occurs a conversion should start if there is a "timer" conversion * active. - * @note If the ADC is stopped, doesn't have a "timer" conversion active or is currently executing - * a non-timer conversion then the interrupt can be ignored other than (optionally) incrementing + * @note Timer interrupts occurring before @p gadc_lld_adc_timerI() has been called, + * if @p gadc_lld_adc_timerI() has been called quick enough, or while + * a non-timer conversion is active should be ignored other than (optionally) incrementing * the GADC_Timer_Missed variable. + * @note The pdata and now members of the pgtd structure are now yet valid. * * @api */ -void gadc_lld_start_timer(uint32_t physdev, uint32_t frequency); +void gadc_lld_start_timer(GadcLldTimerData *pgtd); /** * @brief Stop the periodic timer for high frequency conversions. * @details Also stops any current "timer" conversion (but not a current "non-timer" conversion). * - * @param[in] physdev A value passed to describe which physical ADC devices/channels in use. - * - * @note The exact meaning of physdev is hardware dependent. + * @param[in] pgtd The structure containing the sample frequency and physical device to use. * + * @note After this function returns there should be no more calls to @p gadcDataReadyI() + * or @p gadcDataFailI() in relation to timer conversions. * @api */ -void gadc_lld_stop_timer(uint32_t physdev); +void gadc_lld_stop_timer(GadcLldTimerData *pgtd); /** - * @brief Start a "timer" conversion. + * @brief Start a set of "timer" conversions. * @details Starts a series of conversions triggered by the timer. * * @param[in] pgtd Contains the parameters for the timer conversion. * * @note The exact meaning of physdev is hardware dependent. It is likely described in the * drivers gadc_lld_config.h - * @note Some versions of ChibiOS actually call the callback function more than once, once - * at the half-way point and once on completion. The high level code handles this. - * @note The driver should call @p GADC_ISR_CompleteI() when it completes the operation - * (or at the half-way point), or @p GAD_ISR_ErrorI() on an error. + * @note The driver should call @p gadcDataReadyI() when it completes the operation + * or @p gadcDataFailI() on an error. * @note The high level code ensures that this is not called while a non-timer conversion is in * progress * @@ -171,8 +152,8 @@ void gadc_lld_adc_timerI(GadcLldTimerData *pgtd); * * @note The exact meaning of physdev is hardware dependent. It is likely described in the * drivers gadc_lld_config.h - * @note The driver should call @p GADC_ISR_CompleteI() when it completes the operation - * or @p GAD_ISR_ErrorI() on an error. + * @note The driver should call @p gadcDataReadyI() when it completes the operation + * or @p gadcDataFailI() on an error. * @note The high level code ensures that this is not called while a timer conversion is in * progress * |