|
@@ -1,17 +1,17 @@
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*
|
|
*
|
|
-* Ä£¿éÃû³Æ : DM9KAEP µ×²ãÇý¶¯Ä£¿é(For STM32F4XX£¬ uip)
|
|
|
|
-* ÎļþÃû³Æ : dm9k_uip.c
|
|
|
|
-* °æ ±¾ : V1.1
|
|
|
|
-* ˵ Ã÷ : ÕâÊÇÓ²¼þµ×²ãÇý¶¯³ÌÐòµÄÖ÷Îļþ¡£Ã¿¸öcÎļþ¿ÉÒÔ #include "bsp.h" À´°üº¬ËùÓеÄÍâÉèÇý¶¯Ä£¿é¡£
|
|
|
|
-* bsp = Borad surport packet °å¼¶Ö§³Ö°ü
|
|
|
|
-* Ð޸ļǼ :
|
|
|
|
-* °æ±¾ºÅ ÈÕÆÚ ×÷Õß ËµÃ÷
|
|
|
|
-* V1.0 2013-03-01 armfly Õýʽ·¢²¼
|
|
|
|
-* V1.1 2013-06-20 armfly ¹æ·¶×¢ÊÍ£¬Ìí¼Ó±ØҪ˵Ã÷
|
|
|
|
|
|
+* 模��称 : DM9KAEP 底层驱动模�(For STM32F4XX, uip)
|
|
|
|
+* 文件�称 : dm9k_uip.c
|
|
|
|
+* 版 本 : V1.1
|
|
|
|
+* 说 明 : 这是硬件底层驱动程�的主文件。�个c文件�以 #include "bsp.h" �包�所有的外设驱动模�。
|
|
|
|
+* bsp = Borad surport packet �级支�包
|
|
|
|
+* 修改记录 :
|
|
|
|
+* 版本� 日期 作者 说明
|
|
|
|
+* V1.0 2013-03-01 armfly æ£å¼�å�‘布
|
|
|
|
+* V1.1 2013-06-20 armfly è§„èŒƒæ³¨é‡Šï¼Œæ·»åŠ å¿…è¦�说明
|
|
*
|
|
*
|
|
-* Copyright (C), 2013-2014, °²¸»À³µç×Ó www.armfly.com
|
|
|
|
|
|
+* Copyright (C), 2013-2014, 安富莱电å� www.armfly.com
|
|
*
|
|
*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
@@ -19,7 +19,7 @@
|
|
#include "dm9k.h"
|
|
#include "dm9k.h"
|
|
|
|
|
|
uint8_t SendPackOk = 0;
|
|
uint8_t SendPackOk = 0;
|
|
-uint8_t is_fsmc_ok = 0; /* ÓÃÓÚָʾFSMCÊÇ·ñ³õʼ»¯ */
|
|
|
|
|
|
+uint8_t is_fsmc_ok = 0; /* 用于指示FSMC是��始化 */
|
|
|
|
|
|
void dm9k_debug_test(void);
|
|
void dm9k_debug_test(void);
|
|
|
|
|
|
@@ -28,10 +28,10 @@ static void dm9k_initnic(void);
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_init
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: uIP ½Ó¿Úº¯Êý,³õʼ»¯Íø¿¨. uIP ½Ó¿Úº¯Êý.
|
|
|
|
-* ÐÎ ²Î: ÎÞ
|
|
|
|
-* ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+* 函 数 �: dm9k_init
|
|
|
|
+* 功能说明: uIP 接�函数,�始化网�. uIP 接�函数.
|
|
|
|
+* å½¢ å�‚: æ—
|
|
|
|
+* è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void dm9k_init(void)
|
|
void dm9k_init(void)
|
|
@@ -40,15 +40,15 @@ void dm9k_init(void)
|
|
|
|
|
|
is_fsmc_ok = 1;
|
|
is_fsmc_ok = 1;
|
|
|
|
|
|
- dm9k_initnic(); /* ÅäÖÃDM9K */
|
|
|
|
|
|
+ dm9k_initnic(); /* �置DM9K */
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_fsmc
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: ÅäÖÃFSMC²¢¿Ú·ÃÎÊʱÐò
|
|
|
|
-* ÐÎ ²Î: ÎÞ
|
|
|
|
-* ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+* 函 数 �: dm9k_fsmc
|
|
|
|
+* 功能说明: �置FSMC并�访问时�
|
|
|
|
+* å½¢ å�‚: æ—
|
|
|
|
+* è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
static void dm9k_fsmc(void)
|
|
static void dm9k_fsmc(void)
|
|
@@ -59,9 +59,9 @@ static void dm9k_fsmc(void)
|
|
/*-- FSMC Configuration ------------------------------------------------------*/
|
|
/*-- FSMC Configuration ------------------------------------------------------*/
|
|
/*----------------------- SRAM Bank 3 ----------------------------------------*/
|
|
/*----------------------- SRAM Bank 3 ----------------------------------------*/
|
|
/*-- FSMC Configuration ------------------------------------------------------*/
|
|
/*-- FSMC Configuration ------------------------------------------------------*/
|
|
- p.FSMC_AddressSetupTime = 6; /* ÉèÖÃΪ2»á³ö´í; 3Õý³£ */
|
|
|
|
|
|
+ p.FSMC_AddressSetupTime = 6; /* 设置为2会出错; 3æ£å¸¸ */
|
|
p.FSMC_AddressHoldTime = 2;
|
|
p.FSMC_AddressHoldTime = 2;
|
|
- p.FSMC_DataSetupTime = 4; /* ÉèÖÃΪ1³ö´í£¬2Õý³£ */
|
|
|
|
|
|
+ p.FSMC_DataSetupTime = 4; /* 设置为1出错,2æ£å¸¸ */
|
|
p.FSMC_BusTurnAroundDuration = 1;
|
|
p.FSMC_BusTurnAroundDuration = 1;
|
|
p.FSMC_CLKDivision = 0;
|
|
p.FSMC_CLKDivision = 0;
|
|
p.FSMC_DataLatency = 0;
|
|
p.FSMC_DataLatency = 0;
|
|
@@ -91,10 +91,10 @@ static void dm9k_fsmc(void)
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_ReadReg
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: ¶Á³öDM9KÖ¸¶¨¼Ä´æÆ÷µÄÖµ
|
|
|
|
-* ÐÎ ²Î: reg ¼Ä´æÆ÷µØÖ·
|
|
|
|
-* ·µ »Ø Öµ: ¼Ä´æÆ÷Öµ
|
|
|
|
|
|
+* 函 数 �: dm9k_ReadReg
|
|
|
|
+* 功能说明: 读出DM9K指定寄å˜å™¨çš„值
|
|
|
|
+* å½¢ å�‚: reg 寄å˜å™¨åœ°å�€
|
|
|
|
+* è¿” 回 值: 寄å˜å™¨å€¼
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
uint8_t dm9k_ReadReg(uint8_t reg)
|
|
uint8_t dm9k_ReadReg(uint8_t reg)
|
|
@@ -105,11 +105,11 @@ uint8_t dm9k_ReadReg(uint8_t reg)
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_WriteReg
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: ¶Á³öDM9KÖ¸¶¨¼Ä´æÆ÷µÄÖµ
|
|
|
|
-* ÐÎ ²Î: reg £º¼Ä´æÆ÷µØÖ·
|
|
|
|
-* writedata : дÈëµÄÊý¾Ý
|
|
|
|
-* ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+* 函 数 �: dm9k_WriteReg
|
|
|
|
+* 功能说明: 读出DM9K指定寄å˜å™¨çš„值
|
|
|
|
+* å½¢ å�‚: reg :寄å˜å™¨åœ°å�€
|
|
|
|
+* writedata : 写入的数�
|
|
|
|
+* è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void dm9k_WriteReg(uint8_t reg, uint8_t writedata)
|
|
void dm9k_WriteReg(uint8_t reg, uint8_t writedata)
|
|
@@ -120,17 +120,17 @@ void dm9k_WriteReg(uint8_t reg, uint8_t writedata)
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_hash_table
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: ÉèÖà DM9KA MAC ¡¢ ¹ã²¥ ¡¢ ¶à²¥ ¼Ä´æÆ÷
|
|
|
|
-* ÐÎ ²Î: ÎÞ
|
|
|
|
-* ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+* 函 数 �: dm9k_hash_table
|
|
|
|
+* 功能说明: 设置 DM9KA MAC ã€� å¹¿æ’ ã€� å¤šæ’ å¯„å˜å™¨
|
|
|
|
+* å½¢ å�‚: æ—
|
|
|
|
+* è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void dm9k_hash_table()
|
|
void dm9k_hash_table()
|
|
{
|
|
{
|
|
uint8_t i;
|
|
uint8_t i;
|
|
|
|
|
|
- /* ÉèÖà Íø¿¨ MAC λÖã¬À´×Ôì¶ MyHardware */
|
|
|
|
|
|
+ /* 设置 网� MAC �置,�自於 MyHardware */
|
|
dm9k_WriteReg(DM9K_REG_PAR, DM9K_MAC_ADDR0);
|
|
dm9k_WriteReg(DM9K_REG_PAR, DM9K_MAC_ADDR0);
|
|
dm9k_WriteReg(DM9K_REG_PAR + 1, DM9K_MAC_ADDR1);
|
|
dm9k_WriteReg(DM9K_REG_PAR + 1, DM9K_MAC_ADDR1);
|
|
dm9k_WriteReg(DM9K_REG_PAR + 2, DM9K_MAC_ADDR2);
|
|
dm9k_WriteReg(DM9K_REG_PAR + 2, DM9K_MAC_ADDR2);
|
|
@@ -138,131 +138,151 @@ void dm9k_hash_table()
|
|
dm9k_WriteReg(DM9K_REG_PAR + 4, DM9K_MAC_ADDR4);
|
|
dm9k_WriteReg(DM9K_REG_PAR + 4, DM9K_MAC_ADDR4);
|
|
dm9k_WriteReg(DM9K_REG_PAR + 5, DM9K_MAC_ADDR5);
|
|
dm9k_WriteReg(DM9K_REG_PAR + 5, DM9K_MAC_ADDR5);
|
|
|
|
|
|
- /* Çå³ý Íø¿¨¶à²¥ÉèÖà */
|
|
|
|
|
|
+ /* 清除 网å�¡å¤šæ’设置 */
|
|
for (i = 0; i < 8; i++)
|
|
for (i = 0; i < 8; i++)
|
|
{
|
|
{
|
|
dm9k_WriteReg(DM9K_REG_MAR + i, 0x00);
|
|
dm9k_WriteReg(DM9K_REG_MAR + i, 0x00);
|
|
}
|
|
}
|
|
|
|
|
|
- /* ÉèÖà ¹ã²¥°ü ÉèÖà */
|
|
|
|
|
|
+ /* 设置 广æ’包 设置 */
|
|
dm9k_WriteReg(DM9K_REG_MAR + 7, 0x80);
|
|
dm9k_WriteReg(DM9K_REG_MAR + 7, 0x80);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_reset
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: Èí¼þ¸´Î»DM9KAE
|
|
|
|
-* ÐÎ ²Î: ÎÞ
|
|
|
|
-* ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+* 函 数 �: dm9k_reset
|
|
|
|
+* 功能说明: 软件��DM9KAE
|
|
|
|
+* å½¢ å�‚: æ—
|
|
|
|
+* è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void dm9k_reset(void)
|
|
void dm9k_reset(void)
|
|
{
|
|
{
|
|
- dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* ¶Ô DM9KA ½øÐÐÈí¼þÖØÖÃ */
|
|
|
|
- OSTimeDly(10); /* delay 10us */
|
|
|
|
- dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* ¶Ô DM9KA ½øÐÐÈí¼þÖØÖÃ */
|
|
|
|
- OSTimeDly(10); /* delay 10us */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* 对 DM9KA 进行软件�置 */
|
|
|
|
+ us_delay(10); /* delay 10us */
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* 对 DM9KA 进行软件�置 */
|
|
|
|
+ us_delay(10); /* delay 10us */
|
|
|
|
|
|
- /* »ù±¾¼Ç´æÆ÷Ïà¹ØÉèÖà */
|
|
|
|
- dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* ¿ªÆôÄÚ´æ×Ô»·Ä£Ê½ */
|
|
|
|
- dm9k_WriteReg(DM9K_REG_TCR2, DM9K_TCR2_SET); /* ÉèÖà LED ÏÔʾģʽ1:È«Ë«¹¤ÁÁ£¬°ëË«¹¤Ãð */
|
|
|
|
|
|
+ /* 基本记å˜å™¨ç›¸å…³è®¾ç½® */
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* å¼€å�¯å†…å˜è‡ªçŽ¯æ¨¡å¼� */
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_TCR2, DM9K_TCR2_SET); /* 设置 LED 显示模å¼�1:å…¨å�Œå·¥äº®ï¼Œå�Šå�Œå·¥ç� */
|
|
|
|
|
|
- /* Çå³ý¶àÓà×ÊѶ */
|
|
|
|
|
|
+ /* 清除多余资讯 */
|
|
dm9k_WriteReg(DM9K_REG_NSR, 0x2c);
|
|
dm9k_WriteReg(DM9K_REG_NSR, 0x2c);
|
|
dm9k_WriteReg(DM9K_REG_TCR, 0x00);
|
|
dm9k_WriteReg(DM9K_REG_TCR, 0x00);
|
|
dm9k_WriteReg(DM9K_REG_ISR, 0x3f);
|
|
dm9k_WriteReg(DM9K_REG_ISR, 0x3f);
|
|
|
|
|
|
#ifdef DM9KA_FLOW_CONTROL
|
|
#ifdef DM9KA_FLOW_CONTROL
|
|
- dm9k_WriteReg(DM9K_REG_BPTR, DM9K_BPTR_SET); /* °ëË«¹¤Á÷¿ØÉèÖà */
|
|
|
|
- dm9k_WriteReg(DM9K_REG_FCTR, DM9K_FCTR_SET); /* È«Ë«¹¤Á÷¿ØÉèÖà */
|
|
|
|
- dm9k_WriteReg(DM9K_REG_FCR, DM9K_FCR_SET); /* ¿ªÆôÁ÷¿ØÉèÖà */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_BPTR, DM9K_BPTR_SET); /* ��工�控设置 */
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_FCTR, DM9K_FCTR_SET); /* 全�工�控设置 */
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_FCR, DM9K_FCR_SET); /* 开��控设置 */
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef DM9KA_UPTO_100M
|
|
#ifdef DM9KA_UPTO_100M
|
|
- /* DM9KAÎ޴˼ĴæÆ÷ */
|
|
|
|
- dm9k_WriteReg(DM9K_REG_OTCR, DM9K_OTCR_SET); /* ¹¤×÷ƵÂʵ½ 100Mhz ÉèÖà */
|
|
|
|
|
|
+ /* DM9KAæ— æ¤å¯„å˜å™¨ */
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_OTCR, DM9K_OTCR_SET); /* 工作频率到 100Mhz 设置 */
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef Rx_Int_enable
|
|
#ifdef Rx_Int_enable
|
|
- dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* ¿ªÆô ÖжÏģʽ */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* å¼€å�¯ ä¸æ–模å¼� */
|
|
#else
|
|
#else
|
|
- dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* ¹Ø±Õ ÖжÏģʽ */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* å…³é— ä¸æ–模å¼� */
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- dm9k_WriteReg(DM9K_REG_RCR, DM9K_RCR_SET); /* ¿ªÆô ½ÓÊÕ¹¤ÄÜ */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_RCR, DM9K_RCR_SET); /* 开� 接收工能 */
|
|
|
|
|
|
SendPackOk = 0;
|
|
SendPackOk = 0;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_phy_write
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: Èí¼þ¸´Î»DM9KAE
|
|
|
|
-* ÐÎ ²Î: phy_reg £º PHY¼Ä´æÆ÷µØÖ·
|
|
|
|
-* writedata £º дÈëµÄÊý¾Ý
|
|
|
|
-* ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+* 函 数 �: dm9k_phy_write
|
|
|
|
+* 功能说明: 软件��DM9KAE
|
|
|
|
+* å½¢ å�‚: phy_reg : PHY寄å˜å™¨åœ°å�€
|
|
|
|
+* writedata : 写入的数�
|
|
|
|
+* è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void dm9k_phy_write(uint8_t phy_reg, uint16_t writedata)
|
|
void dm9k_phy_write(uint8_t phy_reg, uint16_t writedata)
|
|
{
|
|
{
|
|
- /* ÉèÖÃдÈë PHY ¼Ä´æÆ÷µÄλÖà */
|
|
|
|
|
|
+ /* 设置写入 PHY 寄å˜å™¨çš„ä½�ç½® */
|
|
dm9k_WriteReg(DM9K_REG_EPAR, phy_reg | DM9K_PHY);
|
|
dm9k_WriteReg(DM9K_REG_EPAR, phy_reg | DM9K_PHY);
|
|
|
|
|
|
- /* ÉèÖÃдÈë PHY ¼Ä´æÆ÷µÄÖµ */
|
|
|
|
|
|
+ /* 设置写入 PHY 寄å˜å™¨çš„值 */
|
|
dm9k_WriteReg(DM9K_REG_EPDRH, (writedata >> 8) & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_EPDRH, (writedata >> 8) & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_EPDRL, writedata & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_EPDRL, writedata & 0xff);
|
|
|
|
|
|
- dm9k_WriteReg(DM9K_REG_EPCR, 0x0a); /* ½«×ÊÁÏдÈë PHY ¼Ä´æÆ÷ */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_EPCR, 0x0a); /* 将资料写入 PHY 寄å˜å™¨ */
|
|
while (dm9k_ReadReg(DM9K_REG_EPCR) & 0x01)
|
|
while (dm9k_ReadReg(DM9K_REG_EPCR) & 0x01)
|
|
- ; /* ²éÑ°ÊÇ·ñÖ´ÐнáÊø */
|
|
|
|
- dm9k_WriteReg(DM9K_REG_EPCR, 0x08); /* Çå³ýдÈëÃüÁî */
|
|
|
|
|
|
+ ; /* 查寻是�执行结� */
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_EPCR, 0x08); /* 清除写入命令 */
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_initnic
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: ÅäÖÃDM9KAEоƬ£¨³õʼ»¯£©
|
|
|
|
-* ÐÎ ²Î: ÎÞ
|
|
|
|
-* ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+* 函 数 �: dm9k_initnic
|
|
|
|
+* 功能说明: �置DM9KAE芯片(�始化)
|
|
|
|
+* å½¢ å�‚: æ—
|
|
|
|
+* è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
static void dm9k_initnic(void)
|
|
static void dm9k_initnic(void)
|
|
{
|
|
{
|
|
- dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* ¶Ô DM9KA ½øÐÐÈí¼þÖØÖÃ */
|
|
|
|
- OSTimeDly(10); /* delay 10us */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* 对 DM9KA 进行软件�置 */
|
|
|
|
+ us_delay(10); /* delay 10us */
|
|
|
|
|
|
- dm9k_hash_table(); /* ÉèÖà DM9KA MAC ¼° ¶à²¥*/
|
|
|
|
|
|
+ dm9k_hash_table(); /* 设置 DM9KA MAC å�Š 多æ’*/
|
|
|
|
|
|
- dm9k_reset(); /* ½øÐÐ DM9KA Èí¼þÉèÖÃ */
|
|
|
|
|
|
+ dm9k_reset(); /* 进行 DM9KA 软件设置 */
|
|
|
|
|
|
- dm9k_WriteReg(DM9K_REG_GPR, DM9K_PHY_OFF); /* ¹Ø±Õ PHY £¬½øÐÐ PHY ÉèÖÃ*/
|
|
|
|
- dm9k_phy_write(0x00, 0x8000); /* ÖØÖà PHY µÄ¼Ä´æÆ÷ */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_GPR, DM9K_PHY_OFF); /* å…³é— PHY ,进行 PHY 设置*/
|
|
|
|
+ dm9k_phy_write(0x00, 0x8000); /* é‡�ç½® PHY 的寄å˜å™¨ */
|
|
#ifdef DM9KA_FLOW_CONTROL
|
|
#ifdef DM9KA_FLOW_CONTROL
|
|
- dm9k_phy_write(0x04, 0x01e1 | 0x0400); /* ÉèÖà ×ÔÊÊӦģʽÏàÈݱí */
|
|
|
|
|
|
+ dm9k_phy_write(0x04, 0x01e1 | 0x0400); /* 设置 自适应模�相容表 */
|
|
#else
|
|
#else
|
|
- dm9k_phy_write(0x04, 0x01e1); /* ÉèÖà ×ÔÊÊӦģʽÏàÈݱí */
|
|
|
|
|
|
+ dm9k_phy_write(0x04, 0x01e1); /* 设置 自适应模�相容表 */
|
|
#endif
|
|
#endif
|
|
- // dm9k_phy_write(0x00, 0x1000); /* ÉèÖà »ù±¾Á¬½Óģʽ */
|
|
|
|
- /* Á¬½ÓģʽÉèÖÃ
|
|
|
|
- 0x0000 : ¹Ì¶¨10M°ëË«¹¤
|
|
|
|
- 0x0100 : ¹Ì¶¨10MÈ«Ë«¹¤
|
|
|
|
- 0x2000 : ¹Ì¶¨100M°ëË«¹¤
|
|
|
|
- 0x2100 : ¹Ì¶¨100MÈ«Ë«¹¤
|
|
|
|
- 0x1000 : ×ÔÊÊӦģʽ
|
|
|
|
|
|
+ // dm9k_phy_write(0x00, 0x1000); /* 设置 基本连接模� */
|
|
|
|
+ /* 连接模�设置
|
|
|
|
+ 0x0000 : 固定10M��工
|
|
|
|
+ 0x0100 : 固定10M全�工
|
|
|
|
+ 0x2000 : 固定100M��工
|
|
|
|
+ 0x2100 : 固定100M全�工
|
|
|
|
+ 0x1000 : 自适应模�
|
|
*/
|
|
*/
|
|
- dm9k_phy_write(0x00, 0x1000); /* ÉèÖà »ù±¾Á¬½Óģʽ */
|
|
|
|
|
|
+ dm9k_phy_write(0x00, 0x1000); /* 设置 基本连接模� */
|
|
|
|
|
|
- dm9k_WriteReg(DM9K_REG_GPR, DM9K_PHY_ON); /* ½áÊø PHY ÉèÖÃ, ¿ªÆô PHY */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_GPR, DM9K_PHY_ON); /* 结� PHY 设置, 开� PHY */
|
|
|
|
+
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* 设置ä¸æ– */
|
|
|
|
+
|
|
|
|
+ EXTI_InitTypeDef EXTI_InitStructure;
|
|
|
|
+ NVIC_InitTypeDef NVIC_InitStructure;
|
|
|
|
+
|
|
|
|
+ SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource14);
|
|
|
|
+
|
|
|
|
+ /* �置 EXTI LineXXX */
|
|
|
|
+ EXTI_InitStructure.EXTI_Line = EXTI_Line2 | EXTI_Line3 | EXTI_Line7 | EXTI_Line8 | EXTI_Line11 | EXTI_Line13 | EXTI_Line14;
|
|
|
|
+ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
|
|
|
+ EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
|
|
|
|
+ EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
|
|
|
+ EXTI_Init(&EXTI_InitStructure);
|
|
|
|
+
|
|
|
|
+ NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
|
|
|
|
+ NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
|
|
|
|
+ NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
|
|
|
+ NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
|
|
+ NVIC_Init(&NVIC_InitStructure);
|
|
|
|
|
|
// dm9k_debug_test();
|
|
// dm9k_debug_test();
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_receive_packet
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: ÅäÖÃDM9KAEоƬ£¨³õʼ»¯£©
|
|
|
|
-* ÐÎ ²Î: _uip_buf : ½ÓÊÕ½á¹û´æ·ÅµÄ»º³åÇøÖ¸Õë
|
|
|
|
-* ·µ »Ø Öµ: > 0 ±íʾ½ÓÊÕµÄÊý¾Ý³¤¶È, 0±íʾûÓÐÊý¾Ý
|
|
|
|
|
|
+* 函 数 �: dm9k_receive_packet
|
|
|
|
+* 功能说明: �置DM9KAE芯片(�始化)
|
|
|
|
+* å½¢ å�‚: _uip_buf : 接收结果å˜æ”¾çš„缓冲区指针
|
|
|
|
+* 返 回 值: > 0 表示接收的数�长度, 0表示没有数�
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
uint16_t dm9k_receive_packet(uint8_t *_uip_buf)
|
|
uint16_t dm9k_receive_packet(uint8_t *_uip_buf)
|
|
@@ -279,35 +299,35 @@ uint16_t dm9k_receive_packet(uint8_t *_uip_buf)
|
|
|
|
|
|
do
|
|
do
|
|
{
|
|
{
|
|
- ReceiveLength = 0; /* Çå³ý½ÓÊյij¤¶È */
|
|
|
|
|
|
+ ReceiveLength = 0; /* 清除接收的长度 */
|
|
ReceiveData = (uint16_t *)_uip_buf;
|
|
ReceiveData = (uint16_t *)_uip_buf;
|
|
- jump_packet = 0; /* Çå³ýÌø°ü¶¯×÷ */
|
|
|
|
- dm9k_ReadReg(DM9K_REG_MRCMDX); /* ¶ÁÈ¡ÄÚ´æÊý¾Ý£¬µØÖ·²»Ôö¼Ó */
|
|
|
|
- /* ¼ÆËãÄÚ´æÊý¾ÝλÖà */
|
|
|
|
|
|
+ jump_packet = 0; /* 清除跳包动作 */
|
|
|
|
+ dm9k_ReadReg(DM9K_REG_MRCMDX); /* 读å�–内å˜æ•°æ�®ï¼Œåœ°å�€ä¸�å¢žåŠ */
|
|
|
|
+ /* 计算内å˜æ•°æ�®ä½�ç½® */
|
|
calc_MRR = (dm9k_ReadReg(DM9K_REG_MRRH) << 8) + dm9k_ReadReg(DM9K_REG_MRRL);
|
|
calc_MRR = (dm9k_ReadReg(DM9K_REG_MRRH) << 8) + dm9k_ReadReg(DM9K_REG_MRRL);
|
|
rx_checkbyte = dm9k_ReadReg(DM9K_REG_MRCMDX); /* */
|
|
rx_checkbyte = dm9k_ReadReg(DM9K_REG_MRCMDX); /* */
|
|
|
|
|
|
- if (rx_checkbyte == DM9K_PKT_RDY) /* È¡ */
|
|
|
|
|
|
+ if (rx_checkbyte == DM9K_PKT_RDY) /* � */
|
|
{
|
|
{
|
|
- /* ¶ÁÈ¡·â°üÏà¹Ø×ÊѶ ¼° ³¤¶È */
|
|
|
|
|
|
+ /* 读��包相关资讯 � 长度 */
|
|
NET_REG_ADDR = DM9K_REG_MRCMD;
|
|
NET_REG_ADDR = DM9K_REG_MRCMD;
|
|
rx_status = NET_REG_DATA;
|
|
rx_status = NET_REG_DATA;
|
|
rx_length = NET_REG_DATA;
|
|
rx_length = NET_REG_DATA;
|
|
|
|
|
|
- /* ÈôÊÕµ½³¬¹ýϵͳ¿É³ÐÊܵķâ°ü£¬´Ë°üÌø¹ý */
|
|
|
|
|
|
+ /* 若收到超过系统å�¯æ‰¿å�—çš„å°�包,æ¤åŒ…跳过 */
|
|
if (rx_length > Max_Ethernet_Lenth)
|
|
if (rx_length > Max_Ethernet_Lenth)
|
|
jump_packet = 1;
|
|
jump_packet = 1;
|
|
|
|
|
|
#ifdef Broadcast_Jump
|
|
#ifdef Broadcast_Jump
|
|
- /* ÈôÊÕµ½µÄ¹ã²¥»ò¶à²¥°ü³¬¹ýÌض¨³¤¶È£¬´Ë°üÌø¹ý */
|
|
|
|
|
|
+ /* 若收到的广æ’或多æ’包超过特定长度,æ¤åŒ…跳过 */
|
|
if (rx_status & 0x4000)
|
|
if (rx_status & 0x4000)
|
|
{
|
|
{
|
|
if (rx_length > Max_Broadcast_Lenth)
|
|
if (rx_length > Max_Broadcast_Lenth)
|
|
jump_packet = 1;
|
|
jump_packet = 1;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
- /* ¼ÆËãÏÂÒ»¸ö°üµÄÖ¸Õëλ , Èô½ÓÊÕ³¤¶ÈΪÆæÊý£¬Ðè¼ÓÒ»¶ÔÆëż×Ö½Ú¡£*/
|
|
|
|
- /* ÈôÊdz¬¹ý 0x3fff £¬ÔòÐè»Ø¹éÈƵ½ 0x0c00 ÆðʼλÖà */
|
|
|
|
|
|
+ /* 计算下一个包的指针ä½� , è‹¥æŽ¥æ”¶é•¿åº¦ä¸ºå¥‡æ•°ï¼Œéœ€åŠ ä¸€å¯¹é½�å�¶å—节。*/
|
|
|
|
+ /* 若是超过 0x3fff ,则需回归绕到 0x0c00 起始�置 */
|
|
calc_MRR += (rx_length + 4);
|
|
calc_MRR += (rx_length + 4);
|
|
if (rx_length & 0x01)
|
|
if (rx_length & 0x01)
|
|
calc_MRR++;
|
|
calc_MRR++;
|
|
@@ -316,30 +336,30 @@ uint16_t dm9k_receive_packet(uint8_t *_uip_buf)
|
|
|
|
|
|
if (jump_packet == 0x01)
|
|
if (jump_packet == 0x01)
|
|
{
|
|
{
|
|
- /* ½«Ö¸ÕëÒƵ½ÏÂÒ»¸ö°üµÄ°üͷλÖà */
|
|
|
|
|
|
+ /* 将指针移到下一个包的包头�置 */
|
|
dm9k_WriteReg(DM9K_REG_MRRH, (calc_MRR >> 8) & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_MRRH, (calc_MRR >> 8) & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_MRRL, calc_MRR & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_MRRL, calc_MRR & 0xff);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- /* ¿ªÊ¼½«ÄÚ´æµÄ×ÊÁÏ°áµ½µ½ÏµÍ³ÖУ¬Ã¿´ÎÒƶ¯Ò»¸ö word */
|
|
|
|
|
|
+ /* 开始将内å˜çš„资料æ�¬åˆ°åˆ°ç³»ç»Ÿä¸ï¼Œæ¯�次移动一个 word */
|
|
calc_len = (rx_length + 1) >> 1;
|
|
calc_len = (rx_length + 1) >> 1;
|
|
for (i = 0; i < calc_len; i++)
|
|
for (i = 0; i < calc_len; i++)
|
|
ReceiveData[i] = NET_REG_DATA;
|
|
ReceiveData[i] = NET_REG_DATA;
|
|
|
|
|
|
- /* ½«°ü³¤»Ø±¨¸ø TCP/IP Éϲ㣬²¢¼õÈ¥×îáá 4 BYTE µÄ CRC-32 ¼ìºËÂë */
|
|
|
|
|
|
+ /* 将包长回报给 TCP/IP 上层,并å‡�去最後 4 BYTE çš„ CRC-32 æ£€æ ¸ç � */
|
|
ReceiveLength = rx_length - 4;
|
|
ReceiveLength = rx_length - 4;
|
|
|
|
|
|
- rx_int_count++; /* ÀÛ¼ÆÊÕ°ü´ÎÊý */
|
|
|
|
|
|
+ rx_int_count++; /* 累计收包次数 */
|
|
|
|
|
|
#ifdef FifoPointCheck
|
|
#ifdef FifoPointCheck
|
|
if (calc_MRR != ((dm9k_ReadReg(DM9K_REG_MRRH) << 8) + dm9k_ReadReg(DM9K_REG_MRRL)))
|
|
if (calc_MRR != ((dm9k_ReadReg(DM9K_REG_MRRH) << 8) + dm9k_ReadReg(DM9K_REG_MRRL)))
|
|
{
|
|
{
|
|
#ifdef Point_Error_Reset
|
|
#ifdef Point_Error_Reset
|
|
- dm9k_reset(); /* ÈôÊÇÖ¸Õë³ö´í£¬ÖØÖà */
|
|
|
|
|
|
+ dm9k_reset(); /* 若是指针出错,�置 */
|
|
return ReceiveLength;
|
|
return ReceiveLength;
|
|
#endif
|
|
#endif
|
|
- /*ÈôÊÇÖ¸Õë³ö´í£¬½«Ö¸ÕëÒƵ½ÏÂÒ»¸ö°üµÄ°üͷλÖà */
|
|
|
|
|
|
+ /*若是指针出错,将指针移到下一个包的包头�置 */
|
|
dm9k_WriteReg(DM9K_REG_MRRH, (calc_MRR >> 8) & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_MRRH, (calc_MRR >> 8) & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_MRRL, calc_MRR & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_MRRL, calc_MRR & 0xff);
|
|
}
|
|
}
|
|
@@ -348,26 +368,26 @@ uint16_t dm9k_receive_packet(uint8_t *_uip_buf)
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- if (rx_checkbyte == DM9K_PKT_NORDY) /* δÊÕµ½°ü */
|
|
|
|
|
|
+ if (rx_checkbyte == DM9K_PKT_NORDY) /* 未收到包 */
|
|
{
|
|
{
|
|
dm9k_WriteReg(DM9K_REG_ISR, 0x3f); /* */
|
|
dm9k_WriteReg(DM9K_REG_ISR, 0x3f); /* */
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- dm9k_reset(); /* ½ÓÊÕÖ¸Õë³ö´í£¬ÖØÖà */
|
|
|
|
|
|
+ dm9k_reset(); /* 接收指针出错,�置 */
|
|
}
|
|
}
|
|
return (0);
|
|
return (0);
|
|
}
|
|
}
|
|
- } while (rx_int_count < Max_Int_Count); /* ÊÇ·ñ³¬¹ý×î¶à½ÓÊÕ·â°ü¼ÆÊý */
|
|
|
|
|
|
+ } while (rx_int_count < Max_Int_Count); /* 是�超过最多接收�包计数 */
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_send_packet
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: ·¢ËÍÒ»°üÊý¾Ý
|
|
|
|
-* ÐÎ ²Î: p_char : ·¢ËÍÊý¾Ý»º³åÇø
|
|
|
|
-* ·µ »Ø Öµ: length : Êý¾Ý³¤¶È
|
|
|
|
|
|
+* 函 数 �: dm9k_send_packet
|
|
|
|
+* 功能说明: ��一包数�
|
|
|
|
+* 形 �: p_char : ��数�缓冲区
|
|
|
|
+* 返 回 值: length : 数�长度
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void dm9k_send_packet(uint8_t *p_char, uint16_t length)
|
|
void dm9k_send_packet(uint8_t *p_char, uint16_t length)
|
|
@@ -378,21 +398,21 @@ void dm9k_send_packet(uint8_t *p_char, uint16_t length)
|
|
uint16_t calc_len;
|
|
uint16_t calc_len;
|
|
__IO uint16_t calc_MWR;
|
|
__IO uint16_t calc_MWR;
|
|
|
|
|
|
- /* ¼ì²é DM9KA ÊÇ·ñ»¹ÔÚ´«ËÍÖУ¡ÈôÊǵȴýÖ±µ½´«ËͽáÊø */
|
|
|
|
|
|
+ /* 检查 DM9KA 是å�¦è¿˜åœ¨ä¼ é€�ä¸ï¼�若是ç‰å¾…ç›´åˆ°ä¼ é€�结æ�Ÿ */
|
|
if (SendPackOk == Max_Send_Pack)
|
|
if (SendPackOk == Max_Send_Pack)
|
|
{
|
|
{
|
|
while (dm9k_ReadReg(DM9K_REG_TCR) & DM9K_TCR_SET)
|
|
while (dm9k_ReadReg(DM9K_REG_TCR) & DM9K_TCR_SET)
|
|
{
|
|
{
|
|
- OSTimeDly(5);
|
|
|
|
|
|
+ us_delay(5);
|
|
}
|
|
}
|
|
SendPackOk = 0;
|
|
SendPackOk = 0;
|
|
}
|
|
}
|
|
|
|
|
|
- SendPackOk++; /* ÉèÖô«ËͼÆÊý */
|
|
|
|
|
|
+ SendPackOk++; /* è®¾ç½®ä¼ é€�计数 */
|
|
|
|
|
|
#ifdef FifoPointCheck
|
|
#ifdef FifoPointCheck
|
|
- /* ¼ÆËãÏÂÒ»¸ö´«Ë͵ÄÖ¸Õëλ , Èô½ÓÊÕ³¤¶ÈΪÆæÊý£¬Ðè¼ÓÒ»¶ÔÆëż×Ö½Ú¡£*/
|
|
|
|
- /* ÈôÊdz¬¹ý 0x0bff £¬ÔòÐè»Ø¹éÈƵ½ 0x0000 ÆðʼλÖà */
|
|
|
|
|
|
+ /* è®¡ç®—ä¸‹ä¸€ä¸ªä¼ é€�的指针ä½� , è‹¥æŽ¥æ”¶é•¿åº¦ä¸ºå¥‡æ•°ï¼Œéœ€åŠ ä¸€å¯¹é½�å�¶å—节。*/
|
|
|
|
+ /* 若是超过 0x0bff ,则需回归绕到 0x0000 起始�置 */
|
|
calc_MWR = (dm9k_ReadReg(DM9K_REG_MWRH) << 8) + dm9k_ReadReg(DM9K_REG_MWRL);
|
|
calc_MWR = (dm9k_ReadReg(DM9K_REG_MWRH) << 8) + dm9k_ReadReg(DM9K_REG_MWRL);
|
|
calc_MWR += SendLength;
|
|
calc_MWR += SendLength;
|
|
if (SendLength & 0x01)
|
|
if (SendLength & 0x01)
|
|
@@ -401,28 +421,28 @@ void dm9k_send_packet(uint8_t *p_char, uint16_t length)
|
|
calc_MWR -= 0x0c00;
|
|
calc_MWR -= 0x0c00;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- dm9k_WriteReg(DM9K_REG_TXPLH, (SendLength >> 8) & 0xff); /* ÉèÖô«ËÍ·â°üµÄ³¤¶È */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_TXPLH, (SendLength >> 8) & 0xff); /* è®¾ç½®ä¼ é€�å°�包的长度 */
|
|
dm9k_WriteReg(DM9K_REG_TXPLL, SendLength & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_TXPLL, SendLength & 0xff);
|
|
|
|
|
|
- /* ¿ªÊ¼½«ÏµÍ³µÄ×ÊÁÏ°áµ½µ½ÄÚ´æÖУ¬Ã¿´ÎÒƶ¯Ò»¸ö word */
|
|
|
|
|
|
+ /* 开始将系统的资料æ�¬åˆ°åˆ°å†…å˜ä¸ï¼Œæ¯�次移动一个 word */
|
|
NET_REG_ADDR = DM9K_REG_MWCMD;
|
|
NET_REG_ADDR = DM9K_REG_MWCMD;
|
|
calc_len = (SendLength + 1) >> 1;
|
|
calc_len = (SendLength + 1) >> 1;
|
|
for (i = 0; i < calc_len; i++)
|
|
for (i = 0; i < calc_len; i++)
|
|
NET_REG_DATA = SendData[i];
|
|
NET_REG_DATA = SendData[i];
|
|
|
|
|
|
- dm9k_WriteReg(DM9K_REG_TCR, DM9K_TCR_SET); /* ½øÐд«ËÍ */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_TCR, DM9K_TCR_SET); /* è¿›è¡Œä¼ é€� */
|
|
|
|
|
|
#ifdef FifoPointCheck
|
|
#ifdef FifoPointCheck
|
|
if (calc_MWR != ((dm9k_ReadReg(DM9K_REG_MWRH) << 8) + dm9k_ReadReg(DM9K_REG_MWRL)))
|
|
if (calc_MWR != ((dm9k_ReadReg(DM9K_REG_MWRH) << 8) + dm9k_ReadReg(DM9K_REG_MWRL)))
|
|
{
|
|
{
|
|
#ifdef Point_Error_Reset
|
|
#ifdef Point_Error_Reset
|
|
- /* ÈôÊÇÖ¸Õë³ö´í£¬µÈ´ý´ËÒ»·â°üËÍÍê , Ö®áá½øÐÐÖØÖà */
|
|
|
|
|
|
+ /* 若是指针出错,ç‰å¾…æ¤ä¸€å°�包é€�完 , 之後进行é‡�ç½® */
|
|
while (dm9k_ReadReg(DM9K_REG_TCR) & DM9K_TCR_SET)
|
|
while (dm9k_ReadReg(DM9K_REG_TCR) & DM9K_TCR_SET)
|
|
bsp_DelayUS(5);
|
|
bsp_DelayUS(5);
|
|
dm9k_reset();
|
|
dm9k_reset();
|
|
return;
|
|
return;
|
|
#endif
|
|
#endif
|
|
- /*ÈôÊÇÖ¸Õë³ö´í£¬½«Ö¸ÕëÒƵ½ÏÂÒ»¸ö´«ËÍ°üµÄ°üͷλÖà */
|
|
|
|
|
|
+ /*è‹¥æ˜¯æŒ‡é’ˆå‡ºé”™ï¼Œå°†æŒ‡é’ˆç§»åˆ°ä¸‹ä¸€ä¸ªä¼ é€�包的包头ä½�ç½® */
|
|
dm9k_WriteReg(DM9K_REG_MWRH, (calc_MWR >> 8) & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_MWRH, (calc_MWR >> 8) & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_MWRL, calc_MWR & 0xff);
|
|
dm9k_WriteReg(DM9K_REG_MWRL, calc_MWR & 0xff);
|
|
}
|
|
}
|
|
@@ -431,11 +451,11 @@ void dm9k_send_packet(uint8_t *p_char, uint16_t length)
|
|
}
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
/*******************************************************************************
|
|
- * º¯ÊýÃû: etherdev_send
|
|
|
|
- * ²Î Êý: p_char : Êý¾Ý»º³åÇø
|
|
|
|
- * length : Êý¾Ý³¤¶È
|
|
|
|
- * ·µ »Ø: ÎÞ
|
|
|
|
- * ¹¦ ÄÜ: uIP ½Ó¿Úº¯Êý,·¢ËÍÒ»°üÊý¾Ý
|
|
|
|
|
|
+ * 函数�: etherdev_send
|
|
|
|
+ * � 数: p_char : 数�缓冲区
|
|
|
|
+ * length : 数�长度
|
|
|
|
+ * è¿” 回: æ—
|
|
|
|
+ * 功 能: uIP 接�函数,��一包数�
|
|
*/
|
|
*/
|
|
void etherdev_send(uint8_t *p_char, uint16_t length)
|
|
void etherdev_send(uint8_t *p_char, uint16_t length)
|
|
{
|
|
{
|
|
@@ -448,11 +468,11 @@ uint16_t etherdev_read(uint8_t *p_char)
|
|
}
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
/*******************************************************************************
|
|
- * º¯ÊýÃû: etherdev_chkmedia
|
|
|
|
- * ²Î Êý: p_char : Êý¾Ý»º³åÇø
|
|
|
|
- * length : Êý¾Ý³¤¶È
|
|
|
|
- * ·µ »Ø: ÎÞ
|
|
|
|
- * ¹¦ ÄÜ: uIP ½Ó¿Úº¯Êý, ¼ì²âÍøÂçÁ¬½Ó״̬
|
|
|
|
|
|
+ * 函数�: etherdev_chkmedia
|
|
|
|
+ * � 数: p_char : 数�缓冲区
|
|
|
|
+ * length : 数�长度
|
|
|
|
+ * è¿” 回: æ—
|
|
|
|
+ * 功 能: uIP 接�函数, 检测网络连接状�
|
|
*/
|
|
*/
|
|
void etherdev_chkmedia(void)
|
|
void etherdev_chkmedia(void)
|
|
{
|
|
{
|
|
@@ -460,16 +480,16 @@ void etherdev_chkmedia(void)
|
|
|
|
|
|
while (!(dm9k_ReadReg(DM9K_REG_NSR) & DM9K_PHY))
|
|
while (!(dm9k_ReadReg(DM9K_REG_NSR) & DM9K_PHY))
|
|
{
|
|
{
|
|
- OSTimeDly(2000);
|
|
|
|
|
|
+ us_delay(2000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
-* º¯ Êý Ãû: dm9k_interrupt
|
|
|
|
-* ¹¦ÄÜ˵Ã÷: Öжϴ¦Àíº¯Êý (webserverÀý³ÌδʹÓÃÖжÏ)
|
|
|
|
-* ÐÎ ²Î: ÎÞ
|
|
|
|
-* ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+* 函 数 �: dm9k_interrupt
|
|
|
|
+* 功能说明: ä¸æ–处ç�†å‡½æ•° (webserver例程未使用ä¸æ–)
|
|
|
|
+* å½¢ å�‚: æ—
|
|
|
|
+* è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void dm9k_interrupt(void)
|
|
void dm9k_interrupt(void)
|
|
@@ -477,25 +497,25 @@ void dm9k_interrupt(void)
|
|
uint8_t save_reg;
|
|
uint8_t save_reg;
|
|
uint16_t isr_status;
|
|
uint16_t isr_status;
|
|
|
|
|
|
- save_reg = NET_REG_ADDR; /* ÔÝ´æËùʹÓõÄλÖà */
|
|
|
|
|
|
+ save_reg = NET_REG_ADDR; /* æš‚å˜æ‰€ä½¿ç”¨çš„ä½�ç½® */
|
|
|
|
|
|
- dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* ¹Ø±Õ DM9KA ÖÐ¶Ï */
|
|
|
|
- isr_status = dm9k_ReadReg(DM9K_REG_ISR); /* È¡µÃÖжϲúÉúÖµ */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF); /* å…³é— DM9KA ä¸æ– */
|
|
|
|
+ isr_status = dm9k_ReadReg(DM9K_REG_ISR); /* å�–å¾—ä¸æ–产生值 */
|
|
|
|
|
|
if (isr_status & DM9K_RX_INTR)
|
|
if (isr_status & DM9K_RX_INTR)
|
|
- { /* ¼ì²éÊÇ·ñΪ½ÓÊÕÖÐ¶Ï */
|
|
|
|
- // dm9k_receive_packet(); /* Ö´ÐнÓÊÕ´¦Àí³ÌÐò */
|
|
|
|
|
|
+ { /* 检查是å�¦ä¸ºæŽ¥æ”¶ä¸æ– */
|
|
|
|
+ // dm9k_receive_packet(); /* 执行接收处�程� */
|
|
}
|
|
}
|
|
|
|
|
|
- dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* ¿ªÆô DM9KA ÖÐ¶Ï */
|
|
|
|
- NET_REG_ADDR = save_reg; /* »Ø¸´ËùʹÓõÄλÖà */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_SET); /* å¼€å�¯ DM9KA ä¸æ– */
|
|
|
|
+ NET_REG_ADDR = save_reg; /* 回�所使用的�置 */
|
|
}
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
/*******************************************************************************
|
|
- * º¯ÊýÃû: dm9k_ReadID
|
|
|
|
- * ²Î Êý: ÎÞ
|
|
|
|
- * ·µ »Ø: ÎÞ
|
|
|
|
- * ¹¦ ÄÜ: ¶ÁȡоƬID
|
|
|
|
|
|
+ * 函数�: dm9k_ReadID
|
|
|
|
+ * å�‚ æ•°: æ—
|
|
|
|
+ * è¿” 回: æ—
|
|
|
|
+ * 功 能: 读�芯片ID
|
|
*/
|
|
*/
|
|
uint32_t dm9k_ReadID(void)
|
|
uint32_t dm9k_ReadID(void)
|
|
{
|
|
{
|
|
@@ -527,10 +547,10 @@ uint8_t dm9k_linkstat(void)
|
|
#if 0
|
|
#if 0
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
- * º¯ Êý Ãû: dm9k_debug_test
|
|
|
|
- * ¹¦ÄÜ˵Ã÷: ²âÊÔDM9KAEµÄº¯Êý,ÓÃÓÚÅÅ´í
|
|
|
|
- * ÐÎ ²Î: ÎÞ
|
|
|
|
- * ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+ * 函 数 �: dm9k_debug_test
|
|
|
|
+ * 功能说明: 测试DM9KAE的函数,用于排错
|
|
|
|
+ * å½¢ å�‚: æ—
|
|
|
|
+ * è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void dm9k_debug_test(void)
|
|
void dm9k_debug_test(void)
|
|
@@ -542,10 +562,10 @@ uint8_t dm9k_linkstat(void)
|
|
uint16_t i;
|
|
uint16_t i;
|
|
uint16_t j;
|
|
uint16_t j;
|
|
|
|
|
|
- dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* ¶Ô DM9KA ½øÐÐÈí¼þÖØÖÃ */
|
|
|
|
- OSTimeDly(10); /* delay 10us */
|
|
|
|
- dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* ¶Ô DM9KA ½øÐÐÈí¼þÖØÖÃ */
|
|
|
|
- OSTimeDly(10); /* delay 10us */
|
|
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* 对 DM9KA 进行软件�置 */
|
|
|
|
+ us_delay(10); /* delay 10us */
|
|
|
|
+ dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET); /* 对 DM9KA 进行软件�置 */
|
|
|
|
+ us_delay(10); /* delay 10us */
|
|
|
|
|
|
check_device = dm9k_ReadReg(DM9K_REG_VID_L);
|
|
check_device = dm9k_ReadReg(DM9K_REG_VID_L);
|
|
check_device |= dm9k_ReadReg(DM9K_REG_VID_H) << 8;
|
|
check_device |= dm9k_ReadReg(DM9K_REG_VID_H) << 8;
|
|
@@ -643,9 +663,9 @@ uint8_t dm9k_linkstat(void)
|
|
|
|
|
|
printk("DM9K_DEBUG ==> PACKET SEND & INT TEST !! \n");
|
|
printk("DM9K_DEBUG ==> PACKET SEND & INT TEST !! \n");
|
|
dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET);
|
|
dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET);
|
|
- OSTimeDly(10);
|
|
|
|
|
|
+ us_delay(10);
|
|
dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET);
|
|
dm9k_WriteReg(DM9K_REG_NCR, DM9K_REG_RESET);
|
|
- OSTimeDly(10);
|
|
|
|
|
|
+ us_delay(10);
|
|
|
|
|
|
dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF | DM9K_TX_INTR);
|
|
dm9k_WriteReg(DM9K_REG_IMR, DM9K_IMR_OFF | DM9K_TX_INTR);
|
|
|
|
|
|
@@ -683,10 +703,10 @@ uint8_t dm9k_linkstat(void)
|
|
|
|
|
|
/*
|
|
/*
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
- * º¯ Êý Ãû: etherdev_chkmedia
|
|
|
|
- * ¹¦ÄÜ˵Ã÷: ¼ì²âÍøÂçÁ¬½Ó״̬
|
|
|
|
- * ÐÎ ²Î: ÎÞ
|
|
|
|
- * ·µ »Ø Öµ: ÎÞ
|
|
|
|
|
|
+ * 函 数 �: etherdev_chkmedia
|
|
|
|
+ * 功能说明: 检测网络连接状�
|
|
|
|
+ * å½¢ å�‚: æ—
|
|
|
|
+ * è¿” 回 值: æ—
|
|
*********************************************************************************************************
|
|
*********************************************************************************************************
|
|
*/
|
|
*/
|
|
void etherdev_chkmedia(void)
|
|
void etherdev_chkmedia(void)
|
|
@@ -701,10 +721,10 @@ uint8_t dm9k_linkstat(void)
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
/*******************************************************************************
|
|
- * º¯ÊýÃû: etherdev_poll
|
|
|
|
- * ²Î Êý: ÎÞ
|
|
|
|
- * ·µ »Ø: ÎÞ
|
|
|
|
- * ¹¦ ÄÜ: uIP ½Ó¿Úº¯Êý, ²ÉÓòéѯ·½Ê½½ÓÊÕÒ»¸öIP°ü
|
|
|
|
|
|
+ * 函数�: etherdev_poll
|
|
|
|
+ * å�‚ æ•°: æ—
|
|
|
|
+ * è¿” 回: æ—
|
|
|
|
+ * 功 能: uIP 接�函数, 采用查询方�接收一个IP包
|
|
*/
|
|
*/
|
|
/*
|
|
/*
|
|
etherdev_poll()
|
|
etherdev_poll()
|