Skip to content

Commit

Permalink
cleanup + prep for more tests! (commaai#1172)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
adeebshihadeh committed Nov 30, 2022
1 parent e8bd1df commit 2750463
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 104 deletions.
42 changes: 20 additions & 22 deletions board/config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef PANDA_CONFIG_H
#define PANDA_CONFIG_H
#pragma once

#include <stdbool.h>

//#define DEBUG
//#define DEBUG_UART
Expand All @@ -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))))]))

#define MIN(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
(_a < _b) ? _a : _b; })
// USB definitions
#define USB_VID 0xBBAAU

#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); })
#ifdef BOOTSTUB
#define USB_PID 0xDDEEU
#else
#define USB_PID 0xDDCCU
#endif

#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
30 changes: 30 additions & 0 deletions board/fake_stm.h
Original file line number Diff line number Diff line change
@@ -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;
}
15 changes: 0 additions & 15 deletions board/panda.h

This file was deleted.

25 changes: 25 additions & 0 deletions board/utils.h
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
72 changes: 5 additions & 67 deletions tests/safety/test.c
Original file line number Diff line number Diff line change
@@ -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"

#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; })
#include "main_declarations.h"
#include "boards/board_declarations.h"

#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);
}
Expand Down
File renamed without changes.

0 comments on commit 2750463

Please sign in to comment.