Skip to content

Commit

Permalink
fix(Examples)!: Require DMA Channel as Input Argument for ADC DMA Con…
Browse files Browse the repository at this point in the history
…versions, Fix ADC DMA Transfer Bug for Channels > 0 (#643)
  • Loading branch information
Vignesh-VVadivel authored Jul 11, 2023
1 parent 11240f5 commit 2b10962
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 25 deletions.
9 changes: 5 additions & 4 deletions Documentation/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ The `Documentation/build.py` script can be used to build the MSDK User Guide and
To **build** the docs:

1. Install [doxygen](https://www.doxygen.nl/download.html)
2. Install Python 3
3. `pip install -r Documentation/requirements.txt`
4. `python Documentation/build.py`
5. The site will be built in the `docs` folder of the repo.
2. Add doxygen's binary diretory to the [Environmental Path](https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee537574(v=office.14)) Variable
3. Install Python 3
4. `pip install -r Documentation/requirements.txt`
5. `python Documentation/build.py`
6. The site will be built in the `docs` folder of the repo.

To **preview** the generated site:

Expand Down
11 changes: 8 additions & 3 deletions Examples/MAX32662/ADC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void adc_dma_callback(int ch, int err)
dma_done = 1;
}

void DMA0_IRQHandler(void)
void DMA_IRQHandler(void)
{
MXC_DMA_Handler();
}
Expand Down Expand Up @@ -335,7 +335,6 @@ int main(void)

#ifdef DMA
MXC_DMA_Init();
NVIC_EnableIRQ(DMA0_IRQn);
#endif
while (1) {
/* Flash LED when starting ADC cycle */
Expand All @@ -360,10 +359,16 @@ int main(void)
#ifdef DMA
dma_done = 0;

MXC_DMA_ReleaseChannel(0);
int dma_channel = MXC_DMA_AcquireChannel();
adc_conv.dma_channel = dma_channel;

MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(dma_channel), DMA_IRQHandler);
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(dma_channel));
MXC_ADC_StartConversionDMA(&adc_conv, adc_val, adc_dma_callback);

while (!dma_done) {}

MXC_DMA_ReleaseChannel(adc_conv.dma_channel);
#endif

ShowAdcResult();
Expand Down
12 changes: 8 additions & 4 deletions Examples/MAX32672/ADC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void adc_dma_callback(int ch, int err)
dma_done = 1;
}

void DMA0_IRQHandler(void)
void DMA_IRQHandler(void)
{
MXC_DMA_Handler();
}
Expand Down Expand Up @@ -375,15 +375,13 @@ int main(void)

#ifdef DMA
MXC_DMA_Init();
NVIC_EnableIRQ(DMA0_IRQn);
#endif

while (1) {
/* Flash LED when starting ADC cycle */
LED_On(0);
MXC_TMR_Delay(MXC_TMR0, MSEC(10));
LED_Off(0);

#ifdef POLLING
adc_temp_conversion();
WaitforConversionComplete();
Expand Down Expand Up @@ -414,10 +412,16 @@ int main(void)
MXC_TMR_Delay(MXC_TMR0, USEC(500));
}

MXC_DMA_ReleaseChannel(0);
int dma_channel = MXC_DMA_AcquireChannel();
adc_conv.dma_channel = dma_channel;

MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(dma_channel), DMA_IRQHandler);
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(dma_channel));
MXC_ADC_StartConversionDMA(&adc_conv, &adc_val[0], adc_dma_callback);

while (!dma_done) {}

MXC_DMA_ReleaseChannel(adc_conv.dma_channel);
#endif
ShowAdcResult();

Expand Down
11 changes: 8 additions & 3 deletions Examples/MAX32690/ADC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void adc_dma_callback(int ch, int err)
dma_done = 1;
}

void DMA0_IRQHandler(void)
void DMA_IRQHandler(void)
{
MXC_DMA_Handler();
}
Expand Down Expand Up @@ -416,7 +416,6 @@ int main(void)

