SPI Wild While Usage

Post Reply
FredCailloux
Posts: 69
Joined: Sat Mar 28, 2015 4:45 am
Location: Quebec - Canada

SPI Wild While Usage

Post by FredCailloux » Mon Feb 08, 2016 10:10 pm

I have this code snipet from an SPI driver for the LS7366 and it include a strange usage of the While keyword.
while (pReg->stat.SPIRBF == 0); with no Loop or internal conditional execution, just the plain While() with one condition and that's it? :o

Code: Select all

void read_7366(int reg, unsigned char *bytearray) {
	unsigned char ir = (0x1 << 6 ) | (reg << 3); 			//Instruction
	unsigned char ReadData;

	if ( (reg == MDR0) || (reg == MDR1) || (reg == STR) ) {
		volatile SpiRegMap*	pReg=SpiMapTbl[SPICHN-1];	//One byte to read
		SLAVE_SELECT = 0;
		delay();						//Setup time
		SpiChnPutC(SPICHN, ir);					//Write instruction after TX buffer empty
		while (pReg->stat.SPIRBF == 0);				//Wait for RX buffer full
		ReadData = SpiChnGetC(SPICHN);				//Read what was clocked in during last write (nothing)
		SpiChnPutC(SPICHN, 0);					//Clock out dummy byte after TX buffer empty
		while (pReg->stat.SPIRBF == 0);				//Wait for RX buffer full
		ReadData = SpiChnGetC(SPICHN);				//Read what was clocked in during last write (register)
		*bytearray = ReadData;
		SLAVE_SELECT = 1;					//End comm
		return; }
Cna anyone explain the details and the why ?
Thanks
Prashant Tripathi :idea: Knowing is to the Self what knowledge is to the ego

User avatar
majenko
Site Admin
Posts: 2165
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: SPI Wild While Usage

Post by majenko » Mon Feb 08, 2016 10:29 pm

It is exactly what it says it is.

While SPIRBF is 0 do nothing.

That is, wait here until SPIRPF is anything other than 0. I.e., wait for something to arrive in the receive buffer before continuing.

In BASIC it would be something like:

Code: Select all

10 IF SPIRBF = 0 THEN GOTO 10
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

Post Reply