From 4a3e3fc01ec6dfb4a710db771bee262d5dc9327e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 22 Sep 2011 14:53:42 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3381 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/adc.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'os/hal/include/adc.h') diff --git a/os/hal/include/adc.h b/os/hal/include/adc.h index 53c7c199a..cb392f4e2 100644 --- a/os/hal/include/adc.h +++ b/os/hal/include/adc.h @@ -80,7 +80,8 @@ typedef enum { ADC_STOP = 1, /**< Stopped. */ ADC_READY = 2, /**< Ready. */ ADC_ACTIVE = 3, /**< Converting. */ - ADC_COMPLETE = 4 /**< Conversion complete. */ + ADC_COMPLETE = 4, /**< Conversion complete. */ + ADC_ERROR = 5 /**< Conversion complete. */ } adcstate_t; #include "adc_lld.h" @@ -144,10 +145,30 @@ typedef enum { } \ } +/** + * @brief Wakes up the waiting thread with a timeout message. + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @notapi + */ +#define _adc_timeout_isr(adcp) { \ + if ((adcp)->thread != NULL) { \ + Thread *tp; \ + chSysLockFromIsr(); \ + tp = (adcp)->thread; \ + (adcp)->thread = NULL; \ + tp->p_u.rdymsg = RDY_TIMEOUT; \ + chSchReadyI(tp); \ + chSysUnlockFromIsr(); \ + } \ +} + #else /* !ADC_USE_WAIT */ #define _adc_reset_i(adcp) #define _adc_reset_s(adcp) #define _adc_wakeup_isr(adcp) +#define _adc_timeout_isr(adcp) #endif /* !ADC_USE_WAIT */ /** @@ -220,6 +241,32 @@ typedef enum { _adc_wakeup_isr(adcp); \ } \ } + +/** + * @brief Common ISR code, error event. + * @details This code handles the portable part of the ISR code: + * - Callback invocation. + * - Waiting thread timeout signaling, if any. + * - Driver state transitions. + * . + * @note This macro is meant to be used in the low level drivers + * implementation only. + * + * @param[in] adcp pointer to the @p ADCDriver object + * + * @notapi + */ +#define _adc_isr_error_code(adcp, err) { \ + adc_lld_stop_conversion(adcp); \ + if ((adcp)->grpp->error_cb != NULL) { \ + (adcp)->state = ADC_ERROR; \ + (adcp)->grpp->error_cb(adcp, err); \ + if ((adcp)->state == ADC_ERROR) \ + (adcp)->state = ADC_READY; \ + } \ + (adcp)->grpp = NULL; \ + _adc_timeout_isr(adcp); \ +} /** @} */ /*===========================================================================*/ -- cgit v1.2.3 From c39d08fc2ae9c43f73114e24292520306bddde19 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 23 Sep 2011 15:48:55 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3384 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/adc.h | 1 + 1 file changed, 1 insertion(+) (limited to 'os/hal/include/adc.h') diff --git a/os/hal/include/adc.h b/os/hal/include/adc.h index cb392f4e2..ff9e6b18f 100644 --- a/os/hal/include/adc.h +++ b/os/hal/include/adc.h @@ -253,6 +253,7 @@ typedef enum { * implementation only. * * @param[in] adcp pointer to the @p ADCDriver object + * @param[in] err platform dependent error code * * @notapi */ -- cgit v1.2.3 From 83d562f6b2842c4ec03ff08662ddc629ccc4e424 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 16 Nov 2011 21:21:28 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3504 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/adc.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'os/hal/include/adc.h') diff --git a/os/hal/include/adc.h b/os/hal/include/adc.h index ff9e6b18f..9ebe3754c 100644 --- a/os/hal/include/adc.h +++ b/os/hal/include/adc.h @@ -134,15 +134,15 @@ typedef enum { * @notapi */ #define _adc_wakeup_isr(adcp) { \ + chSysLockFromIsr(); \ if ((adcp)->thread != NULL) { \ Thread *tp; \ - chSysLockFromIsr(); \ tp = (adcp)->thread; \ (adcp)->thread = NULL; \ tp->p_u.rdymsg = RDY_OK; \ chSchReadyI(tp); \ - chSysUnlockFromIsr(); \ } \ + chSysUnlockFromIsr(); \ } /** @@ -153,15 +153,15 @@ typedef enum { * @notapi */ #define _adc_timeout_isr(adcp) { \ + chSysLockFromIsr(); \ if ((adcp)->thread != NULL) { \ Thread *tp; \ - chSysLockFromIsr(); \ tp = (adcp)->thread; \ (adcp)->thread = NULL; \ tp->p_u.rdymsg = RDY_TIMEOUT; \ chSchReadyI(tp); \ - chSysUnlockFromIsr(); \ } \ + chSysUnlockFromIsr(); \ } #else /* !ADC_USE_WAIT */ -- cgit v1.2.3