Exemple #1
0
// main programm
void main(void)
{
   // Hardware initialization
   HW_init();
   // setup interrupts
   setup_timer1(TMR_INTERNAL|TMR_DIV_BY_256);   
   
   // Command buffer initialization
   init_ESPBuffer();

   while(true)
   {
      // usb for debug
      usb_task();
      
      // wi-fi esp8266
      wifi_task();
      
      /*******************************
      * *****************************
      * User code must be situated here!
      * *****************************
      *******************************/

   }//while(true)
}
Exemple #2
0
int main(void)
{
	uint8_t i;

	cli();
	MCUSR = 0;
	wdt_disable();

	//TODO replace by an ana comp polling loop
	_delay_ms(10);

	setup_datastructs();
	setup_led();
	setup_ar_uart();
	setup_adc();
	setup_pulse_input();
	setup_analog_comparator();
	setup_timer0();
	setup_timer1();
	
	// initialize the CTRL buffers
	ctrlInit();
	// initialize the SPI in slave mode
	setup_spi(SPI_MODE_0, SPI_MSB, SPI_INTERRUPT, SPI_SLAVE);

	// initialize the Si4421/RFM12 radio and buffers
	rfm12_init();

	// the clk/8 fuse bit is set
	clock_prescale_set(clock_div_1);
	FLAG_CLR_ICF1();
	sei();


	for(;;) {
		if (spi_status & SPI_NEW_CTRL_MSG) {
			ctrlDecode();
			spi_status &= ~SPI_NEW_CTRL_MSG;
		}

		for (i = 0; i < max_analog_sensors; i++) {
			if (state[i].flags & STATE_POWER_CALC) {
				calculate_power(&state[i]);
				state[i].flags &= ~STATE_POWER_CALC;
				state[i].flags |= STATE_POWER;
			}
		}

		rfm12_tick();
	}

	return 0;
}
Exemple #3
0
int main(void)
{
	uint8_t i;

	cli();

	// RS-485: Configure PD5=DE as output pin with low as default
	DDRD |= (1<<DDD5);
	// set high to transmit
	//PORTD |= (1<<PD5);

	setup_datastructs();
	setup_led();
	setup_adc();
	setup_pulse_input();
	setup_analog_comparator();
	setup_timer1();
	
	// initialize the CTRL buffers
	ctrlInit();
	// initialize the UART hardware and buffers
	uartInit();
	// initialize the SPI in slave mode
	setup_spi(SPI_MODE_2, SPI_MSB, SPI_INTERRUPT, SPI_SLAVE);

	sei();


	for(;;) {
		if (spi_status & SPI_NEW_CTRL_MSG) {
			ctrlDecode();
			spi_status &= ~SPI_NEW_CTRL_MSG;
		}

		for (i = 0; i < MAX_ANALOG_SENSORS; i++) {
			if (state[i].flags & STATE_POWER_CALC) {
				calculate_power(&state[i]);
				state[i].flags &= ~STATE_POWER_CALC;
				state[i].flags |= STATE_POWER;
			}
		}
	}

	return 0;
}
Exemple #4
0
void config(void)
{	
	//Define inputs/outputs
	define_io();		
	
	//Assignation des périphériques
	peripheral_pin_select();
	
	//Config peripherals:
 	setup_usart1(); 		//PC/GPS
	setup_usart2(); 		//Radio
	setup_timer1();			//10ms timebase
	setup_adc();			//ADC
	
	//Encoder interrupts:
	_INT0IF = 0;
	_INT1IF = 0;
	_INT0IE = 1;
	_INT1IE = 1;
	
	//Disable unwanted interrupts:
	_U1TXIE = 0;
	_U2TXIE = 0;
	_SPI1IE = 0;
	_SPI1IF = 0;
	_T3IE = 0;
	_T2IE = 0;
	_OC2IE = 0;
	_IC1IE = 0;
	_OC1IE = 0;
	_IC1IE = 0;
	_U1ERIE = 0;
	_U2ERIE = 0;
	_PMPIE = 0;
	
	#ifdef USE_GLCD
	//Init GLCD
	GLCD_Initalize();
	GLCD_ClearScreen();
	#endif		
}
int kbd_drv_init (void)
{
	unsigned long flags;

	save_flags_cli (flags);
#ifndef CONFIG_SA1100_ITSY
	initKBCTL();
#endif
	setup_timer1( (TIMER1_RATE+30)/60 );
	if (request_irq (IRQ_OST1, kbd_drv_rx, SA_SHIRQ, "keyboard", NULL) != 0)
	  printk("Could not allocate keyboard receive IRQ!");
	/* LSB should use panic() above */
	
	restore_flags (flags);

	printk (KERN_INFO "Keyboard driver v%d.%02d\n", VERSION/100, VERSION%100);
	//printk("**** Turning off console printing ****\n");

	/* Turn off console printk messages */
#ifndef CONFIG_SA1100_ITSY
 	// con_printable(0);
#endif
	return 0;
}
Exemple #6
0
int main (void)
{
	int i=0;
        tmp_debug = 0;

	//Setup oscillator/ports/pins first
	setup_oscillator();
	setup_ports();
	setup_peripheral_pin_select();
	setup_interrupt_priorities();

        //init_temperature_model();

	//Blinking HB LED and Timestamp
	#ifdef USE_DIO
	setup_dio();
	#endif
	
	//ToDo Used?
	#ifdef USE_TIMER1 
	setup_timer1(); //do before setup_pwm
	#endif	//ToDo: there was a missing #endif, maybe that's why disabling Timer1 was breaking the code!
	
	//Motor control PWM
	#ifdef USE_PWM
	//setup_pwm();
	#endif
	
	//Brushless motor
	#ifdef USE_BLDC
	setup_bldc();
	#endif
		
	//Torque PID and Current PID
	#ifdef USE_CONTROL
	setup_control();
	#endif
	
	//Analog to Digital
	#ifdef USE_ADC        
	setup_adc();
	#endif
	
	//Torso external ADC
	#ifdef USE_ADC_SPI
	setup_adc_spi();
	#endif
	
	//Current measurment, control and limitation
	#ifdef USE_CURRENT
	setup_current();
	#endif
	
	//ToDo: Remvove?
	#ifdef USE_TIMER3
	setup_timer3();
	#endif
	
	//VerteX SPI Encoder
	#ifdef USE_ENCODER_VERTX
	setup_vertx();
	#endif
	
	//Torso motor brake
	#ifdef USE_BRAKE
	setup_brake();
	#endif

	//EtherCAT Communication
	#ifdef USE_ETHERCAT
	while (!eeprom_loaded())	//Wait until ESC is ready
		SetHeartbeatLED;
	setup_ethercat();
	ClrHeartbeatLED;
	#endif

	setup_interrupt_priorities();

        if (RCONbits.WDTO)
            SetHeartbeatLED;

        //RCONbits.SWDTEN = 1;//enable watchdog timer

        if (RCON & 0x03 == 0x03)
        {
            RCONbits.BOR = 0;
            RCONbits.POR = 0;
        }
        
        rcon_reg = RCON;


	while(1)
	{
		if (i++%10001==0)
		{
			//ToggleHeartbeatLED();
                        #if defined USE_ETHERCAT
                        step_ethercat();
                        #endif
		}
		
	}
}
void setup() {
	// initialize the digital pin as an output.
	pinMode(led, OUTPUT);
	setup_timer1();
//	Serial.begin(115200);
}