diff options
author | gdisirio <gdisirio@110e8d01-0319-4d1e-a829-52ad28d1bb01> | 2018-12-15 17:50:05 +0000 |
---|---|---|
committer | gdisirio <gdisirio@110e8d01-0319-4d1e-a829-52ad28d1bb01> | 2018-12-15 17:50:05 +0000 |
commit | f20ecc78178fc8cdfa682e100398c240224dbb4a (patch) | |
tree | 64272a45778baea1c1deed82d9223c3ddc87f6e7 /os/hal/include | |
parent | 984f865b45b110915616c3c9629fe47b064bed99 (diff) | |
download | ChibiOS-f20ecc78178fc8cdfa682e100398c240224dbb4a.tar.gz ChibiOS-f20ecc78178fc8cdfa682e100398c240224dbb4a.tar.bz2 ChibiOS-f20ecc78178fc8cdfa682e100398c240224dbb4a.zip |
HAL callbacks rework.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12470 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os/hal/include')
-rw-r--r-- | os/hal/include/hal_adc.h | 43 | ||||
-rw-r--r-- | os/hal/include/hal_dac.h | 39 | ||||
-rw-r--r-- | os/hal/include/hal_i2s.h | 25 | ||||
-rw-r--r-- | os/hal/include/hal_spi.h | 25 |
4 files changed, 87 insertions, 45 deletions
diff --git a/os/hal/include/hal_adc.h b/os/hal/include/hal_adc.h index 8ccc8241e..57797c7ee 100644 --- a/os/hal/include/hal_adc.h +++ b/os/hal/include/hal_adc.h @@ -104,11 +104,8 @@ typedef struct hal_adc_configuration_group ADCConversionGroup; * @brief Type of an ADC notification callback.
*
* @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);
+typedef void (*adccallback_t)(ADCDriver *adcp);
/**
* @brief Type of an ADC error callback.
@@ -204,6 +201,26 @@ struct hal_adc_driver { /*===========================================================================*/
/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Buffer state.
+ * @note This function is meant to be called from the SPI callback only.
+ *
+ * @param[in] adcp pointer to the @p ADCDriver object
+ * @return The buffer state.
+ * @retval false if the driver filled/sent the first half of the
+ * buffer.
+ * @retval true if the driver filled/sent the second half of the
+ * buffer.
+ *
+ * @special
+ */
+#define adcIsBufferComplete(adcp) ((bool)((adcp)->state == ADC_COMPLETE))
+/** @} */
+
+/**
* @name Low level driver helper macros
* @{
*/
@@ -275,7 +292,7 @@ struct hal_adc_driver { */
#define _adc_isr_half_code(adcp) { \
if ((adcp)->grpp->end_cb != NULL) { \
- (adcp)->grpp->end_cb(adcp, (adcp)->samples, (adcp)->depth / 2); \
+ (adcp)->grpp->end_cb(adcp); \
} \
}
@@ -297,15 +314,10 @@ struct hal_adc_driver { if ((adcp)->grpp->circular) { \
/* Callback handling.*/ \
if ((adcp)->grpp->end_cb != NULL) { \
- if ((adcp)->depth > 1) { \
- /* Invokes the callback passing the 2nd half of the buffer.*/ \
- size_t half = (adcp)->depth / 2; \
- size_t half_index = half * (adcp)->grpp->num_channels; \
- (adcp)->grpp->end_cb(adcp, (adcp)->samples + half_index, half); \
- } \
- else { \
- /* Invokes the callback passing the whole buffer.*/ \
- (adcp)->grpp->end_cb(adcp, (adcp)->samples, (adcp)->depth); \
+ (adcp)->state = ADC_COMPLETE; \
+ (adcp)->grpp->end_cb(adcp); \
+ if ((adcp)->state == ADC_COMPLETE) { \
+ (adcp)->state = ADC_ACTIVE; \
} \
} \
} \
@@ -314,8 +326,7 @@ struct hal_adc_driver { adc_lld_stop_conversion(adcp); \
if ((adcp)->grpp->end_cb != NULL) { \
(adcp)->state = ADC_COMPLETE; \
- /* Invoke the callback passing the whole buffer.*/ \
- (adcp)->grpp->end_cb(adcp, (adcp)->samples, (adcp)->depth); \
+ (adcp)->grpp->end_cb(adcp); \
if ((adcp)->state == ADC_COMPLETE) { \
(adcp)->state = ADC_READY; \
(adcp)->grpp = NULL; \
diff --git a/os/hal/include/hal_dac.h b/os/hal/include/hal_dac.h index 6533f35d6..403df4970 100644 --- a/os/hal/include/hal_dac.h +++ b/os/hal/include/hal_dac.h @@ -99,11 +99,8 @@ typedef struct hal_dac_conversion_group DACConversionGroup; * @brief DAC notification callback type.
*
* @param[in] dacp pointer to the @p DACDriver object triggering the
- * @param[in] buffer pointer to the next semi-buffer to be filled
- * @param[in] n number of buffer rows available starting from @p buffer
- * callback
*/
-typedef void (*daccallback_t)(DACDriver *dacp, dacsample_t *buffer, size_t n);
+typedef void (*daccallback_t)(DACDriver *dacp);
/**
* @brief DAC error callback type.
@@ -193,6 +190,21 @@ struct hal_dac_driver { * @name Low level driver helper macros
* @{
*/
+/**
+ * @brief Buffer state.
+ * @note This function is meant to be called from the DAC callback only.
+ *
+ * @param[in] dacp pointer to the @p DACDriver object
+ * @return The buffer state.
+ * @retval false if the driver filled/sent the first half of the
+ * buffer.
+ * @retval true if the driver filled/sent the second half of the
+ * buffer.
+ *
+ * @special
+ */
+#define dacIsBufferComplete(dacp) ((bool)((dacp)->state == DAC_COMPLETE))
+
#if (DAC_USE_WAIT == TRUE) || defined(__DOXYGEN__)
/**
* @brief Waits for operation completion.
@@ -274,7 +286,7 @@ struct hal_dac_driver { */
#define _dac_isr_half_code(dacp) { \
if ((dacp)->grpp->end_cb != NULL) { \
- (dacp)->grpp->end_cb(dacp, (dacp)->samples, (dacp)->depth / 2); \
+ (dacp)->grpp->end_cb(dacp); \
} \
}
@@ -282,7 +294,6 @@ struct hal_dac_driver { * @brief Common ISR code, full buffer event.
* @details This code handles the portable part of the ISR code:
* - Callback invocation.
- * - Waiting thread wakeup, if any.
* - Driver state transitions.
* .
* @note This macro is meant to be used in the low level drivers
@@ -293,17 +304,11 @@ struct hal_dac_driver { * @notapi
*/
#define _dac_isr_full_code(dacp) { \
- if ((dacp)->grpp->end_cb != NULL) { \
- if ((dacp)->depth > 1) { \
- /* Invokes the callback passing the 2nd half of the buffer.*/ \
- size_t half = (dacp)->depth / 2; \
- size_t half_index = half * (dacp)->grpp->num_channels; \
- (dacp)->grpp->end_cb(dacp, (dacp)->samples + half_index, half); \
- } \
- else { \
- /* Invokes the callback passing the whole buffer.*/ \
- (dacp)->grpp->end_cb(dacp, (dacp)->samples, (dacp)->depth); \
- } \
+ if ((dacp)->grpp->end_cb) { \
+ (dacp)->state = DAC_COMPLETE; \
+ (dacp)->grpp->end_cb(dacp); \
+ if ((dacp)->state == DAC_COMPLETE) \
+ (dacp)->state = DAC_ACTIVE; \
} \
}
diff --git a/os/hal/include/hal_i2s.h b/os/hal/include/hal_i2s.h index 9811423f5..1dccaaa1e 100644 --- a/os/hal/include/hal_i2s.h +++ b/os/hal/include/hal_i2s.h @@ -76,10 +76,8 @@ typedef struct hal_i2s_config I2SConfig; * @brief I2S notification callback type.
*
* @param[in] i2sp pointer to the @p I2SDriver object
- * @param[in] offset offset in buffers of the data to read/write
- * @param[in] n number of samples to read/write
*/
-typedef void (*i2scallback_t)(I2SDriver *i2sp, size_t offset, size_t n);
+typedef void (*i2scallback_t)(I2SDriver *i2sp);
/* Including the low level driver header, it exports information required
for completing types.*/
@@ -136,6 +134,21 @@ struct hal_i2s_config { * @{
*/
/**
+ * @brief Buffer state.
+ * @note This function is meant to be called from the SPI callback only.
+ *
+ * @param[in] i2sp pointer to the @p I2SDriver object
+ * @return The buffer state.
+ * @retval false if the driver filled/sent the first half of the
+ * buffer.
+ * @retval true if the driver filled/sent the second half of the
+ * buffer.
+ *
+ * @special
+ */
+#define i2sIsBufferComplete(i2sp) ((bool)((i2sp)->state == I2S_COMPLETE))
+
+/**
* @brief Starts a I2S data exchange.
*
* @param[in] i2sp pointer to the @p I2SDriver object
@@ -175,7 +188,7 @@ struct hal_i2s_config { */
#define _i2s_isr_half_code(i2sp) { \
if ((i2sp)->config->end_cb != NULL) { \
- (i2sp)->config->end_cb(i2sp, 0, (i2sp)->config->size / 2); \
+ (i2sp)->config->end_cb(i2sp); \
} \
}
@@ -195,9 +208,7 @@ struct hal_i2s_config { #define _i2s_isr_full_code(i2sp) { \
if ((i2sp)->config->end_cb) { \
(i2sp)->state = I2S_COMPLETE; \
- (i2sp)->config->end_cb(i2sp, \
- (i2sp)->config->size / 2, \
- (i2sp)->config->size / 2); \
+ (i2sp)->config->end_cb(i2sp); \
if ((i2sp)->state == I2S_COMPLETE) { \
(i2sp)->state = I2S_ACTIVE; \
} \
diff --git a/os/hal/include/hal_spi.h b/os/hal/include/hal_spi.h index 4d2ebdefb..57f63e13c 100644 --- a/os/hal/include/hal_spi.h +++ b/os/hal/include/hal_spi.h @@ -225,6 +225,21 @@ struct hal_spi_driver { * @name Macro Functions
* @{
*/
+/**
+ * @brief Buffer state.
+ * @note This function is meant to be called from the SPI callback only.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object
+ * @return The buffer state.
+ * @retval false if the driver filled/sent the first half of the
+ * buffer.
+ * @retval true if the driver filled/sent the second half of the
+ * buffer.
+ *
+ * @special
+ */
+#define spiIsBufferComplete(spip) ((bool)((spip)->state == SPI_COMPLETE))
+
#if (SPI_SELECT_MODE == SPI_SELECT_MODE_LLD) || defined(__DOXYGEN__)
/**
* @brief Asserts the slave select signal and prepares for transfers.
@@ -408,7 +423,7 @@ do { \ #endif /* !SPI_USE_WAIT */
/**
- * @brief Common ISR code.
+ * @brief Common ISR code when circular mode is not supported.
* @details This code handles the portable part of the ISR code:
* - Callback invocation.
* - Waiting thread wakeup, if any.
@@ -434,7 +449,7 @@ do { \ }
/**
- * @brief Common ISR code in circular mode.
+ * @brief Half buffer filled ISR code in circular mode.
* @details This code handles the portable part of the ISR code:
* - Callback invocation.
* .
@@ -445,14 +460,14 @@ do { \ *
* @notapi
*/
-#define _spi_isr_code_half1(spip) { \
+#define _spi_isr_half_code(spip) { \
if ((spip)->config->end_cb) { \
(spip)->config->end_cb(spip); \
} \
}
/**
- * @brief Common ISR code in circular mode.
+ * @brief Full buffer filled ISR code in circular mode.
* @details This code handles the portable part of the ISR code:
* - Callback invocation.
* - Driver state transitions.
@@ -464,7 +479,7 @@ do { \ *
* @notapi
*/
-#define _spi_isr_code_half2(spip) { \
+#define _spi_isr_full_code(spip) { \
if ((spip)->config->end_cb) { \
(spip)->state = SPI_COMPLETE; \
(spip)->config->end_cb(spip); \
|