在 main.c
初始化网络,IO端口 等。
调用 官方的 网络部分函数实现 一个tcp server
将 dap部分与 tcp server 挂接
#include "DAP_queue.h"
static uint8_t *ptrDataIn;
static uint16_t DataInReceLen;
static DAP_queue DAP_Cmd_queue;
void WCHNET_Data_Dap(u8 id)
{
u32 n;
uint8_t * rbuf;
uint8_t * sbuf = 0;
n = WCHNET_SocketRecvLen(id, NULL); //query length
// printf("Receive Len = %02x\n", n);
if(n>0)
{
WCHNET_SocketRecv(id, ptrDataIn,&n); //Read the data of the receive buffer into MyBuf
ptrDataIn += n;
DataInReceLen += n;
if (DAP_queue_execute_buf(&DAP_Cmd_queue, MyBuf, DataInReceLen,&rbuf))
{
if(DAP_queue_get_send_buf(&DAP_Cmd_queue, &sbuf, &n))
{
WCHNET_SocketSend(id, sbuf,&n); //Send the data
}
}
//revert the input pointers
DataInReceLen = 0;
ptrDataIn = MyBuf;
}
}
void Dap_data_Init(void)
{
memset(MyBuf,0xff,RECE_BUF_LEN);
ptrDataIn = MyBuf;
DataInReceLen = 0;
DAP_queue_init(&DAP_Cmd_queue);
}
|