panda/board/main.c

906 lines
25 KiB
C
Raw Normal View History

//#define EON
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
//#define PANDA
2019-05-21 13:48:38 -06:00
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// ********************* Includes *********************
#include "config.h"
2017-04-06 19:11:36 -06:00
#include "obj/gitversion.h"
#include "main_declarations.h"
#include "critical.h"
Revert commits that broke USB for openpilot. Revert "fix openpilot board flashing" This reverts commit 8ff93ad5da39f8dc4bf6fe632f26418b696fd230. Revert "Fixed output_enabled led not turning off when mode changed to no output." This reverts commit 27a8af11075d92d03c389713694a879905877cf0. Revert "Fixed loopback test for new GMLAN 'can4' behavior." This reverts commit 59592f599af01a667b4fd966e613b8f504d62dc2. Revert "GMLAN is now always mapped through CAN4 (index 3)" This reverts commit 329c09102435bfd9b1fbb60694139a5ff7bf4148. Revert "Removed compile time config for CAN loopback, implemented as usb message." This reverts commit e1a4c3298557fccf854ed5cbda448f8c0015b7ea. Revert "Change all output safety mode identifier to prevent user mistakes." This reverts commit 6b363e2e92fcd5e7f25b5458fe9008ff8f9fd664. Revert "untabify" This reverts commit 191f67b083e182323ba956c3ab75df10bec2f863. Revert "Refactor of safety to support more modular additions of safety policies." This reverts commit e5b524eddc82e53587cc47dcf15b22fd35890a92. Revert "Split up some more header files into compilation units." This reverts commit e2a78912f5b649822974fc0e974ec50d9d9c7d10. Revert "Enabled emulated control writes over USB." This reverts commit 133cfe970379d6881de26289616d1d9085bb5986. Revert "Moved CAN and USART code out of main.c and into more appropriate files." This reverts commit daad2dc0620d629e7db0dd68dee5595ed2b57160. Revert "Large Panda CAN cleanup. Restrict GMLAN to valid baud rates." This reverts commit a0616a2bc2ac2bfd99223aaa84912e6f649c9d54. Revert "Panda library now correctly sends USB direction bit." This reverts commit 1712c901d4b46b2726b3165a7cb2e91c281c662b. Revert "Board makefile now automatically calculates header file dependencies." This reverts commit 4a8d4e597b397ca6d68dd5dd2a376c8354dc3422. Revert "Loopback test works over wifi. (Disable trying to send over wifi)" This reverts commit dae636968af482e170aade1d785a1e197e9f3c04. Revert "Fix legacy board build" This reverts commit 62bf4e575686c84c672eb0d341ad41f174141c2d. Revert "Style cop" This reverts commit c439f43726feb30cf2ec486ffcad6ac94ab5e128. Revert "Untabify" This reverts commit 41e5eec6211c23836535af49380f74350a0ceb12. Revert "Fixed disabling gmlan." This reverts commit 5e1e45a4afade384b628e44587dd8e37d3dcd8cd. Revert "Removed dead code, standardized canid in more commands, better erroring behavior." This reverts commit b59aeb6d87ddd85406ec42e4ed8a74a232d506a4. Revert "loopback test works with new CAN bus ids." This reverts commit 75970861cf2b025173afb906e4e243861bed506a. Revert "Large reorganization of code and early integration of can bitrate setting." This reverts commit a1ed7b62ee66ec8f56bba488c38c67b69eead8cf.
2017-07-12 12:25:10 -06:00
#include "libc.h"
2017-07-30 09:26:48 -06:00
#include "provision.h"
#include "faults.h"
2017-07-21 00:45:48 -06:00
#include "drivers/registers.h"
#include "drivers/interrupts.h"
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
#include "drivers/llcan.h"
2017-07-29 18:53:39 -06:00
#include "drivers/llgpio.h"
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
#include "drivers/adc.h"
#include "drivers/pwm.h"
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
#include "board.h"
2017-07-29 18:53:39 -06:00
2017-07-21 00:45:48 -06:00
#include "drivers/uart.h"
#include "drivers/usb.h"
#include "drivers/gmlan_alt.h"
#include "drivers/kline_init.h"
2017-07-21 12:48:03 -06:00
#include "drivers/timer.h"
#include "drivers/clock.h"
2017-07-21 12:48:03 -06:00
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
#include "gpio.h"
2019-06-26 13:01:57 -06:00
#ifndef EON
#include "drivers/spi.h"
#endif
#include "power_saving.h"
#include "safety.h"
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
#include "drivers/can.h"
2017-07-29 18:53:39 -06:00
extern int _app_start[0xc000]; // Only first 3 sectors of size 0x4000 are used
2021-05-03 06:59:36 -06:00
// When changing this struct, boardd and python/__init__.py needs to be kept up to date!
struct __attribute__((packed)) health_t {
uint32_t uptime_pkt;
uint32_t voltage_pkt;
uint32_t current_pkt;
2019-12-19 19:16:31 -07:00
uint32_t can_rx_errs_pkt;
uint32_t can_send_errs_pkt;
uint32_t can_fwd_errs_pkt;
uint32_t gmlan_send_errs_pkt;
uint32_t faults_pkt;
uint8_t ignition_line_pkt;
uint8_t ignition_can_pkt;
uint8_t controls_allowed_pkt;
uint8_t gas_interceptor_detected_pkt;
uint8_t car_harness_status_pkt;
uint8_t usb_power_mode_pkt;
uint8_t safety_mode_pkt;
int16_t safety_param_pkt;
uint8_t fault_status_pkt;
uint8_t power_save_enabled_pkt;
};
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// ********************* Serial debugging *********************
2017-07-20 14:41:21 -06:00
bool check_started(void) {
return current_board->check_ignition() || ignition_can;
}
2017-07-20 14:41:21 -06:00
void debug_ring_callback(uart_ring *ring) {
char rcv;
while (getc(ring, &rcv)) {
(void)putc(ring, rcv); // misra-c2012-17.7: cast to void is ok: debug function
2017-07-20 14:41:21 -06:00
// only allow bootloader entry on debug builds
#ifdef ALLOW_DEBUG
// jump to DFU flash
if (rcv == 'z') {
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
NVIC_SystemReset();
}
#endif
2017-07-20 14:41:21 -06:00
// normal reset
if (rcv == 'x') {
NVIC_SystemReset();
}
// enable CDP mode
if (rcv == 'C') {
puts("switching USB to CDP mode\n");
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
current_board->set_usb_power_mode(USB_POWER_CDP);
2017-07-20 14:41:21 -06:00
}
if (rcv == 'c') {
puts("switching USB to client mode\n");
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
current_board->set_usb_power_mode(USB_POWER_CLIENT);
2017-07-20 14:41:21 -06:00
}
if (rcv == 'D') {
puts("switching USB to DCP mode\n");
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
current_board->set_usb_power_mode(USB_POWER_DCP);
2017-07-20 14:41:21 -06:00
}
}
}
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// ****************************** safety mode ******************************
// this is the only way to leave silent mode
void set_safety_mode(uint16_t mode, int16_t param) {
uint16_t mode_copy = mode;
int err = set_safety_hooks(mode_copy, param);
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
if (err == -1) {
puts("Error: safety set mode failed. Falling back to SILENT\n");
mode_copy = SAFETY_SILENT;
err = set_safety_hooks(mode_copy, 0);
if (err == -1) {
puts("Error: Failed setting SILENT mode. Hanging\n");
while (true) {
// TERMINAL ERROR: we can't continue if SILENT safety mode isn't succesfully set
}
}
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
}
switch (mode_copy) {
case SAFETY_SILENT:
set_intercept_relay(false);
if (board_has_obd()) {
current_board->set_can_mode(CAN_MODE_NORMAL);
}
can_silent = ALL_CAN_SILENT;
break;
case SAFETY_NOOUTPUT:
set_intercept_relay(false);
if (board_has_obd()) {
current_board->set_can_mode(CAN_MODE_NORMAL);
}
can_silent = ALL_CAN_LIVE;
break;
case SAFETY_ELM327:
set_intercept_relay(false);
heartbeat_counter = 0U;
if (board_has_obd()) {
current_board->set_can_mode(CAN_MODE_OBD_CAN2);
}
can_silent = ALL_CAN_LIVE;
break;
default:
set_intercept_relay(true);
heartbeat_counter = 0U;
if (board_has_obd()) {
current_board->set_can_mode(CAN_MODE_NORMAL);
}
can_silent = ALL_CAN_LIVE;
break;
2019-11-20 15:04:07 -07:00
}
can_init_all();
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
}
// ***************************** USB port *****************************
2017-04-06 19:11:36 -06:00
int get_health_pkt(void *dat) {
COMPILE_TIME_ASSERT(sizeof(struct health_t) <= MAX_RESP_LEN);
struct health_t * health = (struct health_t*)dat;
2017-07-21 00:36:06 -06:00
health->uptime_pkt = uptime_cnt;
health->voltage_pkt = adc_get_voltage();
health->current_pkt = current_board->read_current();
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
//Use the GPIO pin to determine ignition or use a CAN based logic
health->ignition_line_pkt = (uint8_t)(current_board->check_ignition());
health->ignition_can_pkt = (uint8_t)(ignition_can);
2017-04-06 19:11:36 -06:00
health->controls_allowed_pkt = controls_allowed;
health->gas_interceptor_detected_pkt = gas_interceptor_detected;
2019-12-19 19:16:31 -07:00
health->can_rx_errs_pkt = can_rx_errs;
health->can_send_errs_pkt = can_send_errs;
health->can_fwd_errs_pkt = can_fwd_errs;
health->gmlan_send_errs_pkt = gmlan_send_errs;
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
health->car_harness_status_pkt = car_harness_status;
health->usb_power_mode_pkt = usb_power_mode;
2019-10-24 16:33:27 -06:00
health->safety_mode_pkt = (uint8_t)(current_safety_mode);
health->safety_param_pkt = current_safety_param;
health->power_save_enabled_pkt = (uint8_t)(power_save_status == POWER_SAVE_STATUS_ENABLED);
health->fault_status_pkt = fault_status;
health->faults_pkt = faults;
2019-11-26 18:07:51 -07:00
2017-04-06 19:11:36 -06:00
return sizeof(*health);
}
int get_rtc_pkt(void *dat) {
timestamp_t t = rtc_get_time();
(void)memcpy(dat, &t, sizeof(t));
return sizeof(t);
}
int usb_cb_ep1_in(void *usbdata, int len, bool hardwired) {
UNUSED(hardwired);
2017-07-18 11:19:42 -06:00
CAN_FIFOMailBox_TypeDef *reply = (CAN_FIFOMailBox_TypeDef *)usbdata;
2017-04-06 19:11:36 -06:00
int ilen = 0;
2019-06-28 14:46:57 -06:00
while (ilen < MIN(len/0x10, 4) && can_pop(&can_rx_q, &reply[ilen])) {
ilen++;
}
return ilen*0x10;
2017-04-06 19:11:36 -06:00
}
2017-07-21 00:36:06 -06:00
// send on serial, first byte to select the ring
void usb_cb_ep2_out(void *usbdata, int len, bool hardwired) {
UNUSED(hardwired);
uint8_t *usbdata8 = (uint8_t *)usbdata;
uart_ring *ur = get_ring_by_number(usbdata8[0]);
2019-06-26 19:24:21 -06:00
if ((len != 0) && (ur != NULL)) {
if ((usbdata8[0] < 2U) || safety_tx_lin_hook(usbdata8[0] - 2U, &usbdata8[1], len - 1)) {
2019-06-28 14:46:57 -06:00
for (int i = 1; i < len; i++) {
while (!putc(ur, usbdata8[i])) {
2019-06-28 14:46:57 -06:00
// wait
}
}
2019-06-26 16:52:34 -06:00
}
2017-05-01 21:22:19 -06:00
}
2017-04-06 19:11:36 -06:00
}
// send on CAN
void usb_cb_ep3_out(void *usbdata, int len, bool hardwired) {
UNUSED(hardwired);
2017-04-06 19:11:36 -06:00
int dpkt = 0;
uint32_t *d32 = (uint32_t *)usbdata;
for (dpkt = 0; dpkt < (len / 4); dpkt += 4) {
2017-04-06 19:11:36 -06:00
CAN_FIFOMailBox_TypeDef to_push;
to_push.RDHR = d32[dpkt + 3];
to_push.RDLR = d32[dpkt + 2];
to_push.RDTR = d32[dpkt + 1];
to_push.RIR = d32[dpkt];
2017-04-06 19:11:36 -06:00
uint8_t bus_number = (to_push.RDTR >> 4) & CAN_BUS_NUM_MASK;
can_send(&to_push, bus_number, false);
2017-04-06 19:11:36 -06:00
}
}
void usb_cb_ep3_out_complete() {
if (can_tx_check_min_slots_free(MAX_CAN_MSGS_PER_BULK_TRANSFER)) {
usb_outep3_resume_if_paused();
}
}
Revert commits that broke USB for openpilot. Revert "fix openpilot board flashing" This reverts commit 8ff93ad5da39f8dc4bf6fe632f26418b696fd230. Revert "Fixed output_enabled led not turning off when mode changed to no output." This reverts commit 27a8af11075d92d03c389713694a879905877cf0. Revert "Fixed loopback test for new GMLAN 'can4' behavior." This reverts commit 59592f599af01a667b4fd966e613b8f504d62dc2. Revert "GMLAN is now always mapped through CAN4 (index 3)" This reverts commit 329c09102435bfd9b1fbb60694139a5ff7bf4148. Revert "Removed compile time config for CAN loopback, implemented as usb message." This reverts commit e1a4c3298557fccf854ed5cbda448f8c0015b7ea. Revert "Change all output safety mode identifier to prevent user mistakes." This reverts commit 6b363e2e92fcd5e7f25b5458fe9008ff8f9fd664. Revert "untabify" This reverts commit 191f67b083e182323ba956c3ab75df10bec2f863. Revert "Refactor of safety to support more modular additions of safety policies." This reverts commit e5b524eddc82e53587cc47dcf15b22fd35890a92. Revert "Split up some more header files into compilation units." This reverts commit e2a78912f5b649822974fc0e974ec50d9d9c7d10. Revert "Enabled emulated control writes over USB." This reverts commit 133cfe970379d6881de26289616d1d9085bb5986. Revert "Moved CAN and USART code out of main.c and into more appropriate files." This reverts commit daad2dc0620d629e7db0dd68dee5595ed2b57160. Revert "Large Panda CAN cleanup. Restrict GMLAN to valid baud rates." This reverts commit a0616a2bc2ac2bfd99223aaa84912e6f649c9d54. Revert "Panda library now correctly sends USB direction bit." This reverts commit 1712c901d4b46b2726b3165a7cb2e91c281c662b. Revert "Board makefile now automatically calculates header file dependencies." This reverts commit 4a8d4e597b397ca6d68dd5dd2a376c8354dc3422. Revert "Loopback test works over wifi. (Disable trying to send over wifi)" This reverts commit dae636968af482e170aade1d785a1e197e9f3c04. Revert "Fix legacy board build" This reverts commit 62bf4e575686c84c672eb0d341ad41f174141c2d. Revert "Style cop" This reverts commit c439f43726feb30cf2ec486ffcad6ac94ab5e128. Revert "Untabify" This reverts commit 41e5eec6211c23836535af49380f74350a0ceb12. Revert "Fixed disabling gmlan." This reverts commit 5e1e45a4afade384b628e44587dd8e37d3dcd8cd. Revert "Removed dead code, standardized canid in more commands, better erroring behavior." This reverts commit b59aeb6d87ddd85406ec42e4ed8a74a232d506a4. Revert "loopback test works with new CAN bus ids." This reverts commit 75970861cf2b025173afb906e4e243861bed506a. Revert "Large reorganization of code and early integration of can bitrate setting." This reverts commit a1ed7b62ee66ec8f56bba488c38c67b69eead8cf.
2017-07-12 12:25:10 -06:00
void usb_cb_enumeration_complete() {
2017-07-21 00:36:06 -06:00
puts("USB enumeration complete\n");
2017-08-22 09:27:00 -06:00
is_enumerated = 1;
Revert commits that broke USB for openpilot. Revert "fix openpilot board flashing" This reverts commit 8ff93ad5da39f8dc4bf6fe632f26418b696fd230. Revert "Fixed output_enabled led not turning off when mode changed to no output." This reverts commit 27a8af11075d92d03c389713694a879905877cf0. Revert "Fixed loopback test for new GMLAN 'can4' behavior." This reverts commit 59592f599af01a667b4fd966e613b8f504d62dc2. Revert "GMLAN is now always mapped through CAN4 (index 3)" This reverts commit 329c09102435bfd9b1fbb60694139a5ff7bf4148. Revert "Removed compile time config for CAN loopback, implemented as usb message." This reverts commit e1a4c3298557fccf854ed5cbda448f8c0015b7ea. Revert "Change all output safety mode identifier to prevent user mistakes." This reverts commit 6b363e2e92fcd5e7f25b5458fe9008ff8f9fd664. Revert "untabify" This reverts commit 191f67b083e182323ba956c3ab75df10bec2f863. Revert "Refactor of safety to support more modular additions of safety policies." This reverts commit e5b524eddc82e53587cc47dcf15b22fd35890a92. Revert "Split up some more header files into compilation units." This reverts commit e2a78912f5b649822974fc0e974ec50d9d9c7d10. Revert "Enabled emulated control writes over USB." This reverts commit 133cfe970379d6881de26289616d1d9085bb5986. Revert "Moved CAN and USART code out of main.c and into more appropriate files." This reverts commit daad2dc0620d629e7db0dd68dee5595ed2b57160. Revert "Large Panda CAN cleanup. Restrict GMLAN to valid baud rates." This reverts commit a0616a2bc2ac2bfd99223aaa84912e6f649c9d54. Revert "Panda library now correctly sends USB direction bit." This reverts commit 1712c901d4b46b2726b3165a7cb2e91c281c662b. Revert "Board makefile now automatically calculates header file dependencies." This reverts commit 4a8d4e597b397ca6d68dd5dd2a376c8354dc3422. Revert "Loopback test works over wifi. (Disable trying to send over wifi)" This reverts commit dae636968af482e170aade1d785a1e197e9f3c04. Revert "Fix legacy board build" This reverts commit 62bf4e575686c84c672eb0d341ad41f174141c2d. Revert "Style cop" This reverts commit c439f43726feb30cf2ec486ffcad6ac94ab5e128. Revert "Untabify" This reverts commit 41e5eec6211c23836535af49380f74350a0ceb12. Revert "Fixed disabling gmlan." This reverts commit 5e1e45a4afade384b628e44587dd8e37d3dcd8cd. Revert "Removed dead code, standardized canid in more commands, better erroring behavior." This reverts commit b59aeb6d87ddd85406ec42e4ed8a74a232d506a4. Revert "loopback test works with new CAN bus ids." This reverts commit 75970861cf2b025173afb906e4e243861bed506a. Revert "Large reorganization of code and early integration of can bitrate setting." This reverts commit a1ed7b62ee66ec8f56bba488c38c67b69eead8cf.
2017-07-12 12:25:10 -06:00
}
2019-06-26 13:18:06 -06:00
int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired) {
unsigned int resp_len = 0;
2017-04-06 19:11:36 -06:00
uart_ring *ur = NULL;
timestamp_t t;
switch (setup->b.bRequest) {
// **** 0xa0: get rtc time
case 0xa0:
resp_len = get_rtc_pkt(resp);
break;
// **** 0xa1: set rtc year
case 0xa1:
t = rtc_get_time();
t.year = setup->b.wValue.w;
rtc_set_time(t);
break;
// **** 0xa2: set rtc month
case 0xa2:
t = rtc_get_time();
t.month = setup->b.wValue.w;
rtc_set_time(t);
break;
// **** 0xa3: set rtc day
case 0xa3:
t = rtc_get_time();
t.day = setup->b.wValue.w;
rtc_set_time(t);
break;
// **** 0xa4: set rtc weekday
case 0xa4:
t = rtc_get_time();
t.weekday = setup->b.wValue.w;
rtc_set_time(t);
break;
// **** 0xa5: set rtc hour
case 0xa5:
t = rtc_get_time();
t.hour = setup->b.wValue.w;
rtc_set_time(t);
break;
// **** 0xa6: set rtc minute
case 0xa6:
t = rtc_get_time();
t.minute = setup->b.wValue.w;
rtc_set_time(t);
break;
// **** 0xa7: set rtc second
case 0xa7:
t = rtc_get_time();
t.second = setup->b.wValue.w;
rtc_set_time(t);
break;
// **** 0xb0: set IR power
case 0xb0:
current_board->set_ir_power(setup->b.wValue.w);
break;
// **** 0xb1: set fan power
case 0xb1:
current_board->set_fan_power(setup->b.wValue.w);
break;
// **** 0xb2: get fan rpm
case 0xb2:
resp[0] = (fan_rpm & 0x00FFU);
resp[1] = ((fan_rpm & 0xFF00U) >> 8U);
resp_len = 2;
break;
// **** 0xb3: set phone power
case 0xb3:
current_board->set_phone_power(setup->b.wValue.w > 0U);
break;
2017-07-18 13:29:16 -06:00
// **** 0xc0: get CAN debug info
case 0xc0:
puts("can tx: "); puth(can_tx_cnt);
puts(" txd: "); puth(can_txd_cnt);
puts(" rx: "); puth(can_rx_cnt);
puts(" err: "); puth(can_err_cnt);
puts("\n");
break;
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// **** 0xc1: get hardware type
2018-01-23 21:10:23 -07:00
case 0xc1:
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
resp[0] = hw_type;
2018-01-23 21:10:23 -07:00
resp_len = 1;
break;
2017-07-17 11:48:16 -06:00
// **** 0xd0: fetch serial number
2017-04-28 17:56:40 -06:00
case 0xd0:
2019-05-21 10:47:43 -06:00
// addresses are OTP
if (setup->b.wValue.w == 1U) {
(void)memcpy(resp, (uint8_t *)0x1fff79c0, 0x10);
2019-05-21 10:47:43 -06:00
resp_len = 0x10;
} else {
get_provision_chunk(resp);
resp_len = PROVISION_CHUNK_LEN;
}
2017-04-28 17:56:40 -06:00
break;
2017-07-17 11:48:16 -06:00
// **** 0xd1: enter bootloader mode
2017-04-06 19:11:36 -06:00
case 0xd1:
2017-07-22 15:18:00 -06:00
// this allows reflashing of the bootstub
// so it's blocked over wifi
2017-07-24 16:16:22 -06:00
switch (setup->b.wValue.w) {
case 0:
// only allow bootloader entry on debug builds
#ifdef ALLOW_DEBUG
if (hardwired) {
puts("-> entering bootloader\n");
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
NVIC_SystemReset();
}
#endif
2017-07-24 16:16:22 -06:00
break;
case 1:
2017-07-27 16:54:55 -06:00
puts("-> entering softloader\n");
2017-07-24 16:16:22 -06:00
enter_bootloader_mode = ENTER_SOFTLOADER_MAGIC;
NVIC_SystemReset();
break;
2019-06-27 16:50:00 -06:00
default:
puts("Bootloader mode invalid\n");
break;
}
2017-04-06 19:11:36 -06:00
break;
2017-07-17 11:48:16 -06:00
// **** 0xd2: get health packet
2017-04-06 19:11:36 -06:00
case 0xd2:
resp_len = get_health_pkt(resp);
break;
// **** 0xd3: get first 64 bytes of signature
case 0xd3:
{
resp_len = 64;
char * code = (char*)_app_start;
int code_len = _app_start[0];
(void)memcpy(resp, &code[code_len], resp_len);
}
break;
// **** 0xd4: get second 64 bytes of signature
case 0xd4:
{
resp_len = 64;
char * code = (char*)_app_start;
int code_len = _app_start[0];
(void)memcpy(resp, &code[code_len + 64], resp_len);
}
break;
2017-07-17 11:48:16 -06:00
// **** 0xd6: get version
case 0xd6:
COMPILE_TIME_ASSERT(sizeof(gitversion) <= MAX_RESP_LEN);
(void)memcpy(resp, gitversion, sizeof(gitversion));
resp_len = sizeof(gitversion) - 1U;
2017-04-06 19:11:36 -06:00
break;
2017-07-17 11:48:16 -06:00
// **** 0xd8: reset ST
case 0xd8:
2017-04-06 19:11:36 -06:00
NVIC_SystemReset();
break;
2017-07-17 11:48:16 -06:00
// **** 0xd9: set ESP power
case 0xd9:
if (setup->b.wValue.w == 1U) {
current_board->set_gps_mode(GPS_ENABLED);
} else if (setup->b.wValue.w == 2U) {
current_board->set_gps_mode(GPS_BOOTMODE);
2017-04-26 13:38:33 -06:00
} else {
current_board->set_gps_mode(GPS_DISABLED);
2017-04-26 13:38:33 -06:00
}
break;
2017-07-17 11:48:16 -06:00
// **** 0xda: reset ESP, with optional boot mode
case 0xda:
current_board->set_gps_mode(GPS_DISABLED);
2017-04-06 19:11:36 -06:00
delay(1000000);
if (setup->b.wValue.w == 1U) {
current_board->set_gps_mode(GPS_BOOTMODE);
2017-07-22 15:18:00 -06:00
} else {
current_board->set_gps_mode(GPS_ENABLED);
2017-04-06 19:11:36 -06:00
}
2017-07-22 15:18:00 -06:00
delay(1000000);
current_board->set_gps_mode(GPS_ENABLED);
2017-04-06 19:11:36 -06:00
break;
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// **** 0xdb: set GMLAN (white/grey) or OBD CAN (black) multiplexing mode
2017-07-17 11:48:16 -06:00
case 0xdb:
if(board_has_obd()){
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
if (setup->b.wValue.w == 1U) {
// Enable OBD CAN
current_board->set_can_mode(CAN_MODE_OBD_CAN2);
} else {
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// Disable OBD CAN
current_board->set_can_mode(CAN_MODE_NORMAL);
}
2019-05-21 10:47:43 -06:00
} else {
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
if (setup->b.wValue.w == 1U) {
// GMLAN ON
if (setup->b.wIndex.w == 1U) {
can_set_gmlan(1);
} else if (setup->b.wIndex.w == 2U) {
can_set_gmlan(2);
} else {
puts("Invalid bus num for GMLAN CAN set\n");
}
} else {
can_set_gmlan(-1);
}
2019-05-21 10:47:43 -06:00
}
2017-04-06 19:11:36 -06:00
break;
2017-07-17 11:48:16 -06:00
// **** 0xdc: set safety mode
case 0xdc:
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// Blocked over WiFi.
// Allow SILENT, NOOUTPUT and ELM security mode to be set over wifi.
if (hardwired || (setup->b.wValue.w == SAFETY_SILENT) ||
(setup->b.wValue.w == SAFETY_NOOUTPUT) ||
(setup->b.wValue.w == SAFETY_ELM327)) {
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
set_safety_mode(setup->b.wValue.w, (uint16_t) setup->b.wIndex.w);
2017-07-17 11:48:16 -06:00
}
2017-05-02 00:40:49 -06:00
break;
2017-07-17 11:48:16 -06:00
// **** 0xdd: enable can forwarding
case 0xdd:
// wValue = Can Bus Num to forward from
// wIndex = Can Bus Num to forward to
if ((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w < BUS_MAX) &&
(setup->b.wValue.w != setup->b.wIndex.w)) { // set forwarding
2017-07-21 12:30:07 -06:00
can_set_forwarding(setup->b.wValue.w, setup->b.wIndex.w & CAN_BUS_NUM_MASK);
} else if((setup->b.wValue.w < BUS_MAX) && (setup->b.wIndex.w == 0xFFU)){ //Clear Forwarding
2017-07-21 12:30:07 -06:00
can_set_forwarding(setup->b.wValue.w, -1);
} else {
puts("Invalid CAN bus forwarding\n");
}
Revert commits that broke USB for openpilot. Revert "fix openpilot board flashing" This reverts commit 8ff93ad5da39f8dc4bf6fe632f26418b696fd230. Revert "Fixed output_enabled led not turning off when mode changed to no output." This reverts commit 27a8af11075d92d03c389713694a879905877cf0. Revert "Fixed loopback test for new GMLAN 'can4' behavior." This reverts commit 59592f599af01a667b4fd966e613b8f504d62dc2. Revert "GMLAN is now always mapped through CAN4 (index 3)" This reverts commit 329c09102435bfd9b1fbb60694139a5ff7bf4148. Revert "Removed compile time config for CAN loopback, implemented as usb message." This reverts commit e1a4c3298557fccf854ed5cbda448f8c0015b7ea. Revert "Change all output safety mode identifier to prevent user mistakes." This reverts commit 6b363e2e92fcd5e7f25b5458fe9008ff8f9fd664. Revert "untabify" This reverts commit 191f67b083e182323ba956c3ab75df10bec2f863. Revert "Refactor of safety to support more modular additions of safety policies." This reverts commit e5b524eddc82e53587cc47dcf15b22fd35890a92. Revert "Split up some more header files into compilation units." This reverts commit e2a78912f5b649822974fc0e974ec50d9d9c7d10. Revert "Enabled emulated control writes over USB." This reverts commit 133cfe970379d6881de26289616d1d9085bb5986. Revert "Moved CAN and USART code out of main.c and into more appropriate files." This reverts commit daad2dc0620d629e7db0dd68dee5595ed2b57160. Revert "Large Panda CAN cleanup. Restrict GMLAN to valid baud rates." This reverts commit a0616a2bc2ac2bfd99223aaa84912e6f649c9d54. Revert "Panda library now correctly sends USB direction bit." This reverts commit 1712c901d4b46b2726b3165a7cb2e91c281c662b. Revert "Board makefile now automatically calculates header file dependencies." This reverts commit 4a8d4e597b397ca6d68dd5dd2a376c8354dc3422. Revert "Loopback test works over wifi. (Disable trying to send over wifi)" This reverts commit dae636968af482e170aade1d785a1e197e9f3c04. Revert "Fix legacy board build" This reverts commit 62bf4e575686c84c672eb0d341ad41f174141c2d. Revert "Style cop" This reverts commit c439f43726feb30cf2ec486ffcad6ac94ab5e128. Revert "Untabify" This reverts commit 41e5eec6211c23836535af49380f74350a0ceb12. Revert "Fixed disabling gmlan." This reverts commit 5e1e45a4afade384b628e44587dd8e37d3dcd8cd. Revert "Removed dead code, standardized canid in more commands, better erroring behavior." This reverts commit b59aeb6d87ddd85406ec42e4ed8a74a232d506a4. Revert "loopback test works with new CAN bus ids." This reverts commit 75970861cf2b025173afb906e4e243861bed506a. Revert "Large reorganization of code and early integration of can bitrate setting." This reverts commit a1ed7b62ee66ec8f56bba488c38c67b69eead8cf.
2017-07-12 12:25:10 -06:00
break;
2017-07-17 20:43:30 -06:00
// **** 0xde: set can bitrate
case 0xde:
2017-07-18 22:05:09 -06:00
if (setup->b.wValue.w < BUS_MAX) {
2017-07-17 20:43:30 -06:00
can_speed[setup->b.wValue.w] = setup->b.wIndex.w;
bool ret = can_init(CAN_NUM_FROM_BUS_NUM(setup->b.wValue.w));
UNUSED(ret);
2017-07-17 20:43:30 -06:00
}
break;
// **** 0xdf: set unsafe mode
case 0xdf:
2020-03-31 17:30:01 -06:00
// you can only set this if you are in a non car safety mode
if ((current_safety_mode == SAFETY_SILENT) ||
(current_safety_mode == SAFETY_NOOUTPUT) ||
(current_safety_mode == SAFETY_ELM327)) {
2020-03-31 17:30:01 -06:00
unsafe_mode = setup->b.wValue.w;
}
break;
2017-07-17 11:48:16 -06:00
// **** 0xe0: uart read
case 0xe0:
ur = get_ring_by_number(setup->b.wValue.w);
2019-06-28 14:46:57 -06:00
if (!ur) {
break;
}
// TODO: Remove this again and fix boardd code to hande the message bursts instead of single chars
if (ur == &uart_ring_gps) {
dma_pointer_handler(ur, DMA2_Stream5->NDTR);
}
// read
2019-06-17 14:48:14 -06:00
while ((resp_len < MIN(setup->b.wLength.w, MAX_RESP_LEN)) &&
2017-07-21 12:48:03 -06:00
getc(ur, (char*)&resp[resp_len])) {
++resp_len;
2017-04-06 19:11:36 -06:00
}
break;
2017-07-17 11:48:16 -06:00
// **** 0xe1: uart set baud rate
case 0xe1:
ur = get_ring_by_number(setup->b.wValue.w);
2019-06-28 14:46:57 -06:00
if (!ur) {
break;
}
uart_set_baud(ur->uart, setup->b.wIndex.w);
2017-04-06 19:11:36 -06:00
break;
2017-07-17 11:48:16 -06:00
// **** 0xe2: uart set parity
case 0xe2:
2017-04-25 16:16:23 -06:00
ur = get_ring_by_number(setup->b.wValue.w);
2019-06-28 14:46:57 -06:00
if (!ur) {
break;
}
2017-04-25 16:16:23 -06:00
switch (setup->b.wIndex.w) {
case 0:
2017-04-26 19:39:26 -06:00
// disable parity, 8-bit
ur->uart->CR1 &= ~(USART_CR1_PCE | USART_CR1_M);
2017-04-25 16:16:23 -06:00
break;
case 1:
2017-04-26 19:39:26 -06:00
// even parity, 9-bit
2017-04-25 16:16:23 -06:00
ur->uart->CR1 &= ~USART_CR1_PS;
2017-04-26 19:39:26 -06:00
ur->uart->CR1 |= USART_CR1_PCE | USART_CR1_M;
2017-04-25 16:16:23 -06:00
break;
case 2:
2017-04-26 19:39:26 -06:00
// odd parity, 9-bit
2017-04-25 16:16:23 -06:00
ur->uart->CR1 |= USART_CR1_PS;
2017-04-26 19:39:26 -06:00
ur->uart->CR1 |= USART_CR1_PCE | USART_CR1_M;
2017-04-25 16:16:23 -06:00
break;
default:
break;
}
break;
2017-07-17 11:48:16 -06:00
// **** 0xe4: uart set baud rate extended
case 0xe4:
2017-05-30 00:03:11 -06:00
ur = get_ring_by_number(setup->b.wValue.w);
2019-06-28 14:46:57 -06:00
if (!ur) {
break;
}
2017-05-30 00:03:11 -06:00
uart_set_baud(ur->uart, (int)setup->b.wIndex.w*300);
break;
2017-07-17 11:48:16 -06:00
// **** 0xe5: set CAN loopback (for testing)
case 0xe5:
can_loopback = (setup->b.wValue.w > 0U);
2017-07-17 11:48:16 -06:00
can_init_all();
break;
2017-08-23 10:28:52 -06:00
// **** 0xe6: set USB power
case 0xe6:
current_board->set_usb_power_mode(setup->b.wValue.w);
2017-08-23 10:28:52 -06:00
break;
// **** 0xe7: set power save state
case 0xe7:
set_power_save_state(setup->b.wValue.w);
break;
// **** 0xf0: k-line/l-line wake-up pulse for KWP2000 fast initialization
2017-07-17 20:43:30 -06:00
case 0xf0:
if(board_has_lin()) {
bool k = (setup->b.wValue.w == 0U) || (setup->b.wValue.w == 2U);
bool l = (setup->b.wValue.w == 1U) || (setup->b.wValue.w == 2U);
if (bitbang_wakeup(k, l)) {
resp_len = -1; // do not clear NAK yet (wait for bit banging to finish)
2017-04-06 19:11:36 -06:00
}
}
break;
// **** 0xf1: Clear CAN ring buffer.
case 0xf1:
if (setup->b.wValue.w == 0xFFFFU) {
puts("Clearing CAN Rx queue\n");
can_clear(&can_rx_q);
} else if (setup->b.wValue.w < BUS_MAX) {
puts("Clearing CAN Tx queue\n");
can_clear(can_queues[setup->b.wValue.w]);
} else {
puts("Clearing CAN CAN ring buffer failed: wrong bus number\n");
}
break;
// **** 0xf2: Clear UART ring buffer.
case 0xf2:
{
uart_ring * rb = get_ring_by_number(setup->b.wValue.w);
if (rb != NULL) {
puts("Clearing UART queue.\n");
clear_uart_buff(rb);
}
break;
}
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// **** 0xf3: Heartbeat. Resets heartbeat counter.
case 0xf3:
{
heartbeat_counter = 0U;
break;
}
// **** 0xf4: k-line/l-line 5 baud initialization
case 0xf4:
if(board_has_lin()) {
bool k = (setup->b.wValue.w == 0U) || (setup->b.wValue.w == 2U);
bool l = (setup->b.wValue.w == 1U) || (setup->b.wValue.w == 2U);
uint8_t five_baud_addr = (setup->b.wIndex.w & 0xFFU);
if (bitbang_five_baud_addr(k, l, five_baud_addr)) {
resp_len = -1; // do not clear NAK yet (wait for bit banging to finish)
}
}
break;
// **** 0xf5: set clock source mode
case 0xf5:
current_board->set_clock_source_mode(setup->b.wValue.w);
break;
// **** 0xf6: set siren enabled
case 0xf6:
siren_enabled = (setup->b.wValue.w != 0U);
break;
// **** 0xf7: set green led enabled
case 0xf7:
green_led_enabled = (setup->b.wValue.w != 0U);
break;
2017-04-06 19:11:36 -06:00
default:
puts("NO HANDLER ");
puth(setup->b.bRequest);
2017-04-06 19:11:36 -06:00
puts("\n");
Revert commits that broke USB for openpilot. Revert "fix openpilot board flashing" This reverts commit 8ff93ad5da39f8dc4bf6fe632f26418b696fd230. Revert "Fixed output_enabled led not turning off when mode changed to no output." This reverts commit 27a8af11075d92d03c389713694a879905877cf0. Revert "Fixed loopback test for new GMLAN 'can4' behavior." This reverts commit 59592f599af01a667b4fd966e613b8f504d62dc2. Revert "GMLAN is now always mapped through CAN4 (index 3)" This reverts commit 329c09102435bfd9b1fbb60694139a5ff7bf4148. Revert "Removed compile time config for CAN loopback, implemented as usb message." This reverts commit e1a4c3298557fccf854ed5cbda448f8c0015b7ea. Revert "Change all output safety mode identifier to prevent user mistakes." This reverts commit 6b363e2e92fcd5e7f25b5458fe9008ff8f9fd664. Revert "untabify" This reverts commit 191f67b083e182323ba956c3ab75df10bec2f863. Revert "Refactor of safety to support more modular additions of safety policies." This reverts commit e5b524eddc82e53587cc47dcf15b22fd35890a92. Revert "Split up some more header files into compilation units." This reverts commit e2a78912f5b649822974fc0e974ec50d9d9c7d10. Revert "Enabled emulated control writes over USB." This reverts commit 133cfe970379d6881de26289616d1d9085bb5986. Revert "Moved CAN and USART code out of main.c and into more appropriate files." This reverts commit daad2dc0620d629e7db0dd68dee5595ed2b57160. Revert "Large Panda CAN cleanup. Restrict GMLAN to valid baud rates." This reverts commit a0616a2bc2ac2bfd99223aaa84912e6f649c9d54. Revert "Panda library now correctly sends USB direction bit." This reverts commit 1712c901d4b46b2726b3165a7cb2e91c281c662b. Revert "Board makefile now automatically calculates header file dependencies." This reverts commit 4a8d4e597b397ca6d68dd5dd2a376c8354dc3422. Revert "Loopback test works over wifi. (Disable trying to send over wifi)" This reverts commit dae636968af482e170aade1d785a1e197e9f3c04. Revert "Fix legacy board build" This reverts commit 62bf4e575686c84c672eb0d341ad41f174141c2d. Revert "Style cop" This reverts commit c439f43726feb30cf2ec486ffcad6ac94ab5e128. Revert "Untabify" This reverts commit 41e5eec6211c23836535af49380f74350a0ceb12. Revert "Fixed disabling gmlan." This reverts commit 5e1e45a4afade384b628e44587dd8e37d3dcd8cd. Revert "Removed dead code, standardized canid in more commands, better erroring behavior." This reverts commit b59aeb6d87ddd85406ec42e4ed8a74a232d506a4. Revert "loopback test works with new CAN bus ids." This reverts commit 75970861cf2b025173afb906e4e243861bed506a. Revert "Large reorganization of code and early integration of can bitrate setting." This reverts commit a1ed7b62ee66ec8f56bba488c38c67b69eead8cf.
2017-07-12 12:25:10 -06:00
break;
2017-04-06 19:11:36 -06:00
}
return resp_len;
2017-04-06 19:11:36 -06:00
}
#ifndef EON
2017-07-24 13:31:47 -06:00
int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
2017-04-18 08:34:56 -06:00
// data[0] = endpoint
// data[2] = length
// data[4:] = data
UNUSED(len);
2017-07-24 13:31:47 -06:00
int resp_len = 0;
2017-04-18 08:34:56 -06:00
switch (data[0]) {
case 0:
// control transfer
2017-07-24 13:31:47 -06:00
resp_len = usb_cb_control_msg((USB_Setup_TypeDef *)(data+4), data_out, 0);
2017-04-18 08:34:56 -06:00
break;
case 1:
// ep 1, read
2017-07-24 13:31:47 -06:00
resp_len = usb_cb_ep1_in(data_out, 0x40, 0);
2017-04-18 08:34:56 -06:00
break;
case 2:
// ep 2, send serial
usb_cb_ep2_out(data+4, data[2], 0);
2017-04-18 08:34:56 -06:00
break;
case 3:
// ep 3, send CAN
usb_cb_ep3_out(data+4, data[2], 0);
2017-04-18 08:34:56 -06:00
break;
2019-06-27 16:50:00 -06:00
default:
puts("SPI data invalid");
break;
2017-04-18 08:34:56 -06:00
}
2017-07-24 13:31:47 -06:00
return resp_len;
2017-05-03 16:54:47 -06:00
}
#endif
2017-07-21 12:48:03 -06:00
2017-04-06 19:11:36 -06:00
// ***************************** main code *****************************
// cppcheck-suppress unusedFunction ; used in headers not included in cppcheck
void __initialize_hardware_early(void) {
2017-04-06 19:11:36 -06:00
early();
}
void __attribute__ ((noinline)) enable_fpu(void) {
2018-04-11 20:52:42 -06:00
// enable the FPU
SCB->CPACR |= ((3UL << (10U * 2U)) | (3UL << (11U * 2U)));
2018-04-11 20:52:42 -06:00
}
// 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
// called at 8Hz
uint8_t loop_counter = 0U;
void TIM1_BRK_TIM9_IRQ_Handler(void) {
if (TIM9->SR != 0) {
// siren
current_board->set_siren((loop_counter & 1U) && siren_enabled);
// decimated to 1Hz
if(loop_counter == 0U){
can_live = pending_can_live;
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 ((uptime_cnt & 0xFU) == 0U) {
pending_can_live = 0;
}
#ifdef DEBUG
puts("** blink ");
puth(can_rx_q.r_ptr); puts(" "); puth(can_rx_q.w_ptr); puts(" ");
puth(can_tx1_q.r_ptr); puts(" "); puth(can_tx1_q.w_ptr); puts(" ");
puth(can_tx2_q.r_ptr); puts(" "); puth(can_tx2_q.w_ptr); puts("\n");
#endif
// Tick drivers
fan_tick();
// set green LED to be controls allowed
current_board->set_led(LED_GREEN, controls_allowed | green_led_enabled);
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// turn off the blue LED, turned on by CAN
// unless we are in power saving mode
current_board->set_led(LED_BLUE, (uptime_cnt & 1U) && (power_save_status == POWER_SAVE_STATUS_ENABLED));
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// increase heartbeat counter and cap it at the uint32 limit
if (heartbeat_counter < __UINT32_MAX__) {
heartbeat_counter += 1U;
}
#ifdef EON
// check heartbeat counter if we are running EON code.
// if the heartbeat has been gone for a while, go to SILENT safety mode and enter power save
if (heartbeat_counter >= (check_started() ? EON_HEARTBEAT_IGNITION_CNT_ON : EON_HEARTBEAT_IGNITION_CNT_OFF)) {
puts("EON hasn't sent a heartbeat for 0x");
puth(heartbeat_counter);
puts(" seconds. Safety is set to SILENT mode.\n");
if (current_safety_mode != SAFETY_SILENT) {
set_safety_mode(SAFETY_SILENT, 0U);
}
if (power_save_status != POWER_SAVE_STATUS_ENABLED) {
set_power_save_state(POWER_SAVE_STATUS_ENABLED);
}
// Also disable IR when the heartbeat goes missing
current_board->set_ir_power(0U);
// If enumerated but no heartbeat (phone up, boardd not running), turn the fan on to cool the device
if(usb_enumerated()){
current_board->set_fan_power(50U);
} else {
current_board->set_fan_power(0U);
}
}
// enter CDP mode when car starts to ensure we are charging a turned off EON
if (check_started() && (usb_power_mode != USB_POWER_CDP)) {
current_board->set_usb_power_mode(USB_POWER_CDP);
}
#endif
// check registers
check_registers();
// set ignition_can to false after 2s of no CAN seen
if (ignition_can_cnt > 2U) {
ignition_can = false;
};
// on to the next one
uptime_cnt += 1U;
safety_mode_cnt += 1U;
ignition_can_cnt += 1U;
// synchronous safety check
safety_tick(current_hooks);
}
loop_counter++;
loop_counter %= 8U;
}
TIM9->SR = 0;
}
#define MAX_FADE 8192U
int main(void) {
// Init interrupt table
init_interrupts(true);
// 8Hz timer
REGISTER_INTERRUPT(TIM1_BRK_TIM9_IRQn, TIM1_BRK_TIM9_IRQ_Handler, 10U, FAULT_INTERRUPT_RATE_TIM9)
2017-07-21 00:42:19 -06:00
// shouldn't have interrupts here, but just in case
disable_interrupts();
2017-07-21 00:14:27 -06:00
2017-07-27 16:54:55 -06:00
// init early devices
2017-04-06 19:11:36 -06:00
clock_init();
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
peripherals_init();
detect_configuration();
detect_board_type();
adc_init();
2017-07-27 16:54:55 -06:00
// print hello
puts("\n\n\n************************ MAIN START ************************\n");
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// check for non-supported board types
if(hw_type == HW_TYPE_UNKNOWN){
puts("Unsupported board type\n");
while (1) { /* hang */ }
2019-06-28 14:46:57 -06:00
}
2019-05-19 10:12:03 -06:00
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
puts("Config:\n");
puts(" Board type: "); puts(current_board->board_type); puts("\n");
puts(has_external_debug_serial ? " Real serial\n" : " USB serial\n");
// init board
current_board->init();
2017-04-06 19:11:36 -06:00
2018-04-11 20:52:42 -06:00
// panda has an FPU, let's use it!
enable_fpu();
2017-07-29 20:50:35 -06:00
// enable main uart if it's connected
if (has_external_debug_serial) {
// WEIRDNESS: without this gate around the UART, it would "crash", but only if the ESP is enabled
// assuming it's because the lines were left floating and spurious noise was on them
uart_init(&uart_ring_debug, 115200);
2017-07-29 20:50:35 -06:00
}
2017-04-06 19:11:36 -06:00
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
if (board_has_gps()) {
uart_init(&uart_ring_gps, 9600);
2018-01-26 00:51:52 -07:00
} else {
// enable ESP uart
uart_init(&uart_ring_gps, 115200);
2018-01-26 00:51:52 -07:00
}
2019-05-21 10:47:43 -06:00
if(board_has_lin()){
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// enable LIN
uart_init(&uart_ring_lin1, 10400);
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
UART5->CR2 |= USART_CR2_LINEN;
uart_init(&uart_ring_lin2, 10400);
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
USART3->CR2 |= USART_CR2_LINEN;
}
2017-04-06 19:11:36 -06:00
2017-10-26 19:44:25 -06:00
// init microsecond system timer
// increments 1000000 times per second
// generate an update to set the prescaler
TIM2->PSC = 48-1;
TIM2->CR1 = TIM_CR1_CEN;
TIM2->EGR = TIM_EGR_UG;
// use TIM2->CNT to read
// init to SILENT and can silent
set_safety_mode(SAFETY_SILENT, 0);
2017-05-30 10:46:21 -06:00
// enable CAN TXs
2020-09-28 08:19:09 -06:00
current_board->enable_can_transceivers(true);
2019-06-26 13:01:57 -06:00
#ifndef EON
2017-04-06 19:11:36 -06:00
spi_init();
2019-06-26 13:01:57 -06:00
#endif
2019-05-21 10:47:43 -06:00
// 8hz
timer_init(TIM9, 183);
NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn);
#ifdef DEBUG
puts("DEBUG ENABLED\n");
#endif
Black (#254) * late usb * Added type support for black panda * Added harness presence and orientation detection * harness relay driving code * Added intercept support in black panda code. Switched around can0 and can2 * Disable ADCs after orientation detection. Ignition interrupts via harness * WIP: Hardware abstraction layer + black panda bringup * Fixed bootstub build * Fixed bootstub for pedal * Fixed infinite loops * Got CAN buses working on white again * Fixed pedal build and black can interfaces * Got CAN buses working on black panda * Finished loopback test for black panda * Erase all flash sectors on the panda. Increased binary limit. Added extra python functions. * Fixed python * Made new code MISRA compliant * Cleaned up ignition. Fixed build * Fixed health packet * Fixed CAN mode on black bug. Changed OBD to switch on ELM mode * Fixes from Github review * Fixed MISRA issue for pedal * Fixed failing gmlan tests * ELM327 safety: allow diagnostic on all buses * Cleaned up EON relay code * delete only 3 sectors instead of 11 to allow a new build to be flashed. Much faster to flash * Removed CAN only can0 output mode. Does not make sense on black panda due to reversibility issues. * Added heartbeat logic for EON code on panda. Go to NOOUTPUT if EON does not send a heartbeat for 5 seconds. * Remove all CAN buses live on EON startup. Shouldn't be necessary to have this separate case * Formatting * Added file I forgot to push * Added heartbeat to testing code to make sure EON tests don't fail. Should probably find a better way to do this though. Heartbeat thread didn't work, concurrent USB connection issues... * Safety: support black panda for Honda Bosch * Disable OBD2 if setting to NOOUTPUT mode * Run safety tests for all hw_types * Fail test if subtest fails * fix safety tests
2019-07-23 16:07:06 -06:00
// enable USB (right before interrupts or enum can fail!)
usb_init();
2017-04-06 19:11:36 -06:00
puts("**** INTERRUPTS ON ****\n");
2019-06-14 14:28:15 -06:00
enable_interrupts();
2017-04-06 19:11:36 -06:00
// LED should keep on blinking all the time
2017-08-22 09:27:00 -06:00
uint64_t cnt = 0;
2017-04-06 19:11:36 -06:00
for (cnt=0;;cnt++) {
if (power_save_status == POWER_SAVE_STATUS_DISABLED) {
#ifdef DEBUG_FAULTS
if(fault_status == FAULT_STATUS_NONE){
#endif
uint32_t div_mode = ((usb_power_mode == USB_POWER_DCP) ? 4U : 1U);
// useful for debugging, fade breaks = panda is overloaded
for(uint32_t fade = 0U; fade < MAX_FADE; fade += div_mode){
current_board->set_led(LED_RED, true);
delay(fade >> 4);
current_board->set_led(LED_RED, false);
delay((MAX_FADE - fade) >> 4);
2019-05-21 10:47:43 -06:00
}
for(uint32_t fade = MAX_FADE; fade > 0U; fade -= div_mode){
current_board->set_led(LED_RED, true);
delay(fade >> 4);
current_board->set_led(LED_RED, false);
delay((MAX_FADE - fade) >> 4);
}
#ifdef DEBUG_FAULTS
} else {
current_board->set_led(LED_RED, 1);
delay(512000U);
current_board->set_led(LED_RED, 0);
delay(512000U);
}
#endif
} else {
__WFI();
2017-08-22 10:44:08 -06:00
}
2017-04-06 19:11:36 -06:00
}
return 0;
}