Пример #1
0
int main() {
  char *testdata, *testin, *testexp, *testout, *diffcmd;
  const char *srcdir;
  DIR *dp;
  struct dirent *de;

  if(!(srcdir = getenv("srcdir")))
    srcdir = ".";
  dp = opendirf(&testdata, "%s/%s", srcdir, "testdata-rc");
  while((de = xreaddir(testdata, dp))) {
    if(strchr(de->d_name, '.') || strchr(de->d_name, '~'))
      continue;
    xasprintf(&testin, "%s/%s", testdata, de->d_name);
    xasprintf(&testout, "%s/%s.out", testdata, de->d_name);
    xasprintf(&testexp, "%s/%s.exp", testdata, de->d_name);
    reset_rc();
    read_rc_path(testin);
    write_rc_path(testout);
    xasprintf(&diffcmd, "diff -u %s %s", testexp, testout);
    if(system(diffcmd))
      exit(1);
  }

  return 0;
}
Пример #2
0
void mwii_process_events(void){
	compute_rc_values(); 
	
	//TIMSK0 |= _BV(TOIE0); 
	if(timestamp_expired(brd->rc_reset_timeout)){
		reset_rc(); 
	}
	
}
Пример #3
0
void mwii_init(void){
	//soc_init(); 
	time_init(); 
	uart_init(0, 38400); 
	gpio_init();
	//spi_init(); 
	twi_init(0); 
	pwm_init(); 
	adc0_init_default(); 
	sei(); 
	
	// setup printf stuff (specific to avr-libc)
	fdev_set_udata(&uart_fd, uart_get_serial_interface(0)); 
	stdout = &uart_fd; 
	stderr = &uart_fd; 
	
	/*
	// setup stdout and stderr (avr-libc specific) 
	fdev_setup_stream(stdout, _serial_fd_putc, _serial_fd_getc, _FDEV_SETUP_RW); 
	fdev_set_udata(stdout, uart_get_serial_interface(0)); 
	fdev_setup_stream(stderr, _serial_fd_putc, _serial_fd_getc, _FDEV_SETUP_RW); 
	fdev_set_udata(stderr, uart_get_serial_interface(0)); 
*/
	// first thing must enable interrupts
	kdebug("BOOT\n");
	
	gpio_configure(GPIO_MWII_LED, GP_OUTPUT); 
	//gpio_set(GPIO_MWII_LED); 
	
	gpio_configure(GPIO_MWII_MOTOR0, GP_OUTPUT);
	gpio_configure(GPIO_MWII_MOTOR1, GP_OUTPUT);
	gpio_configure(GPIO_MWII_MOTOR2, GP_OUTPUT);
	gpio_configure(GPIO_MWII_MOTOR3, GP_OUTPUT);
	
	gpio_configure(GPIO_MWII_RX0, GP_INPUT | GP_PULLUP | GP_PCINT);
	gpio_configure(GPIO_MWII_RX1, GP_INPUT | GP_PULLUP | GP_PCINT);
	gpio_configure(GPIO_MWII_RX2, GP_INPUT | GP_PULLUP | GP_PCINT);
	gpio_configure(GPIO_MWII_RX3, GP_INPUT | GP_PULLUP | GP_PCINT);
	
	// calibrate escs
	//mwii_calibrate_escs(); 
	
	// set initial motor speeds
	mwii_write_motors(MINCOMMAND, MINCOMMAND, MINCOMMAND, MINCOMMAND); 
	
	brd->gpio0 = gpio_get_parallel_interface();
	
	brd->twi0 = twi_get_interface(0);
	
	/* 
	// I2C scanner 
	for(int c = 0; c < 255; c++){
		uint8_t buf[2]; 
		i2c_start_read(brd->twi0, c, buf, 1); 
		if(i2c_stop(brd->twi0) == 1 && c & 1){
			kprintf("Device %x@i2c\n", c >> 1); 
		}
		delay_us(10000); 
	}
	*/
	gpio_set(GPIO_MWII_LED);
	 
	mpu6050_init(&brd->mpu, brd->twi0, MPU6050_ADDR); 
	kdebug("MPU6050: %s\n", ((mpu6050_probe(&brd->mpu))?"found":"not found!")); 
	
	bmp085_init(&brd->bmp, brd->twi0, BMP085_ADDR); 
	kdebug("BMP085: found\n");
	
	hmc5883l_init(&brd->hmc, brd->twi0, HMC5883L_ADDR);
	
	gpio_clear(GPIO_MWII_LED); 
	
	hcsr04_init(&brd->hcsr, brd->gpio0, GPIO_MWII_HCSR_TRIGGER, GPIO_MWII_HCSR_ECHO); 
	
	reset_rc();
	
	mwii_calibrate_mpu6050(); 
	// let the escs init as well
	delay_us(500000L); 
}