コード例 #1
0
ファイル: usb.c プロジェクト: copterpilot/bricklib
void usb_message_loop_return(char *data, uint16_t length) {
	const uint8_t stack_id = get_stack_id_from_data(data);

	if(stack_id == com_stack_id || stack_id == 0) {
		const ComMessage *com_message = get_com_from_data(data);
		if(com_message->reply_func != NULL) {
			com_message->reply_func(COM_USB, (void*)data);
			return;
		}
	}
	for(uint8_t i = 0; i < BRICKLET_NUM; i++) {
		if(bs[i].stack_id == stack_id) {
			baddr[i].entry(BRICKLET_TYPE_INVOCATION, COM_USB, (void*)data);
			return;
		}
	}

	if(stack_id <= com_last_spi_stack_id) {
		send_blocking_with_timeout(data, length, COM_SPI_STACK);
		return;
	}

	if(stack_id <= com_last_ext_id[0]) {
		send_blocking_with_timeout(data, length, com_ext[0]);
		return;
	}
}
コード例 #2
0
ファイル: com_messages.c プロジェクト: Tinkerforge/bricklib
void enumerate(const ComType com, const Enumerate *data) {
	logd("Returning Enumeration for Brick: %d\n\r", com);

	// Enumerate Brick
	EnumerateCallback ec = MESSAGE_EMPTY_INITIALIZER;
	make_brick_enumerate(&ec);

	ec.enumeration_type = ENUMERATE_TYPE_AVAILABLE;

	send_blocking_with_timeout(&ec, sizeof(EnumerateCallback), com);

	// Enumerate Bricklet
	for(uint8_t i = 0; i < BRICKLET_NUM; i++) {
		if(bs[i].uid == 0 || bricklet_attached[i] == BRICKLET_INIT_CO_MCU) {
			continue;
		}

		logd("Returning Enumeration for Bricklet %c\n\r", 'a' + i);

		EnumerateCallback ec = MESSAGE_EMPTY_INITIALIZER;
		make_bricklet_enumerate(&ec, i);

		ec.enumeration_type = ENUMERATE_TYPE_AVAILABLE;

		send_blocking_with_timeout(&ec, sizeof(EnumerateCallback), com);
	}

	com_info.current = com;
}
コード例 #3
0
void com_forward_message(const ComType com, const MessageHeader *data) {
	logd("com forward from %d (fid %d)\n\r", com, data->fid);
	if(com == COM_WIFI2) {
		send_blocking_with_timeout(data, data->length, COM_USB);
	} else {
		send_blocking_with_timeout(data, data->length, COM_WIFI2);
	}
}
コード例 #4
0
void dc_check_error_callbacks(void) {
	const uint16_t external_voltage = dc_get_external_voltage();
	const uint16_t stack_voltage    = dc_get_stack_voltage();

	// Under Voltage if external voltage is below minimum voltage (regardless
	// of stack voltage), or if external voltage is zero and stack voltage is
	// below minimum voltage
	if((dc_message_tick_counter % 1000 == 0 && dc_enabled) &&
	   ((external_voltage > DC_VOLTAGE_EPSILON &&
		 external_voltage < dc_minimum_voltage) ||
		(external_voltage < DC_VOLTAGE_EPSILON &&
		 stack_voltage > DC_VOLTAGE_EPSILON &&
		 stack_voltage < dc_minimum_voltage))) {

		UnderVoltageCallback uvs;
		com_make_default_header(&uvs, com_info.uid, sizeof(UnderVoltageCallback), FID_UNDER_VOLTAGE);
		uvs.voltage = external_voltage < DC_VOLTAGE_EPSILON ? stack_voltage : external_voltage;

		send_blocking_with_timeout(&uvs,
		                           sizeof(UnderVoltageCallback),
		                           com_info.current);

		led_on(LED_STD_RED);
	// If there is no under voltage, we are currently enabled and the
	// status flag is low: There is a short-circuit or over-temperature
	// -> Emergency Shutdown
	} else if(!PIO_Get(&pin_status_flag) &&
	          dc_enabled &&
	          dc_mode == DC_MODE_DRIVE_BRAKE) {
		dc_emergency_shutdown_counter++;
		// Wait for DC_MAX_EMERGENCY_SHUTDOWN ms until callback is emitted
		if(dc_emergency_shutdown_counter >= DC_MAX_EMERGENCY_SHUTDOWN) {
			EmergencyShutdownCallback ess;
			com_make_default_header(&ess, com_info.uid, sizeof(EmergencyShutdownCallback), FID_EMERGENCY_SHUTDOWN);

			send_blocking_with_timeout(&ess,
									   sizeof(EmergencyShutdownCallback),
									   com_info.current);

			dc_disable();
			dc_emergency_shutdown_counter = 0;

			dc_led_error_reason |= DC_LED_ERROR_SHUTDOWN;
			led_on(LED_STD_RED);
		}
	} else {
		dc_emergency_shutdown_counter = 0;
		if(!(dc_led_error_reason & DC_LED_ERROR_SHUTDOWN) &&
		   (dc_tick_counter % 1000 == 0)) {
			led_off(LED_STD_RED);
		}
	}
}
コード例 #5
0
ファイル: com_messages.c プロジェクト: Tinkerforge/bricklib
void get_send_timeout_count(const ComType com, const GetSendTimeoutCount *data) {
#ifdef BRICK_CAN_BE_MASTER
	if(data->communication_method > COM_WIFI2) {
#else
	if(data->communication_method > COM_SPI_STACK) {
#endif
		com_return_error(data, sizeof(GetSendTimeoutCountReturn), MESSAGE_ERROR_CODE_INVALID_PARAMETER, com);
		logblete("Communication Method %d does not exist (get_send_timeout_count)\n\r", data->communication_method);
		return;
	}

	GetSendTimeoutCountReturn gtcr;

	gtcr.header        = data->header;
	gtcr.header.length = sizeof(GetSendTimeoutCountReturn);
	gtcr.timeout_count = com_timeout_count[data->communication_method];

	send_blocking_with_timeout(&gtcr, sizeof(GetSendTimeoutCountReturn), com);
}

#ifdef BRICK_HAS_CO_MCU_SUPPORT
void set_spitfp_baudrate(const ComType com, const SetSPITFPBaudrate *data) {
	uint8_t port = tolower((uint8_t)data->bricklet_port) - 'a';
	if(port >= BRICKLET_NUM) {
		com_return_error(data, sizeof(GetSPITFPErrorCountReturn), MESSAGE_ERROR_CODE_INVALID_PARAMETER, com);
		logblete("Bricklet Port %d does not exist (set_spitfp_baudrate)\n\r", port);
		return;
	}

	if(bricklet_attached[port] == BRICKLET_INIT_CO_MCU) {
		bricklet_spitfp_baudrate[port] = BETWEEN(CO_MCU_MINIMUM_BAUDRATE, data->baudrate, CO_MCU_MAXIMUM_BAUDRATE);
	}

	com_return_setter(com, data);
}
コード例 #6
0
ファイル: com_messages.c プロジェクト: Tinkerforge/bricklib
void get_spitfp_error_count(const ComType com, const GetSPITFPErrorCount *data) {
	uint8_t port = tolower((uint8_t)data->bricklet_port) - 'a';
	if(port >= BRICKLET_NUM) {
		com_return_error(data, sizeof(GetSPITFPErrorCountReturn), MESSAGE_ERROR_CODE_INVALID_PARAMETER, com);
		logblete("Bricklet Port %d does not exist (get_spitfp_error_count)\n\r", port);
		return;
	}

	GetSPITFPErrorCountReturn gsecr;

	gsecr.header                           = data->header;
	gsecr.header.length                    = sizeof(GetSPITFPErrorCountReturn);
	if(bricklet_attached[port] == BRICKLET_INIT_CO_MCU) {
		gsecr.error_count_ack_checksum     = CO_MCU_DATA(port)->error_count.error_count_ack_checksum;
		gsecr.error_count_message_checksum = CO_MCU_DATA(port)->error_count.error_count_message_checksum;
		gsecr.error_count_frame            = CO_MCU_DATA(port)->error_count.error_count_frame;

	} else {
		gsecr.error_count_ack_checksum     = 0;
		gsecr.error_count_message_checksum = 0;
		gsecr.error_count_frame            = 0;
	}

	// There is no overflow in SPITFP on master side possible
	// We keep it to here to be able to use the same API between Co-MCU Bricklets and Bricks
	gsecr.error_count_overflow             = 0;

	send_blocking_with_timeout(&gsecr, sizeof(GetSPITFPErrorCountReturn), com);
}
コード例 #7
0
ファイル: com_messages.c プロジェクト: Tinkerforge/bricklib
void stack_enumerate(const ComType com, const StackEnumerate *data) {
	if(com != COM_WIFI2) {
		StackEnumerateReturn ser = MESSAGE_EMPTY_INITIALIZER;
		ser.header               = data->header;
		ser.header.length        = sizeof(StackEnumerateReturn);
		ser.uids[0]              = com_info.uid;

		uint8_t i = 1;
		for(uint8_t j = 0; j < BRICKLET_NUM; j++) {
			// Search for Bricklet UIDs
			if(bs[j].uid != 0) {
				ser.uids[i]      = bs[j].uid;
				i++;
			}

			// Search for Isolators that are between the Brick and the Bricklet
			if(bs[j].uid_isolator != 0) {
				ser.uids[i]      = bs[j].uid_isolator;
				i++;
			}
		}

		com_info.current = com;

		send_blocking_with_timeout(&ser, sizeof(StackEnumerateReturn), com);
		logd("Stack Enumerate: %lu %lu %lu %lu %lu\n\r", ser.uids[0], ser.uids[1], ser.uids[2], ser.uids[3], ser.uids[4]);
	}

	// Start stack enumerate timer. We will issue an enumeration if there is no
	// enumeration request in the next 1000ms. This is for backwards compatibility to
	// old Brick firmware versions.
	stack_enumerate_timer = system_timer_get_ms();
}
コード例 #8
0
void com_return_setter(const ComType com, const void *data) {
	if(((MessageHeader*)data)->return_expected) {
		MessageHeader ret = *((MessageHeader*)data);
		ret.length = sizeof(MessageHeader);
		send_blocking_with_timeout(&ret, sizeof(MessageHeader), com);
	}
}
コード例 #9
0
ファイル: stepper.c プロジェクト: Nic2012/stepper-brick
void stepper_check_error_signals(void) {
	if(stepper_tick_counter % 1000 != 0 || stepper_state == STEPPER_STATE_OFF) {
		return;
	}

	const uint16_t external_voltage = stepper_get_external_voltage();
	const uint16_t stack_voltage    = stepper_get_stack_voltage();

	// Under Voltage if external voltage is below minimum voltage (regardless
	// of stack voltage), or if external voltage is zero and stack velotage is
	// below minimum voltage

	if((external_voltage > STEPPER_VOLTAGE_EPSILON &&
	    external_voltage < stepper_minimum_voltage) ||
	   (external_voltage < STEPPER_VOLTAGE_EPSILON &&
	    stack_voltage > STEPPER_VOLTAGE_EPSILON &&
	    stack_voltage < stepper_minimum_voltage)) {
		UnderVoltageSignal uvs = {
			com_stack_id,
			TYPE_UNDER_VOLTAGE,
			sizeof(UnderVoltageSignal),
			external_voltage < STEPPER_VOLTAGE_EPSILON ? stack_voltage : external_voltage
		};

		send_blocking_with_timeout(&uvs,
		                           sizeof(UnderVoltageSignal),
		                           com_current);
		led_on(LED_STD_RED);
	} else {
		led_off(LED_STD_RED);
	}
}
コード例 #10
0
void get_remaining_steps(const ComType com, const GetRemainingSteps *data) {
	GetRemainingStepsReturn grsr;

	grsr.header        = data->header;
	grsr.header.length = sizeof(GetRemainingStepsReturn);
	grsr.steps         = stepper_get_remaining_steps();
	send_blocking_with_timeout(&grsr, sizeof(GetRemainingStepsReturn), com);
}
コード例 #11
0
void get_steps(const ComType com, const GetSteps *data) {
	GetStepsReturn gsr;

	gsr.header        = data->header;
	gsr.header.length = sizeof(GetStepsReturn);
	gsr.steps         = stepper_steps;

	send_blocking_with_timeout(&gsr, sizeof(GetStepsReturn), com);
}
コード例 #12
0
void get_target_position(const ComType com, const GetTargetPosition *data) {
	GetTargetPositionReturn gtpr;

	gtpr.header        = data->header;
	gtpr.header.length = sizeof(GetTargetPositionReturn);
	gtpr.position      = stepper_target_position;

	send_blocking_with_timeout(&gtpr, sizeof(GetTargetPositionReturn), com);
}
コード例 #13
0
void getSiteStateStatus(const ComType com, const GetSiteSateStatus *data) {
	GetSiteSateStatusReturn response;
	
	response.header = data->header;
	response.header.length = sizeof(GetSiteSateStatusReturn);
	response.currentStatus = convertFromStateEnumToInt(getSiteState());
	
	send_blocking_with_timeout(&response, sizeof(GetSiteSateStatusReturn), com);
}
コード例 #14
0
void get_stack_input_voltage(const ComType com, const GetStackInputVoltage *data) {
	GetStackInputVoltageReturn gsivr;

	gsivr.header        = data->header;
	gsivr.header.length = sizeof(GetStackInputVoltageReturn);
    gsivr.voltage       = stepper_get_stack_voltage();

	send_blocking_with_timeout(&gsivr, sizeof(GetStackInputVoltageReturn), com);
}
コード例 #15
0
void get_external_input_voltage(const ComType com, const GetExternalInputVoltage *data) {
	GetExternalInputVoltageReturn geivr;

	geivr.header        = data->header;
	geivr.header.length = sizeof(GetExternalInputVoltageReturn);
	geivr.voltage       = stepper_get_external_voltage();

	send_blocking_with_timeout(&geivr, sizeof(GetExternalInputVoltageReturn), com);
}
コード例 #16
0
ファイル: com_messages.c プロジェクト: Tinkerforge/bricklib
void get_chip_temperature(const ComType com, const GetChipTemperature *data) {
	GetChipTemperatureReturn gctr;

	gctr.header          = data->header;
	gctr.header.length   = sizeof(GetChipTemperatureReturn);
	gctr.temperature     = adc_get_temperature();

	send_blocking_with_timeout(&gctr, sizeof(GetChipTemperatureReturn), com);
}
コード例 #17
0
void dc_velocity_reached_callback(void) {
	VelocityReachedCallback vrs;
	com_make_default_header(&vrs, com_info.uid, sizeof(VelocityReachedCallback), FID_VELOCITY_REACHED);
	vrs.velocity = dc_velocity/DC_VELOCITY_MULTIPLIER;

	send_blocking_with_timeout(&vrs,
	                           sizeof(VelocityReachedCallback),
	                           com_info.current);
}
コード例 #18
0
void get_current_velocity(const ComType com, const GetCurrentVelocity *data) {
	GetCurrentVelocityReturn gcvr;

	gcvr.header        = data->header;
	gcvr.header.length = sizeof(GetCurrentVelocityReturn);
	gcvr.velocity      = stepper_velocity > 0xFFFF ? 0xFFFF : stepper_velocity;

	send_blocking_with_timeout(&gcvr, sizeof(GetCurrentVelocityReturn), com);
}
コード例 #19
0
void get_max_velocity(const ComType com, const GetMaxVelocity *data) {
	GetMaxVelocityReturn gmvr;

	gmvr.header        = data->header;
	gmvr.header.length = sizeof(GetMaxVelocityReturn);
	gmvr.velocity      = stepper_velocity_goal;

	send_blocking_with_timeout(&gmvr, sizeof(GetMaxVelocityReturn), com);
}
コード例 #20
0
void is_enabled(const ComType com, const IsEnabled *data) {
	IsEnabledReturn ier;

	ier.header        = data->header;
	ier.header.length = sizeof(IsEnabledReturn);
	ier.enabled       = stepper_state != STEPPER_STATE_OFF;

	send_blocking_with_timeout(&ier, sizeof(IsEnabledReturn), com);
}
コード例 #21
0
void get_motor_current(const ComType com, const GetMotorCurrent *data) {
	GetMotorCurrentReturn gmcr;

	gmcr.header        = data->header;
	gmcr.header.length = sizeof(GetMotorCurrentReturn);
	gmcr.current       = stepper_output_current;

	send_blocking_with_timeout(&gmcr, sizeof(GetMotorCurrentReturn), com);
}
コード例 #22
0
void get_current_consumption(const ComType com, const GetCurrentConsumption *data) {
	GetCurrentConsumptionReturn gccr;

	gccr.header        = data->header;
	gccr.header.length = sizeof(GetCurrentConsumptionReturn);
	gccr.current       = stepper_get_current();

	send_blocking_with_timeout(&gccr, sizeof(GetCurrentConsumptionReturn), com);
}
コード例 #23
0
ファイル: communication.c プロジェクト: Nic2012/stepper-brick
void get_minimum_voltage(uint8_t com, const GetMinimumVoltage *data) {
	GetMinimumVoltageReturn gmvr;

	gmvr.stack_address = data->stack_address;
	gmvr.type          = data->type;
	gmvr.length        = sizeof(GetMinimumVoltageReturn);
	gmvr.voltage       = stepper_minimum_voltage;

	send_blocking_with_timeout(&gmvr, sizeof(GetMinimumVoltageReturn), com);
}
コード例 #24
0
ファイル: communication.c プロジェクト: Nic2012/stepper-brick
void is_sync_rect(uint8_t com, const IsSyncRect *data) {
	IsSyncRectReturn isrr;

	isrr.stack_address = data->stack_address;
	isrr.type          = data->type;
	isrr.length        = sizeof(IsSyncRectReturn);
	isrr.sync_rect     = stepper_sync_rect;

	send_blocking_with_timeout(&isrr, sizeof(IsSyncRectReturn), com);
}
コード例 #25
0
ファイル: communication.c プロジェクト: Nic2012/stepper-brick
void get_max_velocity(uint8_t com, const GetMaxVelocity *data) {
	GetMaxVelocityReturn gmvr;

	gmvr.stack_address = data->stack_address;
	gmvr.type          = data->type;
	gmvr.length        = sizeof(GetMaxVelocityReturn);
	gmvr.velocity      = stepper_velocity_goal;

	send_blocking_with_timeout(&gmvr, sizeof(GetMaxVelocityReturn), com);
}
コード例 #26
0
ファイル: com_messages.c プロジェクト: Tinkerforge/bricklib
void get_adc_calibration(const ComType com, const GetADCCalibration *data) {
	GetADCCalibrationReturn gadccr;
	gadccr.header        = data->header;
	gadccr.header.length = sizeof(GetADCCalibrationReturn);
	gadccr.offset        = adc_offset;
	gadccr.gain          = adc_gain_div;

	send_blocking_with_timeout(&gadccr, sizeof(GetADCCalibrationReturn), com);
	logd("Get ADC Calibration (offset, gain): %ld, %lu\n\r", adc_offset, adc_gain_div);
}
コード例 #27
0
ファイル: com_messages.c プロジェクト: Tinkerforge/bricklib
void is_status_led_enabled(const ComType com, const IsStatusLEDEnabled *data) {
	IsStatusLEDEnabledReturn isleder;

	isleder.header        = data->header;
	isleder.header.length = sizeof(IsStatusLEDEnabledReturn);
	isleder.enabled       = led_status_is_enabled;

	logd("is_status_led_enabled: %d\n\r", isleder.enabled);
	send_blocking_with_timeout(&isleder, sizeof(IsStatusLEDEnabledReturn), com);
}
コード例 #28
0
ファイル: communication.c プロジェクト: Nic2012/stepper-brick
void get_current_velocity(uint8_t com, const GetCurrentVelocity *data) {
	GetCurrentVelocityReturn gcvr;

	gcvr.stack_address = data->stack_address;
	gcvr.type          = data->type;
	gcvr.length        = sizeof(GetCurrentVelocityReturn);
	gcvr.velocity      = stepper_velocity > 0xFFFF ? 0xFFFF : stepper_velocity;

	send_blocking_with_timeout(&gcvr, sizeof(GetCurrentVelocityReturn), com);
}
コード例 #29
0
void get_speed_ramping(const ComType com, const GetSpeedRamping *data) {
	GetSpeedRampingReturn gsrr;

	gsrr.header        = data->header;
	gsrr.header.length = sizeof(GetSpeedRampingReturn);
	gsrr.acceleration  = stepper_acceleration;
	gsrr.deceleration  = stepper_deceleration;

	send_blocking_with_timeout(&gsrr, sizeof(GetSpeedRampingReturn), com);
}
コード例 #30
0
void get_step_configuration(const ComType com, const GetStepConfiguration *data) {
	GetStepConfigurationReturn gscr;

	gscr.header          = data->header;
	gscr.header.length   = sizeof(GetStepConfigurationReturn);
	gscr.step_resolution = tmc2130_reg_chopconf.bit.mres;
	gscr.interpolation   = tmc2130_reg_chopconf.bit.intpol;

	send_blocking_with_timeout(&gscr, sizeof(GetStepConfigurationReturn), com);
}