void mavlink_init(void) { int16_t index; udb_init_USART(&mavlink_callback_get_byte_to_send, &mavlink_callback_received_byte); udb_serial_set_rate(MAVLINK_BAUD); mavlink_process_message_handle = register_event_p(&handleMessage, EVENT_PRIORITY_MEDIUM); mavlink_system.sysid = MAVLINK_SYSID; // System ID, 1-255, ID of your Plane for GCS mavlink_system.compid = 1; // Component/Subsystem ID, (1-255) MatrixPilot on UDB is component 1. // Fill stream rates array with zeros to default all streams off; for (index = 0; index < MAV_DATA_STREAM_ENUM_END; index++) streamRates[index] = 0; // QGroundControl GCS lets user send message to increase stream rate streamRates[MAV_DATA_STREAM_RC_CHANNELS] = MAVLINK_RATE_RC_CHAN; streamRates[MAV_DATA_STREAM_RAW_SENSORS] = MAVLINK_RATE_RAW_SENSORS; streamRates[MAV_DATA_STREAM_POSITION] = MAVLINK_RATE_POSITION; streamRates[MAV_DATA_STREAM_EXTRA1] = MAVLINK_RATE_SUE; streamRates[MAV_DATA_STREAM_EXTRA2] = MAVLINK_RATE_POSITION_SENSORS; }
void udb_init(void) { defaultCorcon = CORCON ; #if (BOARD_TYPE == UDB4_BOARD) //<GUIOTT> /* * Clock speed up to 80MHz following the Mark Whitehorn branch on UDB4 * The following values have been parametrized: * DCM frame rate: changed from hardwired 40Hz to parameter HEARTBEAT_HZ * PID loop frame rate: changed from hardwired 40Hz to parameter PID_HZ * ESC frame rate ESC_HZ ** note that the above three rates are not orthogonal * Mark Whitehorn notes * CPU clock: (limitation: UDB4 only: BOARD_TYPE not in {GREEN,RED,UDB3, RUSTYS} * and BOARD_IS_CLASSIC_UDB==0), changed (or added) following parameters and macros * CLK_PHASES set to 2 ** FREQOSC set to 80 MHz (FCY = 40MHz) ** PWMOUTSCALE ratio of Timer 3 frequency T3FREQ to original hardwired 2 MHz *** T3 prescaler was already at max. value of 8 ** ADC_CLK speed also increases at 40MIPS since ADCLK_DIV_N_MINUS_1 was at max. value of 63 ** I2CBRGVAL in magneto_udb4.c now calculated using FREQOSC and CLK_PHASES to achieve 100KHz rate ** CPU_RES defined such that cpu_timer units are .01% ** CPU_LOAD_PERCENT is changed, I think, but untested since raw cpu_timer values are already in units of .01% ** PWINSCALE is added to make pwIn values independent of CPU clock freq. ** Timer 1 period now calculated from HEARTBEAT_HZ (sets DCM rate) */ PLLFBDbits.PLLDIV = 38 ; // FOSC = 80 MHz (XT = 8.00MHz, N1=2, N2=2, M = 40) CLKDIVbits.PLLPOST = 0; // N1=2 CLKDIVbits.PLLPRE = 0; // N2=2 // Clock switching to incorporate PLL __builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary // Oscillator with PLL (NOSC=0b011) __builtin_write_OSCCONL(0x01); // Start clock switching #ifndef SIM while (OSCCONbits.COSC != 0b011);// Wait for Clock switch to occur while(OSCCONbits.LOCK!=1) {}; // Wait for PLL to lock #endif //</GUIOT> #endif udb_flags.B = 0 ; #if (ANALOG_CURRENT_INPUT_CHANNEL != CHANNEL_UNUSED) battery_current.WW = 0 ; battery_mAh_used.WW = 0 ; #endif #if (ANALOG_VOLTAGE_INPUT_CHANNEL != CHANNEL_UNUSED) battery_voltage.WW = 0 ; #endif #if (ANALOG_RSSI_INPUT_CHANNEL != CHANNEL_UNUSED) rc_signal_strength = 0 ; #endif udb_init_leds() ; udb_init_ADC() ; udb_init_clock() ; udb_init_capture() ; #if (MAG_YAW_DRIFT == 1 || USE_BAROMETER == 1) #if (USE_I2C1_DRIVER == 1) I2C1_init(); #endif #if (USE_I2C2_DRIVER == 1) I2C2_init(); // NEW I2C QUEUE FUNCTION FOR MULTIPLE SENSOR SUPPORT #endif // I2C1_init() ; #endif udb_init_GPS() ; udb_init_USART() ; udb_init_pwm() ; #if (USE_OSD == 1) udb_init_osd() ; #endif SRbits.IPL = 0 ; // turn on all interrupt priorities return ; }