Beispiel #1
0
void device_max31855_init(device_max31855_t* const max31855,
		spi_master_regs_t* const spi_master, const int id) {
	datastream_source_init(&max31855->super, id);  //call parents init function
	/*
	 * set method pointer(s) of super-"class" to sub-class function(s)
	 */
	max31855->super.super.update = device_max31855_update;
	max31855->super.send_data = device_max31855_send_data;

	max31855->spi_master = spi_master;

	max31855->control_in = control_port_dummy;
	max31855->control_in.parent = (void*) max31855;
	max31855->control_in.new_control_message = device_max31855_control_message;

	max31855->data_out = &data_port_dummy;
	max31855->error_out = &data_port_dummy;
	max31855->internal_temp_out = &data_port_dummy;

	int prescaler = 0;
	long int clk = get_peri_clock() >> 2;  //spi peripheral divides by 4
	while (clk > MAX31855_MAX_SPI_CLK) {
		clk >>= 1;
		prescaler++;
	}
	spi_set_div((spi_t*) spi_master, prescaler);
	//CPOL = 0, CPAH = 0 is default
	spi_enable((spi_t*) spi_master);
}
void device_input_pins_init(device_input_pins_t* const input_pins,
		const int int_id, port_in_regs_t* port_in) {
	datastream_source_init(&input_pins->super, int_id);  //call parents init function
	/*
	 * set method pointer(s) of super-"class" to sub-class function(s)
	 */
	input_pins->super.send_data = device_input_pins_send_data;

	input_pins->data_out = &data_port_dummy;
	input_pins->control_in = control_port_dummy;
	input_pins->control_in.parent = (void*) input_pins;
	input_pins->control_in.new_control_message =
			device_input_pins_control_message;

	input_pins->port_in = port_in;
}
void device_contrast_box_init(
		device_contrast_box_t* const contrast_box,
		contrast_box_regs_t* contrast_box_peri, const unsigned int id) {
	datastream_source_init(&contrast_box->super, id);  //call parents init function
	/*
	 * set method pointer(s) of super-"class" to sub-class function(s)
	 */
	contrast_box->super.send_data = device_contrast_box_send_data;

	contrast_box->contrast_box = contrast_box_peri;

	contrast_box->data_out = &data_port_dummy;

	//Enable Contrast Box
	contrast_box->contrast_box->control |= CONTRAST_BOX_ENABLE;
	number_of_boxes = contrast_box->contrast_box->control>>15;	//The Number of Boxes specified by the user
}
Beispiel #4
0
void device_gps_nmea_init(device_gps_nmea_t* const gps_nmea,
		uart_light_regs_t* const uart_light, device_gps_sync_mode sync_logger_time,
		const int id) {
	datastream_source_init(&gps_nmea->super, id);  //call parents init function
	/*
	 * set method pointer(s) of super-"class" to sub-class function(s)
	 */
	gps_nmea->super.send_data = device_gps_nmea_send_data;

	gps_nmea->raw_data_out = &data_port_dummy;
	gps_nmea->parsed_data_out = &data_port_dummy;

	gps_nmea->sync_logger_time = sync_logger_time;
	gps_nmea->uart_light = uart_light;

	uart_light_enable_rxint(uart_light);

	gps_nmea->parse_status = 0;
	gps_nmea->parse_package.source_id = id;
}
Beispiel #5
0
void device_uart_raw_init(device_uart_raw_t* const uart_raw,
		uart_light_regs_t* const uart_light, const int id,
		device_uart_raw_print_mode print_mode) {
	datastream_source_init(&uart_raw->super, id);  //call parents init function
	/*
	 * set method pointer(s) of super-"class" to sub-class function(s)
	 */
	uart_raw->super.send_data = device_uart_raw_send_data;

	uart_raw->data_out = &data_port_dummy;

	uart_raw->control_in = control_port_dummy;
	uart_raw->control_in.parent = (void*) uart_raw;
	uart_raw->control_in.new_control_message =
			device_uart_raw_new_control_message;

	uart_raw->print_mode = print_mode;

	uart_raw->uart_light = uart_light;

	uart_light_enable_rxint(uart_light);
}
Beispiel #6
0
void device_ads1299_init(device_ads1299_t* const ads1299,
                         spi_master_regs_t* const spi_master, const int drdy_id, ads1299_srb2 srb2,
                         ads1299_data_rate sample_rate) {
    datastream_source_init(&ads1299->super, drdy_id);

    ads1299->super.super.update = device_ads1299_update;
    ads1299->super.send_data = device_ads1299_send_data;

    ads1299->spi_master = spi_master;

    ads1299->data_out = &data_port_dummy;
    ads1299->control_in = control_port_dummy;
    ads1299->control_in.parent = (void*) ads1299;
    ads1299->control_in.new_control_message = device_ads1299_new_control_message;

    ads1299->running = 0;
    ads1299->use_srb2 = srb2;
    ads1299->auto_bias = ADS1299_AUTO_BIAS_ON;

    spi_set_div((spi_t *) spi_master, 2);
    //CPOL = 0 is default
    spi_set_cpah((spi_t *) spi_master, 1);
    spi_enable((spi_t *) spi_master);
    sleep(10000);

    device_ads1299_send_command(ads1299, ADS1299_COMMAND_RESET);
    device_ads1299_send_command(ads1299, ADS1299_COMMAND_SDATAC);

    device_ads1299_write_reg(ads1299, ADS1299_REG_CONFIG1,
                             0b10010000 | sample_rate);

    if (srb2 == ADS1299_SRB2_OPEN) {
        //we're using positive.  Set to default polarity
        device_ads1299_write_reg(ads1299, ADS1299_REG_LOFF_FLIP, 0b00000000);
    } else {
        //we're using negative.  flip the polarity
        device_ads1299_write_reg(ads1299, ADS1299_REG_LOFF_FLIP, 0b11111111);
    }

    int i;
    for (i = 1; i <= ADS1299_CHANNELS; i++) {  //really necessary to first turn all channels ofg??
        device_ads1299_configure_channel(ads1299, i, ADS1299_CHANNEL_POWER_DOWN,
                                         ADS1299_PGA_24, ADS1299_MUX_NORMAL, srb2);  //turn off the channel
        device_ads1299_change_channel_loff(ads1299, i, ADS1299_LOFF_NCHAN_DEACTIVATE);
        device_ads1299_change_channel_loff(ads1299, i, ADS1299_LOFF_PCHAN_DEACTIVATE);  //turn off any impedance monitoring
    }

    //srb1 setting
    if (srb2 == ADS1299_SRB2_OPEN) {
        device_ads1299_write_reg(ads1299, ADS1299_REG_BIAS_MISC1, 0b00100000);
    }

    //activate auto bias
    device_ads1299_set_auto_bias_generation(ads1299, ADS1299_AUTO_BIAS_ON);
    //configure internal test signal
    device_ads1299_config_test_signal(ads1299, ADS1299_TEST_SIG_AMP_1X,
                                      ADS1299_TEST_SIG_FREQ_FAST);

    device_ads1299_config_loff(ads1299, ADS1299_LOFF_FREQ_31_2HZ,
                               ADS1299_LOFF_MAG_6NA, ADS1299_LOFF_THRES_95);

    //acitvate and configure all channels
    device_ads1299_configure_all_channels(ads1299, ADS1299_CHANNEL_ACTIVE,
                                          ADS1299_PGA_24, ADS1299_MUX_NORMAL, srb2);
}