Other Parts Discussed in Thread: SYSBIOS
Hi,
I was wondering how can I send and receive packets over ethernet.
I have tried to port the example given in:
C:\ti\pdk_C6657_1_1_1_4\packages\ti\drv\emac\example\EMACBenchmark
but without success, since I do not wish to work with tasks.
My init function looks as follows:
void eth_init (void)
{
EMAC_CONFIG_INFO_T emac_cfg;
#ifdef TWO_PORT_DEV
port_num = 1;
#endif
open_cfg.master_core_flag = TRUE;
open_cfg.mdio_flag = TRUE;
open_cfg.loop_back = FALSE;
open_cfg.num_of_tx_pkt_desc = APP_EMAC_INIT_TX_PKTS;
open_cfg.num_of_rx_pkt_desc = APP_EMAC_INIT_RX_PKTS;
open_cfg.max_pkt_size = APP_EMAC_INIT_PKT_SIZE;
open_cfg.num_of_chans = APP_EMAC_NUM_CHANS_PER_CORE;
open_cfg.p_chan_mac_addr = &chan_cfg;
open_cfg.rx_pkt_cb = app_rx_pkt;
open_cfg.alloc_pkt_cb = app_alloc_pkt;
open_cfg.free_pkt_cb = app_free_pkt;
if (port_num == 0)
{
open_cfg.phy_addr = APP_PORT0_PHY_ADDR;
}
#ifdef TWO_PORT_DEV
else
{
open_cfg.phy_addr = APP_PORT1_PHY_ADDR;
}
#endif
/* Set the channel configuration */
chan_cfg.chan_num = chan_num;
chan_cfg.num_of_mac_addrs = APP_EMAC_NUM_MACADDRS_PER_CHAN;
memcpy(mac_addr.addr, tx_mac_addr, EMAC_MAC_ADDR_LENTH);
chan_cfg.p_mac_addr = &mac_addr;
/* Always open the channel 0 on port 0 for receive task */
if (emac_open(port_num, &open_cfg) == EMAC_DRV_RESULT_OK)
{
emac_cfg.mcast_cnt = 0;
emac_cfg.p_mcast_list = NULL;
emac_cfg.rx_filter = EMAC_PKTFLT_MULTICAST;
emac_config(port_num, &emac_cfg);
/* Enable RX/TX interrupt */
Osal_emacExitSingleCoreCriticalSection(port_num);
}
else
{
printf ("Application open EMAC port %d error \n", port_num);
}
}
And to transmit the packet I use the following:
void Transmit_Pkt(unsigned char* buffer, unsigned int len){
EMAC_PKT_DESC_T p_pkt_desc;
unsigned char send_buf[APP_EMAC_MAX_PKT_SIZE] = {0};
p_pkt_desc.AppPrivate = (Uint32) &p_pkt_desc;
p_pkt_desc.Flags = EMAC_PKT_FLAG_SOP | EMAC_PKT_FLAG_EOP;
p_pkt_desc.ValidLen = APP_EMAC_TEST_TX_PKT_SIZE;
p_pkt_desc.DataOffset = 0;
p_pkt_desc.PktChannel = chan_num;
p_pkt_desc.PktLength = APP_EMAC_TEST_TX_PKT_SIZE;
p_pkt_desc.PktFrags = 1;
p_pkt_desc.pDataBuffer = send_buf;
/* Invalidate cache if data in external memory */
//Osal_emacBeginMemAccess(send_buf, APP_EMAC_TEST_TX_PKT_SIZE);
// copy data
memcpy(app_mcb.test_pkt_buf, buffer, len);
if (multicast)
{
/* Fill in the multicast destination address */
memcpy(p_pkt_desc.pDataBuffer, mcast_mac_addr0, EMAC_MAC_ADDR_LENTH);
}
else if (broadcast)
{
/* Fill in the broadcast destination address */
memset(p_pkt_desc.pDataBuffer, 0xff, EMAC_MAC_ADDR_LENTH);
}
else
{
/* Fill in the unitcast destination address */
memcpy(p_pkt_desc.pDataBuffer, rx_mac_addr, EMAC_MAC_ADDR_LENTH);
}
/* Fill in the source address */
memcpy(&p_pkt_desc.pDataBuffer[EMAC_MAC_ADDR_LENTH], tx_mac_addr, EMAC_MAC_ADDR_LENTH);
/* Fill in the Ether Type and Payload */
memcpy(&p_pkt_desc.pDataBuffer[2*EMAC_MAC_ADDR_LENTH],
app_mcb.test_pkt_buf,
APP_EMAC_TEST_TX_PKT_SIZE-2*EMAC_MAC_ADDR_LENTH);
/* Write back cache to memory if data in external memory */
//Osal_emacEndMemAccess(p_pkt_desc.pDataBuffer, APP_EMAC_TEST_TX_PKT_SIZE);
emac_send(port_num, &p_pkt_desc);
}
My transmit function causes exception.
Can you please provide me an example or point out my mistake?
Thanks in advance,
Kfir.

