📄 rtl8019.lst
字号:
183 1 WriteReg(RSARL_WPAGE0,(BYTE)address);
184 1 WriteReg(RBCRH_WPAGE0,(BYTE)((size>>8)&0x00ff));
185 1 WriteReg(RBCRL_WPAGE0,(BYTE)size);
186 1 WriteReg(CR,(0x00 | CR_REMOTE_READ | CR_START_COMMAND));
187 1 for(Endp = buff + size; buff < Endp;)
188 1 {
189 2 *(buff++) = ReadReg(REMOTE_DMA_PORT);
190 2 }
191 1 /* complete dma */
192 1 WriteReg(RBCRH_WPAGE0,0);
193 1 WriteReg(RBCRL_WPAGE0,0);
194 1 WriteReg(CR,((PrePage&0xC0) | CR_ABORT_COMPLETE_DMA | CR_START_COMMAND));
195 1 }
196 /* call this function to send a packet by RTL8019. packet store in ram
197 starts at 'buffer' and its size is 'size'. 'size' should not large than
198 MAX_PACKET_SIZE or the excess data will be discard. */
199 BOOL RTLSendPacket(BYTE DT_XDATA * buffer,WORD size) REENTRANT_SIG
200 {
201 1 BYTE StartPage;
202 1 BYTE PrePage;
203 1
204 1 /* if send is already running */
205 1 if(InSending == TRUE)
206 1 return FALSE;
207 1 else
208 1 InSending = TRUE;
209 1 /* store page */
210 1 PrePage = ReadReg(CR);
211 1
212 1 /* check pakcet size */
213 1 if(size < MIN_PACKET_SIZE)
214 1 {
215 2 size = MIN_PACKET_SIZE;
216 2 }
217 1 else
218 1 {
219 2 if(size > MAX_PACKET_SIZE)
220 2 size = MAX_PACKET_SIZE;
221 2 }
222 1
223 1 /* write packet to ram */
224 1 if(LastSendStartPage == SEND_START_PAGE0)
225 1 {
226 2 StartPage = SEND_START_PAGE1;
227 2 LastSendStartPage = SEND_START_PAGE1;
228 2 }
229 1 else
230 1 {
231 2 StartPage = SEND_START_PAGE0;
232 2 LastSendStartPage = SEND_START_PAGE0;
233 2 }
234 1 RTLWriteRam((WORD)(((WORD)StartPage)<<8),size,buffer);
235 1
236 1 /* wait for last time trasmition to complete */
237 1 while((ReadReg(CR) & CR_TXP) == CR_TXP);
238 1
239 1 /* write trasmit start page and size */
C51 COMPILER V8.05a RTL8019 11/16/2006 19:20:21 PAGE 5
240 1 RTLPage(0);
241 1 WriteReg(TPSR_WPAGE0,StartPage); /* TPSR */
242 1 WriteReg(TBCRL_WPAGE0,(BYTE)size);/*low */
243 1 WriteReg(TBCRH_WPAGE0,(BYTE)((size>>8)&0x00ff)); /*high*/
244 1 WriteReg(CR,((PrePage&0xC0) | CR_ABORT_COMPLETE_DMA | CR_TXP | CR_START_COMMAND));
245 1
246 1 InSending = FALSE;
247 1 return TRUE;
248 1 }
249
250 /* call this function to receive a ethernet packet from RTL8019.
251 return value:
252 NULL: no packet can receive yet.
253 not NULL:
254 a address point to MemHead. This Head contain merory
255 Imformation(memory start address, memory end address ...) of
256 received packet. Memory is allocated by function 'MemAllocate(WORD size)'.
257 a example of struct SMemHead is:
258
259 struct SMemHead
260 {
261 BOOL used; // if in using
262 BYTE DT_XDATA *pStart; // the start address of memory
263 BYTE DT_XDATA *pEnd;
264 };
265
266 You can use your own struct SMemHead and MemAllocat function in your project.
267 */
268 struct SMemHead DT_XDATA * RTLReceivePacket() REENTRANT_SIG
269 {
270 1 BYTE curr,bnry;
271 1 WORD address;
272 1 WORD PacketSize;
273 1 struct SMemHead DT_XDATA *MemHead;
274 1
275 1 /* if send is running don't crrupt RTL register*/
276 1 if(InSending == TRUE)
277 1 return NULL;
278 1
279 1 MemHead = NULL;
280 1
281 1 RTLPage(1);
282 1 curr = ReadReg(CURR_RPAGE1);
283 1 RTLPage(0);
284 1
285 1 /* check if startpage exceed range becasue of unknow error */
286 1 if(StartPageOfPacket >= RECEIVE_STOP_PAGE || StartPageOfPacket < RECEIVE_START_PAGE)
287 1 {
288 2 /* use curr as the StartPageOfPacket in this case */
289 2 StartPageOfPacket = curr;
290 2 return NULL;
291 2 }
292 1
293 1 /* check if there is packets to read */
294 1 if(StartPageOfPacket == curr)
295 1 return NULL;
296 1
297 1 /*
298 1 * read a packet
299 1 */
300 1
301 1 /* read packet head imformation */
C51 COMPILER V8.05a RTL8019 11/16/2006 19:20:21 PAGE 6
302 1 address = ((WORD)StartPageOfPacket)<<8;
303 1 RTLReadRam(address,4,Head);
304 1
305 1 /* check rsr, if isn't a good packet no read */
306 1 if(Head[0] & RSR_RECEIVE_NO_ERROR)
307 1 {
308 2 /* this is a good packet */
309 2
310 2 /* packet size, sub 4 bytes, this 4 byte is MAC checksum */
311 2 PacketSize = ((WORD)Head[3])*256 + Head[2] - 4;
312 2
313 2 /* allocate buffer and read packet into buffer */
314 2 if((MemHead = MemAllocate(PacketSize)) != NULL)
315 2 {
316 3 /* if packet is put from bnry+1 to receive_stop_page and receive
317 3 start page to next packet startpage, that is if bnry+1 > next
318 3 packet start page and next start page != receive_start_page,
319 3 we need read by two times. the first time from bnry+1 to receive
320 3 _stop_page, the second time from receive start page to next packet
321 3 startpage.
322 3 */
323 3 address += 4;
324 3 if(StartPageOfPacket > Head[1] && Head[1] != RECEIVE_START_PAGE)
325 3 {
326 4 RTLReadRam(address,(WORD)((((WORD)RECEIVE_STOP_PAGE)<<8) - address),MemHead->pStart); /* read from rtl
- */
327 4 RTLReadRam((WORD)(((WORD)RECEIVE_START_PAGE)<<8),(WORD)(PacketSize - ((((WORD)RECEIVE_STOP_PAGE)<<8) -
- address)),
328 4 MemHead->pStart + ((((WORD)RECEIVE_STOP_PAGE)<<8) - address)); /* read from rtl */
329 4 }
330 3 else
331 3 {
332 4 RTLReadRam(address,PacketSize,MemHead->pStart); /* read from rtl */
333 4 }
334 3
335 3 }
336 2 }
337 1
338 1 /* get next packet start page */
339 1 StartPageOfPacket = Head[1];
340 1
341 1 /* reset bnry */
342 1 bnry = StartPageOfPacket - 1;
343 1 if(bnry < RECEIVE_START_PAGE)
344 1 bnry = RECEIVE_STOP_PAGE - 1;
345 1 WriteReg(BNRY_WPAGE0,bnry);
346 1
347 1 return MemHead;
348 1 }
349
350 /*void Start8019()
351 {
352 WriteReg(CR,CR_ABORT_COMPLETE_DMA | CR_START_COMMAND);
353 }
354
355 void Stop8019()
356 {
357 WriteReg(CR,CR_ABORT_COMPLETE_DMA | CR_STOP_COMMAND);
358 }*/
MODULE INFORMATION: STATIC OVERLAYABLE
C51 COMPILER V8.05a RTL8019 11/16/2006 19:20:21 PAGE 7
CODE SIZE = 1172 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 7 ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 4
IDATA SIZE = ---- 2
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -