Espanol
AddThis Social Bookmark Button

10 Reception

Reception
First of all, to verify if it was received a packet, it is controlled that the EPKTCNT register isn't zero; actually this register maintains the received packets counts, and, once elaborated the packet, is decrement.
The happened reception can be saw through the EIR.RXIF bit, but after the Errata, the value of this bit isn't safe.
The dates received are wrote by the controller in the reception buffer beginning with ERXWRPT address, which in initialization phase is automatically set at zero.
At these addresses the first bytes don't belong to the packet, but there are control byte: the first two contain the address where will be write the next packet; the others aren't so important (consult the datasheet to know more).
Let's explain two new variables, the first one is initialized at zero in encInit:

u16  RdPt;
u16  packetStart;

RdPt contains tha address of the next packet, while the packetStart the address of the current packet.
Let's see the methode MACGetHeader:

void MACGetHeader(MAC_Header* header){
	u8 buf[6];

	packetStart = RdPt;					// save RdPt in packetStart
	setBank(0);
	writeReg(ERDPTL, LOW(RdPt));				//
	writeReg(ERDPTH, HIGH(RdPt));				// ERDPT = RdPt
	encGetArray(&buf[0], 6);				// read the 6 byte control 
	RdPt = (u16)((u16)buf[0] | ((u16)buf[1] << 8 )); 	// punter next packet

	encGetArray((u8*)header, sizeof(MAC_Header));		// read the MAC heading 

	header->type = htons(header->type);			// swapp the field type
}

Like you can see, the first thing that is charged in ERDPT the read packet address (saved in RdPt, initially zero), then are read the control bytes and are saved the new RdPt; al last is read the MAC and saved in header.
The htons instructions is defined in the file utility.c; it's explain its utility in this elaboration: