dsp28377控制DM9000收发数据——第二版程序,能够实现手术功能,但是容易掉帧;使用读取中断寄存器的方式判断中断

Posted havihouston

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dsp28377控制DM9000收发数据——第二版程序,能够实现手术功能,但是容易掉帧;使用读取中断寄存器的方式判断中断相关的知识,希望对你有一定的参考价值。

G:\controlSUITE\device_support\F2837xD\v180\F2837xD_examples_Cpu1\emif1_16bit_asram\cpu01\emif1_16bit_asram.c 2016112220:35
//--------------------------------------------------------------------------------------------
-
//DSP28377 利用EMIF控制网口DM9000芯片收发数据
//--------------------------------------------------------------------------------------------
-
#include "F28x_Project.h" // Device Headerfile and Examples Include File
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;
-1-
G:\controlSUITE\device_support\F2837xD\v180\F2837xD_examples_Cpu1\emif1_16bit_asram\cpu01\emif1_16bit_asram.c 2016112220:35
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));
-2-
G:\controlSUITE\device_support\F2837xD\v180\F2837xD_examples_Cpu1\emif1_16bit_asram\cpu01\emif1_16bit_asram.c 2016112220:35
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(10000);
iow(DM_NCR , 0X00);
iow(DM_NCR , 0X01);
DELAY_US(10000);
iow(DM_NCR , 0X00);
//clear the RX/TX flag
iow(DM_NSR, 0x2C);
iow(DM_ISR, 0x3F);
// //write the NODE_ADDR to physical register
iow(DM_PAB0 , NODE_ADDR[0]);
iow(DM_PAB1 , NODE_ADDR[1]);
iow(DM_PAB2 , NODE_ADDR[2]);
iow(DM_PAB3 , NODE_ADDR[3]);
iow(DM_PAB4 , NODE_ADDR[4]);
iow(DM_PAB5 , NODE_ADDR[5]);
//Eenable RX/TX function
iow(DM_RCR , 0x31);//去掉混杂模式//iow(DM_RCR , 0x31);
iow(DM_TCR , 0x00);
//setting phy of dm9000
phy_write(0x00 , 0x8000);
DELAY_US(100000);
phy_write(0x04 , 0x01e1 | 0x0400);
DELAY_US(100000);
//set back presure threshold register
iow(DM_BPTR , 0x3F);
iow(DM_FCTR , 0x3A);
iow(DM_RTFCR , 0xFF);
iow(DM_SMCR , 0x00);
//clear all flags agin
iow(DM_NSR, 0x2C);
iow(DM_ISR, 0x3B);
//open the rx interrupt
iow(DM_IMR , 0x81);
-3-
G:\controlSUITE\device_support\F2837xD\v180\F2837xD_examples_Cpu1\emif1_16bit_asram\cpu01\emif1_16bit_asram.c 2016112220:35
DELAY_US(1000);
}
//--------------------------------------------------------------------------------------
//发送网络包
void PACKE_SEND(Uint16 *datain , Uint16 datalen){
Uint16 i = 0;
Uint16 len=0;
//关闭RX中断
iow(DM_IMR , 0x80);
//write length to internal sram
//将包的长度写入到寄存器中;
len = datalen * 2;
iow(DM_TXPLH , ((len&0xff00)>>8));
iow(DM_TXPLL , len&0x00ff);
//DM_MWCMD is pointer to internal TX sdram address
outw(DM_MWCMD , 2);
//write data int internal sram
for(i = 0; i < datalen ; i++) outw(datain[i] , 1);
//start transmit
iow(DM_TCR , 0X01);
// wait transmit complit
while((ior(DM_NSR) & 0x0c) == 0);
DELAY_US(20);
//clear the tx flag
iow(DM_NSR , 0X2C);
//oprn rx intterupt
iow(DM_IMR , 0x81);
}
//----------------------------------------------------------------------------------------
//接受网络包
//在调试的过程中;通过一片DSP发送1040个数据(8bit);并设置发送长度为1040;但对于接受的网络包
而言;不仅仅会在接收到的网络包前包含4
//信息byte;分别是接受准备;接受状态位;帧长度(2byte);后面跟随1040个数据(byte);后面还会
跟随4byte位;作用不知;同时接受到的
//帧长度为1044个;所以在读取数据是必须读取完成整个1044个数据;rx指针才会自动跳转到SRAM的首地址
等待下一次触发
void PACKE_RECIVE(Uint16 *datain , Uint16 datalen){
Uint16 i = 0;
Uint16 rx_length = 0;
Uint16 rx_status = 0;
Uint16 state = 0;
Uint16 ready = 0;
//获取中断标识
state = ior(DM_ISR);
if(state & 0x01){
//清除中断标志
iow(DM_ISR , 0x01);
//rx指针指向SRAM(此指针的指向方式为读取数据后指针不会自动增加)
-4-
G:\controlSUITE\device_support\F2837xD\v180\F2837xD_examples_Cpu1\emif1_16bit_asram\cpu01\emif1_16bit_asram.c 2016112220:35
ready = ior(DM_MRCMDX);
DELAY_US(200);
//在读取一次状态寄存器
ready = ior(DM_MRCMDX);
//取状态寄存器的低8
ready = ready & 0X00FF;
if(ready == 0x01){
//rx指针指向SRAM(此指针的指向方式为读取数据后指针会自动增加)
outw(DM_MRCMD , 2);
//读取状态信息
rx_status = inw();
//读取帧字节数
rx_length = inw();
//获取数据
if((rx_length % 2) == 1) rx_length = rx_length + 1;
for(i=0;i<rx_length/2;i++){
*(datain + i) = inw();
}
ESTOP0;
}
else if(ready == 0x00)
{
/*iow(DM_IMR , 0x80);
iow(DM_ISR , 0x0F);
iow(DM_RCR , 0x00);
iow(DM_NCR , 0x01);
DELAY_US(20);
iow(DM_NSR, 0x2C);
iow(DM_ISR, 0x80);
iow(DM_RCR, 0x39);*/
ESTOP0;
}
}
iow(DM_ISR , 0x01);
iow(DM_IMR , 0x81);
}
void main(void)
{
Uint16 i = 0;
Uint16 datalen = 0;
InitSysCtrl();
DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xD_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
EALLOW;
IER = 0x0000;
IFR = 0x0000;
EDIS;
// Initialize the PIE vector table with pointers to the shell Interrupt
// GService Routines (ISR).
-5-
G:\controlSUITE\device_support\F2837xD\v180\F2837xD_examples_Cpu1\emif1_16bit_asram\cpu01\emif1_16bit_asram.c 2016112220:35
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
InitPieVectTable();
Emif1Initialize();
//Configure to run EMIF1 on full Rate (EMIF1CLK = CPU1SYSCLK)
EALLOW;
ClkCfgRegs.PERCLKDIVSEL.bit.EMIF1CLKDIV = 0x1;
EDIS;
EALLOW;
//Grab EMIF1 For CPU1
Emif1ConfigRegs.EMIF1MSEL.all = 0x93A5CE71;
//Disable Access Protection (CPU_FETCH/CPU_WR/DMA_WR)
Emif1ConfigRegs.EMIF1ACCPROT0.all = 0x0;
if (Emif1ConfigRegs.EMIF1ACCPROT0.all != 0x0)
{
while(1);
}
// Commit the configuration related to protection. Till this bit remains set
// content of EMIF1ACCPROT0 register can‘t be changed.
Emif1ConfigRegs.EMIF1COMMIT.all = 0x1;
if(Emif1ConfigRegs.EMIF1COMMIT.all != 0x1)
{
while(1);
}
// Lock the configuration so that EMIF1COMMIT register can‘t be changed any more.
Emif1ConfigRegs.EMIF1LOCK.all = 0x1;
if (Emif1ConfigRegs.EMIF1LOCK.all != 1)
{
while(1);
}
//
EDIS;
//
// //Configure GPIO pins for EMIF1
setup_emif1_pinmux_async_16bit(0);
//
// //Configure the access timing for CS2 space
//net
Emif1Regs.ASYNC_CS3_CR.all = ( EMIF_ASYNC_ASIZE_16 | // 16Bit Memory Interface
EMIF_ASYNC_TA_3 | // Turn Around time of 2 Emif
Clock
EMIF_ASYNC_RHOLD_1 | // Read Hold time of 1 Emif
Clock
EMIF_ASYNC_RSTROBE_5 | // Read Strobe time of 4 Emif
Clock
EMIF_ASYNC_RSETUP_1 | // Read Setup time of 1 Emif
Clock
EMIF_ASYNC_WHOLD_1 | // Write Hold time of 1 Emif
Clock
EMIF_ASYNC_WSTROBE_2 | // Write Strobe time of 1 Emif
Clock
EMIF_ASYNC_WSETUP_1 | // Write Setup time of 1 Emif
Clock
EMIF_ASYNC_EW_DISABLE | // Extended Wait Disable.
EMIF_ASYNC_SS_DISABLE // Strobe Select Mode Disable.
);
DELAY_US(500000);
DM9000_INIT();
DELAY_US(500000);
-6-
G:\controlSUITE\device_support\F2837xD\v180\F2837xD_examples_Cpu1\emif1_16bit_asram\cpu01\emif1_16bit_asram.c 2016112220:35
//********************************************************************
//接受数据测试段代码
//******************************************************************
// for(i=0;i<520;i++){
// databuffer[i] = 0;
// }
//
// while(1){
// PACKE_RECIVE(&databuffer[0] , 520);
//
// if(datalen > 10) ESTOP0;
// }
//*************************************************************************
//发送数据测试段代码
//*************************************************************************
databuffer[0] = 0xFFFF; databuffer[1] = 0xFFFF; databuffer[2] = 0xFFFF;
databuffer[3] = 0x285B; databuffer[4] = 0xC92D; databuffer[5] = 0x587D;
databuffer[6] = 0X00;databuffer[7]=0X00;
for(i = 0 ; i< 512 ; i++){
databuffer[i+8] = i;
}
while(1){
PACKE_SEND(&databuffer[0] , buffersize);
DELAY_US(1000);
}
}
-7-

以上是关于dsp28377控制DM9000收发数据——第二版程序,能够实现手术功能,但是容易掉帧;使用读取中断寄存器的方式判断中断的主要内容,如果未能解决你的问题,请参考以下文章

dm9000网口收发控制以及mac地址过滤设置

dsp 28377在线升级 实例总结

带你学习DSP系列一:走进TMS320F28377

ucos-ii在ti dsp 28377芯片上的运行过程和移植过程

X210开发板(S5PV210芯片)uboot移植DM9000驱动移植

驱动12.移植dm9000驱动程序