#include "main.h"
#include "string.h"
#include "Public.h"
u8 a;
u32 c;
u8 Send[5]={0x02,0x02,0x02,0x02,0x02};
u32 receiveLen;
u8 *receiveBuffer;
u8 lamp;
extern u32 b;
extern u8 step;
u8 arpSucess=0;
u32 number1=0;
u32 number2=0;
u32 number3=0;
u32 error=0;
/* Ethernet Rx & Tx DMA Descriptors */
extern ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB], DMATxDscrTab[ETH_TXBUFNB];
/* Ethernet Driver Receive buffers */
extern uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE];
/* Ethernet Driver Transmit buffers */
extern uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE];
/* Global pointers to track current transmit and receive descriptors */
extern ETH_DMADESCTypeDef *DMATxDescToSet;
extern ETH_DMADESCTypeDef *DMARxDescToGet;
/* Global pointer for last received frame infos */
extern ETH_DMA_Rx_Frame_infos *DMA_RX_FRAME_infos;
u8 MyMacAddr[6]={0x00,0xe0,0x4c,0x45,0x07,0x09};
int main(void)
{
// //初始化板子
BSP_Init();
Task_StartUp(MyMacAddr);
//初始化网络
DP83848Init(MyMacAddr);
step=0;
}
//启动任务堆栈
OS_STK Stk_TaskStartUp[TASK_STARTUP_STK_SIZE];
void Task_StartUp(void *pdata)
{
//初始化UCOS时钟
//OS_TICKS_PER_SEC 为 UCOS-II 每秒嘀嗒数
SysTick_Config(SystemCoreClock/OS_TICKS_PER_SEC - 1);
Task_UDP_Client(pdata);
while (1)
{
// __IO uint32_t LocalTime = 0;
// //OSTimeDlyHMSM(0, 0, 1, 0);//1000ms
// udp_send(udp_pcb,udp_p);//发送数据
// UDP_Send_Data(udp_pcb,udp_p);
// LocalTime = 10;
// LwIP_Periodic_Handle(LocalTime);
// udp_p=udp_x();
//DP83848Send(mydata, 66);
// UDP_Send_Data(udp_pcb,udp_p);
// sprintf(mydata,"%c.%c",mydata_WHY,mydata_off);
// DP83848Send(sendMotorpulse1(), 66);
// sendMotorpulse (moduleNumber1,motorNumber3,dirForward,speed2,655380);
if (a>=3)
{
if(arpSucess) //配网完成不需要再发配网的命令
{
a=1;
}
else
a=0;
}
switch (a)
{
case 0:
//组网
mydata_ARP();
number1 ;
break;
case 1:
//查询
mydata_WHY();
number2 ;
break;
case 2:
//流程
mydata_Process();
break;
default :
a=0;
}
a ;
M_Delay_ms(50);
lamp=!lamp;
if(lamp)
{
LED1_OFF;
}else
{
LED1_ON;
}
}
}
void DP83848Init(u8 * HWADDR)
{
int i ;
ETH_MACAddressConfig(ETH_MAC_Address0,HWADDR);
/* Initialize Tx Descriptors list: Chain Mode */
ETH_DMATxDescChainInit(DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB);
/* Initialize Rx Descriptors list: Chain Mode */
ETH_DMARxDescChainInit(DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB);
#ifdef CHECKSUM_BY_HARDWARE
/* Enable the TCP, UDP and ICMP checksum insertion for the Tx frames */
for(i=0; i<ETH_TXBUFNB; i )
{
ETH_DMATxDescChecksumInsertionConfig(&DMATxDscrTab[i], ETH_DMATxDesc_ChecksumTCPUDPICMPFull);
}
#endif
/* Note: TCP, UDP, ICMP checksum checking for received frame are enabled in DMA config */
/* Enable MAC and DMA transmission and reception */
ETH_Start();
}
/*DP83848 Send data*/
void DP83848Send(u8 * data, u16 length)
{
memcpy((u8 *)DMATxDescToSet->Buffer1Addr,data,length);
if(ETH_Prepare_Transmit_Descriptors(length)==0)
{
error ;
}
c ;
}
评论