#ifdef DMA
MXC_DMA_Init();
NVIC_EnableIRQ(DMA0_IRQn);
#endif
while (1) {
/* Flash LED when starting ADC cycle */
Expand Down Expand Up @@ -454,10 +453,16 @@ int main(void)
MXC_TMR_Delay(MXC_TMR0, USEC(500));
}

MXC_DMA_ReleaseChannel(0);
int dma_channel = MXC_DMA_AcquireChannel();
adc_conv.dma_channel = dma_channel;

MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(dma_channel), DMA_IRQHandler);
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(dma_channel));
MXC_ADC_StartConversionDMA(&adc_conv, &adc_val[0], adc_dma_callback);

while (!dma_done) {}

MXC_DMA_ReleaseChannel(adc_conv.dma_channel);
#endif
ShowAdcResult();

Expand Down
13 changes: 9 additions & 4 deletions Examples/MAX78002/ADC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void adc_dma_callback(int ch, int err)
dma_done = 1;
}

void DMA0_IRQHandler(void)
void DMA_IRQHandler(void)
{
MXC_DMA_Handler();
}
Expand Down Expand Up @@ -385,7 +385,6 @@ int main(void)

#ifdef DMA
MXC_DMA_Init();
NVIC_EnableIRQ(DMA0_IRQn);
#endif
while (1) {
/* Flash LED when starting ADC cycle */
Expand Down Expand Up @@ -423,10 +422,16 @@ int main(void)
MXC_TMR_Delay(MXC_TMR0, USEC(500));
}

MXC_DMA_ReleaseChannel(0);
MXC_ADC_StartConversionDMA(&adc_conv, &adc_val[0], adc_dma_callback);
int dma_channel = MXC_DMA_AcquireChannel();
adc_conv.dma_channel = dma_channel;

MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(dma_channel), DMA_IRQHandler);
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(dma_channel));
MXC_ADC_StartConversionDMA(&adc_conv, adc_val, adc_dma_callback);

while (!dma_done) {}

MXC_DMA_ReleaseChannel(adc_conv.dma_channel);
#endif
ShowAdcResult();

