Skip to content

Commit

Permalink
-some typo fixes
Browse files Browse the repository at this point in the history
-prevent branching
-replaced magic number -1 by PIO_INVALID_SM
-small consistency changes
  • Loading branch information
Reneg973 committed May 13, 2021
1 parent 607b420 commit 3cbccd6
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/rp2_common/hardware_dma/include/hardware/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ typedef struct {
* Usually disabled for peripheral to memory transfers
*/
static inline void channel_config_set_read_increment(dma_channel_config *c, bool incr) {
c->ctrl = incr ? (c->ctrl | DMA_CH0_CTRL_TRIG_INCR_READ_BITS) : (c->ctrl & ~DMA_CH0_CTRL_TRIG_INCR_READ_BITS);
c->ctrl = (c->ctrl & ~DMA_CH0_CTRL_TRIG_INCR_READ_BITS) | (incr * DMA_CH0_CTRL_TRIG_INCR_READ_BITS);
}

/*! \brief Set DMA channel write increment
Expand All @@ -138,7 +138,7 @@ static inline void channel_config_set_read_increment(dma_channel_config *c, bool
* Usually disabled for memory to peripheral transfers
*/
static inline void channel_config_set_write_increment(dma_channel_config *c, bool incr) {
c->ctrl = incr ? (c->ctrl | DMA_CH0_CTRL_TRIG_INCR_WRITE_BITS) : (c->ctrl & ~DMA_CH0_CTRL_TRIG_INCR_WRITE_BITS);
c->ctrl = (c->ctrl & ~DMA_CH0_CTRL_TRIG_INCR_WRITE_BITS) | (incr * DMA_CH0_CTRL_TRIG_INCR_WRITE_BITS);
}

/*! \brief Select a transfer request signal
Expand Down
19 changes: 10 additions & 9 deletions src/rp2_common/hardware_pio/include/hardware/pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static inline void sm_config_set_wrap(pio_sm_config *c, uint wrap_target, uint w
* \ingroup sm_config
*
* \param c Pointer to the configuration structure to modify
* \param pin The raw GPIO pin number to use as the source for a `jmp pin` instruction
* \param pin The raw GPIO pin number to use as the source for a `jmp pin` instruction
*/
static inline void sm_config_set_jmp_pin(pio_sm_config *c, uint pin) {
valid_params_if(PIO, pin < 32);
Expand All @@ -281,7 +281,7 @@ static inline void sm_config_set_jmp_pin(pio_sm_config *c, uint pin) {
* \param c Pointer to the configuration structure to modify
* \param shift_right true to shift ISR to right, false to shift ISR to left
* \param autopush whether autopush is enabled
* \param push_threshold threshold in bits to shift in before auto/conditional re-pushing of the ISR
* \param push_threshold threshold in bits to shift in before auto/conditional re-pushing of the ISR
*/
static inline void sm_config_set_in_shift(pio_sm_config *c, bool shift_right, bool autopush, uint push_threshold) {
valid_params_if(PIO, push_threshold <= 32);
Expand All @@ -300,7 +300,7 @@ static inline void sm_config_set_in_shift(pio_sm_config *c, bool shift_right, bo
* \param c Pointer to the configuration structure to modify
* \param shift_right true to shift OSR to right, false to shift OSR to left
* \param autopull whether autopull is enabled
* \param pull_threshold threshold in bits to shift out before auto/conditional re-pulling of the OSR
* \param pull_threshold threshold in bits to shift out before auto/conditional re-pulling of the OSR
*/
static inline void sm_config_set_out_shift(pio_sm_config *c, bool shift_right, bool autopull, uint pull_threshold) {
valid_params_if(PIO, pull_threshold <= 32);
Expand Down Expand Up @@ -330,7 +330,7 @@ static inline void sm_config_set_fifo_join(pio_sm_config *c, enum pio_fifo_join
*
* \param c Pointer to the configuration structure to modify
* \param sticky to enable 'sticky' output (i.e. re-asserting most recent OUT/SET pin values on subsequent cycles)
* \param has_enable_pin true to enable auxiliary OUT enable pin
* \param has_enable_pin true to enable auxiliary OUT enable pin
* \param enable_pin_index pin index for auxiliary OUT enable
*/
static inline void sm_config_set_out_special(pio_sm_config *c, bool sticky, bool has_enable_pin, uint enable_pin_index) {
Expand All @@ -352,7 +352,7 @@ static inline void sm_config_set_out_special(pio_sm_config *c, bool sticky, bool
static inline void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_status_type status_sel, uint status_n) {
valid_params_if(PIO, status_sel == STATUS_TX_LESSTHAN || status_sel == STATUS_RX_LESSTHAN);
c->execctrl = (c->execctrl
& ~(PIO_SM0_EXECCTRL_STATUS_SEL_BITS | PIO_SM0_EXECCTRL_STATUS_N_BITS))
& ~(PIO_SM0_EXECCTRL_STATUS_SEL_BITS | PIO_SM0_EXECCTRL_STATUS_N_BITS))
| ((((uint)status_sel) << PIO_SM0_EXECCTRL_STATUS_SEL_LSB) & PIO_SM0_EXECCTRL_STATUS_SEL_BITS)
| ((status_n << PIO_SM0_EXECCTRL_STATUS_N_LSB) & PIO_SM0_EXECCTRL_STATUS_N_BITS);
}
Expand All @@ -372,7 +372,7 @@ static inline void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_statu
* In Shift | shift_direction=right, autopush=false, push_thrshold=32
* Out Shift | shift_direction=right, autopull=false, pull_thrshold=32
* Jmp Pin | 0
* Out Special | sticky=false, has_enable_pin=false, enable_pin_index=0
* Out Special | sticky=false, has_enable_pin=false, enable_pin_index=0
* Mov Status | status_sel=STATUS_TX_LESSTHAN, n=0
*
* \return the default state machine configuration which can then be modified.
Expand Down Expand Up @@ -413,7 +413,7 @@ static inline uint pio_get_index(PIO pio) {
return pio == pio1 ? 1 : 0;
}

/*! \brief Setup the function select for a GPIO to use output from the given PIO instance
/*! \brief Setup the function select for a GPIO to use output from the given PIO instance
* \ingroup hardware_pio
*
* PIO appears as an alternate function in the GPIO muxing, just like an SPI
Expand Down Expand Up @@ -1127,14 +1127,15 @@ void pio_claim_sm_mask(PIO pio, uint sm_mask);
*/
void pio_sm_unclaim(PIO pio, uint sm);

#define PIO_INVALID_SM ((uint)-1)
/*! \brief Claim a free state machine on a PIO instance
* \ingroup hardware_pio
*
* \param pio The PIO instance; either \ref pio0 or \ref pio1
* \param required if true the function will panic if none are available
* \return the state machine index or -1 if required was false, and none were free
* \return the state machine index or PIO_INVALID_SM if required was false, and none were free
*/
int pio_claim_unused_sm(PIO pio, bool required);
uint pio_claim_unused_sm(PIO pio, bool required);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions src/rp2_common/hardware_pio/pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ void pio_sm_unclaim(PIO pio, uint sm) {
hw_claim_clear(&claimed, which * NUM_PIO_STATE_MACHINES + sm);
}

int pio_claim_unused_sm(PIO pio, bool required) {
uint pio_claim_unused_sm(PIO pio, bool required) {
// PIO index is 0 or 1.
uint which = pio_get_index(pio);
uint base = which * NUM_PIO_STATE_MACHINES;
int index = hw_claim_unused_from_range((uint8_t*)&claimed, required, base,
base + NUM_PIO_STATE_MACHINES - 1, "No PIO state machines are available");
return index >= (int)base ? index - (int)base : -1;
return index >= base ? index - base : PIO_INVALID_SM;
}

static_assert(PIO_INSTRUCTION_COUNT <= 32, "");
Expand Down
2 changes: 1 addition & 1 deletion src/rp2_common/hardware_pwm/include/hardware/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern "C" {
#endif

// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_PWM, Enable/disable assertions in the PWM module, type=bool, default=0, group=hadrware_pwm
// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_PWM, Enable/disable assertions in the PWM module, type=bool, default=0, group=hardware_pwm
#ifndef PARAM_ASSERTIONS_ENABLED_PWM
#define PARAM_ASSERTIONS_ENABLED_PWM 0
#endif
Expand Down
3 changes: 1 addition & 2 deletions src/rp2_common/hardware_sync/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ void spin_locks_reset(void) {

spin_lock_t *spin_lock_init(uint lock_num) {
assert(lock_num < NUM_SPIN_LOCKS);
spin_lock_t *lock = spin_lock_instance(lock_num);
spin_unlock_unsafe(lock);
spin_unlock_unsafe(spin_lock_instance(lock_num));
return lock;
}

Expand Down
4 changes: 3 additions & 1 deletion src/rp2_common/hardware_uart/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ uint uart_set_baudrate(uart_inst_t *uart, uint baudrate) {
invalid_params_if(UART, baudrate == 0);
uint32_t baud_rate_div = (8 * clock_get_hz(clk_peri) / baudrate);
uint32_t baud_ibrd = baud_rate_div >> 7;
uint32_t baud_fbrd = ((baud_rate_div & 0x7f) + 1) / 2;
uint32_t baud_fbrd;

if (baud_ibrd == 0) {
baud_ibrd = 1;
baud_fbrd = 0;
} else if (baud_ibrd >= 65535) {
baud_ibrd = 65535;
baud_fbrd = 0;
} else {
baud_fbrd = ((baud_rate_div & 0x7f) + 1) / 2;
}

// Load PL011's baud divisor registers
Expand Down
2 changes: 1 addition & 1 deletion src/rp2_common/pico_multicore/include/pico/multicore.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" {
* \include multicore.c
*/

// PICO_CONFIG: PICO_CORE1_STACK_SIZE, Stack size for core 1, min=0x100, max=0x10000, default=PICO_STACK_SIZE/0x800, group=pico_multicore
// PICO_CONFIG: PICO_CORE1_STACK_SIZE, Stack size for core 1, min=0x100, max=0x10000, default=PICO_STACK_SIZE (0x800), group=pico_multicore
#ifndef PICO_CORE1_STACK_SIZE
#ifdef PICO_STACK_SIZE
#define PICO_CORE1_STACK_SIZE PICO_STACK_SIZE
Expand Down
2 changes: 1 addition & 1 deletion src/rp2_common/pico_multicore/multicore.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void multicore_launch_core1(void (*entry)(void)) {
}

void multicore_launch_core1_raw(void (*entry)(void), uint32_t *sp, uint32_t vector_table) {
uint32_t cmd_sequence[] = {0, 0, 1, (uintptr_t) vector_table, (uintptr_t) sp, (uintptr_t) entry};
const uint32_t cmd_sequence[] = {0, 0, 1, (uintptr_t) vector_table, (uintptr_t) sp, (uintptr_t) entry};

bool enabled = irq_is_enabled(SIO_IRQ_PROC0);
irq_set_enabled(SIO_IRQ_PROC0, false);
Expand Down
8 changes: 4 additions & 4 deletions src/rp2_common/pico_printf/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
#define PICO_PRINTF_FTOA_BUFFER_SIZE 32U
#endif

// PICO_CONFIG: PICO_PRINTF_SUPPORT_FLOAT, Enable floating point printing, default=1, group=pico_printf
// PICO_CONFIG: PICO_PRINTF_SUPPORT_FLOAT, Enable floating point printing, type=bool, default=1, group=pico_printf
// support for the floating point type (%f)
#ifndef PICO_PRINTF_SUPPORT_FLOAT
#define PICO_PRINTF_SUPPORT_FLOAT 1
#endif

// PICO_CONFIG: PICO_PRINTF_SUPPORT_EXPONENTIAL, Enable exponential floating point printing, default=1, group=pico_printf
// PICO_CONFIG: PICO_PRINTF_SUPPORT_EXPONENTIAL, Enable exponential floating point printing, type=bool, default=1, group=pico_printf
// support for exponential floating point notation (%e/%g)
#ifndef PICO_PRINTF_SUPPORT_EXPONENTIAL
#define PICO_PRINTF_SUPPORT_EXPONENTIAL 1
Expand All @@ -73,12 +73,12 @@
#define PICO_PRINTF_MAX_FLOAT 1e9
#endif

// PICO_CONFIG: PICO_PRINTF_SUPPORT_LONG_LONG, Enable support for long long types (%llu or %p), default=1, group=pico_printf
// PICO_CONFIG: PICO_PRINTF_SUPPORT_LONG_LONG, Enable support for long long types (%llu or %p), type=bool, default=1, group=pico_printf
#ifndef PICO_PRINTF_SUPPORT_LONG_LONG
#define PICO_PRINTF_SUPPORT_LONG_LONG 1
#endif

// PICO_CONFIG: PICO_PRINTF_SUPPORT_PTRDIFF_T, Enable support for the ptrdiff_t type (%t), default=1, group=pico_printf
// PICO_CONFIG: PICO_PRINTF_SUPPORT_PTRDIFF_T, Enable support for the ptrdiff_t type (%t), type=bool, default=1, group=pico_printf
// ptrdiff_t is normally defined in <stddef.h> as long or long long type
#ifndef PICO_PRINTF_SUPPORT_PTRDIFF_T
#define PICO_PRINTF_SUPPORT_PTRDIFF_T 1
Expand Down
6 changes: 3 additions & 3 deletions src/rp2_common/pico_stdio/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ static void stdio_out_chars_crlf(stdio_driver_t *driver, const char *s, int len)
}

static bool stdio_put_string(const char *s, int len, bool newline) {
bool serialzed = stdout_serialize_begin();
if (!serialzed) {
bool serialized = stdout_serialize_begin();
if (!serialized) {
#if PICO_STDIO_IGNORE_NESTED_STDOUT
return false;
#endif
Expand All @@ -106,7 +106,7 @@ static bool stdio_put_string(const char *s, int len, bool newline) {
stdio_out_chars_crlf(driver, &c, 1);
}
}
if (serialzed) {
if (serialized) {
stdout_serialize_end();
}
return len;
Expand Down

0 comments on commit 3cbccd6

Please sign in to comment.