SNTPtest.c File Reference

Sample Application Program for obtaining the time from internet. More...

#include <BoardSupport/inc/stdtypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#include <Libs/NETlib/net.h>
#include <BoardSupport/inc/BoardSpecific.h>
#include <Common/Common.h>
#include <Common/uartio.h>
#include <Common/timer.h>
#include <Common/CPrintf.h>
#include <BoardSupport/config/netconfig.c>
#include "SNTP.h"

Macros

#define MAX_PING_DATA   100
 
#define UTC_PRINTF   " Current UTC time: "VT100_BLUE"%s\r"VT100_DEFAULT
 

Functions

int main (void)
 

Variables

char * program_name = "SNTP"
 
char * aNTPServerList []
 

Detailed Description

                          _         _             _
                       __| |    ___(_) ____ _ __ | |_
                      / _` |   / __| |/ _` | '_ \| __|
                     | (_| | _ \__ \ | (_| | | | | |_
                      \__,_|(_) ___/_|\__, |_| |_|\__|
                     Signalprocessing |___/ Technology
Author
D.SignT GmbH & Co. KG, Claus Hermbusche
Date
2019-06-03

Macro Definition Documentation

#define MAX_PING_DATA   100
#define UTC_PRINTF   " Current UTC time: "VT100_BLUE"%s\r"VT100_DEFAULT

Function Documentation

int main ( void  )
160 {
161  /***************************************************************************
162  locals
163  ***************************************************************************/
164  int main_loop = 1; /* main loop switch, set to 0 to exit */
165  struct tm *local_time; /* structure to hold time and date */
166  timeval CurrentTime;
167 
168  /***************************************************************************
169  initialize application (e.g. timer clocks, PLL settings, EMIF etc.)
170  (ref. \Common\Common.c)
171  ***************************************************************************/
172  AppInit (GET_CLOCK);
173 
174  /***************************************************************************
175  select output device for CPrintf (ref. \Common\cprintf.c)
176  possible settings:
177  CPRINTF_UART_OUTPUT -> output to UART
178  CPRINTF_CCS_OUTPUT -> output to CCS
179  CPRINTF_UART_OUTPUT | CPRINTF_CCS_OUTPUT -> output to UART and CCS
180  ***************************************************************************/
181  CPrintf_select_output (CPRINTF_DEFAULT_OUTPUT); /* default outputs */
182 
183  /***************************************************************************
184  print a start up message
185  ***************************************************************************/
186  START_UP_MESSAGE (BLANK_REV NETLIB_REV);
187 
188  /**************************************************************************/
189  // CPrintfProgress (" Heap check ");
190  // at least 0x2000 bytes required for this app
191  /**************************************************************************/
192  ASSERT_HEAP (initial_heap_size, 0x2000);
193  // CPrintfProgressSuccess();
194 
195  /**************************************************************************/
196  CPrintfProgress (" Setup system time ");
197  // 1 second resolution
198  /**************************************************************************/
201  CPrintf (" *** timer %d mapped to CPU int %d ***\r\n",
203 
204  /**************************************************************************/
205  CPrintfProgress (" Enable interrupts ");
206  /**************************************************************************/
209 
210  /**************************************************************************/
211  CPrintfProgress (" Start system timer ");
212  /**************************************************************************/
213  StartSystemTimer ();
215  CPrintf (" *** timer %d running at %"PRId32" Hz ***\r\n", SystemTimerDev, RES_SECONDS/GetSystemTimerRes());
216 
217 
218  /**************************************************************************/
219  CPrintfProgress (" Initialize network ");
220  /**************************************************************************/
221  InitializeNetwork ( 64); // 64 bytes for ping
222  // net_set_gateway ("192.168.168.1",
223  // "255.255.255.0");
225 
226  LED_on (0);
227 
228  /***************************************************************************
229  main program loop: set main_loop to 0 to exit loop
230  ***************************************************************************/
231  CPuts ("\r\n Entering main loop ...\r\n");
232  while ( main_loop )
233  {
234  /***********************************************************************
235  process net_isq()
236  ***********************************************************************/
237  net_isq ();
238 
239  /***********************************************************************
240  monitor link status
241  ***********************************************************************/
243 
244  ntp_client (aNTPServerList, 3);
245 
246  /***********************************************************************
247  print time each second
248  ***********************************************************************/
249  if ( tv_elapsed (&CurrentTime, UINT32_C(1), UINT32_C(0), TRUE) )
250  {
251  LED_toggle(0);
252  LED_toggle(1);
253 
254  /*******************************************************************
255  print time
256  *******************************************************************/
257  local_time = localtime ((const time_t *)&RecentEpoch);
258  CPrintf (UTC_PRINTF, asctime (local_time));
259  }
260  }
261 
262  /***************************************************************************
263  exit program, shut down peripherals
264  ***************************************************************************/
265  return(0);
266 }
void BoardEnableInterrupts(void)
global enable interrupts
Definition: BoardSpecific.c:365
void StartSystemTimer(void)
start system timer
Definition: timer.c:447
#define RES_MSECONDS
Definition: timer.h:67
uint16_t CPrintf_select_output(uint16_t device)
Definition: cprintf.c:206
#define ASSERT_HEAP(i, h)
Definition: Common.h:262
void LED_on(unsigned int ledNum)
Definition: BoardSpecific.c:1302
time_t GetSystemTimerRes(void)
Definition: timer.c:160
#define UINT32_C(value)
Definition: stdint.h:210
#define GET_CLOCK
Definition: BoardSpecific.h:258
int tv_elapsed(timeval *t, time_t s, time_t u, uint16_t retrigger)
check if given time has elapsed
Definition: timer.c:286
int CPrintf(const char *_format,...)
Custom printf function.
Definition: cprintf.c:708
void SetupSystemTime(int32_t cpuint, int port, time_t resolution)
Setup System Time.
Definition: timer.c:392
void AppInit(uint32_t dsp_clock)
Initialize application.
Definition: Common.c:230
uint32_t initial_heap_size
Definition: Common.c:140
timeval RecentEpoch
Definition: timer.c:81
#define CPRINTF_DEFAULT_OUTPUT
Definition: BoardSpecific.h:129
#define UTC_PRINTF
Definition: SNTPtest.c:117
int InitializeNetwork(uint16_t icmp_size)
Initialize MAC, sockets and protocols.
Definition: BoardSpecific.c:597
Definition: timer.h:75
void LED_toggle(unsigned int ledNum)
Definition: BoardSpecific.c:1320
#define SYSTEM_TIMER_INT
Definition: BoardSpecific.h:174
#define SYSTEM_TIMER
Definition: BoardSpecific.h:167
void net_isq(void)
The main polling function for processing sockets, must be periodically called in the main application...
#define BLANK_REV
Definition: BoardSpecific.h:191
Uint16 SystemTimerDev
#define START_UP_MESSAGE(rev)
Definition: BoardSpecific.h:192
char * aNTPServerList[]
Definition: SNTPtest.c:134
#define RES_SECONDS
Definition: timer.h:70
uint16_t monitor_link_status(tpOutputFunc pLog)
monitor link status change
Definition: BoardSpecific.c:497
int CPuts(const char *_ptr)
Definition: cprintf.c:399
#define CPrintfProgress(s)
Definition: cprintf.h:230
#define CPrintfProgressSuccess()
Definition: cprintf.h:263

Variable Documentation

char* program_name = "SNTP"
char* aNTPServerList[]
Initial value:
= {
"europe.pool.ntp.org",
"ptbtime1.ptb.de",
"ptbtime2.ptb.de",
"ntp0.fau.de",
"ntp1.sul",
}
#define NULL
Definition: net.h:126
Examples:
SNTPTest.c.