Skip to content

Commit

Permalink
spi: initialize spi_dev array
Browse files Browse the repository at this point in the history
avoids hitting an infitine loop while waiting on spi1 in the dshot driver.
  • Loading branch information
bkleiner committed Apr 11, 2024
1 parent eb85ba6 commit e50eda2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/driver/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "core/failloop.h"
#include "driver/interrupt.h"

FAST_RAM spi_device_t spi_dev[SPI_PORT_MAX];
FAST_RAM spi_device_t spi_dev[SPI_PORT_MAX] = {
[RANGE_INIT(0, SPI_PORT_MAX)] = {.is_init = false, .dma_done = true, .txn_head = 0, .txn_tail = 0},
};
FAST_RAM spi_txn_t txn_pool[SPI_TXN_MAX];
DMA_RAM uint8_t txn_buffers[SPI_TXN_MAX][DMA_ALIGN(512)];

Expand Down
5 changes: 3 additions & 2 deletions src/driver/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ typedef struct {
bool is_init;
volatile bool dma_done;

spi_txn_t *txns[SPI_TXN_MAX];
// only modified by the main loop
volatile uint8_t txn_head;
// only modified by the intterupt or protected code
volatile uint8_t txn_tail;

spi_txn_t *txns[SPI_TXN_MAX];

spi_mode_t mode;
uint32_t hz;
} spi_device_t;
Expand All @@ -137,7 +138,7 @@ static inline void spi_bus_device_reconfigure(spi_bus_device_t *bus, spi_mode_t
bus->hz = hz;
}

static inline uint8_t spi_dma_is_ready(spi_ports_t port) {
static inline bool spi_dma_is_ready(spi_ports_t port) {
const spi_device_t *dev = &spi_dev[port];
return dev->dma_done;
}
Expand Down
2 changes: 1 addition & 1 deletion src/driver/spi_sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ sdcard_status_t sdcard_update() {
break;
}

const uint8_t buf[20] = {[0 ... 19] = 0xff};
const uint8_t buf[20] = {[RANGE_INIT(0, 20)] = 0xff};
const spi_txn_segment_t segs[] = {
spi_make_seg_buffer(NULL, buf, 20),
};
Expand Down
3 changes: 3 additions & 0 deletions src/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

#define MAKE_SEMVER(major, minor, patch) ((major << 16) | (minor << 8) | patch)

// workaround for vscode not reconginzing this synatx
#define RANGE_INIT(start, end) start...(end - 1)

float mapf(float x, float in_min, float in_max, float out_min, float out_max);

float atan2approx(float y, float x);
Expand Down

0 comments on commit e50eda2

Please sign in to comment.