mirror of https://github.com/commaai/panda.git
cleanup + prep for more tests! (#1172)
* panda for pc! * little more * fake panda * move some more stuff * increase timeout * move that * print helpers * cleanup * just move it for now * revert jenkins changes
This commit is contained in:
parent
e8bd1df511
commit
27504639f0
|
@ -1,5 +1,6 @@
|
|||
#ifndef PANDA_CONFIG_H
|
||||
#define PANDA_CONFIG_H
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
//#define DEBUG
|
||||
//#define DEBUG_UART
|
||||
|
@ -8,31 +9,28 @@
|
|||
//#define DEBUG_FAULTS
|
||||
//#define DEBUG_COMMS
|
||||
|
||||
#define CAN_INIT_TIMEOUT_MS 500U
|
||||
#define DEEPSLEEP_WAKEUP_DELAY 3U
|
||||
#define USBPACKET_MAX_SIZE 0x40U
|
||||
#define MAX_CAN_MSGS_PER_BULK_TRANSFER 51U
|
||||
#define MAX_EP1_CHUNK_PER_BULK_TRANSFER 16256U // max data stream chunk in bytes, shouldn't be higher than 16320 or counter will overflow
|
||||
|
||||
#define NULL ((void*)0)
|
||||
#define COMPILE_TIME_ASSERT(pred) ((void)sizeof(char[1 - (2 * ((int)(!(pred))))]))
|
||||
// USB definitions
|
||||
#define USB_VID 0xBBAAU
|
||||
|
||||
#define MIN(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
(_a < _b) ? _a : _b; })
|
||||
#ifdef BOOTSTUB
|
||||
#define USB_PID 0xDDEEU
|
||||
#else
|
||||
#define USB_PID 0xDDCCU
|
||||
#endif
|
||||
|
||||
#define MAX(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
(_a > _b) ? _a : _b; })
|
||||
|
||||
#define ABS(a) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
(_a > 0) ? _a : (-_a); })
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "panda.h"
|
||||
// platform includes
|
||||
#ifdef STM32H7
|
||||
#include "stm32h7/stm32h7_config.h"
|
||||
#else
|
||||
#elif defined(STM32F2) || defined(STM32F4)
|
||||
#include "stm32fx/stm32fx_config.h"
|
||||
#endif
|
||||
|
||||
#else
|
||||
// TODO: uncomment this, cppcheck complains
|
||||
// building for tests
|
||||
//#include "fake_stm.h"
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// minimal code to fake a panda for tests
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define CANFD
|
||||
#define ALLOW_DEBUG
|
||||
#define PANDA
|
||||
|
||||
void print(const char *a) {
|
||||
printf(a);
|
||||
}
|
||||
|
||||
void puth(unsigned int i) {
|
||||
printf("%u", i);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint32_t CNT;
|
||||
} TIM_TypeDef;
|
||||
|
||||
TIM_TypeDef timer;
|
||||
TIM_TypeDef *MICROSECOND_TIMER = &timer;
|
||||
uint32_t microsecond_timer_get(void);
|
||||
|
||||
uint32_t microsecond_timer_get(void) {
|
||||
return MICROSECOND_TIMER->CNT;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// USB definitions
|
||||
#define USB_VID 0xBBAAU
|
||||
|
||||
#ifdef BOOTSTUB
|
||||
#define USB_PID 0xDDEEU
|
||||
#else
|
||||
#define USB_PID 0xDDCCU
|
||||
#endif
|
||||
|
||||
#define USBPACKET_MAX_SIZE 0x40U
|
||||
|
||||
#define MAX_CAN_MSGS_PER_BULK_TRANSFER 51U
|
||||
#define MAX_EP1_CHUNK_PER_BULK_TRANSFER 16256U // max data stream chunk in bytes, shouldn't be higher than 16320 or counter will overflow
|
||||
|
||||
#define CAN_INIT_TIMEOUT_MS 500U
|
|
@ -1,3 +1,28 @@
|
|||
#define MIN(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
(_a < _b) ? _a : _b; })
|
||||
|
||||
#define MAX(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
(_a > _b) ? _a : _b; })
|
||||
|
||||
#define ABS(a) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
(_a > 0) ? _a : (-_a); })
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
// STM32 HAL defines this
|
||||
#ifndef UNUSED
|
||||
#define UNUSED(x) ((void)(x))
|
||||
#endif
|
||||
|
||||
#define COMPILE_TIME_ASSERT(pred) ((void)sizeof(char[1 - (2 * ((int)(!(pred))))]))
|
||||
|
||||
// compute the time elapsed (in microseconds) from 2 counter samples
|
||||
// case where ts < ts_last is ok: overflow is properly re-casted into uint32_t
|
||||
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last) {
|
||||
|
|
|
@ -1,74 +1,12 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "panda.h"
|
||||
#include "config.h"
|
||||
#include "fake_stm.h"
|
||||
#include "can_definitions.h"
|
||||
#include "utils.h"
|
||||
#include "main_declarations.h"
|
||||
#include "boards/board_declarations.h"
|
||||
|
||||
#define CANFD
|
||||
|
||||
typedef struct {
|
||||
uint32_t CNT;
|
||||
} TIM_TypeDef;
|
||||
|
||||
struct sample_t torque_meas;
|
||||
struct sample_t torque_driver;
|
||||
|
||||
TIM_TypeDef timer;
|
||||
TIM_TypeDef *MICROSECOND_TIMER = &timer;
|
||||
uint32_t microsecond_timer_get(void);
|
||||
|
||||
// from board_declarations.h
|
||||
#define HW_TYPE_UNKNOWN 0U
|
||||
#define HW_TYPE_WHITE_PANDA 1U
|
||||
#define HW_TYPE_GREY_PANDA 2U
|
||||
#define HW_TYPE_BLACK_PANDA 3U
|
||||
#define HW_TYPE_PEDAL 4U
|
||||
#define HW_TYPE_UNO 5U
|
||||
#define HW_TYPE_DOS 6U
|
||||
|
||||
#define ALLOW_DEBUG
|
||||
|
||||
// from main_declarations.h
|
||||
uint8_t hw_type = HW_TYPE_UNKNOWN;
|
||||
|
||||
// from config.h
|
||||
#define MIN(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; })
|
||||
|
||||
#define MAX(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
|
||||
#define ABS(a) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
(_a > 0) ? _a : (-_a); })
|
||||
|
||||
// from faults.h
|
||||
#define FAULT_RELAY_MALFUNCTION (1U << 0)
|
||||
void fault_occurred(uint32_t fault) {
|
||||
}
|
||||
void fault_recovered(uint32_t fault) {
|
||||
}
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
#ifndef PANDA
|
||||
#define PANDA
|
||||
#endif
|
||||
#define NULL ((void*)0)
|
||||
#define static
|
||||
#include "faults.h"
|
||||
#include "safety.h"
|
||||
|
||||
uint32_t microsecond_timer_get(void) {
|
||||
return MICROSECOND_TIMER->CNT;
|
||||
}
|
||||
|
||||
void safety_tick_current_rx_checks() {
|
||||
safety_tick(current_rx_checks);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue