openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
6.1 KiB

Squashed 'panda/' changes from 30c7ca8a5..256d274e7 256d274e7 Fix Mac installation instruction per: https://github.com/commaai/panda/pull/308/files bfd8ff1b1 Update cppcheck commit with more coverage b143a1cf9 Fixed Misra complaint 606f1d913 Fixed RTC on non-uno boards, second try. Cannot work when there is no xtal. 933c75770 Fix RTC on non-uno boards (#311) 48d0d0c78 VW button spam: fix safety and add tests (#306) 6cccf969a Fan and IR at 0 when in power savings mode (#309) 05373282a board get_sdk scripts were left on python2 de18a7ef1 bump version after uno merge 1965817d3 Changed default values for testing a12a148d5 Uno (#274) 7d29dc5a2 bump panda version. We really need a better way 40075321d VW: stricter limits to comply with comma safety policy e2e2be92c add safety mode to health packet 101238c7f turned on VW ignition based CAN logic a0d8d5dae fix misra 5.3: check_ignition is intended as check_started and can't be used twice ea636de61 made check_ignition function to both look at ignition_line and ignition_can 1102e6965 make ignition logic common for all cars (#303) 3a110c6f6 bump version after CMSIS core upgrade 55dfa5230 Update core to CMSIS 5.6 release (#251) ee864907c fix linter 2 f410b110d fix linter 55957d6e4 proper python3 exception inheritance 6ba0f47b5 fix linter errors 5c49fe050 Merge pull request #145 from gregjhogan/uds 0f361999b timeout is float 396d6aad5 safety_replay only installs few extra requirements 25af7d301 Misra also need python 3 env 7434c5ce2 centralize requirements for tests a0c37c70a coverage not needed in linter reqs fce38a91d Linter python (#299) 62e2f5caa update cppcheck commit 711810d2f more uds debug 4454e3a6b better CAN comm abstraction 6b1f28f57 fix more encoding and some bytes cleanup (#300) 43adad311 fix WARNING_INDICATOR_REQUESTED name 9c857da37 0x b64d6fa5d typing 768fdf7e1 bytes() > chr().encode() 1be15ea93 custom errors from thread 68da8315f more python3 eb358e81c uds lib example 4f288586d updates for python3 932745f62 support tx flow control for chunked messages b1c371292 add timeout param cdf2f626b bug fixes b1a319577 fix rx message filtering bug 80fb6a6fa convert uds lib to class 59cd2b47f handle separation time in microseconds 4429600d8 fix separation time parsing c641e66f7 fix typo 48b8dcc6f fix flow control delay scale 78f413d88 flow control delay 33a5167d9 bug fixes 8ee89a091 multi-frame tx 5e89a9c72 clear rx buffer and numeric error ids 966230063 fix remaining size calculation 01ef1fae3 zero pad messages before sending 1ddc9735d uds can communication dca176e71 syntax errors 95be4811e SERVICE_TYPE enum 98e73b51d more UDS message type implementation c1c5b0356 uds lib 162f4853d fix chr to bytes conversions (#298) 4972376de Update VW regression test to follow Comma safety index refactoring (#296) f9053f5df more Python 3 fixes, attempting to fix jenkins wifi regresison test (#295) 2f9e07628 Panda safety code for Volkswagen, Audi, SEAT, and Škoda (#293) git-subtree-dir: panda git-subtree-split: 256d274e760ce00d4e5ff5e0d9b86d0fb5924568
6 years ago
// ///////////// //
// Uno + Harness //
// ///////////// //
void uno_enable_can_transciever(uint8_t transciever, bool enabled) {
switch (transciever){
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
break;
case 2U:
set_gpio_output(GPIOC, 13, !enabled);
break;
case 3U:
set_gpio_output(GPIOA, 0, !enabled);
break;
case 4U:
set_gpio_output(GPIOB, 10, !enabled);
break;
default:
puts("Invalid CAN transciever ("); puth(transciever); puts("): enabling failed\n");
break;
}
}
void uno_enable_can_transcievers(bool enabled) {
for(uint8_t i=1U; i<=4U; i++){
uno_enable_can_transciever(i, enabled);
}
}
void uno_set_led(uint8_t color, bool enabled) {
switch (color){
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
break;
case LED_GREEN:
set_gpio_output(GPIOC, 7, !enabled);
break;
case LED_BLUE:
set_gpio_output(GPIOC, 6, !enabled);
break;
default:
break;
}
}
void uno_set_gps_load_switch(bool enabled) {
set_gpio_output(GPIOC, 12, enabled);
}
void uno_set_usb_power_mode(uint8_t mode) {
UNUSED(mode);
puts("Setting USB mode makes no sense on UNO\n");
}
void uno_set_esp_gps_mode(uint8_t mode) {
switch (mode) {
case ESP_GPS_DISABLED:
// GPS OFF
set_gpio_output(GPIOB, 1, 0);
set_gpio_output(GPIOC, 5, 0);
uno_set_gps_load_switch(false);
break;
case ESP_GPS_ENABLED:
// GPS ON
set_gpio_output(GPIOB, 1, 1);
set_gpio_output(GPIOC, 5, 1);
uno_set_gps_load_switch(true);
break;
case ESP_GPS_BOOTMODE:
set_gpio_output(GPIOB, 1, 1);
set_gpio_output(GPIOC, 5, 0);
uno_set_gps_load_switch(true);
break;
default:
puts("Invalid ESP/GPS mode\n");
break;
}
}
void uno_set_can_mode(uint8_t mode){
switch (mode) {
case CAN_MODE_NORMAL:
case CAN_MODE_OBD_CAN2:
if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(car_harness_status == HARNESS_STATUS_NORMAL)) {
// B12,B13: disable OBD mode
set_gpio_mode(GPIOB, 12, MODE_INPUT);
set_gpio_mode(GPIOB, 13, MODE_INPUT);
// B5,B6: normal CAN2 mode
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
} else {
// B5,B6: disable normal CAN2 mode
set_gpio_mode(GPIOB, 5, MODE_INPUT);
set_gpio_mode(GPIOB, 6, MODE_INPUT);
// B12,B13: OBD mode
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
}
break;
default:
puts("Tried to set unsupported CAN mode: "); puth(mode); puts("\n");
break;
}
}
void uno_set_bootkick(bool enabled){
set_gpio_output(GPIOB, 14, !enabled);
}
void uno_usb_power_mode_tick(uint64_t tcnt){
if(tcnt == 3U){
uno_set_bootkick(false);
}
}
bool uno_check_ignition(void){
// ignition is checked through harness
return harness_check_ignition();
}
void uno_set_usb_switch(bool phone){
set_gpio_output(GPIOB, 3, phone);
}
void uno_set_ir_power(uint8_t percentage){
pwm_set(TIM4, 2, percentage);
}
void uno_set_fan_power(uint8_t percentage){
// Enable fan power only if percentage is non-zero.
set_gpio_output(GPIOA, 1, (percentage != 0U));
fan_set_power(percentage);
}
uint32_t uno_read_current(void){
// No current sense on Uno
return 0U;
}
void uno_init(void) {
common_init_gpio();
// A8,A15: normal CAN3 mode
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
// C0: OBD_SBU1 (orientation detection)
// C3: OBD_SBU2 (orientation detection)
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
// C10: OBD_SBU1_RELAY (harness relay driving output)
// C11: OBD_SBU2_RELAY (harness relay driving output)
set_gpio_mode(GPIOC, 10, MODE_OUTPUT);
set_gpio_mode(GPIOC, 11, MODE_OUTPUT);
set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN);
set_gpio_output(GPIOC, 10, 1);
set_gpio_output(GPIOC, 11, 1);
// C8: FAN PWM aka TIM3_CH3
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);
// Turn on GPS load switch.
uno_set_gps_load_switch(true);
// Turn on phone regulator
set_gpio_output(GPIOB, 4, 1);
// Initialize IR PWM and set to 0%
set_gpio_alternate(GPIOB, 7, GPIO_AF2_TIM4);
pwm_init(TIM4, 2);
uno_set_ir_power(0U);
// Initialize fan and set to 0%
fan_init();
uno_set_fan_power(0U);
// Initialize harness
harness_init();
// Initialize RTC
rtc_init();
// Enable CAN transcievers
uno_enable_can_transcievers(true);
// Disable LEDs
uno_set_led(LED_RED, false);
uno_set_led(LED_GREEN, false);
uno_set_led(LED_BLUE, false);
// Set normal CAN mode
uno_set_can_mode(CAN_MODE_NORMAL);
// flip CAN0 and CAN2 if we are flipped
if (car_harness_status == HARNESS_STATUS_NORMAL) {
can_flip_buses(0, 2);
}
// init multiplexer
can_set_obd(car_harness_status, false);
// Switch to phone usb mode if harness connection is powered by less than 7V
if(adc_get_voltage() < 7000U){
uno_set_usb_switch(true);
} else {
uno_set_usb_switch(false);
}
// Bootkick phone
uno_set_bootkick(true);
}
const harness_configuration uno_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
.GPIO_SBU2 = GPIOC,
.GPIO_relay_normal = GPIOC,
.GPIO_relay_flipped = GPIOC,
.pin_SBU1 = 0,
.pin_SBU2 = 3,
.pin_relay_normal = 10,
.pin_relay_flipped = 11,
.adc_channel_SBU1 = 10,
.adc_channel_SBU2 = 13
};
const board board_uno = {
.board_type = "Uno",
.harness_config = &uno_harness_config,
.init = uno_init,
.enable_can_transciever = uno_enable_can_transciever,
.enable_can_transcievers = uno_enable_can_transcievers,
.set_led = uno_set_led,
.set_usb_power_mode = uno_set_usb_power_mode,
.set_esp_gps_mode = uno_set_esp_gps_mode,
.set_can_mode = uno_set_can_mode,
.usb_power_mode_tick = uno_usb_power_mode_tick,
.check_ignition = uno_check_ignition,
.read_current = uno_read_current,
.set_fan_power = uno_set_fan_power,
.set_ir_power = uno_set_ir_power
};