Expand Down
17 changes: 16 additions & 1 deletion Libraries/PeriphDrivers/Include/MAX32662/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern "C" {
/**
* @defgroup adc ADC
* @ingroup periphlibs
* @details API for Analog to Digital Converter (ADC).
* @{
*/

Expand Down Expand Up @@ -180,6 +181,9 @@ typedef enum {
///< Callback used when a conversion event is complete
typedef void (*mxc_adc_complete_cb_t)(void *req, int error);

/**
* @brief ADC Settings
*/
typedef struct {
mxc_adc_clock_t clock; ///< clock to use
mxc_adc_clkdiv_t clkdiv; ///< clock divider
Expand All @@ -189,10 +193,16 @@ typedef struct {
uint32_t idleCount; ///< Sample Clock Low time
} mxc_adc_req_t;

/**
* @brief ADC Slot Settings
*/
typedef struct {
mxc_adc_chsel_t channel; ///< channel select
} mxc_adc_slot_req_t;

/**
* @brief ADC Conversion Settings
*/
typedef struct {
mxc_adc_conversion_mode_t mode; ///< conversion mode
mxc_adc_trig_mode_t trig; ///< trigger mode
Expand All @@ -202,6 +212,7 @@ typedef struct {
mxc_adc_avg_t avg_number; ///< no of samples to average
mxc_adc_div_lpmode_t lpmode_divder; ///< Divide by 2 control in lpmode
uint8_t num_slots; ///< num of slots in the sequence
int8_t dma_channel; ///<The channel to use for DMA-enabled transactions
} mxc_adc_conversion_req_t;

/**
Expand Down Expand Up @@ -267,7 +278,11 @@ int MXC_ADC_StartConversion(void);
int MXC_ADC_StartConversionAsync(mxc_adc_complete_cb_t callback);

/**
* @brief Perform a conversion on a specific channel using a DMA transfer
* @brief Perform a conversion on a specific channel using a DMA transfer.
* DMA channel must be acquired using \ref MXC_DMA_AcquireChannel and should
* be passed to this function via "dma_channel" member of "req" input struct.
* DMA IRQ corresponding to that channel must be enabled using \ref MXC_NVIC_SetVector,
* and the \ref MXC_DMA_Handler should be called from the respective ISR.
*
* @param req \ref mxc_adc_conversion_req_t
* @param pointer to the variable to hold the conversion result
Expand Down
19 changes: 17 additions & 2 deletions Libraries/PeriphDrivers/Include/MAX32672/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern "C" {
/**
* @defgroup adc ADC
* @ingroup periphlibs
* @details API for Analog to Digital Converter (ADC).
* @{
*/

Expand Down Expand Up @@ -222,6 +223,9 @@ typedef enum {
///< Callback used when a conversion event is complete
typedef void (*mxc_adc_complete_cb_t)(void *req, int error);

/**
* @brief ADC Settings
*/
typedef struct {
mxc_adc_clock_t clock; ///< clock to use
mxc_adc_clkdiv_t clkdiv; ///< clock divider
Expand All @@ -231,12 +235,18 @@ typedef struct {
uint32_t idleCount; ///< Sample Clock Low time
} mxc_adc_req_t;

/**
* @brief ADC Slot Settings
*/
typedef struct {
mxc_adc_chsel_t channel; ///< channel select
mxc_adc_divsel_t div; ///< Analog input divider
mxc_adc_dynamic_pullup_t pullup_dyn; ///< Dynamic Pullup
} mxc_adc_slot_req_t;

/**
* @brief ADC Conversion Settings
*/
typedef struct {
mxc_adc_conversion_mode_t mode; ///< conversion mode
mxc_adc_trig_mode_t trig; ///< trigger mode
Expand All @@ -246,6 +256,7 @@ typedef struct {
mxc_adc_avg_t avg_number; ///< no of samples to average
mxc_adc_div_lpmode_t lpmode_divder; ///< Divide by 2 control in lpmode
uint8_t num_slots; ///< num of slots in the sequence
int8_t dma_channel; ///<The channel to use for DMA-enabled transactions
} mxc_adc_conversion_req_t;

/**
Expand Down Expand Up @@ -311,8 +322,12 @@ int MXC_ADC_StartConversion(void);
int MXC_ADC_StartConversionAsync(mxc_adc_complete_cb_t callback);

/**
* @brief Perform a conversion on a specific channel using a DMA transfer
*
* @brief Perform a conversion on a specific channel using a DMA transfer.
* DMA channel must be acquired using \ref MXC_DMA_AcquireChannel and should
* be passed to this function via "dma_channel" member of "req" input struct.
* DMA IRQ corresponding to that channel must be enabled using \ref MXC_NVIC_SetVector,
* and the \ref MXC_DMA_Handler should be called from the respective ISR.
*
* @param req \ref mxc_adc_conversion_req_t
* @param pointer to the variable to hold the conversion result
* @param callback the function to call when the conversion is complete
Expand Down
19 changes: 17 additions & 2 deletions Libraries/PeriphDrivers/Include/MAX32690/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern "C" {
/**
* @defgroup adc ADC
* @ingroup periphlibs
* @details API for Analog to Digital Converter (ADC).
* @{
*/

Expand Down Expand Up @@ -204,6 +205,9 @@ typedef enum {
///< Callback used when a conversion event is complete
typedef void (*mxc_adc_complete_cb_t)(void *req, int error);

/**
* @brief ADC Settings
*/
typedef struct {
mxc_adc_clock_t clock; ///< clock to use
mxc_adc_clkdiv_t clkdiv; ///< clock divider
Expand All @@ -213,12 +217,18 @@ typedef struct {
uint32_t idleCount; ///< Sample Clock Low time
} mxc_adc_req_t;

/**
* @brief ADC Slot Settings
*/
typedef struct {
mxc_adc_chsel_t channel; ///< channel select
// mxc_adc_divsel_t div; ///< Analog input divider
// mxc_adc_dynamic_pullup_t pullup_dyn; ///< Dynamic Pullup
} mxc_adc_slot_req_t;

/**
* @brief ADC Conversion Settings
*/
typedef struct {
mxc_adc_conversion_mode_t mode; ///< conversion mode
mxc_adc_trig_mode_t trig; ///< trigger mode
Expand All @@ -228,6 +238,7 @@ typedef struct {
mxc_adc_avg_t avg_number; ///< no of samples to average
mxc_adc_div_lpmode_t lpmode_divder; ///< Divide by 2 control in lpmode
uint8_t num_slots; ///< num of slots in the sequence
int8_t dma_channel; ///<The channel to use for DMA-enabled transactions
} mxc_adc_conversion_req_t;

/**
Expand Down Expand Up @@ -302,8 +313,12 @@ int MXC_ADC_StartConversion(void);
int MXC_ADC_StartConversionAsync(mxc_adc_complete_cb_t callback);

/**
* @brief Perform a conversion on a specific channel using a DMA transfer
*
* @brief Perform a conversion on a specific channel using a DMA transfer.
* DMA channel must be acquired using \ref MXC_DMA_AcquireChannel and should
* be passed to this function via "dma_channel" member of "req" input struct.
* DMA IRQ corresponding to that channel must be enabled using \ref MXC_NVIC_SetVector,
* and the \ref MXC_DMA_Handler should be called from the respective ISR.
*
* @param req \ref mxc_adc_conversion_req_t
* @param pointer to the variable to hold the conversion result
* @param callback the function to call when the conversion is complete
Expand Down
17 changes: 16 additions & 1 deletion Libraries/PeriphDrivers/Include/MAX78002/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern "C" {
/**
* @defgroup adc ADC
* @ingroup periphlibs
* @details API for Analog to Digital Converter (ADC).
* @{
*/

Expand Down Expand Up @@ -224,6 +225,9 @@ typedef enum {
///< Callback used when a conversion event is complete
typedef void (*mxc_adc_complete_cb_t)(void *req, int error);

/**
* @brief ADC Settings
*/
typedef struct {
mxc_adc_clock_t clock; ///< clock to use
mxc_adc_clkdiv_t clkdiv; ///< clock divider
Expand All @@ -233,12 +237,18 @@ typedef struct {
uint32_t idleCount; ///< Sample Clock Low time
} mxc_adc_req_t;

/**
* @brief ADC Slot Settings
*/
typedef struct {
mxc_adc_chsel_t channel; ///< channel select
mxc_adc_divsel_t div; ///< Analog input divider
mxc_adc_dynamic_pullup_t pullup_dyn; ///< Dynamic Pullup
} mxc_adc_slot_req_t;

/**
* @brief ADC Conversion Settings
*/
typedef struct {
mxc_adc_conversion_mode_t mode; ///< conversion mode
mxc_adc_trig_mode_t trig; ///< trigger mode
Expand All @@ -248,6 +258,7 @@ typedef struct {
mxc_adc_avg_t avg_number; ///< no of samples to average
mxc_adc_div_lpmode_t lpmode_divder; ///< Divide by 2 control in lpmode
uint8_t num_slots; ///< num of slots in the sequence
int8_t dma_channel; ///<The channel to use for DMA-enabled transactions
} mxc_adc_conversion_req_t;

/**
Expand Down Expand Up @@ -313,7 +324,11 @@ int MXC_ADC_StartConversion(void);
int MXC_ADC_StartConversionAsync(mxc_adc_complete_cb_t callback);

/**
* @brief Perform a conversion on a specific channel using a DMA transfer
* @brief Perform a conversion on a specific channel using a DMA transfer.
* DMA channel must be acquired using \ref MXC_DMA_AcquireChannel and should
* be passed to this function via "dma_channel" member of "req" input struct.
* DMA IRQ corresponding to that channel must be enabled using \ref MXC_NVIC_SetVector,
* and the \ref MXC_DMA_Handler should be called from the respective ISR.
*
* @param req \ref mxc_adc_conversion_req_t
* @param pointer to the variable to hold the conversion result
Expand Down
Loading

0 comments on commit 2b10962

Please sign in to comment.