Skip to content

Commit 46d726c

Browse files
committed
Further DMA/PIO IRQ API cleanup (and review fixes)
1 parent 2562366 commit 46d726c

File tree

2 files changed

+102
-9
lines changed
  • src/rp2_common
    • hardware_dma/include/hardware
    • hardware_pio/include/hardware

2 files changed

+102
-9
lines changed

src/rp2_common/hardware_dma/include/hardware/dma.h

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static inline void dma_channel_abort(uint channel) {
479479
while (dma_hw->abort & (1ul << channel)) tight_loop_contents();
480480
}
481481

482-
/*! \brief Enable single DMA channel interrupt 0
482+
/*! \brief Enable single DMA channel's interrupt via DMA_IRQ_0
483483
* \ingroup hardware_dma
484484
*
485485
* \param channel DMA channel
@@ -494,7 +494,7 @@ static inline void dma_channel_set_irq0_enabled(uint channel, bool enabled) {
494494
hw_clear_bits(&dma_hw->inte0, 1u << channel);
495495
}
496496

497-
/*! \brief Enable multiple DMA channels interrupt 0
497+
/*! \brief Enable multiple DMA channels' interrupts via DMA_IRQ_0
498498
* \ingroup hardware_dma
499499
*
500500
* \param channel_mask Bitmask of all the channels to enable/disable. Channel 0 = bit 0, channel 1 = bit 1 etc.
@@ -508,7 +508,7 @@ static inline void dma_set_irq0_channel_mask_enabled(uint32_t channel_mask, bool
508508
}
509509
}
510510

511-
/*! \brief Enable single DMA channel interrupt 1
511+
/*! \brief Enable single DMA channel's interrupt via DMA_IRQ_1
512512
* \ingroup hardware_dma
513513
*
514514
* \param channel DMA channel
@@ -523,7 +523,7 @@ static inline void dma_channel_set_irq1_enabled(uint channel, bool enabled) {
523523
hw_clear_bits(&dma_hw->inte1, 1u << channel);
524524
}
525525

526-
/*! \brief Enable multiple DMA channels interrupt 0
526+
/*! \brief Enable multiple DMA channels' interrupts via DMA_IRQ_1
527527
* \ingroup hardware_dma
528528
*
529529
* \param channel_mask Bitmask of all the channels to enable/disable. Channel 0 = bit 0, channel 1 = bit 1 etc.
@@ -537,6 +537,38 @@ static inline void dma_set_irq1_channel_mask_enabled(uint32_t channel_mask, bool
537537
}
538538
}
539539

540+
/*! \brief Enable single DMA channel interrupt on either DMA_IRQ_0 or DMA_IRQ_1
541+
* \ingroup hardware_dma
542+
*
543+
* \param irq_index the IRQ index; either 0 or 1 for DMA_IRQ_0 or DMA_IRQ_1
544+
* \param channel DMA channel
545+
* \param enabled true to enable interrupt via irq_index for specified channel, false to disable.
546+
*/
547+
static inline void dma_irqn_set_channel_enabled(uint irq_index, uint channel, bool enabled) {
548+
invalid_params_if(DMA, irq_index > 1);
549+
if (irq_index) {
550+
dma_channel_set_irq1_enabled(channel, enabled);
551+
} else {
552+
dma_channel_set_irq0_enabled(channel, enabled);
553+
}
554+
}
555+
556+
/*! \brief Enable multiple DMA channels' interrupt via either DMA_IRQ_0 or DMA_IRQ_1
557+
* \ingroup hardware_dma
558+
*
559+
* \param irq_index the IRQ index; either 0 or 1 for DMA_IRQ_0 or DMA_IRQ_1
560+
* \param channel_mask Bitmask of all the channels to enable/disable. Channel 0 = bit 0, channel 1 = bit 1 etc.
561+
* \param enabled true to enable all the interrupts specified in the mask, false to disable all the interrupts specified in the mask.
562+
*/
563+
static inline void dma_set_irqn_channel_mask_enabled(uint irq_index, uint32_t channel_mask, bool enabled) {
564+
invalid_params_if(DMA, irq_index > 1);
565+
if (irq_index) {
566+
dma_set_irq1_channel_mask_enabled(channel_mask, enabled);
567+
} else {
568+
dma_set_irq0_channel_mask_enabled(channel_mask, enabled);
569+
}
570+
}
571+
540572
/*! \brief Determine if a particular channel is a cause of DMA_IRQ_0
541573
* \ingroup hardware_dma
542574
*
@@ -556,7 +588,20 @@ static inline bool dma_channel_get_irq0_status(uint channel) {
556588
*/
557589
static inline bool dma_channel_get_irq1_status(uint channel) {
558590
check_dma_channel_param(channel);
559-
return dma_hw->ints0 & (1u << channel);
591+
return dma_hw->ints1 & (1u << channel);
592+
}
593+
594+
/*! \brief Determine if a particular channel is a cause of DMA_IRQ_N
595+
* \ingroup hardware_dma
596+
*
597+
* \param irq_index the IRQ index; either 0 or 1 for DMA_IRQ_0 or DMA_IRQ_1
598+
* \param channel DMA channel
599+
* \return true if the channel is a cause of the DMA_IRQ_N, false otherwise
600+
*/
601+
static inline bool dma_irqn_get_channel_status(uint irq_index, uint channel) {
602+
invalid_params_if(DMA, irq_index > 1);
603+
check_dma_channel_param(channel);
604+
return (irq_index ? dma_hw->ints1 : dma_hw->ints0) & (1u << channel);
560605
}
561606

562607
/*! \brief Acknowledge a channel IRQ, resetting it as the cause of DMA_IRQ_0
@@ -569,7 +614,7 @@ static inline void dma_channel_acknowledge_irq0(uint channel) {
569614
hw_set_bits(&dma_hw->ints0, (1u << channel));
570615
}
571616

572-
/*! \brief Acknowledge a channel IRQ, resetting it as the cause of DMA_IRQ_0
617+
/*! \brief Acknowledge a channel IRQ, resetting it as the cause of DMA_IRQ_1
573618
* \ingroup hardware_dma
574619
*
575620
* \param channel DMA channel
@@ -579,6 +624,18 @@ static inline void dma_channel_acknowledge_irq1(uint channel) {
579624
hw_set_bits(&dma_hw->ints1, (1u << channel));
580625
}
581626

627+
/*! \brief Acknowledge a channel IRQ, resetting it as the cause of DMA_IRQ_N
628+
* \ingroup hardware_dma
629+
*
630+
* \param irq_index the IRQ index; either 0 or 1 for DMA_IRQ_0 or DMA_IRQ_1
631+
* \param channel DMA channel
632+
*/
633+
static inline void dma_irqn_acknowledge_channel(uint irq_index, uint channel) {
634+
invalid_params_if(DMA, irq_index > 1);
635+
check_dma_channel_param(channel);
636+
hw_set_bits(irq_index ? &dma_hw->ints1 : &dma_hw->ints0, (1u << channel));
637+
}
638+
582639
/*! \brief Check if DMA channel is busy
583640
* \ingroup hardware_dma
584641
*

src/rp2_common/hardware_pio/include/hardware/pio.h

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,9 @@ static inline void pio_set_irq1_source_enabled(PIO pio, enum pio_interrupt_sourc
726726
/*! \brief Enable/Disable multiple sources on a PIO's IRQ 0
727727
* \ingroup hardware_pio
728728
*
729+
* \param pio The PIO instance; either \ref pio0 or \ref pio1
729730
* \param source_mask Mask of bits, one for each source number (see \ref pio_interrupt_source) to affect
730-
* \param enabled true to enable all the source specified in the mask on IRQ 0, false to disable all the source specified in the mask on IRQ 0
731+
* \param enabled true to enable all the sources specified in the mask on IRQ 0, false to disable all the sources specified in the mask on IRQ 0
731732
*/
732733
static inline void pio_set_irq0_source_mask_enabled(PIO pio, uint32_t source_mask, bool enabled) {
733734
check_pio_param(pio);
@@ -742,8 +743,9 @@ static inline void pio_set_irq0_source_mask_enabled(PIO pio, uint32_t source_mas
742743
/*! \brief Enable/Disable multiple sources on a PIO's IRQ 1
743744
* \ingroup hardware_pio
744745
*
746+
* \param pio The PIO instance; either \ref pio0 or \ref pio1
745747
* \param source_mask Mask of bits, one for each source number (see \ref pio_interrupt_source) to affect
746-
* \param enabled true to enable all the source specified in the mask on IRQ 1, false to disable all the source specified in the mask on IRQ 1
748+
* \param enabled true to enable all the sources specified in the mask on IRQ 1, false to disable all the source specified in the mask on IRQ 1
747749
*/
748750
static inline void pio_set_irq1_source_mask_enabled(PIO pio, uint32_t source_mask, bool enabled) {
749751
check_pio_param(pio);
@@ -755,12 +757,46 @@ static inline void pio_set_irq1_source_mask_enabled(PIO pio, uint32_t source_mas
755757
}
756758
}
757759

760+
/*! \brief Enable/Disable a single source PIO's specified (0/1) IRQ index
761+
* \ingroup hardware_pio
762+
*
763+
* \param pio The PIO instance; either \ref pio0 or \ref pio1
764+
* \param irq_index the IRQ index; either 0 or 1
765+
* \param source the source number (see \ref pio_interrupt_source)
766+
* \param enabled true to enable IRQ 0 for the source, false to disable.
767+
*/
768+
static inline void pio_set_irqn_source_enabled(PIO pio, uint irq_index, enum pio_interrupt_source source, bool enabled) {
769+
invalid_params_if(PIO, irq_index > 1);
770+
if (irq_index) {
771+
pio_set_irq1_source_enabled(pio, source, enabled);
772+
} else {
773+
pio_set_irq0_source_enabled(pio, source, enabled);
774+
}
775+
}
776+
777+
/*! \brief Enable/Disable multiple sources on a PIO's specified (0/1) IRQ index
778+
* \ingroup hardware_pio
779+
*
780+
* \param pio The PIO instance; either \ref pio0 or \ref pio1
781+
* \param irq_index the IRQ index; either 0 or 1
782+
* \param source_mask Mask of bits, one for each source number (see \ref pio_interrupt_source) to affect
783+
* \param enabled true to enable all the source specified in the mask on IRQ 1, false to disable all the source specified in the mask on IRQ 1
784+
*/
785+
static inline void pio_set_irqn_source_mask_enabled(PIO pio, uint irq_index, uint32_t source_mask, bool enabled) {
786+
invalid_params_if(PIO, irq_index > 1);
787+
if (irq_index) {
788+
pio_set_irq0_source_mask_enabled(pio, source_mask, enabled);
789+
} else {
790+
pio_set_irq1_source_mask_enabled(pio, source_mask, enabled);
791+
}
792+
}
793+
758794
/*! \brief Determine if a particular PIO interrupt is set
759795
* \ingroup hardware_pio
760796
*
761797
* \param pio The PIO instance; either \ref pio0 or \ref pio1
762798
* \param pio_interrupt_num the PIO interrupt number 0-7
763-
* \return true if the source a cause of an IRQ, false otherwise
799+
* \return true if corresponding PIO interrupt is currently set
764800
*/
765801
static inline bool pio_interrupt_get(PIO pio, uint pio_interrupt_num) {
766802
check_pio_param(pio);

0 commit comments

Comments
 (0)