mirror of https://github.com/commaai/panda.git
parent
144846e4ce
commit
ac9c1b3b3f
|
@ -14,17 +14,14 @@ uint8_t spi_buf_rx[SPI_BUF_SIZE];
|
|||
uint8_t spi_buf_tx[SPI_BUF_SIZE];
|
||||
#endif
|
||||
|
||||
uint16_t spi_checksum_error_count = 0;
|
||||
|
||||
#if defined(ENABLE_SPI) || defined(BOOTSTUB)
|
||||
static uint8_t spi_state = SPI_STATE_HEADER;
|
||||
static uint16_t spi_data_len_mosi;
|
||||
uint16_t spi_checksum_error_count = 0;
|
||||
static bool spi_can_tx_ready = false;
|
||||
|
||||
static const unsigned char version_text[] = "VERSION";
|
||||
|
||||
void can_tx_comms_resume_spi(void) {
|
||||
spi_can_tx_ready = true;
|
||||
}
|
||||
|
||||
static uint16_t spi_version_packet(uint8_t *out) {
|
||||
// this protocol version request is a stable portion of
|
||||
// the panda's SPI protocol. its contents match that of the
|
||||
|
@ -69,7 +66,6 @@ static uint16_t spi_version_packet(uint8_t *out) {
|
|||
return resp_len;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_SPI) || defined(BOOTSTUB)
|
||||
void spi_init(void) {
|
||||
// platform init
|
||||
llspi_init();
|
||||
|
@ -78,7 +74,6 @@ void spi_init(void) {
|
|||
spi_state = SPI_STATE_HEADER;
|
||||
llspi_mosi_dma(spi_buf_rx, SPI_HEADER_SIZE);
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool validate_checksum(const uint8_t *data, uint16_t len) {
|
||||
// TODO: can speed this up by casting the bulk to uint32_t and xor-ing the bytes afterwards
|
||||
|
@ -231,3 +226,12 @@ void spi_tx_done(bool reset) {
|
|||
print("SPI: TX unexpected state: "); puth(spi_state); print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void can_tx_comms_resume_spi(void) {
|
||||
spi_can_tx_ready = true;
|
||||
}
|
||||
#else
|
||||
void can_tx_comms_resume_spi(void) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -47,6 +47,6 @@ void llspi_miso_dma(uint8_t *addr, int len);
|
|||
void can_tx_comms_resume_spi(void);
|
||||
#if defined(ENABLE_SPI) || defined(BOOTSTUB)
|
||||
void spi_init(void);
|
||||
#endif
|
||||
void spi_rx_done(void);
|
||||
void spi_tx_done(bool reset);
|
||||
#endif
|
||||
|
|
|
@ -149,10 +149,13 @@ void puth2(unsigned int i) {
|
|||
puthx(i, 2U);
|
||||
}
|
||||
|
||||
#if defined(ENABLE_SPI) || defined(BOOTSTUB) || defined(DEBUG)
|
||||
void puth4(unsigned int i) {
|
||||
puthx(i, 4U);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_SPI) || defined(BOOTSTUB) || defined(DEBUG_USB) || defined(DEBUG_COMMS)
|
||||
void hexdump(const void *a, int l) {
|
||||
if (a != NULL) {
|
||||
for (int i=0; i < l; i++) {
|
||||
|
@ -163,3 +166,4 @@ void hexdump(const void *a, int l) {
|
|||
}
|
||||
print("\n");
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -34,5 +34,7 @@ void print(const char *a);
|
|||
void puthx(uint32_t i, uint8_t len);
|
||||
void puth(unsigned int i);
|
||||
void puth2(unsigned int i);
|
||||
#if defined(ENABLE_SPI) || defined(BOOTSTUB) || defined(DEBUG)
|
||||
void puth4(unsigned int i);
|
||||
#endif
|
||||
void hexdump(const void *a, int l);
|
||||
|
|
|
@ -9,7 +9,7 @@ extern uint32_t enter_bootloader_mode;
|
|||
typedef void (*bootloader_fcn)(void);
|
||||
typedef bootloader_fcn *bootloader_fcn_ptr;
|
||||
|
||||
void jump_to_bootloader(void) {
|
||||
static void jump_to_bootloader(void) {
|
||||
// do enter bootloader
|
||||
enter_bootloader_mode = 0;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ extern int _app_start[0xc000]; // Only first 3 sectors of size 0x4000 are used
|
|||
void set_safety_mode(uint16_t mode, uint16_t param);
|
||||
bool is_car_safety_mode(uint16_t mode);
|
||||
|
||||
int get_health_pkt(void *dat) {
|
||||
static int get_health_pkt(void *dat) {
|
||||
COMPILE_TIME_ASSERT(sizeof(struct health_t) <= USBPACKET_MAX_SIZE);
|
||||
struct health_t * health = (struct health_t*)dat;
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ void gen_crc_lookup_table_8(uint8_t poly, uint8_t crc_lut[]) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef CANFD
|
||||
void gen_crc_lookup_table_16(uint16_t poly, uint16_t crc_lut[]) {
|
||||
for (uint16_t i = 0; i < 256U; i++) {
|
||||
uint16_t crc = i << 8U;
|
||||
|
@ -120,6 +121,7 @@ void gen_crc_lookup_table_16(uint16_t poly, uint16_t crc_lut[]) {
|
|||
crc_lut[i] = crc;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool msg_allowed(const CANPacket_t *to_send, const CanMsg msg_list[], int len) {
|
||||
int addr = GET_ADDR(to_send);
|
||||
|
|
|
@ -192,7 +192,9 @@ bool rt_rate_limit_check(int val, int val_last, const int MAX_RT_DELTA);
|
|||
float interpolate(struct lookup_t xy, float x);
|
||||
int ROUND(float val);
|
||||
void gen_crc_lookup_table_8(uint8_t poly, uint8_t crc_lut[]);
|
||||
#ifdef CANFD
|
||||
void gen_crc_lookup_table_16(uint16_t poly, uint16_t crc_lut[]);
|
||||
#endif
|
||||
bool msg_allowed(const CANPacket_t *to_send, const CanMsg msg_list[], int len);
|
||||
int get_addr_check_index(const CANPacket_t *to_push, RxCheck addr_list[], const int len);
|
||||
void update_counter(RxCheck addr_list[], int index, uint8_t counter);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#if defined(ENABLE_SPI) || defined(BOOTSTUB)
|
||||
void llspi_miso_dma(uint8_t *addr, int len) {
|
||||
// disable DMA
|
||||
DMA2_Stream3->CR &= ~DMA_SxCR_EN;
|
||||
|
@ -29,7 +30,6 @@ void llspi_mosi_dma(uint8_t *addr, int len) {
|
|||
DMA2_Stream2->CR |= DMA_SxCR_EN;
|
||||
register_set_bits(&(SPI1->CR2), SPI_CR2_RXDMAEN);
|
||||
}
|
||||
|
||||
// SPI MOSI DMA FINISHED
|
||||
static void DMA2_Stream2_IRQ_Handler(void) {
|
||||
// Clear interrupt flag
|
||||
|
@ -88,3 +88,4 @@ void llspi_init(void) {
|
|||
NVIC_EnableIRQ(DMA2_Stream2_IRQn);
|
||||
NVIC_EnableIRQ(DMA2_Stream3_IRQn);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
static bool spi_tx_dma_done = false;
|
||||
|
||||
#if defined(ENABLE_SPI) || defined(BOOTSTUB)
|
||||
// master -> panda DMA start
|
||||
void llspi_mosi_dma(uint8_t *addr, int len) {
|
||||
// disable DMA + SPI
|
||||
|
@ -50,6 +49,7 @@ void llspi_miso_dma(uint8_t *addr, int len) {
|
|||
register_set_bits(&(SPI4->CR1), SPI_CR1_SPE);
|
||||
}
|
||||
|
||||
static bool spi_tx_dma_done = false;
|
||||
// master -> panda DMA finished
|
||||
static void DMA2_Stream2_IRQ_Handler(void) {
|
||||
// Clear interrupt flag
|
||||
|
@ -106,3 +106,4 @@ void llspi_init(void) {
|
|||
NVIC_EnableIRQ(DMA2_Stream3_IRQn);
|
||||
NVIC_EnableIRQ(SPI4_IRQn);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue