This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/TM4C1294NCPDT:选择了 lwip 的 UDP_SEND ()函数#39;t 在 TM4C1294NCPDT 中工作

Guru**** 2049300 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/960204/ccs-tm4c1294ncpdt-udp_send-function-of-lwip-dosen-t-work-in-tm4c1294ncpdt

器件型号:TM4C1294NCPDT

工具/软件:Code Composer Studio

你好。 

我想在 NTP 上制作数字手表。 因此、我首先尝试建立 UDP 客户端。
我认为我设置了 UDP 的所有必需选项,但 udp_send() fucntion 剂量不起作用。

这是基于"enet_lwip"示例的代码

#include 
#include 
#include 
include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/flash.h"
#include "driverlib/utilid.h"



#include "driverlib/simpline.h"#include "driverlib/snull/driver.h"#include "driverlib.utils/drivers#drivers.ld/drivers#include "driverlib.dl.dl.dl.id.ide"#include"#include "drivers/drivers.util.dlintrintrine"#drivers.dl.dl.dl.id.dl.dl.id.dl.md.utils/udpine"#include "#include "udpine"#drivers/udpintr.id.id.dl.dl.dl.dl.id.id.id.utils/ude"#include"#include "#include "#include "drivers/udpine.h/udpine.h/udpine.h/udpine.h.util














//
//
//定义设置系统时钟。
////
*****************
#define SYSTICKHZ 100
#define SYSTICKMS (1000 / SYSTICKHZ)

//*********
//
//中断优先级定义。 这些值的前3位是
//有效的、较低的值表示较高优先级的中断。
////
*****************
#define SysTK_INT_PRIORITY 0x80
#define ETHERNET_INT_PRIORITY 0xC0


//*********
//
//系统时钟频率。
////
*****************
uint32_t g_ui32SysClock;

//*********
//
//当前 IP 地址。
////
*****************
uint32_t g_ui32IPAddress;
ip_addr_t ui32IPAddress;
ip_addr_t* p_ui32IPAddress =&ui32IPAddress;


//*********
//
// NTP 服务器 IP 地址。
////
*****************
ip_addr_t ntpserver_addr;
ip_addr_t* ntpserver_addr_t =&ntpserver_addr;


const char* NTPServer_addr ="106.247.248.106";
const char* NTPServerName ="kr.pool.ntp.org";

Address &pBuf[16];const char* ntp_packet ="pcntp_size


="int_int_char;const char = p_int_int_int_int_int_int_int_int_int_int_int_int_int //NTP 时间戳位于消息
uint8_t NTPBuffer[ntp_packet_size]的前48个字节中; //用于保存传入和传出数据包的缓冲



区 uint32_t ui32User0、ui32User1;
uint8_t pu8MACArray[8];

volatile bool g_Bolded;
volatile bool udp_ready = false;

//*********

unsigned long intervalntp = 60000;//每分钟请求 NTP 时间
unsigned long tpesntp = 0;
unsigned long lastNTPResponse;

//*********
struct pbuf* p;
struct udp_pcb* udp;

uint32_t NTPTime;
uint32_t UNITXTime;
const uint32_t seventyears = 2208988800UL;





void setupConnection(){
//
//为的以太网控制器过滤配置硬件 MAC 地址
//传入数据包。 MAC 地址将存储在非易失性存储器中
// USER0和 User1寄存器。
//
map_FlashUserGet (&ui32User0、&ui32User1);
if ((ui32User0 == 0xffffffff)||(ui32User1 == 0xffffffff)
{
//
//我们永远不应该来这里。 如果 MAC 地址有、则这是一个错误
//未编程到器件中。 退出程序。
//告知用户没有 MAC 地址
//
UARTprintf ("未对 MAC 进行编程!\n");
while (1)
{
}
}

UARTprintf ("正在等待 IP.\n");


//
//将24/24拆分 MAC 地址从 NV RAM 转换为32/16拆分 MAC
//对硬件寄存器进行编程所需的地址,然后对 MAC 进行编程
//将地址输入以太网控制器寄存器。
//
pui8MACArray[0]=((ui32User0 >> 0)& 0xff);
pui8MACArray[1]=((ui32User0 >> 8)& 0xff);
pui8MACArray[2]=((ui32User0 >> 16)& 0xff);
pui8MACArray[3]=((ui32User1 >> 0)& 0xff);
pui8MACArray[4]=((ui32User1 >> 8)& 0xff);
pui8MACArray[5]=((ui32User1 >> 16)& 0xff);


//
//使用 DHCP 初始化 lwIP 库。
//
lwIPInit (g_ui32SysClock、pui8MACArray、0、0、0、 ipaddr_use_dhcp);

//
//设置设备定位服务。
//
LocatorInit();
LocatorMACAddrSet (pui8MACArray);
LocatorAppTitleSet ("EK-TM4C1294XL enet_IO");

}
void getTime(){
char* p_p_payload;
int i;

if (p!=NULL){
P_PAYLOAD=(char*) p->PAYLOAD;

对于(i=0;i <"%d",unixtime);="" void="" setupudp(){="" udp_init();="" ntpserver_addr.addr="0x6AF7F86A;" ui32ipaddress.addr="(long)g_ui32IPAddress;" int="" error_code;="" udp="udp_new();" change="" string="" form="" ip="" to="" addr_t="" uartprintf("\nchanging="" address");="" ipaddr_aton(ntpserver_addr,ntpserver_addr_t);="" destination="" address="" of="" ntpserver="" form.="" ipaddr_aton(localipaddress,p_ui32ipaddress);="" local="" print="" uartprintf("\n%d.%d.%d.%d",="" ntpserver_addr_t-="">ADDR & 0xff、(ntpserver_addr_t->addr >> 8)& 0xff、
(ntpserver_addr_t->addr >> 16)& 0xff,(ntpserver_addr_t->addr >>24)& 0xff;

//
//将本地 IP 和端口与 UDP PCB 绑定
//
error_code = udp_bind (udp、p_ui32IPAddress、123);
if (error_code=0){
UARTprintf ("\n 绑定成功");
UARTprintf ("\n 绑定的 IP =%d.%d.%d.%d"、UDP->LOCAL_IP.addr & 0xff、(UDP->LOCAL_IP.addr>>8)& 0xff
(udp->local_ip.addr>)>16和0xff、(Up->local_ip.addr>24)和0xff);
UARTprintf ("\n 本地端口:%d"、UDP->local_port);
} 否则{
UARTprintf ("\n 绑定错误:%d"、error_code);
}

//
//使用 UDP PCB 设置远程 IP 和端口
//
error_code = udp_connect (udp、ntpserver_addr_t、123);
if (error_code=0){
UARTprintf ("\n 连接成功");
UARTprintf ("\n 连接的 IP =%d.%d.%d.%d"、UDP->REMOTE_IP.addr & 0xff、(UDP->REMOTE_IP.addr>>8)& 0xff
(udp->remote_ip.addr>>16)& 0xff,(Up->remote_ip.addr>24)& 0xff;
UARTprintf ("\n 远程端口:%d"、UDP->REMOTE_PORT);
} 否则{
UARTprintf ("\n 连接错误:%d"、ERROR_CODE);
}




//
//为 UDP PCB 设置接收回调
//
UDP_recv (UDP、getTime、NULL);

udp_ready=true;
if (udp_ready){
UARTprintf ("\nudp ready");
}
}

void sendNTPpacket(){
int error_code;

P = pbuf_alloc (PBUF_transport、48、PBUF_RAM);
P->PAYLOAD =(void*) NTPBuffer;

UARTprintf ("\n 长度:%d"、p->len);
UARTprintf ("\ntotal_length:%d"、p->to_len);
UARTprintf ("\n 缓冲");
NTPBuffer[0]= 0b11100011;// LI、版本、模式


UARTprintf ("\n 缓冲完成");
error_code = udp_sendto (udp、p、ntpserver_addr_t、123);
if (error_code = 0){
UARTprintf ("\n 申请 SNTP);
} 否则{
UARTprintf ("\n 发送数据错误:%d"、ERROR_CODE);
}
//发送请求时间戳的数据包:


}




//*********
//
// SysTick 中断的中断处理程序。
////
*****************
void
SysTickIntHandler (void)
{
//
//调用 lwIP 计时器处理程序。
//
lwIPTimer (SYSTICKMS);

//
//告诉应用程序更改 LED 的状态(换句话说
//闪烁)。
//
G_bled = true;
}

//*********
//
//显示 lwIP 类型的 IP 地址。
////
*****************
void
DisplayIPAddress (uint32_t ui32Addr)
{


//
//将 IP 地址转换为字符串。
//
usprintf (pcBuf、"%d.%d.%d.%d"、ui32Addr & 0xff、(ui32Addr >> 8)& 0xff、
(ui32Addr >> 16)& 0xff、(ui32Addr >> 24)& 0xff);

//
//显示字符串。
//
UARTprintf (pcBuf);

}

//*************
//
// lwIP 库支持任何与主机相关的计时器函数所需的//。
////
*****************
void
lwIPHostTimerHandler (void)
{
uint32_t ui32NewIPAddress;

//
//获取当前 IP 地址。
//
ui32NewIPAddress = lwIPLocalIPAddrGet ();

//
//查看 IP 地址是否已更改。
//
if (ui32NewIPAddress!= g_ui32IPAddress)
{
//
//查看是否分配了 IP 地址。
//
if (ui32NewIPAddress == 0xffffffff)
{
//
//表示没有链接。
//
UARTprintf ("正在等待链接。\n");
}
否则、如果(ui32NewIPAddress =0)
{
//
//没有 IP 地址,因此请指明 DHCP 进程是什么
//正在运行。
//
UARTprintf ("正在等待 IP 地址。\n");
}
其他
{
//
//显示新的 IP 地址。
//
UARTprintf ("IP 地址:");
DisplayIPAddress (ui32NewIPAddress);
UARTprintf ("\n 正在连接 UDP");
setupUDP();
}

//
//保存新的 IP 地址。
//
G_ui32IPAddress = ui32NewIPAddress;
}

//
//如果没有 IP 地址。
//
if ((ui32NewIPAddress =0)||(ui32NewIPAddress =0xffffffff))
{
//
//不执行任何操作并继续等待。
//
}
}

//UART 设置
void ConfigureUART (void)
{
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOA);
while (!SysCtlPeripheralReady (SYSCTL_Periph_GPIOA));
SysCtlPeripheralEnable (SYSCTL_Periph_UART0);
while (!SysCtlPeripheralReady (SYSCTL_Periph_UART0));

GPIOPinConfigure (GPIO_PA0_U0RX);
GPIOPinConfigure (GPIO_PA1_U0TX);
GPIOPinTypeUART (GPIO_Porta_base、GPIO_PIN_0 | GPIO_PIN_1);

UARTStdioConfig (0、115200、g_ui32SysClock);
UARTIntEnable (UART0_BASE、UART_INT_RX | UART_INT_RT);

}

void printLocalTime (){
struct tm timeinfo;
UARTprintf ("\033[2J\033[H");
UARTprintf ("0:0:0");
}

//**
* main.c
*/
int main (void)
{
int i;


//
//确保主振荡器已启用,因为这是所要求的
// PHY。 系统必须将一个25MHz 晶体连接到 OSC
//引脚。 晶体时使用 SYSCTL_MOSC_HIGHFREQ 参数
//频率为10MHz 或更高。
//
SysCtlMOSCConfigSet (SYSCTL_MOSC_HIGHFREQ);


//设置系统时钟
G_ui32SysClock = SysCtlClockFreqSet ((SYSCTL_XTAL_25MHz |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480)、120000000);

//
//配置器件引脚。
//
PinoutSet (true、false);

//
//配置 UART。
//
ConfigureUART();


//
//将的端口 N1配置为动画 LED 的输出。
//
MAP_GPIOPinTypeGPIOOutput (GPIO_PORTN_BASE、GPIO_PIN_1);

//
//将 LED 初始化为关闭(0)
//
MAP_GPIOPinWrite (GPIO_PORTN_BASE、GPIO_PIN_1、~GPIO_PIN_1);

//
//为周期性中断配置 SysTick。
//
MAP_SysTickPeriodSet (g_ui32SysClock / SYSTICKHZ);
map_SysTickEnable();
map_SysTickIntEnable();

//
//设置中断优先级。 我们将 SysTick 中断设置为更高的值
//优先级比以太网中断高,以确保文件系统
如果 SysTick 在以太网处理程序运行时发生、则处理// tick
//已处理。 这很可能是因为所有 TCP/IP 和 HTTP 工作都是
//在以太网中断上下文中完成。
//
MAP_IntPrioritySet (INT_EMAC0、ETHERNET_INT_PRIORITY);
MAP_IntPrioritySet (FAULT_SysTick、SysTK_INT_PRIORITY);





setupConnection();






//
//循环永久、处理 LED 闪烁。 所有工作都在中完成
//中断处理程序。
//
while (1)
{
//
//等待 SysTick 中断指示更改的状态
// LED。
//
while (g_bled == false)
{
}

//
//清除标志。
//
G_bled = false;

//
//切换 LED。
//
MAP_GPIOPinWrite (GPIO_PORTN_BASE、GPIO_PIN_1、
(MAP_GPIOPinRead (GPIO_PORTN_BASE、GPIO_PIN_1)^
GPIO_PIN_1);

if (udp_ready){
sendNTPpacket();

}



}


返回0;
} 

 

这是 TeraTerm 的显示

我需要帮助。 谢谢