Skip to content

Target check in chdrv_group_prepare() intitialization function #38

@Montso

Description

@Montso

In the implementation of the hardware initialising function, chdrv_group_prepare(ch_group_t *grp_ptr) in soniclib/ch_driver.c, the default code path has an access to the members grp_ptr->sensor_int_pin and grp_ptr->sensor_trig_pin which are only defined for shasta targets. Therefore compilation fails for whitney targets since the access occurs before the #ifdef INCLUDE_WHITNEY_SUPPORT check, and CHIRP_SENSOR_INT_PIN and CHIRP_SENSOR_TRIG_PIN are undefined for whitney targets at compile time.

int chdrv_group_prepare(ch_group_t *grp_ptr) {
	int ch_err = !grp_ptr;
	uint8_t i;

	if (!ch_err) {
		grp_ptr->sensor_count = 0;

		for (i = 0; i < grp_ptr->num_buses; i++) {
			grp_ptr->queue[i].len          = 0;
			grp_ptr->queue[i].idx          = 0;
			grp_ptr->queue[i].read_pending = 0;
			grp_ptr->queue[i].running      = 0;
		}

		grp_ptr->sensor_int_pin  = CHIRP_SENSOR_INT_PIN;
		grp_ptr->sensor_trig_pin = CHIRP_SENSOR_TRIG_PIN;

#ifdef INCLUDE_WHITNEY_SUPPORT
		ch_err = chbsp_i2c_init();
#endif
	}

	return ch_err;
}

Compile error:
Image

Solution

I have added the following logic to check target definition and pick the appropriate initialization for each target in soniclib/ch_driver.c.

#ifdef INCLUDE_SHASTA_SUPPORT
		grp_ptr->sensor_int_pin  = CHIRP_SENSOR_INT_PIN;
		grp_ptr->sensor_trig_pin = CHIRP_SENSOR_TRIG_PIN;
#elif defined(INCLUDE_WHITNEY_SUPPORT)
		ch_err = chbsp_i2c_init();
#endif

Pull Request added for fix
@tdk-invn-oss/ultrasonic-maintainers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions