TMS320C6678以太网通信例程
时间: 2023-09-16 14:12:12 浏览: 169
TMS320C6678全套手册
5星 · 资源好评率100%
TMS320C6678是德州仪器(TI)公司推出的一款高性能数字信号处理器(DSP)。它内置多核ARM Cortex-A15和DSP处理器,具有强大的计算能力和高速的通信接口,因此在实现高速数据传输和处理方面具有很大的优势。下面是TMS320C6678以太网通信例程的代码:
```c
#include <ti/drv/emac/emac_drv.h>
#include <ti/drv/emac/soc/emac_soc_v4.h>
#include <ti/csl/cslr_device.h>
/* EMAC Configuration Parameters */
#define BOARD_PHY_ADDR (0)
#define EMAC_PORT (1)
#define EMAC_RX_MAX_CH (1)
#define EMAC_TX_MAX_CH (1)
#define EMAC_NUM_OF_RX_PKTS (32)
#define EMAC_NUM_OF_TX_PKTS (32)
#define EMAC_RX_PKT_SIZE (1522)
#define EMAC_TX_PKT_SIZE (1522)
/* EMAC Driver Handle */
static EMAC_DRV_Handle emacHandle = NULL;
/* EMAC RX Queue Handle */
static EMAC_PKT_QUEUE_Handle rxQueueHandle = NULL;
/* EMAC TX Queue Handle */
static EMAC_PKT_QUEUE_Handle txQueueHandle = NULL;
/* EMAC Packet Buffer Pool */
static uint8_t pktBuf[EMAC_RX_MAX_CH][EMAC_NUM_OF_RX_PKTS * EMAC_RX_PKT_SIZE];
/* EMAC Init */
void emac_init()
{
EMAC_OPEN_CONFIG_INFO_T emacOpenConfig;
EMAC_HwAttrs_V4 cfg;
/* Get the default configuration */
EMAC_socGetInitCfg(EMAC_PORT, &cfg);
/* Modify the default configuration as needed */
cfg.hwAttrs[0].phyAddr = BOARD_PHY_ADDR;
cfg.rxChannel.numRxCps = EMAC_NUM_OF_RX_PKTS;
cfg.txChannel.numTxCps = EMAC_NUM_OF_TX_PKTS;
cfg.rxChannel.rxFlowCfg[0].cfg.rxMatchEn = 1;
cfg.rxChannel.rxFlowCfg[0].cfg.matchEnMask = 0x00000000;
/* Set the configuration */
EMAC_socSetInitCfg(EMAC_PORT, &cfg);
/* Open the EMAC Driver */
memset(&emacOpenConfig, 0, sizeof(emacOpenConfig));
emacOpenConfig.hwAttrs = (void *)&cfg;
emacOpenConfig.mdioBusFreq = EMAC_MDIO_FREQ_INPUT;
emacHandle = EMAC_open(EMAC_PORT, EMAC_RX_MAX_CH, EMAC_TX_MAX_CH, &emacOpenConfig);
/* Create the RX Queue */
rxQueueHandle = EMAC_pktQueueCreate(emacHandle, EMAC_NUM_OF_RX_PKTS, EMAC_RX_PKT_SIZE, (uint8_t *)&pktBuf[0][0], EMAC_PKT_DESC_SIZE);
/* Create the TX Queue */
txQueueHandle = EMAC_pktQueueCreate(emacHandle, EMAC_NUM_OF_TX_PKTS, EMAC_TX_PKT_SIZE, NULL, EMAC_PKT_DESC_SIZE);
/* Start the EMAC Driver */
EMAC_start(emacHandle);
}
int main()
{
emac_init();
while(1)
{
/* TODO: Add user code here */
}
return 0;
}
```
上述代码中,我们首先定义了一些EMAC的配置参数,包括PHY地址、端口、最大RX/TX通道数、RX/TX数据包数量、RX/TX数据包大小等。然后通过EMAC_socGetInitCfg和EMAC_socSetInitCfg函数来获取和修改默认配置。接着我们创建RX和TX队列,并通过EMAC_pktQueueCreate函数创建队列,最后启动EMAC驱动。
当然,上述代码只是EMAC的初始化部分,实际应用中还需要编写发送和接收数据包的代码。
阅读全文