예제 #1
0
int main(void)
{
	mcu_init();
#if 1
	udb_init();
#else
	// can we move to this and avoid calling udb_init()?
	udb_init_clock();
	udb_init_irq();
#endif
	while (1)
	{
		udb_run();
	}
	return 0;
}
예제 #2
0
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 ;
}