diff options
Diffstat (limited to 'src/gadc/driver.h')
-rw-r--r-- | src/gadc/driver.h | 116 |
1 files changed, 46 insertions, 70 deletions
diff --git a/src/gadc/driver.h b/src/gadc/driver.h index 6e935576..4145bc4a 100644 --- a/src/gadc/driver.h +++ b/src/gadc/driver.h @@ -27,38 +27,27 @@ /** * @brief The structure passed to start a timer conversion - * @note We use the structure instead of parameters purely to save - * interrupt stack space which is very limited in some platforms. * @{ */ -typedef struct GadcLldTimerData_t { - 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; +typedef struct GadcTimerJob_t { + uint32_t physdev; // @< The physical device/s. The exact meaning of physdev is hardware dependent. + uint32_t frequency; // @< The frequency to sample + adcsample_t *buffer; // @< Where to put the samples + size_t todo; // @< How many conversions to do + size_t done; // @< How many conversions have already been done +} GadcTimerJob; /* @} */ /** - * @brief The structure passed to start a non-timer conversion - * @note We use the structure instead of parameters purely to save - * interrupt stack space which is very limited in some platforms. + * @brief The structure passed to do a single conversion * @{ */ -typedef struct GadcLldNonTimerData_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. */ - } GadcLldNonTimerData; +typedef struct GadcNonTimerJob_t { + uint32_t physdev; // @< The physical device/s. The exact meaning of physdev is hardware dependent. + adcsample_t *buffer; // @< Where to put the samples. + } GadcNonTimerJob; /* @} */ -/** - * @brief This can be incremented by the low level driver if a timer interrupt is missed. - * @details Defined in the high level GADC code. - * - * @notapi - */ -extern volatile bool_t GADC_Timer_Missed; - /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -75,14 +64,15 @@ extern "C" { * @{ */ /** - * @brief The last conversion requested is now complete + * @brief Indicate that some data has been placed into the buffer for the current job + * + * @param[in] n The number of samples placed in the buffer + * + * @note Calling this with n = 0 causes the current job to be terminated early or aborted. + * It can be called in this mode on an ADC conversion error. Any job will then be + * restarted by the high level code as appropriate. */ - void gadcDataReadyI(void); - - /** - * @brief The last conversion requested failed - */ - void gadcDataFailI(void); + void gadcGotDataI(size_t n); /** * @} */ @@ -95,71 +85,57 @@ extern "C" { void gadc_lld_init(void); /** + * @brief Return the number of samples per conversion + * + * @param[in] physdev The hardware dependent physical device descriptor + * + * @api + */ +size_t gadc_lld_samplesperconversion(uint32_t physdev); + +/** * @brief Start a periodic timer for high frequency conversions. * - * @param[in] pgtd The structure containing the sample frequency and physical device to use. + * @param[in] freq The frequency for the timer * - * @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 there is a "timer" conversion - * active. - * @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. + * @note This will only be called if the timer is currently stopped. * * @api + * @iclass */ -void gadc_lld_start_timer(GadcLldTimerData *pgtd); +void gadc_lld_start_timerI(uint32_t freq); /** * @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] pgtd The structure containing the sample frequency and physical device to use. + * @note This will only be called if the timer is currently running and all timer jobs + * have been completed/aborted. * - * @note After this function returns there should be no more calls to @p gadcDataReadyI() - * or @p gadcDataFailI() in relation to timer conversions. * @api + * @iclass */ -void gadc_lld_stop_timer(GadcLldTimerData *pgtd); +void gadc_lld_stop_timerI(void); /** - * @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. + * @brief Start a set of high frequency conversions. * - * @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 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 + * @note This will only be called if the timer is currently running and the ADC should be ready for + * a new job. * + * @api * @iclass */ -void gadc_lld_adc_timerI(GadcLldTimerData *pgtd); +void gadc_lld_timerjobI(GadcTimerJob *pjob); /** - * @brief Start a "non-timer" conversion. - * @details Starts a single conversion now. + * @brief Start a non-timer conversion. * - * @param[in] pgntd Contains the parameters for the non-timer conversion. - * - * @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 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 + * @note This will only be called if the ADC should be ready for a new job. * + * @api * @iclass */ -void gadc_lld_adc_nontimerI(GadcLldNonTimerData *pgntd); +void gadc_lld_nontimerjobI(GadcNonTimerJob *pjob); #ifdef __cplusplus } |