MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / init

Method init

libraries/AP_SerialManager/AP_SerialManager.cpp:425–595  ·  view source on GitHub ↗

init - // init - initialise serial ports

Source from the content-addressed store, hash-verified

423
424// init - // init - initialise serial ports
425void AP_SerialManager::init()
426{
427 // always reset passthru port2 on boot
428 passthru_port2.set_and_save_ifchanged(-1);
429
430#ifdef HAL_OTG1_CONFIG
431 /*
432 prevent users from changing USB protocol to other than
433 MAVLink. This fixes an issue where users trying to get SLCAN
434 change SERIAL0_PROTOCOL to 22 and find they can no longer connect
435 */
436 if (state[0].protocol != SerialProtocol_MAVLink &&
437 state[0].protocol != SerialProtocol_MAVLink2) {
438 state[0].protocol.set(SerialProtocol_MAVLink2);
439 }
440#endif
441
442 init_console();
443
444 // initialise serial ports
445 for (uint8_t i=1; i<SERIALMANAGER_NUM_PORTS; i++) {
446 auto *uart = hal.serial(i);
447
448 state[i].idx = i;
449
450 if (uart != nullptr) {
451 set_options(i);
452 switch (state[i].protocol) {
453 case SerialProtocol_None:
454#if HAL_GCS_ENABLED
455 // disable RX and TX pins in case they are shared
456 // with another peripheral (eg. RCIN pin). We
457 // don't do this if GCS is not enabled as in that
458 // case we don't have serialmanager parameters and
459 // this would prevent AP_Periph from using a GPS
460 uart->disable_rxtx();
461#endif
462 break;
463 case SerialProtocol_Console:
464 case SerialProtocol_MAVLink:
465 case SerialProtocol_MAVLink2:
466 case SerialProtocol_MAVLinkHL:
467 uart->begin(state[i].baudrate(),
468 AP_SERIALMANAGER_MAVLINK_BUFSIZE_RX,
469 AP_SERIALMANAGER_MAVLINK_BUFSIZE_TX);
470 break;
471 case SerialProtocol_FrSky_D:
472 // Note baudrate is hardcoded to 9600
473 state[i].baud.set_and_default(AP_SERIALMANAGER_FRSKY_D_BAUD/1000); // update baud param in case user looks at it
474 // begin is handled by AP_Frsky_telem library
475 break;
476 case SerialProtocol_FrSky_SPort:
477 case SerialProtocol_FrSky_SPort_Passthrough:
478 // Note baudrate is hardcoded to 57600
479 state[i].baud.set_and_default(AP_SERIALMANAGER_FRSKY_SPORT_BAUD/1000); // update baud param in case user looks at it
480 // begin is handled by AP_Frsky_telem library
481 break;
482 case SerialProtocol_GPS:

Callers

nothing calls this directly

Calls 15

serialMethod · 0.80
baudrateMethod · 0.80
has_uartMethod · 0.80
add_uartMethod · 0.80
set_imu_out_uartMethod · 0.80
setMethod · 0.45
disable_rxtxMethod · 0.45
beginMethod · 0.45
set_and_defaultMethod · 0.45
set_and_saveMethod · 0.45
configure_parityMethod · 0.45

Tested by

no test coverage detected