Using Trace to Debug Real-Time Systems 

by Michael Lindahl



Listing One



// This function is obviously not correct for actually reading 

// from an i2c bus, but is an example of a function that could

// read from a shared resource.

int read_i2c_value(int DEVICE_ID)

{

    // Select the I2C device

    select_i2c_device(DEVICE_ID);

    // Select the register on this device that we want to read

    write_i2c_register();

    // Actually read the register

    return read_i2c_register();

}

#define TEMPERATURE_SENSOR 1

#define EEPROM 2



void TaskA_entry()

{

    while(1) {

	int temp_c;

	...

	temp_c = read_i2_value(TEMPERATURE_SENSOR);

	if(temp_c > 100) {

	     // Error.  The temperature cannot possibly be

	     // above boiling!

	    printf("Error reading temperature sensor!\n");

	}

	...

    }

}

void TaskB_entry()

{

    while(1) {

	int eeprom_value;

	...

	eeprom_value = read_i2c_value(EEPROM);

	...

    }

}











1



