Skip to content

Commit 5afa363

Browse files
authored
Small API additions and minor fixes (#406)
* Add missing DREQ_s * store actual clock frequency in clock_configure (fixes #368) * use dma DREQ values defined in dreqs/dma.h * Fix hw_is_claimed, and add xxx_is_claimed APIs * Add some PIO irq helper methods * Add DMA channel IRQ status getter and clear methods * Implement the correct PIO IRQ status/clear methods (good to have methods here as the h/w interrupt registers are super confusing) * fix pico_multicore dependencies * add missing wrapper func __aeabi_f2d * Further DMA/PIO IRQ API cleanup (and review fixes) * add PICO_INT64_OPS_IN_RAM flag
1 parent 91e9327 commit 5afa363

File tree

21 files changed

+368
-36
lines changed

21 files changed

+368
-36
lines changed

cmake/preload/toolchains/pico_arm_gcc.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (NOT PICO_GCC_TRIPLE)
1212
message("PICO_GCC_TRIPLE set from environment: $ENV{PICO_GCC_TRIPLE}")
1313
else()
1414
set(PICO_GCC_TRIPLE arm-none-eabi)
15-
pico_message_debug("PICO_GCC_TRIPLE defaulted to arm-none-eabi")
15+
#pico_message_debug("PICO_GCC_TRIPLE defaulted to arm-none-eabi")
1616
endif()
1717
endif()
1818

src/common/pico_time/time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static void alarm_pool_dump_key(pheap_node_id_t id, void *user_data) {
283283
#endif
284284
}
285285

286-
static int64_t repeating_timer_callback(__unused alarm_id_t id, __unused void *user_data) {
286+
static int64_t repeating_timer_callback(__unused alarm_id_t id, void *user_data) {
287287
repeating_timer_t *rt = (repeating_timer_t *)user_data;
288288
assert(rt->alarm_id == id);
289289
if (rt->callback(rt)) {

src/rp2_common/cmsis/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ set(PICO_CMSIS_VENDOR RaspberryPi)
5050
set(PICO_CMSIS_DEVICE RP2040)
5151

5252
if (PICO_CMSIS_CORE_PATH)
53-
add_library(cmsis_core INTERFACE)
53+
pico_add_impl_library(cmsis_core)
5454
target_sources(cmsis_core INTERFACE
5555
${PICO_CMSIS_CORE_PATH}/CMSIS/Device/${PICO_CMSIS_VENDOR}/${PICO_CMSIS_DEVICE}/Source/system_${PICO_CMSIS_DEVICE}.c
5656
)

src/rp2_common/cmsis/include/cmsis/rename_exceptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef _CMSIS_RENAME_EXCEPTIONS_H
88
#define _CMSIS_RENAME_EXCEPTIONS_H
99

10+
#if LIB_CMSIS_CORE
1011
// PICO_CONFIG: PICO_CMSIS_RENAME_EXCEPTIONS, Whether to rename SDK exceptions such as isr_nmi to their CMSIS equivalent i.e. NMI_Handler, type=bool, default=1, group=cmsis_core
1112

1213
// Note that since this header is included at the config stage, if you wish to override this you should do so via build compiler define
@@ -48,4 +49,5 @@
4849
#define isr_irq25 RTC_IRQ_Handler
4950
#endif
5051

52+
#endif
5153
#endif /* _CMSIS_RENAME_EXCEPTIONS_H */

src/rp2_common/hardware_claim/claim.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,13 @@ void hw_claim_unlock(uint32_t save) {
1414
spin_unlock(spin_lock_instance(PICO_SPINLOCK_ID_HARDWARE_CLAIM), save);
1515
}
1616

17-
bool hw_is_claimed(uint8_t *bits, uint bit_index) {
18-
bool rc;
19-
uint32_t save = hw_claim_lock();
20-
if (bits[bit_index >> 3u] & (1u << (bit_index & 7u))) {
21-
rc = false;
22-
} else {
23-
bits[bit_index >> 3u] |= (uint8_t)(1u << (bit_index & 7u));
24-
rc = true;
25-
}
26-
hw_claim_unlock(save);
27-
return rc;
17+
inline bool hw_is_claimed(const uint8_t *bits, uint bit_index) {
18+
return (bits[bit_index >> 3u] & (1u << (bit_index & 7u)));
2819
}
2920

3021
void hw_claim_or_assert(uint8_t *bits, uint bit_index, const char *message) {
3122
uint32_t save = hw_claim_lock();
32-
if (bits[bit_index >> 3u] & (1u << (bit_index & 7u))) {
23+
if (hw_is_claimed(bits, bit_index)) {
3324
panic(message, bit_index);
3425
} else {
3526
bits[bit_index >> 3u] |= (uint8_t)(1u << (bit_index & 7u));
@@ -42,7 +33,7 @@ int hw_claim_unused_from_range(uint8_t *bits, bool required, uint bit_lsb, uint
4233
uint32_t save = hw_claim_lock();
4334
int found_bit = -1;
4435
for(uint bit=bit_lsb; bit <= bit_msb; bit++) {
45-
if (!(bits[bit >> 3u] & (1u << (bit & 7u)))) {
36+
if (!hw_is_claimed(bits, bit)) {
4637
bits[bit >> 3u] |= (uint8_t)(1u << (bit & 7u));
4738
found_bit = (int)bit;
4839
break;
@@ -57,7 +48,7 @@ int hw_claim_unused_from_range(uint8_t *bits, bool required, uint bit_lsb, uint
5748

5849
void hw_claim_clear(uint8_t *bits, uint bit_index) {
5950
uint32_t save = hw_claim_lock();
60-
assert(bits[bit_index >> 3u] & (1u << (bit_index & 7u)));
51+
assert(hw_is_claimed(bits, bit_index));
6152
bits[bit_index >> 3u] &= (uint8_t) ~(1u << (bit_index & 7u));
6253
hw_claim_unlock(save);
6354
}

src/rp2_common/hardware_claim/include/hardware/claim.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ int hw_claim_unused_from_range(uint8_t *bits, bool required, uint bit_lsb, uint
6565
* The resource ownership is indicated by the bit_index bit in an array of bits.
6666
*
6767
* \param bits pointer to an array of bits (8 bits per byte)
68-
* \param bit_index resource to unclaim (bit index into array of bits)
68+
* \param bit_index resource to check (bit index into array of bits)
6969
* \return true if the resource is claimed
7070
*/
71-
bool hw_is_claimed(uint8_t *bits, uint bit_index);
71+
bool hw_is_claimed(const uint8_t *bits, uint bit_index);
7272

7373
/*! \brief Atomically unclaim a resource
7474
* \ingroup hardware_claim

src/rp2_common/hardware_clocks/clocks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ bool clock_configure(enum clock_index clk_index, uint32_t src, uint32_t auxsrc,
112112
clock->div = div;
113113

114114
// Store the configured frequency
115-
configured_freq[clk_index] = freq;
115+
configured_freq[clk_index] = (uint32_t)(((uint64_t) src_freq << 8) / div);
116116

117117
return true;
118118
}

src/rp2_common/hardware_dma/dma.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ int dma_claim_unused_channel(bool required) {
3939
return hw_claim_unused_from_range((uint8_t*)&_claimed, required, 0, NUM_DMA_CHANNELS-1, "No DMA channels are available");
4040
}
4141

42+
bool dma_channel_is_claimed(uint channel) {
43+
check_dma_channel_param(channel);
44+
return hw_is_claimed((uint8_t *) &_claimed, channel);
45+
}
46+
4247
#ifndef NDEBUG
4348

4449
void print_dma_ctrl(dma_channel_hw_t *channel) {

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

Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ extern "C" {
3434
* * Memory to memory
3535
*/
3636

37-
// this is not defined in generated dreq.h
38-
#define DREQ_FORCE 63
37+
// these are not defined in generated dreq.h
38+
#define DREQ_DMA_TIMER0 DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_TIMER0
39+
#define DREQ_DMA_TIMER1 DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_TIMER1
40+
#define DREQ_DMA_TIMER2 DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_TIMER2
41+
#define DREQ_DMA_TIMER3 DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_TIMER3
42+
#define DREQ_FORCE DMA_CH0_CTRL_TRIG_TREQ_SEL_VALUE_PERMANENT
3943

4044
// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_DMA, Enable/disable DMA assertions, type=bool, default=0, group=hardware_dma
4145
#ifndef PARAM_ASSERTIONS_ENABLED_DMA
@@ -94,6 +98,16 @@ void dma_channel_unclaim(uint channel);
9498
*/
9599
int dma_claim_unused_channel(bool required);
96100

101+
/*! \brief Determine if a dma channel is claimed
102+
* \ingroup hardware_dma
103+
*
104+
* \param channel the dma channel
105+
* \return true if the channel is claimed, false otherwise
106+
* \see dma_channel_claim
107+
* \see dma_channel_claim_mask
108+
*/
109+
bool dma_channel_is_claimed(uint channel);
110+
97111
/** \brief DMA channel configuration
98112
* \defgroup channel_config channel_config
99113
* \ingroup hardware_dma
@@ -465,7 +479,7 @@ static inline void dma_channel_abort(uint channel) {
465479
while (dma_hw->abort & (1ul << channel)) tight_loop_contents();
466480
}
467481

468-
/*! \brief Enable single DMA channel interrupt 0
482+
/*! \brief Enable single DMA channel's interrupt via DMA_IRQ_0
469483
* \ingroup hardware_dma
470484
*
471485
* \param channel DMA channel
@@ -480,7 +494,7 @@ static inline void dma_channel_set_irq0_enabled(uint channel, bool enabled) {
480494
hw_clear_bits(&dma_hw->inte0, 1u << channel);
481495
}
482496

483-
/*! \brief Enable multiple DMA channels interrupt 0
497+
/*! \brief Enable multiple DMA channels' interrupts via DMA_IRQ_0
484498
* \ingroup hardware_dma
485499
*
486500
* \param channel_mask Bitmask of all the channels to enable/disable. Channel 0 = bit 0, channel 1 = bit 1 etc.
@@ -494,7 +508,7 @@ static inline void dma_set_irq0_channel_mask_enabled(uint32_t channel_mask, bool
494508
}
495509
}
496510

497-
/*! \brief Enable single DMA channel interrupt 1
511+
/*! \brief Enable single DMA channel's interrupt via DMA_IRQ_1
498512
* \ingroup hardware_dma
499513
*
500514
* \param channel DMA channel
@@ -509,7 +523,7 @@ static inline void dma_channel_set_irq1_enabled(uint channel, bool enabled) {
509523
hw_clear_bits(&dma_hw->inte1, 1u << channel);
510524
}
511525

512-
/*! \brief Enable multiple DMA channels interrupt 0
526+
/*! \brief Enable multiple DMA channels' interrupts via DMA_IRQ_1
513527
* \ingroup hardware_dma
514528
*
515529
* \param channel_mask Bitmask of all the channels to enable/disable. Channel 0 = bit 0, channel 1 = bit 1 etc.
@@ -523,6 +537,105 @@ static inline void dma_set_irq1_channel_mask_enabled(uint32_t channel_mask, bool
523537
}
524538
}
525539

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_irqn_set_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+
572+
/*! \brief Determine if a particular channel is a cause of DMA_IRQ_0
573+
* \ingroup hardware_dma
574+
*
575+
* \param channel DMA channel
576+
* \return true if the channel is a cause of DMA_IRQ_0, false otherwise
577+
*/
578+
static inline bool dma_channel_get_irq0_status(uint channel) {
579+
check_dma_channel_param(channel);
580+
return dma_hw->ints0 & (1u << channel);
581+
}
582+
583+
/*! \brief Determine if a particular channel is a cause of DMA_IRQ_1
584+
* \ingroup hardware_dma
585+
*
586+
* \param channel DMA channel
587+
* \return true if the channel is a cause of DMA_IRQ_1, false otherwise
588+
*/
589+
static inline bool dma_channel_get_irq1_status(uint channel) {
590+
check_dma_channel_param(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);
605+
}
606+
607+
/*! \brief Acknowledge a channel IRQ, resetting it as the cause of DMA_IRQ_0
608+
* \ingroup hardware_dma
609+
*
610+
* \param channel DMA channel
611+
*/
612+
static inline void dma_channel_acknowledge_irq0(uint channel) {
613+
check_dma_channel_param(channel);
614+
hw_set_bits(&dma_hw->ints0, (1u << channel));
615+
}
616+
617+
/*! \brief Acknowledge a channel IRQ, resetting it as the cause of DMA_IRQ_1
618+
* \ingroup hardware_dma
619+
*
620+
* \param channel DMA channel
621+
*/
622+
static inline void dma_channel_acknowledge_irq1(uint channel) {
623+
check_dma_channel_param(channel);
624+
hw_set_bits(&dma_hw->ints1, (1u << channel));
625+
}
626+
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+
526639
/*! \brief Check if DMA channel is busy
527640
* \ingroup hardware_dma
528641
*

src/rp2_common/hardware_interp/include/hardware/interp.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ typedef struct {
5555
} interp_config;
5656

5757
static inline uint interp_index(interp_hw_t *interp) {
58-
assert(interp == interp0 || interp == interp1);
58+
valid_params_if(INTERP, interp == interp0 || interp == interp1);
5959
return interp == interp1 ? 1 : 0;
6060
}
6161

@@ -70,6 +70,8 @@ static inline uint interp_index(interp_hw_t *interp) {
7070
* \param lane The lane number, 0 or 1.
7171
*/
7272
void interp_claim_lane(interp_hw_t *interp, uint lane);
73+
// The above really should be called this for consistency
74+
#define interp_lane_claim interp_claim_lane
7375

7476
/*! \brief Claim the interpolator lanes specified in the mask
7577
* \ingroup hardware_interp
@@ -86,6 +88,19 @@ void interp_claim_lane_mask(interp_hw_t *interp, uint lane_mask);
8688
* \param lane The lane number, 0 or 1
8789
*/
8890
void interp_unclaim_lane(interp_hw_t *interp, uint lane);
91+
// The above really should be called this for consistency
92+
#define interp_lane_unclaim interp_unclaim_lane
93+
94+
/*! \brief Determine if an interpolator lane is claimed
95+
* \ingroup hardware_interp
96+
*
97+
* \param interp Interpolator whose lane to check
98+
* \param lane The lane number, 0 or 1
99+
* \return true if claimed, false otherwise
100+
* \see interp_claim_lane
101+
* \see interp_claim_lane_mask
102+
*/
103+
bool interp_lane_is_claimed(interp_hw_t *interp, uint lane);
89104

90105
/*! \brief Release previously claimed interpolator lanes \see interp_claim_lane_mask
91106
* \ingroup hardware_interp

0 commit comments

Comments
 (0)