Web 51 P-Code Interpreter

P-Code, arith, branch  software.html  Serial line

Part 3 - P-Instructions for basic network operations

Contents of LIBK, basic network functions

instruction parameters description operation flags
ptstr2s (B)a, (W)offset, (W)lng Compare String to Receive Frame for(i=0;i<lng;i++)(B)@a[i]-(B)@receive[offset+i]) zflag
ptstr2e (B)e, (W)offset, (W)lng Compare eepromString to Receive Frame for(i=0;i<lng;i++)(B)@e[i]-(B)@receive[offset+i]) zflag
pr2s (B)a, (W)offset, (W)lng Copy from Receive Frame to String for(i=0;i<lng;i++)(B)@a[i]=(B)@receive[offset+i])  
px2s (B)a, (W)offset, (W)lng Copy from Xmit Frame to String for(i=0;i<lng;i++)(B)@a[i]=(B)@receive[offset+i])  
pi2x (W)offset, (W)imm Mov Word Immediate to Xmit Frame (W)@xmit[offset]=(W)imm  
ps2x (W)offset, (B)a, (W)lng Mov String to Xmit Frame for(i=0;i<lng;i++)(B)@xmit[offset+i]=(B)@a[i])  
pe2x (W)offset, (B)e, (W)lng Mov eepromString to Xmit Frame for(i=0;i<lng;i++)(B)@xmit[offset+i]=(B)@e[i])  
pc2x (W)offset, (B)c, (W)lng Mov codeString to Xmit Frame for(i=0;i<lng;i++)(B)@xmit[offset+i]=(B)@c[i])  
pz2x (W)offset, (W)lng Mov Zero to Xmit Frame for(i=0;i<lng;i++)(B)@xmit[offset+i]=0)  
pr2x (W)xmit_offset, (W)receive_offset, (W)lng Mov Receive Frame to Xmit Frame for(i=0;i<lng;i++)(B)@xmit[xmit_offset+i]=@receive[receive_offset+i])  

Most P-Instructions use DMA channel of the Ethernet controller to directly transfer data between the data field and the controller. Exceptions exist: the pi2x instruction uses variable workreg to store the constant passed as its parameter; and the pr2x instruction must use transfer through a temp data area, since there are no separate DMA channels for transmitted and received frames. It copies data portion by portion using buffer ebuf.

instruction parameters description operation flags
xmit_frame (W)lng Transmit Xmit Frame Transmit lng bytes to Ethernet
psendchar (B)char Write char to Xmit Frame @xmit[tcpWritePointer++]=char
bflush   Flush ebuf to Xmit Frame  

Similarly to pr2x, instruction psendchar does not write data directly into the Ethernet controller but uses buffer ebuf. Buffer is controlled by two global variables: tcpWritePointer contains offset in the xmit frame where data will be stored, and is automatically incremented as the data are copied from ebuf to the xmit frame. unwrited contains offset in ebuf; however, the actual offset is tcpWritePointer + unwrited. Before the first call to psendchar, both variables must be initialized - correct offset stored into tcpWritePointer and unwrited set to 0. It is necessary to call bflush after writing data with psendchar.

instruction parameters description operation flags
in_checksum   Calculate Frame checksum  

in_checksum calculates checksum of the block stored in the Ethernet controller memory. The block is defined by its absolute address in the controller memory which is passed in the global variable chkaddr, and its length passed in global variable chklen. Result as well as initial value are passed in global variable chkaddr.

Sponzored by LPhard Ltd. Graphics by GIMP Created by EasyPad

(c)Copyright 2000 - 2002, HW server & Radek Benedikt
Web51@HW.cz, Web51.HW.cz
P-Code, arith, branch  Obsah  Serial line