dsp28377控制DM9000收发数据
Posted havihouston
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dsp28377控制DM9000收发数据相关的知识,希望对你有一定的参考价值。
首先感谢上一篇转载文章的作者给出的参考,下面是一些自己在调试过程中的一些步骤:
首先把代码贴上来:
//--------------------------------------------------------------------------------------------
-
//DSP28377 利用EMIF控制网口DM9000芯片收发数据
//--------------------------------------------------------------------------------------------
-
#include "F28x_Project.h"
void Emif1Initialize(void);
//emif 映射地址
#define ASRAM_CS3_START_ADDR 0x37FFF0
#define ASRAM_CS3_SIZE 0x8000
extern void setup_emif1_pinmux_async_16bit(Uint16);
//地址指定;通过操作指针实现地址对应数据操作
Uint16 *ADDR_POINT = (Uint16 *)(ASRAM_CS3_START_ADDR);
Uint16 *DATA_POINT = (Uint16 *)(ASRAM_CS3_START_ADDR + 1);
#define EMIF1 0
//##########DM9000 SETING ######################
#define DM_NCR 0X00
#define DM_NSR 0X01
#define DM_TCR 0X02
#define DM_RCR 0X05
#define DM_BPTR 0X08
#define DM_FCTR 0X09
#define DM_RTFCR 0X0A
#define DM_EPCR 0X0B
#define DM_EPAR 0X0C
#define DM_EPDRL 0X0D
#define DM_EPDRH 0X0E
#define DM_PAB0 0X10
#define DM_PAB1 0X11
#define DM_PAB2 0X12
#define DM_PAB3 0X13
#define DM_PAB4 0X14
#define DM_PAB5 0X15
#define DM_GPCR 0X1E
#define DM_GPR 0X1F
#define DM_SMCR 0X2F
#define DM_MRCMDX 0XF0
#define DM_MRCMD 0XF2
#define DM_MWCMD 0XF8
#define DM_TXPLH 0XFD
#define DM_TXPLL 0XFC
#define DM_ISR 0XFE
#define DM_IMR 0XFF
#define PHY_BADDR 0X40
#define PHY_WCMD 0X0A
#define PHY_RCMD 0X0C
Uint16 NODE_ADDR[6] = {0X5A , 0X5A , 0X5A , 0X5A , 0X5A , 0X5A};
Uint16 databuffer[540];
Uint16 buffersize = 520;
//---------------------------------------------------------------------
// 向DM9000内部寄存器写值
void iow(Uint16 IOADDR , Uint16 REGDARA){
*ADDR_POINT = IOADDR;
DELAY_US(20);
*DATA_POINT = REGDARA;
DELAY_US(20);
}
//---------------------------------------------------------------------
// 读取DM9000内部寄存器的值
Uint16 ior(Uint16 IOADDR){
DELAY_US(20);
*ADDR_POINT = IOADDR;
DELAY_US(20);
return(*DATA_POINT);
}
//---------------------------------------------------------------------
// 往固定地址写值
void outw(Uint16 REGDATA , Uint16 addr_data_type){
if(addr_data_type == 1) *DATA_POINT = REGDATA;
else if(addr_data_type == 2) *ADDR_POINT = REGDATA;
DELAY_US(50);
}
//---------------------------------------------------------------------
//读取寄存器的值
Uint16 inw(){
return *DATA_POINT;
}
//---------------------------------------------------------------------
//写物理接口PHY寄存器的值
void phy_write(Uint16 offset , Uint16 REGIN){
iow(DM_EPAR , (offset | PHY_BADDR));
iow(DM_EPDRH , (REGIN >> 8) & 0x00ff);
iow(DM_EPDRL , (REGIN & 0x00ff));
iow(DM_EPCR , PHY_WCMD);
while((ior(DM_EPCR) & 1));
DELAY_US(200);
iow(DM_EPCR , 0x08);
}
//---------------------------------------------------------------------
//读物理接口PHY寄存器的值
Uint16 phy_reaad(Uint16 offset , Uint16 REGIN){
Uint16 returndata=0;
iow(DM_EPAR , (offset | PHY_BADDR));
iow(DM_EPCR , PHY_RCMD);
while((ior(DM_EPCR) & 1));
DELAY_US(200);
iow(DM_EPCR , 0x08);
returndata = ior(DM_EPDRH);
returndata = (returndata << 8) | ior(DM_EPDRL);
return returndata;
}
//---------------------------------------------------------------------
//DM9000 初始化
void DM9000_INIT(){
//开启PHY
iow(DM_GPR , 0X00);
//softerware reset and setting as normal mode(TWICE)
iow(DM_NCR , 0X01);
DELAY_US