Update cmem7_eth.c
This commit is contained in:
parent
2313424f81
commit
bd59276640
|
@ -5,8 +5,8 @@
|
||||||
* @brief CMEM7 ethernet source file
|
* @brief CMEM7 ethernet source file
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @version V1.0
|
* @version V2.0
|
||||||
* @date 3. September 2013
|
* @date 3. September 2014
|
||||||
*
|
*
|
||||||
* @note
|
* @note
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cmem7_eth.h"
|
#include "cmem7_eth.h"
|
||||||
|
#include "cmem7_misc.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
|
@ -190,8 +190,9 @@ static void mac_SetConfig(ETH_InitTypeDef *init) {
|
||||||
ETH->CONFIG_b.IPC = init->ETH_ChecksumOffload;
|
ETH->CONFIG_b.IPC = init->ETH_ChecksumOffload;
|
||||||
ETH->CONFIG_b.DM = init->ETH_Duplex;
|
ETH->CONFIG_b.DM = init->ETH_Duplex;
|
||||||
ETH->CONFIG_b.LM = FALSE;
|
ETH->CONFIG_b.LM = FALSE;
|
||||||
ETH->MMC_RX_MASK = 0xFFFFFFFF;
|
ETH->MMCRIMR = 0xFFFFFFFF;
|
||||||
ETH->MMC_TX_MASK = 0xFFFFFFFF;
|
ETH->MMCTIMR = 0xFFFFFFFF;
|
||||||
|
ETH->MMCIRCOIM = 0xFFFFFFFF;
|
||||||
|
|
||||||
if (init->ETH_Speed == ETH_SPEED_10M) {
|
if (init->ETH_Speed == ETH_SPEED_10M) {
|
||||||
ETH->CONFIG_b.FES = ETH_EXACT_SPEED_10M_BPS;
|
ETH->CONFIG_b.FES = ETH_EXACT_SPEED_10M_BPS;
|
||||||
|
@ -209,7 +210,7 @@ static void mac_SetConfig(ETH_InitTypeDef *init) {
|
||||||
ETH->CONFIG_b.JD = TRUE;
|
ETH->CONFIG_b.JD = TRUE;
|
||||||
ETH->CONFIG_b.WD = TRUE;
|
ETH->CONFIG_b.WD = TRUE;
|
||||||
ETH->CONFIG_b.TC = FALSE;
|
ETH->CONFIG_b.TC = FALSE;
|
||||||
ETH->CONFIG_b.CST = FALSE;
|
ETH->CONFIG_b.CST = TRUE;
|
||||||
ETH->CONFIG_b.TWOKPE = FALSE;
|
ETH->CONFIG_b.TWOKPE = FALSE;
|
||||||
ETH->CONFIG_b.SARC = ETH_SOURCE_ADDR_REPLACE;
|
ETH->CONFIG_b.SARC = ETH_SOURCE_ADDR_REPLACE;
|
||||||
}
|
}
|
||||||
|
@ -318,7 +319,7 @@ static void mac_SetFrameFilter(ETH_FrameFilter *filter) {
|
||||||
ETH->FF_b.VTFE = FALSE;
|
ETH->FF_b.VTFE = FALSE;
|
||||||
ETH->FF_b.IPFE = FALSE;
|
ETH->FF_b.IPFE = FALSE;
|
||||||
ETH->FF_b.DNTU = FALSE;
|
ETH->FF_b.DNTU = FALSE;
|
||||||
ETH->FF_b.RA = TRUE;
|
ETH->FF_b.RA = FALSE;//TRUE
|
||||||
|
|
||||||
// receive all
|
// receive all
|
||||||
if (!filter) {
|
if (!filter) {
|
||||||
|
@ -339,6 +340,8 @@ static void mac_SetFrameFilter(ETH_FrameFilter *filter) {
|
||||||
|
|
||||||
// SA
|
// SA
|
||||||
if (filter->ETH_SourceFilterEnable) {
|
if (filter->ETH_SourceFilterEnable) {
|
||||||
|
uint32_t value;
|
||||||
|
|
||||||
ETH->FF_b.RA = FALSE;
|
ETH->FF_b.RA = FALSE;
|
||||||
ETH->FF_b.SAF = TRUE;
|
ETH->FF_b.SAF = TRUE;
|
||||||
ETH->FF_b.SAIF = filter->ETH_SourceDrop;
|
ETH->FF_b.SAIF = filter->ETH_SourceDrop;
|
||||||
|
@ -346,6 +349,10 @@ static void mac_SetFrameFilter(ETH_FrameFilter *filter) {
|
||||||
ETH->ADDR1_HIGH_b.SA = TRUE;
|
ETH->ADDR1_HIGH_b.SA = TRUE;
|
||||||
ETH->ADDR1_HIGH_b.ADDR =
|
ETH->ADDR1_HIGH_b.ADDR =
|
||||||
(filter->ETH_SourceMacAddr[5] << 8) | filter->ETH_SourceMacAddr[4];
|
(filter->ETH_SourceMacAddr[5] << 8) | filter->ETH_SourceMacAddr[4];
|
||||||
|
|
||||||
|
|
||||||
|
// value = (filter->ETH_SourceMacAddr[5] << 8) | filter->ETH_SourceMacAddr[4];
|
||||||
|
// CMEM7_BFI(&(ETH->ADDR1_HIGH), value, 0, 16);
|
||||||
ETH->ADDR1_LOW = (filter->ETH_SourceMacAddr[3] << 24) |
|
ETH->ADDR1_LOW = (filter->ETH_SourceMacAddr[3] << 24) |
|
||||||
(filter->ETH_SourceMacAddr[2] << 16) |
|
(filter->ETH_SourceMacAddr[2] << 16) |
|
||||||
(filter->ETH_SourceMacAddr[1] << 8) |
|
(filter->ETH_SourceMacAddr[1] << 8) |
|
||||||
|
@ -355,9 +362,9 @@ static void mac_SetFrameFilter(ETH_FrameFilter *filter) {
|
||||||
|
|
||||||
static void mac_setFlowControl(void) {
|
static void mac_setFlowControl(void) {
|
||||||
ETH->FC_b.FCB = FALSE;
|
ETH->FC_b.FCB = FALSE;
|
||||||
ETH->FC_b.TFE = TRUE;
|
ETH->FC_b.TFE = FALSE;//TRUE
|
||||||
ETH->FC_b.RFE = TRUE;
|
ETH->FC_b.RFE = FALSE;//TRUE
|
||||||
ETH->FC_b.UP = TRUE;
|
ETH->FC_b.UP = FALSE;//TRUE
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ETH_PhyRead(uint32_t phyAddr, uint32_t phyReg) {
|
uint32_t ETH_PhyRead(uint32_t phyAddr, uint32_t phyReg) {
|
||||||
|
@ -381,7 +388,24 @@ void ETH_PhyWrite(uint32_t phyAddr, uint32_t phyReg, uint32_t data) {
|
||||||
while (ETH->GMII_ADDR_b.BUSY) ;
|
while (ETH->GMII_ADDR_b.BUSY) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ETH_StructInit(ETH_InitTypeDef* init)
|
||||||
|
{
|
||||||
|
init->ETH_Speed = ETH_SPEED_10M;
|
||||||
|
init->ETH_Duplex = ETH_DUPLEX_FULL;
|
||||||
|
init->ETH_JumboFrame = FALSE;
|
||||||
|
init->ETH_LinkUp = FALSE;
|
||||||
|
init->ETH_RxEn = TRUE;
|
||||||
|
init->ETH_TxEn = TRUE;
|
||||||
|
init->ETH_ChecksumOffload = FALSE;
|
||||||
|
init->ETH_Filter = 0;
|
||||||
|
init->ETH_MacAddr[0] = 0;
|
||||||
|
init->ETH_MacAddr[1] = 0;
|
||||||
|
init->ETH_MacAddr[2] = 0;
|
||||||
|
init->ETH_MacAddr[3] = 0;
|
||||||
|
init->ETH_MacAddr[4] = 0;
|
||||||
|
init->ETH_MacAddr[5] = 0;
|
||||||
|
|
||||||
|
}
|
||||||
BOOL ETH_Init(ETH_InitTypeDef *init) {
|
BOOL ETH_Init(ETH_InitTypeDef *init) {
|
||||||
assert_param(init);
|
assert_param(init);
|
||||||
assert_param(IS_ETH_SPEED(init->ETH_Speed));
|
assert_param(IS_ETH_SPEED(init->ETH_Speed));
|
||||||
|
@ -401,7 +425,7 @@ BOOL ETH_Init(ETH_InitTypeDef *init) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ETH_EnableInt(uint32_t Int, BOOL enable) {
|
void ETH_ITConfig(uint32_t Int, BOOL enable) {
|
||||||
assert_param(IS_ETH_INT(Int));
|
assert_param(IS_ETH_INT(Int));
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
|
@ -426,7 +450,7 @@ void ETH_EnableInt(uint32_t Int, BOOL enable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BOOL ETH_GetIntStatus(uint32_t Int) {
|
BOOL ETH_GetITStatus(uint32_t Int) {
|
||||||
assert_param(IS_ETH_INT(Int));
|
assert_param(IS_ETH_INT(Int));
|
||||||
|
|
||||||
Int &= ETH->INT_EN;
|
Int &= ETH->INT_EN;
|
||||||
|
@ -436,8 +460,7 @@ BOOL ETH_GetIntStatus(uint32_t Int) {
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
void ETH_ClearITPendingBit(uint32_t Int) {
|
||||||
void ETH_ClearInt(uint32_t Int) {
|
|
||||||
uint32_t sta;
|
uint32_t sta;
|
||||||
assert_param(IS_ETH_INT(Int));
|
assert_param(IS_ETH_INT(Int));
|
||||||
|
|
||||||
|
@ -450,15 +473,15 @@ void ETH_ClearInt(uint32_t Int) {
|
||||||
|
|
||||||
if (IS_ETH_INT_NORMAL(Int)) {
|
if (IS_ETH_INT_NORMAL(Int)) {
|
||||||
if (!IS_ETH_INT_NORMAL(sta)) {
|
if (!IS_ETH_INT_NORMAL(sta)) {
|
||||||
// write 1 clear
|
// write 1 clear NIS
|
||||||
ETH->STATUS_b.NIS = 1;
|
ETH->STATUS = ETH_INT_NORMAL_SUMMARY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_ETH_INT_ABNORMAL(Int)) {
|
if (IS_ETH_INT_ABNORMAL(Int)) {
|
||||||
if (!IS_ETH_INT_ABNORMAL(sta)) {
|
if (!IS_ETH_INT_ABNORMAL(sta)) {
|
||||||
// write 1 clear
|
// write 1 clear AIS
|
||||||
ETH->STATUS_b.AIS = 1;
|
ETH->STATUS = ETH_INT_ABNORMAL_SUMMARY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -491,12 +514,25 @@ BOOL ETH_SetTxDescRing(ETH_TX_DESC *ring) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If code mapping */
|
||||||
|
ring = (ETH_TX_DESC *)GLB_ConvertToMappingFromAddr((uint32_t)ring);
|
||||||
|
buf = ring;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
INNER_ETH_TX_DESC *desc = (INNER_ETH_TX_DESC *)buf;
|
INNER_ETH_TX_DESC *desc = (INNER_ETH_TX_DESC *)buf;
|
||||||
|
uint8_t first = desc->TX_0.TX0_b.FS;
|
||||||
|
uint8_t last = desc->TX_0.TX0_b.LS;
|
||||||
|
|
||||||
|
// clear all bits
|
||||||
|
desc->TX_0.TX0 = 0;
|
||||||
|
desc->TX_0.TX0_b.FS = first;
|
||||||
|
desc->TX_0.TX0_b.LS = last;
|
||||||
desc->TX_0.TX0_b.TCH = TRUE;
|
desc->TX_0.TX0_b.TCH = TRUE;
|
||||||
desc->TX_0.TX0_b.IC = TRUE;
|
desc->TX_0.TX0_b.IC = TRUE;
|
||||||
desc->TX_0.TX0_b.OWN = ETH_DESC_OWN_BY_SELF;
|
desc->TX_0.TX0_b.OWN = ETH_DESC_OWN_BY_SELF;
|
||||||
|
|
||||||
|
buf->bufAddr = GLB_ConvertToMappingFromAddr(buf->bufAddr);
|
||||||
|
buf->nextDescAddr = GLB_ConvertToMappingFromAddr(buf->nextDescAddr);
|
||||||
buf = (ETH_TX_DESC *)buf->nextDescAddr;
|
buf = (ETH_TX_DESC *)buf->nextDescAddr;
|
||||||
} while (buf != ring);
|
} while (buf != ring);
|
||||||
|
|
||||||
|
@ -553,6 +589,16 @@ void ETH_ReleaseTxDesc(ETH_TX_DESC *desc) {
|
||||||
inner->TX_0.TX0_b.OWN = ETH_DESC_OWN_BY_HW;
|
inner->TX_0.TX0_b.OWN = ETH_DESC_OWN_BY_HW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ETH_SetTxDescBufAddr(ETH_TX_DESC *desc, uint32_t bufAddr) {
|
||||||
|
if (desc) {
|
||||||
|
desc->bufAddr = GLB_ConvertToMappingFromAddr(bufAddr);;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ETH_GetTxDescBufAddr(ETH_TX_DESC *desc) {
|
||||||
|
return (desc ? GLB_ConvertToMappingToAddr(desc->bufAddr) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
BOOL ETH_SetRxDescRing(ETH_RX_DESC *ring) {
|
BOOL ETH_SetRxDescRing(ETH_RX_DESC *ring) {
|
||||||
ETH_RX_DESC *buf = ring;
|
ETH_RX_DESC *buf = ring;
|
||||||
|
|
||||||
|
@ -564,12 +610,17 @@ BOOL ETH_SetRxDescRing(ETH_RX_DESC *ring) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If code mapping */
|
||||||
|
ring = (ETH_RX_DESC *)GLB_ConvertToMappingFromAddr((uint32_t)ring);
|
||||||
|
buf = ring;
|
||||||
do {
|
do {
|
||||||
INNER_ETH_RX_DESC *desc = (INNER_ETH_RX_DESC *)buf;
|
INNER_ETH_RX_DESC *desc = (INNER_ETH_RX_DESC *)buf;
|
||||||
desc->RX_1.RX1_b.RCH = TRUE;
|
desc->RX_1.RX1_b.RCH = TRUE;
|
||||||
desc->RX_1.RX1_b.DIC = FALSE;
|
desc->RX_1.RX1_b.DIC = FALSE;
|
||||||
desc->RX_0.RX0_b.OWN = ETH_DESC_OWN_BY_HW;
|
desc->RX_0.RX0_b.OWN = ETH_DESC_OWN_BY_HW;
|
||||||
|
|
||||||
|
buf->bufAddr = GLB_ConvertToMappingFromAddr(buf->bufAddr);
|
||||||
|
buf->nextDescAddr = GLB_ConvertToMappingFromAddr(buf->nextDescAddr);
|
||||||
buf = (ETH_RX_DESC *)buf->nextDescAddr;
|
buf = (ETH_RX_DESC *)buf->nextDescAddr;
|
||||||
} while (buf != ring);
|
} while (buf != ring);
|
||||||
|
|
||||||
|
@ -627,3 +678,15 @@ void ETH_ReleaseRxDesc(ETH_RX_DESC *desc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ETH_SetRxDescBufAddr(ETH_RX_DESC *desc, uint32_t bufAddr) {
|
||||||
|
if (desc) {
|
||||||
|
desc->bufAddr = GLB_ConvertToMappingFromAddr(bufAddr);;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ETH_GetRxDescBufAddr(ETH_RX_DESC *desc) {
|
||||||
|
return (desc ? GLB_ConvertToMappingToAddr(desc->bufAddr) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue