⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cs8900.c

📁 此源代码
💻 C
字号:
/****************************************************************** *****                                                        ***** *****  Name: cs8900.c                                        ***** *****  Ver.: 1.0                                             ***** *****  Date: 07/05/2001                                      ***** *****  Auth: Andreas Dannenberg                              ***** *****        HTWK Leipzig                                    ***** *****        university of applied sciences                  ***** *****        Germany                                         ***** *****  Func: ethernet packet-driver for use with LAN-        ***** *****        controller CS8900 from Crystal/Cirrus Logic     ***** *****                                                        ***** ******************************************************************/#include "cs8900.h"// Keil: Following lines are needed to access the CS8900 on the MCB167NET board#include <absacc.h> #include <tcpip.h> #define CS8900IOBASE 0x100300// Keil: End of added lines// configure port-pins for use with LAN-controller,// reset it and send the configuration-sequence// (InitSeq[])void Init8900(void){  unsigned int i;// Keil: function modified to access the CS8900 on the address/data bus  Write8900(ADD_PORT, PP_SelfCTL);  Write8900(DATA_PORT, POWER_ON_RESET);            // Reset the Ethernet-Controller  Write8900(ADD_PORT, PP_SelfST);  while (!(Read8900(DATA_PORT) & INIT_DONE));      // wait until chip-reset is done    for (i = 0; i < sizeof InitSeq / sizeof (TInitSeq); i++) // configure the CS8900  {    Write8900(ADD_PORT, InitSeq[i].Addr);    Write8900(DATA_PORT, InitSeq[i].Data);  }}// writes a word in little-endian byte order to// a specified port-addressvoid Write8900(unsigned char Address, unsigned int Data){// Keil: function modified to access the CS8900 on the address/data bus  HVAR(unsigned int,Address + CS8900IOBASE) = Data;}// writes a word in little-endian byte order to TX_FRAME_PORTvoid WriteFrame8900(unsigned int Data){// Keil: function modified to access the CS8900 on the address/data bus  HVAR(unsigned int,TX_FRAME_PORT + CS8900IOBASE) = Data;}// copies bytes from MCU-memory to frame port// NOTES: * an odd number of byte may only be transfered//          if the frame is written to the end!//        * MCU-memory MUST start at word-boundaryvoid CopyToFrame8900(void *Source, unsigned int Size){  unsigned int * piSource;                       // Keil: Pointer added to correct expression    piSource = Source;                             // Keil: Line added  while (Size > 1) {//  WriteFrame8900(*((unsigned int *)Source)++); // Keil: Line replaced with following line    WriteFrame8900(*piSource++);    Size -= 2;  }    if (Size)                                      // if odd num. of bytes...//  WriteFrame8900(*(unsigned char *)Source);    // Keil: Line replaced with following line    WriteFrame8900(*(unsigned char *)piSource);  // write leftover byte (the LAN-controller}                                                // ignores the highbyte)// reads a word in little-endian byte order from// a specified port-addressunsigned int Read8900(unsigned char Address){  unsigned int ReturnValue;// Keil: function modified to access the CS8900 on the address/data bus  ReturnValue = HVAR(unsigned int,Address + CS8900IOBASE);    return ReturnValue;}// reads a word in little-endian byte order from RX_FRAME_PORTunsigned int ReadFrame8900(void){  unsigned int ReturnValue;// Keil: function modified to access the CS8900 on the address/data bus  ReturnValue = HVAR(unsigned int,RX_FRAME_PORT + CS8900IOBASE);    return ReturnValue;}// reads a word in big-endian byte order from RX_FRAME_PORT// (useful to avoid permanent byte-swapping while reading// TCP/IP-data)unsigned int ReadFrameBE8900(void){  unsigned int ReturnValue;// Keil: function modified to access the CS8900 on the address/data bus  ReturnValue = HVAR(unsigned int,RX_FRAME_PORT + CS8900IOBASE);  ReturnValue = SwapBytes(ReturnValue);    return ReturnValue;}// reads a word in little-endian byte order from// a specified port-address// NOTE: this func. xfers the high-byte 1st, must be used to//       access some special registers (e.g. RxStatus)unsigned int ReadHB1ST8900(unsigned char Address){  unsigned int ReturnValue;// Keil: function modified to access the CS8900 on the address/data bus  ReturnValue = HVAR(unsigned int,Address + CS8900IOBASE);    return ReturnValue;}// copies bytes from frame port to MCU-memory// NOTES: * an odd number of byte may only be transfered//          if the frame is read to the end!//        * MCU-memory MUST start at word-boundaryvoid CopyFromFrame8900(void *Dest, unsigned int Size){  unsigned int * piDest;                         // Keil: Pointer added to correct expression  piDest = Dest;                                 // Keil: Line added  while (Size > 1) {//  *((unsigned int *)Dest)++ = ReadFrame8900(); // Keil: Line replaced with following line    *piDest++ = ReadFrame8900();    Size -= 2;  }    if (Size)                                      // check for leftover byte...//  *(unsigned char *)Dest = ReadFrame8900();    // Keil: Line replaced with following line    *(unsigned char *)piDest = ReadFrame8900();  // the LAN-Controller will return 0}                                                // for the highbyte// does a dummy read on frame-I/O-port// NOTE: only an even number of bytes is read!void DummyReadFrame8900(unsigned int Size)       // discards an EVEN number of bytes{                                                // from RX-fifo  while (Size > 1) {    ReadFrame8900();    Size -= 2;  }}// requests space in CS8900's on-chip memory for// storing an outgoing framevoid RequestSend(unsigned int FrameSize){  Write8900(TX_CMD_PORT, TX_START_ALL_BYTES);  Write8900(TX_LEN_PORT, FrameSize);}// check if CS8900 is ready to accept the// frame we want to sendunsigned int Rdy4Tx(void){  Write8900(ADD_PORT, PP_BusST);  return (Read8900(DATA_PORT) & READY_FOR_TX_NOW);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -