Spanish Italian
8426 Users    

SUCKERmenu

11 Little and big indiens

Little and big Indianians
In the common computer and the microcontrollers the minimum memory locations are usually of 8 bit; but when must represent the 16bit values, must decide how are saved in memory.
A data from 16bit obviously occupies two memory location, so there are two possibilities:
- the byte less important stays at the address lower compared with MSB.
- vice versa, the byte less important stays at the address of the great memory of the two.
These two options are named Little Indian e Big Indian.
The commons computer (with processors x86) and also the PIC, using the first notation, while in the network protocols is diffused the use of the second.
The htons function duty is to convert a data at 16bit between two notations. In the article will be used and wants a lot of attention at its use.

u16 htons(u16 val){
	return (((u16)val >> 8 ) | ((u16)val << 8 ));
}

Like already saw the ERXWRPT register contains the address where the controller writes the received dates, while the ERXRDPT register, point to the address where our software reads the received dates; the zone that finds between these two addresses is interdicted to the writing, for impede the dates loss during theirs elaboration.
Told this, results necessary, end of the packet examination, the ERXRDPT register update with the address of the next packet to read (RdPt).

void freeRxSpace(){
	u16 NewRdPt;
	setBank(0);
	NewRdPt = RdPt -1;
	if ((NewRdPt > RX_BUF_END) || (NewRdPt < RX_BUF_START)) NewRdPt = RX_BUF_END;
	BFSReg(ECON2, 0b01000000);    		// decrements EPKTCNT
	writeReg(ERXRDPTL, LOW(NewRdPt));
	writeReg(ERXRDPTH, HIGH(NewRdPt)); 	// empty the buffer space
}

In this method is updated the register and is decrement EPKTCNT.
Because of a problem described in the Errata, the ERXRDPT value must be odd; we know that RdPt is for sure even
(the controller adds a padding in a way to be even), so is enough to subtract one at this value, and then control that doesn't go outside the buffer (RX_BUF_START e RX_BUF_END) limits.

Who's new

  • nona
  • finnsail
  • cristipop
  • vivek
  • solohobby

Who's online

There are currently 0 users and 53 guests online.