📄 cs8900.c.svn-base
字号:
msgWakeup = 0;
#if ETHER_DEBUG
if ((triggerType & (SEND_INT_TRIGGER | BUF_INT_TRIGGER)) == 0)
{
/* if happened, should not send msg to ether task. */
sysPrnUart("etherDt!\n");
goto recv_int_check;
}
#endif /* ETHER_DEBUG */
triggerType &= ~(SEND_INT_TRIGGER | BUF_INT_TRIGGER);
oseSendIntAsyncMsg(2, &triggerType, sizeof (triggerType), ETHER_TASK_ID);
}
recv_int_check:
#endif
if (triggerType & RECV_INT_TRIGGER)
{
#if ETHER_DEBUG
len = dsm_length_packet(recv_dsm);
etherByteToStr(recv_dsm->data_ptr, (len > 32 ? 32 : len), buf);
sysPrnUart("recv pkt. len=%d, herder:\n%s\n", len, buf);
recv_dsm = 0;
#endif
triggerType &= ~(RECV_INT_TRIGGER);
tcpipCb2();
}
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
static void etherChipReset(void)
{
writeReg(PP_SelfCTL, readReg(PP_SelfCTL) | PP_SelfCTL_Reset);
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
/* stop TX/RX */
#if ETHER_NOT_YET
static void etherHalt(void)
{
writeReg(PP_LineCTL, 0);
}
#endif
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
/* if not load from EEPROM, driver must write. */
static void etherSetMacAddr(LC_BYTE *addr)
{
writeReg (PP_IA + 0, addr[0] | (addr[1] << 8));
writeReg (PP_IA + 2, addr[2] | (addr[3] << 8));
writeReg (PP_IA + 4, addr[4] | (addr[5] << 8));
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
#if ETHER_NOT_YET
static void etherClose(void)
{
writeReg(PP_RxCFG, 0);
writeReg(PP_TxCFG, 0);
writeReg(PP_BufCFG, 0);
writeReg(PP_BusCTL, 0);
}
#endif
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
void etherStatisticGet(LC_BYTE *buf)
{
LC_DWORD *data;
LC_WORD i;
/* assume buf len is enough from caller. */
if (buf)
{
memcpy(buf, ðerStatistic, sizeof (etherStatistic));
}
else
{
data = (LC_DWORD *)ðerStatistic;
for (i = 0; (i < (sizeof (etherStatistic) / 4)); i++)
{
if (data[i])
{
sysPrnUart("%s : %d\n", etherStatisticInfo[i], data[i]);
}
}
sysPrnUart("%s", etherStatisticInfo[i]);
}
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
LC_WORD etherByteToStr(LC_BYTE *in, LC_WORD len, LC_BYTE *out)
{
LC_WORD i;
LC_BYTE *str = "0123456789ABCDEF";
if (!in || !len)
{
return 0;
}
for (i = 0; (i < ETHER_PRN_SIZE * 3) && (i < len); i++)
{
*out++ = str[(in[i] >> 4) &0xF];
*out++ = str[in[i] & 0xF];
*out++ = ' ';
}
*out = 0;
return i;
}
#if ETHER_TEST
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
void etherTestTask(MessageId tEvent, LC_BYTE *pbData, LC_WORD wLen)
{
switch (tEvent)
{
case EV_ACTIVATE_REQ:
etherTestInit();
break;
case EV_TIMER2EVENT:
etherTestSend();
break;
case 12: /* to do recv packets. */
etherTestRecv();
break;
default:
sysPrnUart("ether test task recv unknown event[0x%08x]!\n", tEvent);
break;
}
oseFreeMem(pbData);
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
static void etherTestSend(void)
{
LC_WORD index;
LC_WORD tmp;
LC_WORD itemSize;
LC_BYTE *p;
dsm_item_type *dsm, *next;
index = sendCnt % 4;
dsm = dsm_new_buffer_all(DSM_DS_LARGE_ITEM_POOL, pktLen[index]);
if (!dsm)
{
return;
}
itemSize = dsm_get_item_size(DSM_DS_LARGE_ITEM_POOL);
if (pktLen[index] <= itemSize)
{
memcpy(dsm->data_ptr, pktSend[index], pktLen[index]);
dsm->used = pktLen[index];
}
else
{
next = dsm;
tmp = pktLen[index];
p = pktSend[index];
for (; tmp >= itemSize && next; tmp -= itemSize, p += itemSize)
{
memcpy(next->data_ptr, p, itemSize);
next->used = itemSize;
next = next->pkt_ptr;
}
#if ETHER_DEBUG
if (tmp && !next)
{
sysPrnUart("etherTestSend!\n");
return;
}
#endif
if (tmp)
{
memcpy(next->data_ptr, p, tmp);
next->used = tmp;
}
}
sendCnt++;
/*
sysPrnUart("ether test task: recv %d, send %d \n",
recvCnt, sendCnt);
*/
etherStatisticGet(0);
etherTx(dsm);
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
static void etherTestRecv(void)
{
LC_WORD len;
LC_DWORD pktCnt;
LC_BYTE buf[ETHER_PRN_SIZE * 3];
dsm_item_type *dsm;
/* XXX: INT LOCK. */
pktCnt = q_cnt(ðerRecvQueue);
while (pktCnt--)
{
recvCnt++;
memset(buf, 0x00, sizeof (buf));
dsm = q_get(ðerRecvQueue);
len = dsm_length_packet(dsm);
etherByteToStr(dsm->data_ptr, 64, buf);
sysPrnUart("recv frame len %d. \nrecv pkt header:\n%s \n\n", len, buf);
dsm_free_packet(&dsm);
}
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
static void etherTestInit(void)
{
#define OFFSET 0
LC_WORD i;
/* dst mac addr. temporarily assigned. */
LC_BYTE mac[ETHER_ADDR_LEN] = {0x00, 0x1D, 0x09, 0x09, 0x1A, 0xA9};
recvCnt = 0;
sendCnt = 0;
pktSend[0] = pktSend1;
pktSend[1] = pktSend2;
pktSend[2] = pktSend3;
pktSend[3] = pktSend4;
pktLen[0] = sizeof (pktSend1);
pktLen[1] = sizeof (pktSend2);
pktLen[2] = sizeof (pktSend3);
pktLen[3] = sizeof (pktSend4);
memset((pktSend[0] + OFFSET), 0xaa, pktLen[0] - OFFSET);
memset((pktSend[1] + OFFSET), 0xbb, pktLen[1] - OFFSET);
memset((pktSend[2] + OFFSET), 0xdd, pktLen[2] - OFFSET);
memset((pktSend[3] + OFFSET), 0xee, pktLen[3] - OFFSET);
for (i = 0; i < 4; i++)
{
switch(i)
{
case 0: /*64*/
memset(pktSend[0], 0xff, ETHER_ADDR_LEN);
memcpy(pktSend[0] + ETHER_ADDR_LEN, etherAddr, ETHER_ADDR_LEN);
pktSend1[12] = 0x08;
pktSend1[13] = 0x06;
break;
case 1: /*68*/
memset(pktSend[1], 0xff, ETHER_ADDR_LEN);
memcpy(pktSend[1] + ETHER_ADDR_LEN, etherAddr, ETHER_ADDR_LEN);
pktSend2[12] = 0x08;
pktSend2[13] = 0x00;
break;
case 2: /*72*/
memcpy(pktSend[2], mac, ETHER_ADDR_LEN);
memcpy(pktSend[2] + ETHER_ADDR_LEN, etherAddr, ETHER_ADDR_LEN);
pktSend3[12] = 0x08;
pktSend3[13] = 0x00;
break;
case 3: /*76*/
memcpy(pktSend[3], mac, ETHER_ADDR_LEN);
memcpy(pktSend[3] + ETHER_ADDR_LEN, etherAddr, ETHER_ADDR_LEN);
pktSend4[12] = 0x08;
pktSend4[13] = 0x00;
break;
}
}
oseSetLoopTimer(TIMER2, 1000 * 3, NULL_PARAM);
sysPrnUart("DSM large item size %d\n", dsm_get_item_size(DSM_DS_LARGE_ITEM_POOL));
sysPrnUart("ethernet test task init OK!\n");
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
static void recvQueueAppend(dsm_item_type *dsm)
{
if (q_cnt(ðerRecvQueue) >= SEND_Q_MAX)
{
etherStatistic.dwRecvQueueFull++;
/* drop and free this packet. */
dsm_free_packet(&dsm);
return;
}
/* link into recv queue. */
q_link(dsm, (q_link_type *)dsm);
q_put(ðerRecvQueue, (q_link_type *)dsm);
if ((LC_DWORD)q_cnt(ðerRecvQueue) > etherStatistic.dwRecvQueueMax)
{
etherStatistic.dwRecvQueueMax = q_cnt(ðerRecvQueue);
}
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
static void recvMsgSend(void)
{
oseSendIntAsyncMsg(12, 0, 0, ETHER_TEST_TASK_ID);
}
/*==============================================================================
* Function :
* Description :
* In Parameter :
** Type :
** Description :
* Out Parameter :
** Type :
** Description :
* Return :
* Other :
==============================================================================*/
static void linkStateUpdate(LC_BYTE state)
{
/* nothing to do in test task.*/
sysPrnUart("linkStateUpdate: %s\n", (state?"UP":"DOWN"));
}
#endif /* ETHER_TEST */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -