Other Parts Discussed in Thread: EK-TM4C1294XL
Tool/software: TI-RTOS
Hello,
I use the EK-TM4C1294XL board with TI-RTOS version 2.16.1.14 with the https example.
In the initialization of the https task, the function startNTP () is called and I receive the current time. Now I want to change the NTP address at runtime and use this new NTP address. But every time I call the startNTP function one more time, the getaddrinfo function returns a -2 and I can not use the new NTP address.
What do I have to do to update the ntp address?
void startNTP(void)
{
int ret;
int currPos;
time_t ts;
struct sockaddr_in ntpAddr;
struct addrinfo hints;
struct addrinfo *addrs;
struct addrinfo *currAddr;
Semaphore_Params semParams;
//Semaphore_pend(semNtpHandle, BIOS_WAIT_FOREVER);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
ret = getaddrinfo(ntp_Hostname, NTP_PORT, NULL, &addrs);
if (ret != 0) {
printError("startNTP: NTP host cannot be resolved!", ret);
return;
}
currPos = 0;
for (currAddr = addrs; currAddr != NULL; currAddr = currAddr->ai_next)
{
if (currPos < NTP_SERVERS_SIZE)
{
ntpAddr = *(struct sockaddr_in *)(currAddr->ai_addr);
memcpy(ntpServers + currPos, &ntpAddr, sizeof(struct sockaddr_in));
currPos += sizeof(struct sockaddr_in);
}
else {
break;
}
}
freeaddrinfo(addrs);
ret = SNTP_start(Seconds_get, Seconds_set, timeUpdateHook, (struct sockaddr *)&ntpServers, NTP_SERVERS, 0);
if (ret == 0) {
printError("startNTP: SNTP cannot be started!", -1);
}
Semaphore_Params_init(&semParams);
semParams.mode = Semaphore_Mode_BINARY;
semHandle = Semaphore_create(0, &semParams, NULL);
if (semHandle == NULL) {
printError("startNTP: Cannot create semaphore!", -1);
}
SNTP_forceTimeSync();
bool timeover = Semaphore_pend(semHandle, 1000);
// timeover == 0 -> Keine NTP Verbindung
// timeover == 1 -> Erfolgreiche NTP Verbindung
ts = time(NULL);
sysTime = ts;
System_printf("Current time: %s\n", ctime(&ts));
System_flush();
}