Add uptime counter to the health packet (#391)

* Added uptime counter to the health packet

* fix tests by setting power save on on EON build
master
robbederks 2019-11-21 16:47:49 -08:00 committed by rbiasini
parent 16624811c4
commit f458d67a7c
10 changed files with 48 additions and 42 deletions

View File

@ -1 +1 @@
v1.6.5
v1.6.6

View File

@ -6,7 +6,7 @@ typedef void (*board_set_led)(uint8_t color, bool enabled);
typedef void (*board_set_usb_power_mode)(uint8_t mode);
typedef void (*board_set_esp_gps_mode)(uint8_t mode);
typedef void (*board_set_can_mode)(uint8_t mode);
typedef void (*board_usb_power_mode_tick)(uint64_t tcnt);
typedef void (*board_usb_power_mode_tick)(uint32_t uptime);
typedef bool (*board_check_ignition)(void);
typedef uint32_t (*board_read_current)(void);
typedef void (*board_set_ir_power)(uint8_t percentage);

View File

@ -123,8 +123,8 @@ void black_set_can_mode(uint8_t mode){
}
}
void black_usb_power_mode_tick(uint64_t tcnt){
UNUSED(tcnt);
void black_usb_power_mode_tick(uint32_t uptime){
UNUSED(uptime);
// Not applicable
}

View File

@ -50,8 +50,8 @@ void pedal_set_can_mode(uint8_t mode){
}
}
void pedal_usb_power_mode_tick(uint64_t tcnt){
UNUSED(tcnt);
void pedal_usb_power_mode_tick(uint32_t uptime){
UNUSED(uptime);
// Not applicable
}

View File

@ -110,8 +110,8 @@ void uno_set_bootkick(bool enabled){
set_gpio_output(GPIOB, 14, !enabled);
}
void uno_usb_power_mode_tick(uint64_t tcnt){
if(tcnt == 3U){
void uno_usb_power_mode_tick(uint32_t uptime){
if(uptime == 3U){
uno_set_bootkick(false);
}
}

View File

@ -158,8 +158,8 @@ uint32_t white_read_current(void){
return adc_get(ADCCHAN_CURRENT);
}
uint64_t marker = 0;
void white_usb_power_mode_tick(uint64_t tcnt){
uint32_t marker = 0;
void white_usb_power_mode_tick(uint32_t uptime){
// on EON or BOOTSTUB, no state machine
#if !defined(BOOTSTUB) && !defined(EON)
@ -173,47 +173,47 @@ void white_usb_power_mode_tick(uint64_t tcnt){
switch (usb_power_mode) {
case USB_POWER_CLIENT:
if ((tcnt - marker) >= CLICKS) {
if ((uptime - marker) >= CLICKS) {
if (!is_enumerated) {
puts("USBP: didn't enumerate, switching to CDP mode\n");
// switch to CDP
white_set_usb_power_mode(USB_POWER_CDP);
marker = tcnt;
marker = uptime;
}
}
// keep resetting the timer if it's enumerated
if (is_enumerated) {
marker = tcnt;
marker = uptime;
}
break;
case USB_POWER_CDP:
// been CLICKS clicks since we switched to CDP
if ((tcnt-marker) >= CLICKS) {
if ((uptime - marker) >= CLICKS) {
// measure current draw, if positive and no enumeration, switch to DCP
if (!is_enumerated && (current < CURRENT_THRESHOLD)) {
puts("USBP: no enumeration with current draw, switching to DCP mode\n");
white_set_usb_power_mode(USB_POWER_DCP);
marker = tcnt;
marker = uptime;
}
}
// keep resetting the timer if there's no current draw in CDP
if (current >= CURRENT_THRESHOLD) {
marker = tcnt;
marker = uptime;
}
break;
case USB_POWER_DCP:
// been at least CLICKS clicks since we switched to DCP
if ((tcnt-marker) >= CLICKS) {
if ((uptime - marker) >= CLICKS) {
// if no current draw, switch back to CDP
if (current >= CURRENT_THRESHOLD) {
puts("USBP: no current draw, switching back to CDP mode\n");
white_set_usb_power_mode(USB_POWER_CDP);
marker = tcnt;
marker = uptime;
}
}
// keep resetting the timer if there's current draw in DCP
if (current < CURRENT_THRESHOLD) {
marker = tcnt;
marker = uptime;
}
break;
default:
@ -221,7 +221,7 @@ void white_usb_power_mode_tick(uint64_t tcnt){
break;
}
#else
UNUSED(tcnt);
UNUSED(uptime);
#endif
}

View File

@ -128,6 +128,7 @@ void set_safety_mode(uint16_t mode, int16_t param) {
int get_health_pkt(void *dat) {
struct __attribute__((packed)) {
uint32_t uptime_pkt;
uint32_t voltage_pkt;
uint32_t current_pkt;
uint32_t can_send_errs_pkt;
@ -144,6 +145,7 @@ int get_health_pkt(void *dat) {
uint8_t power_save_enabled_pkt;
} *health = dat;
health->uptime_pkt = uptime_cnt;
health->voltage_pkt = adc_get_voltage();
health->current_pkt = current_board->read_current();
@ -630,8 +632,6 @@ void __attribute__ ((noinline)) enable_fpu(void) {
SCB->CPACR |= ((3UL << (10U * 2U)) | (3UL << (11U * 2U)));
}
uint64_t tcnt = 0;
// go into SILENT when the EON does not send a heartbeat for this amount of seconds.
#define EON_HEARTBEAT_IGNITION_CNT_ON 5U
#define EON_HEARTBEAT_IGNITION_CNT_OFF 2U
@ -642,12 +642,12 @@ void TIM1_BRK_TIM9_IRQHandler(void) {
if (TIM9->SR != 0) {
can_live = pending_can_live;
current_board->usb_power_mode_tick(tcnt);
current_board->usb_power_mode_tick(uptime_cnt);
//puth(usart1_dma); puts(" "); puth(DMA2_Stream5->M0AR); puts(" "); puth(DMA2_Stream5->NDTR); puts("\n");
// reset this every 16th pass
if ((tcnt & 0xFU) == 0U) {
if ((uptime_cnt & 0xFU) == 0U) {
pending_can_live = 0;
}
#ifdef DEBUG
@ -666,7 +666,7 @@ void TIM1_BRK_TIM9_IRQHandler(void) {
// turn off the blue LED, turned on by CAN
// unless we are in power saving mode
current_board->set_led(LED_BLUE, (tcnt & 1U) && (power_save_status == POWER_SAVE_STATUS_ENABLED));
current_board->set_led(LED_BLUE, (uptime_cnt & 1U) && (power_save_status == POWER_SAVE_STATUS_ENABLED));
// increase heartbeat counter and cap it at the uint32 limit
if (heartbeat_counter < __UINT32_MAX__) {
@ -695,7 +695,7 @@ void TIM1_BRK_TIM9_IRQHandler(void) {
#endif
// on to the next one
tcnt += 1U;
uptime_cnt += 1U;
}
TIM9->SR = 0;
}

View File

@ -11,4 +11,5 @@ void can_set_obd(uint8_t harness_orientation, bool obd);
uint8_t hw_type = 0;
const board *current_board;
bool is_enumerated = 0;
uint32_t heartbeat_counter = 0;
uint32_t heartbeat_counter = 0;
uint32_t uptime_cnt = 0;

View File

@ -347,22 +347,23 @@ class Panda(object):
def health(self):
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd2, 0, 0, 28)
a = struct.unpack("IIIIIBBBBBBBBB", dat)
a = struct.unpack("IIIIIIBBBBBBBBB", dat)
return {
"voltage": a[0],
"current": a[1],
"can_send_errs": a[2],
"can_fwd_errs": a[3],
"gmlan_send_errs": a[4],
"ignition_line": a[5],
"ignition_can": a[6],
"controls_allowed": a[7],
"gas_interceptor_detected": a[8],
"car_harness_status": a[9],
"usb_power_mode": a[10],
"safety_mode": a[11],
"fault_status": a[12],
"power_save_enabled": a[13]
"uptime": a[0],
"voltage": a[1],
"current": a[2],
"can_send_errs": a[3],
"can_fwd_errs": a[4],
"gmlan_send_errs": a[5],
"ignition_line": a[6],
"ignition_can": a[7],
"controls_allowed": a[8],
"gas_interceptor_detected": a[9],
"car_harness_status": a[10],
"usb_power_mode": a[11],
"safety_mode": a[12],
"fault_status": a[13],
"power_save_enabled": a[14]
}
# ******************* control *******************
@ -409,6 +410,9 @@ class Panda(object):
def set_usb_power(self, on):
self._handle.controlWrite(Panda.REQUEST_OUT, 0xe6, int(on), 0, b'')
def set_power_save(self, power_save_enabled=0):
self._handle.controlWrite(Panda.REQUEST_OUT, 0xe7, int(power_save_enabled), 0, b'')
def set_esp_power(self, on):
self._handle.controlWrite(Panda.REQUEST_OUT, 0xd9, int(on), 0, b'')

View File

@ -232,6 +232,7 @@ def panda_connect_and_init(fn):
panda.set_can_speed_kbps(bus, speed)
clear_can_buffers(panda)
_thread.start_new_thread(heartbeat_thread, (panda,))
panda.set_power_save(False)
# Run test function
ret = fn(*pandas, **kwargs)