Skip to content

Commit

Permalink
Merge remote-tracking branch 'comma/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rav4kumar committed Feb 17, 2024
2 parents b96eebb + 39671c3 commit c1b3b8c
Show file tree
Hide file tree
Showing 33 changed files with 212 additions and 152 deletions.
19 changes: 1 addition & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,6 @@ jobs:
scons -j$(nproc) ${{ matrix.flags }} && \
tests/safety/test.sh"
safety_coverage:
name: safety coverage
runs-on: ubuntu-20.04
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run safety coverage test
timeout-minutes: 5
run: |
${{ env.RUN }} "cd .. && \
scons -c && \
scons -j$(nproc) opendbc/ cereal/ && \
cd panda/tests/safety && \
./test_coverage.sh"
misra:
name: MISRA C:2012
runs-on: ubuntu-20.04
Expand All @@ -120,7 +103,7 @@ jobs:
timeout-minutes: 1
run: ${{ env.RUN }} "cd tests/misra && ./test_misra.sh"
- name: MISRA mutation tests
timeout-minutes: 3
timeout-minutes: 4
run: ${{ env.RUN }} "cd tests/misra && ./test_mutation.py"

python_linter:
Expand Down
3 changes: 2 additions & 1 deletion board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ const board board_black = {
.set_led = black_set_led,
.set_can_mode = black_set_can_mode,
.check_ignition = black_check_ignition,
.read_current = unused_read_current,
.read_voltage_mV = white_read_voltage_mV,
.read_current_mA = unused_read_current,
.set_fan_enabled = unused_set_fan_enabled,
.set_ir_power = unused_set_ir_power,
.set_siren = unused_set_siren,
Expand Down
6 changes: 4 additions & 2 deletions board/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ typedef void (*board_enable_can_transceivers)(bool enabled);
typedef void (*board_set_led)(uint8_t color, bool enabled);
typedef void (*board_set_can_mode)(uint8_t mode);
typedef bool (*board_check_ignition)(void);
typedef uint32_t (*board_read_current)(void);
typedef uint32_t (*board_read_voltage_mV)(void);
typedef uint32_t (*board_read_current_mA)(void);
typedef void (*board_set_ir_power)(uint8_t percentage);
typedef void (*board_set_fan_enabled)(bool enabled);
typedef void (*board_set_siren)(bool enabled);
Expand All @@ -36,7 +37,8 @@ struct board {
board_set_led set_led;
board_set_can_mode set_can_mode;
board_check_ignition check_ignition;
board_read_current read_current;
board_read_voltage_mV read_voltage_mV;
board_read_current_mA read_current_mA;
board_set_ir_power set_ir_power;
board_set_fan_enabled set_fan_enabled;
board_set_siren set_siren;
Expand Down
15 changes: 14 additions & 1 deletion board/boards/cuatro.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,21 @@ void cuatro_enable_can_transceivers(bool enabled) {
}
}

uint32_t cuatro_read_voltage_mV(void) {
return adc_get_mV(8) * 11U;
}

uint32_t cuatro_read_current_mA(void) {
return adc_get_mV(3) * 2U;
}

void cuatro_init(void) {
red_chiplet_init();

// Power readout
set_gpio_mode(GPIOC, 5, MODE_ANALOG);
set_gpio_mode(GPIOA, 6, MODE_ANALOG);

// CAN transceiver enables
set_gpio_pullup(GPIOB, 7, PULL_NONE);
set_gpio_mode(GPIOB, 7, MODE_OUTPUT);
Expand Down Expand Up @@ -108,7 +120,8 @@ const board board_cuatro = {
.set_led = cuatro_set_led,
.set_can_mode = red_chiplet_set_can_mode,
.check_ignition = red_check_ignition,
.read_current = unused_read_current,
.read_voltage_mV = cuatro_read_voltage_mV,
.read_current_mA = cuatro_read_current_mA,
.set_fan_enabled = tres_set_fan_enabled,
.set_ir_power = tres_set_ir_power,
.set_siren = unused_set_siren,
Expand Down
3 changes: 2 additions & 1 deletion board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ const board board_dos = {
.set_led = dos_set_led,
.set_can_mode = dos_set_can_mode,
.check_ignition = dos_check_ignition,
.read_current = unused_read_current,
.read_voltage_mV = white_read_voltage_mV,
.read_current_mA = unused_read_current,
.set_fan_enabled = dos_set_fan_enabled,
.set_ir_power = dos_set_ir_power,
.set_siren = dos_set_siren,
Expand Down
3 changes: 2 additions & 1 deletion board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const board board_grey = {
.set_led = white_set_led,
.set_can_mode = white_set_can_mode,
.check_ignition = white_check_ignition,
.read_current = white_read_current,
.read_voltage_mV = white_read_voltage_mV,
.read_current_mA = white_read_current_mA,
.set_fan_enabled = unused_set_fan_enabled,
.set_ir_power = unused_set_ir_power,
.set_siren = unused_set_siren,
Expand Down
3 changes: 2 additions & 1 deletion board/boards/pedal.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ const board board_pedal = {
.set_led = pedal_set_led,
.set_can_mode = pedal_set_can_mode,
.check_ignition = pedal_check_ignition,
.read_current = unused_read_current,
.read_voltage_mV = unused_read_voltage,
.read_current_mA = unused_read_current,
.set_fan_enabled = unused_set_fan_enabled,
.set_ir_power = unused_set_ir_power,
.set_siren = unused_set_siren,
Expand Down
7 changes: 6 additions & 1 deletion board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ bool red_check_ignition(void) {
return harness_check_ignition();
}

uint32_t red_read_voltage_mV(void){
return adc_get_mV(2) * 11U; // TODO: is this correct?
}

void red_init(void) {
common_init_gpio();

Expand Down Expand Up @@ -188,7 +192,8 @@ const board board_red = {
.set_led = red_set_led,
.set_can_mode = red_set_can_mode,
.check_ignition = red_check_ignition,
.read_current = unused_read_current,
.read_voltage_mV = red_read_voltage_mV,
.read_current_mA = unused_read_current,
.set_fan_enabled = unused_set_fan_enabled,
.set_ir_power = unused_set_ir_power,
.set_siren = unused_set_siren,
Expand Down
3 changes: 2 additions & 1 deletion board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ const board board_tres = {
.set_led = red_set_led,
.set_can_mode = red_chiplet_set_can_mode,
.check_ignition = red_check_ignition,
.read_current = unused_read_current,
.read_voltage_mV = red_read_voltage_mV,
.read_current_mA = unused_read_current,
.set_fan_enabled = tres_set_fan_enabled,
.set_ir_power = tres_set_ir_power,
.set_siren = fake_siren_set,
Expand Down
5 changes: 3 additions & 2 deletions board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void uno_init(void) {
}

// Switch to phone usb mode if harness connection is powered by less than 7V
if((adc_get_mV(ADCCHAN_VIN) * VIN_READOUT_DIVIDER) < 7000U){
if(white_read_voltage_mV() < 7000U){
uno_set_usb_switch(true);
} else {
uno_set_usb_switch(false);
Expand Down Expand Up @@ -215,7 +215,8 @@ const board board_uno = {
.set_led = uno_set_led,
.set_can_mode = uno_set_can_mode,
.check_ignition = uno_check_ignition,
.read_current = unused_read_current,
.read_voltage_mV = white_read_voltage_mV,
.read_current_mA = unused_read_current,
.set_fan_enabled = uno_set_fan_enabled,
.set_ir_power = uno_set_ir_power,
.set_siren = unused_set_siren,
Expand Down
4 changes: 4 additions & 0 deletions board/boards/unused_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ void unused_set_siren(bool enabled) {
UNUSED(enabled);
}

uint32_t unused_read_voltage(void) {
return 0U;
}

uint32_t unused_read_current(void) {
return 0U;
}
Expand Down
15 changes: 10 additions & 5 deletions board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ void white_set_can_mode(uint8_t mode){
}
}

uint32_t white_read_current(void){
return adc_get_raw(ADCCHAN_CURRENT);
uint32_t white_read_voltage_mV(void){
return adc_get_mV(12) * 11U;
}

uint32_t white_read_current_mA(void){
// This isn't in mA, but we're keeping it for backwards compatibility
return adc_get_raw(13);
}

bool white_check_ignition(void){
Expand Down Expand Up @@ -197,10 +202,9 @@ void white_grey_init(void) {
white_set_can_mode(CAN_MODE_NORMAL);

// Init usb power mode
uint32_t voltage = adc_get_mV(ADCCHAN_VIN) * VIN_READOUT_DIVIDER;
// Init in CDP mode only if panda is powered by 12V.
// Otherwise a PC would not be able to flash a standalone panda
if (voltage > 8000U) { // 8V threshold
if (white_read_voltage_mV() > 8000U) { // 8V threshold
white_set_usb_power_mode(USB_POWER_CDP);
} else {
white_set_usb_power_mode(USB_POWER_CLIENT);
Expand Down Expand Up @@ -239,7 +243,8 @@ const board board_white = {
.set_led = white_set_led,
.set_can_mode = white_set_can_mode,
.check_ignition = white_check_ignition,
.read_current = white_read_current,
.read_voltage_mV = white_read_voltage_mV,
.read_current_mA = white_read_current_mA,
.set_fan_enabled = unused_set_fan_enabled,
.set_ir_power = unused_set_ir_power,
.set_siren = unused_set_siren,
Expand Down
2 changes: 2 additions & 0 deletions board/can_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const uint8_t PANDA_BUS_CNT = 4U;
#define CANPACKET_DATA_SIZE_MAX 8U
#endif

#ifndef STM32F2
typedef struct {
unsigned char reserved : 1;
unsigned char bus : 3;
Expand All @@ -26,6 +27,7 @@ typedef struct {
unsigned char checksum;
unsigned char data[CANPACKET_DATA_SIZE_MAX];
} __attribute__((packed, aligned(4))) CANPacket_t;
#endif

const unsigned char dlc_to_len[] = {0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U};

Expand Down
2 changes: 0 additions & 2 deletions board/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#define MAX_CAN_MSGS_PER_USB_BULK_TRANSFER 51U
#define MAX_CAN_MSGS_PER_SPI_BULK_TRANSFER 170U

#define VIN_READOUT_DIVIDER 11U

// USB definitions
#define USB_VID 0xBBAAU

Expand Down
4 changes: 2 additions & 2 deletions board/drivers/can_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ void can_send(CANPacket_t *to_push, uint8_t bus_number, bool skip_tx_hook) {
}
}

bool is_speed_valid(uint32_t speed, const uint32_t *speeds, uint8_t len) {
bool is_speed_valid(uint32_t speed, const uint32_t *all_speeds, uint8_t len) {
bool ret = false;
for (uint8_t i = 0U; i < len; i++) {
if (speeds[i] == speed) {
if (all_speeds[i] == speed) {
ret = true;
}
}
Expand Down
1 change: 1 addition & 0 deletions board/drivers/harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ uint8_t harness_detect_orientation(void) {
ret = HARNESS_STATUS_FLIPPED;
} else {
// orientation normal (PANDA_SBU2->HARNESS_SBU1(relay), PANDA_SBU1->HARNESS_SBU2(ign))
// (SBU1->SBU2 is the normal orientation connection per USB-C cable spec)
ret = HARNESS_STATUS_NORMAL;
}
} else {
Expand Down
34 changes: 17 additions & 17 deletions board/drivers/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void refresh_can_tx_slots_available(void);
#define STS_SETUP_COMP 4
#define STS_SETUP_UPDT 6

uint8_t resp[USBPACKET_MAX_SIZE];
uint8_t response[USBPACKET_MAX_SIZE];

// for the repeating interfaces
#define DSCR_INTERFACE_LEN 9
Expand Down Expand Up @@ -557,19 +557,19 @@ void usb_setup(void) {
break;
case STRING_OFFSET_ISERIAL:
#ifdef UID_BASE
resp[0] = 0x02 + (12 * 4);
resp[1] = 0x03;
response[0] = 0x02 + (12 * 4);
response[1] = 0x03;

// 96 bits = 12 bytes
for (int i = 0; i < 12; i++){
uint8_t cc = ((uint8_t *)UID_BASE)[i];
resp[2 + (i * 4)] = to_hex_char((cc >> 4) & 0xFU);
resp[2 + (i * 4) + 1] = '\0';
resp[2 + (i * 4) + 2] = to_hex_char((cc >> 0) & 0xFU);
resp[2 + (i * 4) + 3] = '\0';
response[2 + (i * 4)] = to_hex_char((cc >> 4) & 0xFU);
response[2 + (i * 4) + 1] = '\0';
response[2 + (i * 4) + 2] = to_hex_char((cc >> 0) & 0xFU);
response[2 + (i * 4) + 3] = '\0';
}

USB_WritePacket(resp, MIN(resp[0], setup.b.wLength.w), 0);
USB_WritePacket(response, MIN(response[0], setup.b.wLength.w), 0);
#else
USB_WritePacket((const uint8_t *)string_serial_desc, MIN(sizeof(string_serial_desc), setup.b.wLength.w), 0);
#endif
Expand Down Expand Up @@ -599,10 +599,10 @@ void usb_setup(void) {
}
break;
case USB_REQ_GET_STATUS:
// empty resp?
resp[0] = 0;
resp[1] = 0;
USB_WritePacket((void*)&resp, 2, 0);
// empty response?
response[0] = 0;
response[1] = 0;
USB_WritePacket((void*)&response, 2, 0);
USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
break;
case USB_REQ_SET_INTERFACE:
Expand Down Expand Up @@ -648,10 +648,10 @@ void usb_setup(void) {
control_req.param2 = setup.b.wIndex.w;
control_req.length = setup.b.wLength.w;

resp_len = comms_control_handler(&control_req, resp);
resp_len = comms_control_handler(&control_req, response);
// response pending if -1 was returned
if (resp_len != -1) {
USB_WritePacket(resp, MIN(resp_len, setup.b.wLength.w), 0);
USB_WritePacket(response, MIN(resp_len, setup.b.wLength.w), 0);
USBx_OUTEP(0)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
}
}
Expand Down Expand Up @@ -877,7 +877,7 @@ void usb_irqhandler(void) {
print(" IN PACKET QUEUE\n");
#endif
// TODO: always assuming max len, can we get the length?
USB_WritePacket((void *)resp, comms_can_read(resp, 0x40), 1);
USB_WritePacket((void *)response, comms_can_read(response, 0x40), 1);
}
break;

Expand All @@ -888,9 +888,9 @@ void usb_irqhandler(void) {
print(" IN PACKET QUEUE\n");
#endif
// TODO: always assuming max len, can we get the length?
int len = comms_can_read(resp, 0x40);
int len = comms_can_read(response, 0x40);
if (len > 0) {
USB_WritePacket((void *)resp, len, 1);
USB_WritePacket((void *)response, len, 1);
}
}
break;
Expand Down
6 changes: 3 additions & 3 deletions board/health.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ struct __attribute__((packed)) health_t {
uint8_t power_save_enabled_pkt;
uint8_t heartbeat_lost_pkt;
uint16_t alternative_experience_pkt;
float interrupt_load;
float interrupt_load_pkt;
uint8_t fan_power;
uint8_t safety_rx_checks_invalid;
uint16_t spi_checksum_error_count;
uint8_t safety_rx_checks_invalid_pkt;
uint16_t spi_checksum_error_count_pkt;
uint8_t fan_stall_count;
uint16_t sbu1_voltage_mV;
uint16_t sbu2_voltage_mV;
Expand Down
10 changes: 5 additions & 5 deletions board/main_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ int get_health_pkt(void *dat) {
struct health_t * health = (struct health_t*)dat;

health->uptime_pkt = uptime_cnt;
health->voltage_pkt = adc_get_mV(ADCCHAN_VIN) * VIN_READOUT_DIVIDER;
health->current_pkt = current_board->read_current();
health->voltage_pkt = current_board->read_voltage_mV();
health->current_pkt = current_board->read_current_mA();

// Use the GPIO pin to determine ignition or use a CAN based logic
health->ignition_line_pkt = (uint8_t)(current_board->check_ignition());
Expand All @@ -28,14 +28,14 @@ int get_health_pkt(void *dat) {
health->alternative_experience_pkt = alternative_experience;
health->power_save_enabled_pkt = power_save_status == POWER_SAVE_STATUS_ENABLED;
health->heartbeat_lost_pkt = heartbeat_lost;
health->safety_rx_checks_invalid = safety_rx_checks_invalid;
health->safety_rx_checks_invalid_pkt = safety_rx_checks_invalid;

health->spi_checksum_error_count = spi_checksum_error_count;
health->spi_checksum_error_count_pkt = spi_checksum_error_count;

health->fault_status_pkt = fault_status;
health->faults_pkt = faults;

health->interrupt_load = interrupt_load;
health->interrupt_load_pkt = interrupt_load;

health->fan_power = fan_state.power;
health->fan_stall_count = fan_state.total_stall_count;
Expand Down
Loading

0 comments on commit c1b3b8c

Please sign in to comment.