Beispiel #1
0
int main(int argc, char **argv) {
    int ret, opt;

    memset(&rs485_data, 0, sizeof(rs485_data));

    rs485_data.speed = DEFAULT_SPEED;

    while ((opt = getopt(argc, argv, "i:s:h?")) != -1) {
	switch (opt) {
	case 's':
	    rs485_data.speed = atoi(optarg);
	    break;
	case 'h':
	case '?':
	    print_usage(basename(argv[0]));
	    exit(EXIT_SUCCESS);
	    break;
	default:
	    fprintf(stderr, "Unknown option %c\n", opt);
	    print_usage(basename(argv[0]));
	    exit(EXIT_FAILURE);
	}
    }

    ret = init_rs485(&rs485_data);
    if (ret > 0)
	exit(EXIT_FAILURE);

    while (1) {
    }
    ret = close_rs485(&rs485_data);
    if (ret > 0)
	exit(EXIT_FAILURE);
    return 0;
}
Beispiel #2
0
//Initialize and enables all the peripherals
void init_peripherals(void)
{
	//Motor control variables & peripherals:
	init_motor();
	
	//Init Control:
	init_ctrl_data_structure();
	
	//Timebases:
	init_tb_timers();
	
	//UART 2 - RS-485
	init_rs485();
	
	//Analog, expansion port:
	init_analog();
	
	//Clutch:
	init_clutch();	
	
	//Enable Global Interrupts
    CyGlobalIntEnable; 
	
	//I2C1 (internal, potentiometers, Safety-CoP & IMU)
	init_i2c1();
	
	//Peripherals that depend on I2C:
	#ifdef USE_I2C_INT	
		
		//MPU-6500 IMU:
		#ifdef USE_IMU
		init_imu();
		CyDelay(25);
		init_imu();
		CyDelay(25);
		init_imu();
		CyDelay(25);
		#endif	//USE_IMU
		
		//Strain amplifier:
		#ifdef USE_STRAIN
		init_strain();
		#endif	//USE_STRAIN
		
	#endif	//USE_I2C_INT	
	
	//I2C2 (external)	
	#ifdef USE_I2C_EXT
	
	//Enable pull-ups:
	I2C_OPT_PU_Write(1);
		
	//I2C2 peripheral:
	init_i2c2();
	
	//Set RGB LED - Starts Green
	i2c_write_minm_rgb(SET_RGB, 0, 255, 0);
	
	#endif //USE_I2C_EXT
	
	//Magnetic encoder:
	init_as5047();
	
	// First DieTemp reading is always inaccurate -- throw out the first one
	#ifdef USE_DIETEMP	
	DieTemp_1_GetTemp(&temp);
	#endif
	
	//USB CDC
	#ifdef USE_USB	
	init_usb();
	#endif	//USE_USB
}