mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2025-12-09 23:04:37 +01:00
Compare commits
8 commits
37aec75905
...
4dee0bf90f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dee0bf90f | ||
|
|
8fcd44a171 | ||
|
|
6b395cce04 | ||
|
|
87c9c013fe | ||
|
|
17b914418d | ||
|
|
db75b67533 | ||
|
|
9f1958bf3f | ||
|
|
cd4f0bb7ca |
8 changed files with 83 additions and 11 deletions
|
|
@ -62,6 +62,29 @@ static inline void queue_init(queue_t *q, uint element_size, uint element_count)
|
|||
queue_init_with_spinlock(q, element_size, element_count, next_striped_spin_lock_num());
|
||||
}
|
||||
|
||||
/*! \brief Initialise a static queue with a specific spinlock for concurrency protection
|
||||
* \ingroup queue
|
||||
*
|
||||
* \param q Pointer to a queue_t structure, used as a handle
|
||||
* \param element_size Size of each value in the queue
|
||||
* \param spinlock_num The spin ID used to protect the queue
|
||||
* \param storage Pointer to queue storage array
|
||||
* \param storage_size Size of the queue storage array. (Must be N + 1 elements.)
|
||||
*/
|
||||
void static_queue_init_with_spinlock(queue_t *q, uint element_size, uint spinlock_num, uint8_t *storage, uint32_t storage_size);
|
||||
|
||||
/*! \brief Initialise a static queue, allocating a (possibly shared) spinlock
|
||||
* \ingroup queue
|
||||
*
|
||||
* \param q Pointer to a queue_t structure, used as a handle
|
||||
* \param element_size Size of each value in the queue
|
||||
* \param storage Pointer to queue storage array
|
||||
* \param storage_size Size of the queue storage array. (Must be N + 1 elements.)
|
||||
*/
|
||||
static inline void static_queue_init(queue_t *q, uint element_size, uint8_t *storage, uint32_t storage_size) {
|
||||
static_queue_init_with_spinlock(q, element_size, next_striped_spin_lock_num(), storage, storage_size);
|
||||
}
|
||||
|
||||
/*! \brief Destroy the specified queue.
|
||||
* \ingroup queue
|
||||
*
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "pico/util/queue.h"
|
||||
|
||||
void queue_init_with_spinlock(queue_t *q, uint element_size, uint element_count, uint spinlock_num) {
|
||||
assert(q != NULL);
|
||||
lock_init(&q->core, spinlock_num);
|
||||
q->data = (uint8_t *)calloc(element_count + 1, element_size);
|
||||
q->element_count = (uint16_t)element_count;
|
||||
|
|
@ -17,7 +18,19 @@ void queue_init_with_spinlock(queue_t *q, uint element_size, uint element_count,
|
|||
q->rptr = 0;
|
||||
}
|
||||
|
||||
void static_queue_init_with_spinlock(queue_t *q, uint element_size, uint spinlock_num, uint8_t *storage, uint32_t storage_size) {
|
||||
assert(q != NULL);
|
||||
assert((storage_size / element_size) >= 2);
|
||||
lock_init(&q->core, spinlock_num);
|
||||
q->data = storage;
|
||||
q->element_count = (uint16_t) ((storage_size / element_size) - 1);
|
||||
q->element_size = (uint16_t)element_size;
|
||||
q->wptr = 0;
|
||||
q->rptr = 0;
|
||||
}
|
||||
|
||||
void queue_free(queue_t *q) {
|
||||
assert(q != NULL);
|
||||
free(q->data);
|
||||
}
|
||||
|
||||
|
|
@ -99,25 +112,31 @@ static bool queue_peek_internal(queue_t *q, void *data, bool block) {
|
|||
}
|
||||
|
||||
bool queue_try_add(queue_t *q, const void *data) {
|
||||
assert(q != NULL);
|
||||
return queue_add_internal(q, data, false);
|
||||
}
|
||||
|
||||
bool queue_try_remove(queue_t *q, void *data) {
|
||||
assert(q != NULL);
|
||||
return queue_remove_internal(q, data, false);
|
||||
}
|
||||
|
||||
bool queue_try_peek(queue_t *q, void *data) {
|
||||
assert(q != NULL);
|
||||
return queue_peek_internal(q, data, false);
|
||||
}
|
||||
|
||||
void queue_add_blocking(queue_t *q, const void *data) {
|
||||
assert(q != NULL);
|
||||
queue_add_internal(q, data, true);
|
||||
}
|
||||
|
||||
void queue_remove_blocking(queue_t *q, void *data) {
|
||||
assert(q != NULL);
|
||||
queue_remove_internal(q, data, true);
|
||||
}
|
||||
|
||||
void queue_peek_blocking(queue_t *q, void *data) {
|
||||
assert(q != NULL);
|
||||
queue_peek_internal(q, data, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,8 +109,6 @@ extern "C" {
|
|||
|
||||
void __sev();
|
||||
|
||||
void __wev();
|
||||
|
||||
void __wfi();
|
||||
|
||||
void __wfe();
|
||||
|
|
|
|||
|
|
@ -93,23 +93,44 @@ void PICO_WEAK_FUNCTION_IMPL_NAME(spin_unlock)(spin_lock_t *lock, uint32_t saved
|
|||
spin_unlock_unsafe(lock);
|
||||
}
|
||||
|
||||
PICO_WEAK_FUNCTION_DEF(__sev)
|
||||
// These are defined on ARM hosts, but don't do what we want for the host
|
||||
// since this is a simulated build.
|
||||
|
||||
#if PICO_C_COMPILER_IS_GNU || !__has_builtin(__sev)
|
||||
#define __sev_c __sev
|
||||
#else
|
||||
#pragma redefine_extname __sev_c __sev
|
||||
#endif
|
||||
|
||||
#if PICO_C_COMPILER_IS_GNU || !__has_builtin(__wfi)
|
||||
#define __wfi_c __wfi
|
||||
#else
|
||||
#pragma redefine_extname __wfi_c __wfi
|
||||
#endif
|
||||
|
||||
#if PICO_C_COMPILER_IS_GNU || !__has_builtin(__wfe)
|
||||
#define __wfe_c __wfe
|
||||
#else
|
||||
#pragma redefine_extname __wfe_c __wfe
|
||||
#endif
|
||||
|
||||
PICO_WEAK_FUNCTION_DEF(__sev_c)
|
||||
|
||||
volatile bool event_fired;
|
||||
|
||||
void PICO_WEAK_FUNCTION_IMPL_NAME(__sev)() {
|
||||
void PICO_WEAK_FUNCTION_IMPL_NAME(__sev_c)() {
|
||||
event_fired = true;
|
||||
}
|
||||
|
||||
PICO_WEAK_FUNCTION_DEF(__wfi)
|
||||
PICO_WEAK_FUNCTION_DEF(__wfi_c)
|
||||
|
||||
void PICO_WEAK_FUNCTION_IMPL_NAME(__wfi)() {
|
||||
void PICO_WEAK_FUNCTION_IMPL_NAME(__wfi_c)() {
|
||||
panic("Can't wait on irq for host core0 only implementation");
|
||||
}
|
||||
|
||||
PICO_WEAK_FUNCTION_DEF(__wfe)
|
||||
PICO_WEAK_FUNCTION_DEF(__wfe_c)
|
||||
|
||||
void PICO_WEAK_FUNCTION_IMPL_NAME(__wfe)() {
|
||||
void PICO_WEAK_FUNCTION_IMPL_NAME(__wfe_c)() {
|
||||
while (!event_fired) tight_loop_contents();
|
||||
}
|
||||
|
||||
|
|
@ -146,4 +167,4 @@ int PICO_WEAK_FUNCTION_IMPL_NAME(spin_lock_claim_unused)(bool required) {
|
|||
PICO_WEAK_FUNCTION_DEF(spin_lock_num)
|
||||
uint PICO_WEAK_FUNCTION_IMPL_NAME(spin_lock_num)(spin_lock_t *lock) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -556,6 +556,7 @@ static inline uint32_t dma_encode_transfer_count(uint transfer_count) {
|
|||
*/
|
||||
static inline uint32_t dma_encode_transfer_count_with_self_trigger(uint transfer_count) {
|
||||
#if PICO_RP2040
|
||||
(void)transfer_count;
|
||||
panic_unsupported();
|
||||
#else
|
||||
return dma_encode_transfer_count(transfer_count) | (DMA_CH0_TRANS_COUNT_MODE_VALUE_TRIGGER_SELF << DMA_CH0_TRANS_COUNT_MODE_LSB);
|
||||
|
|
|
|||
|
|
@ -94,6 +94,9 @@ __force_inline static void __sev(void) {
|
|||
pico_default_asm_volatile ("sev");
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
// Forward declare so we don't have to #include <arm_acle.h>.
|
||||
void __sev(void);
|
||||
#endif
|
||||
|
||||
/*! \brief Insert a WFE instruction in to the code path.
|
||||
|
|
@ -110,6 +113,9 @@ __force_inline static void __wfe(void) {
|
|||
pico_default_asm_volatile ("wfe");
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
// Forward declare so we don't have to #include <arm_acle.h>.
|
||||
void __wfe(void);
|
||||
#endif
|
||||
|
||||
/*! \brief Insert a WFI instruction in to the code path.
|
||||
|
|
@ -121,6 +127,9 @@ __force_inline static void __wfe(void) {
|
|||
__force_inline static void __wfi(void) {
|
||||
pico_default_asm_volatile("wfi");
|
||||
}
|
||||
#else
|
||||
// Forward declare so we don't have to #include <arm_acle.h>.
|
||||
void __wfi(void);
|
||||
#endif
|
||||
|
||||
/*! \brief Insert a DMB instruction in to the code path.
|
||||
|
|
|
|||
|
|
@ -370,7 +370,7 @@ static bool multicore_doorbell_claim_under_lock(uint doorbell_num, uint core_mas
|
|||
(is_bit_claimed(doorbell_claimed[1], doorbell_num + 1u) << 1));
|
||||
if (claimed_cores_for_doorbell & core_mask) {
|
||||
if (required) {
|
||||
panic( "Multicoore doorbell %d already claimed on core mask 0x%x; requested core mask 0x%x\n",
|
||||
panic( "Multicore doorbell %d already claimed on core mask 0x%x; requested core mask 0x%x\n",
|
||||
claimed_cores_for_doorbell, core_mask);
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -80,7 +80,8 @@ bool colored_status_led_set_state(bool led_on) {
|
|||
if (colored_status_led_supported()) {
|
||||
#if COLORED_STATUS_LED_USING_WS2812_PIO
|
||||
success = true;
|
||||
if (led_on && !colored_status_led_on) {
|
||||
if (led_on) {
|
||||
// Turn the LED "on" even if it was already on, as the color might have changed
|
||||
success = set_ws2812(colored_status_led_on_color);
|
||||
} else if (!led_on && colored_status_led_on) {
|
||||
success = set_ws2812(0);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue