从下面这几个函数看,MAC地址是IP地址生成的,是不一样的。现在两个网卡都初始化完后(两个网口的链路连接指示灯都亮起了),好像程序堵塞了,创建sock的 任务进程不能转入。创建sock的任务在初始化两个网卡函数的最后。仿真时程序能跑到_task_create(0,20, 0);,这个创建函数,但是把断点打在这个函数内部,没任何反应。暂停查看MQX任务中有TCPIP任务,但是SOCK没创建成功。
只初始化一个网卡时,就能正确的执行创建sock任务。
#define A1 192
#define B1 168
#define C1 1
#define D1 120
#define BSP_DEFAULT_ENET_OUI { 0x00, 0x00, 0x5E, 0, 0, 0 }
const _enet_address _enet_oui = BSP_DEFAULT_ENET_OUI;
//////////////////////////////////////////////////////////////////////////
void init_net_task(void)//网卡初始化函数
{
int32_t error;
uint32_t server[BSP_ENET_DEVICE_COUNT];
uint32_t i = 0;
char* indexes[BSP_ENET_DEVICE_COUNT];
uint8_t n_devices = BSP_ENET_DEVICE_COUNT;
#if !HTTP_USE_ONE_SERVER
uint8_t n_servers = BSP_ENET_DEVICE_COUNT;
#else
uint8_t n_servers = 1;
#endif
_int_install_unexpected_isr();
/* Init RTCS */
_RTCSPCB_init = 4;
_RTCSPCB_grow = 2;
_RTCSPCB_max = 8;
_RTCSTASK_stacksize = 4500;
error = RTCS_create();
if (error != RTCS_OK)
{
printf("RTCS failed to initialize, error = 0x%X\n", error);
_task_block();
}
_IP_forward = TRUE;
/* Bind IP address for each interface */
for (i = 1; i <=2; i++)
{
_enet_address address;
uint32_t phy_addr;
// uint32_t sock;
// sock = socket(AF_INET,SOCK_STREAM,0);
phy_addr = i;
if(i==2)
ip_addr[i] = IPADDR(A1,B1,C1,D1);
else
if(i==1)
ip_addr[i] = IPADDR(config1[5],config1[6],config1[7],config1[8]);
ENET_get_mac_address(phy_addr, ip_addr[i], address);
/* Init ENET device */
error = ipcfg_init_device (phy_addr, address);
if (error != RTCS_OK)
{
printf("IPCFG: Device n.%d init failed. Error = 0x%X\n", i, error);
_task_set_error(MQX_OK);
n_devices--;
i--;
continue;
}
#if RTCSCFG_ENABLE_IP4
ip_data.ip = ip_addr[i];
ip_data.mask = IPADDR(config1[9],config1[10],config1[11],config1[12]);
if(i==1)
ip_data.gateway = IPADDR(config1[13],config1[14],config1[15],config1[16]);
/* Bind IPv4 address */
error = ipcfg_bind_staticip (phy_addr, &ip_data);
if (error != RTCS_OK)
{
// printf("\nIPCFG: Failed to bind IP address. Error = 0x%X", error);
_task_block();
}
#endif
}
//userftp_init();
_task_create(0,20, 0); //创建sock函数
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
bool _bsp_get_mac_address//获取网卡地址函数
(
uint32_t device,
uint32_t value,
_enet_address address
)
{ /* Body */
if (device >= BSP_ENET_DEVICE_COUNT)
return FALSE;
switch (device) {
case 0:
address[0] = _enet_oui[0];
address[1] = _enet_oui[1];
address[2] = _enet_oui[2];
address[3] = (value & 0xFF0000) >> 16;
address[4] = (value & 0xFF00) >> 8;
address[5] = (value & 0xFF);
break;
case 1:
/* Try to get mac from eeprom first */
//dm9000_get_mac_address(address);
//if (is_valid_ether_addr(address))
// break;
address[0] = _enet_oui[0];
address[1] = _enet_oui[1];
address[2] = _enet_oui[2];
address[3] = (value & 0xFF0000) >> 16;
address[4] = (value & 0xFF00) >> 8;
address[5] = (value & 0xFF);
break;
case 2:
/* Try to get mac from eeprom first */
//dm9000_get_mac_address(address);
//if (is_valid_ether_addr(address))
// break;
address[0] = _enet_oui[0];
address[1] = _enet_oui[1];
address[2] = _enet_oui[2];
address[3] = (value & 0xFF0000) >> 16;
address[4] = (value & 0xFF00) >> 8;
address[5] = (value & 0xFF);
break;
default:
break;
}
return TRUE;
}