Variable definition question

Hi all,

Look at this piece of code:

======= Code ============================================

void io3w_read(u8 number_bytes, u8 *data_in)
{
	[color=red]u16 idata tmp;[/color]
	u8 i;

	// Loop and read back the 16 bit data from the part and convert to 8 bit data.
	for (i=0; i < (number_bytes+1)/2; i++)
	{
		io3w_operation(READ, IO3W_ADDR | (i+8), &tmp);
		data_in[(i*2)+0] = (u8)(tmp >> 8);
		if (i < number_bytes)
		{
			data_in[(i*2)+1] = (u8)(tmp >> 0);
		}
	}

}

======= Code ============================================

My question concerns the red highlighted part. I am quite sure “u16” means “uint16_t”, but what does “idata” followed by “tmp” (with no comma) mean? Is it a mistake, or is “idata” some kind of data type?

Thanks!

– Roger

I don't recognise idata as a modifier, but it could easily be #defined to something else. I'd expect the compiler to complain if idata was merely another arbitrary variable name, and since the code in that scope doesn't refer to it that probably isn't what it is. (You could confirm that theory by changing 'idata' to 'krupski' and see whether it still compiles.)

It's a storage class qualifier.
http://www.keil.com/support/man/docs/c51/c51_le_idata.htm

Edit: I don't think it will have any equivalent on the AVR - it looks like an attempt to keep local variables in internal memory and therefore faster.

AWOL:
It's a storage class qualifier.
http://www.keil.com/support/man/docs/c51/c51_le_idata.htm

Edit: I don't think it will have any equivalent on the AVR - it looks like an attempt to keep local variables in internal memory and therefore faster.

Ah I see. I'll bet I can just do away with it altogether. Any var I declare is in SRAM anyway.

What I am doing, as you can probably guess, is convert that code to run on the AVR (i.e. Arduino). The whole thing (much more than I posted) is a driver for the Si470x FM radio chip in 3 wire mode (ENABLE, SCLK and SDIO).

At first I tried to use SPI by tying MISO and MOSI together to make an SDIO pin, but it didn't work! :slight_smile:

The FM radio board works fine in 2 wire (i.e. the Wire library), but I want to be able to use it on any pins, not the dedicated SDA/SCL pins.

Thanks for the input. That site you linked to makes sense. I don't think I even need that keyword.

The data sent to and from the chip is tiny (only 16 words of register data), so speed isn't important. A bit-bang driver is good enough.

Krupski:

AWOL:
It's a storage class qualifier.
http://www.keil.com/support/man/docs/c51/c51_le_idata.htm

Edit: I don't think it will have any equivalent on the AVR - it looks like an attempt to keep local variables in internal memory and therefore faster.

Ah I see. I'll bet I can just do away with it altogether. Any var I declare is in SRAM anyway.

What I am doing, as you can probably guess, is convert that code to run on the AVR (i.e. Arduino). The whole thing (much more than I posted) is a driver for the Si470x FM radio chip in 3 wire mode (ENABLE, SCLK and SDIO).

At first I tried to use SPI by tying MISO and MOSI together to make an SDIO pin, but it didn't work! :slight_smile:

The FM radio board works fine in 2 wire (i.e. the Wire library), but I want to be able to use it on any pins, not the dedicated SDA/SCL pins.

Thanks for the input. That site you linked to makes sense. I don't think I even need that keyword.

The data sent to and from the chip is tiny (only 16 words of register data), so speed isn't important. A bit-bang driver is good enough.

SparkFun seems to sell a version using that chip and has some kind of arduino sketch to support it, you night want to check it out:

SparkFun FM Tuner Evaluation Board - Si4703 - WRL-12938 - SparkFun Electronics?

http://www.sparkfun.com/datasheets/BreakoutBoards/Si4703_Example.pde

Lefty