ping2.c File Reference

Initiate ping request. 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/timer.h>
#include <Common/CPrintf.h>
#include <BoardSupport/config/netconfig.c>
#include "ICMP.h"

Functions

int main (void)
 

Variables

char * program_name = "Ping2"
 
char target_ip [16] = "192.168.168.111"
 

Detailed Description

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

Function Documentation

int main ( void  )
143 {
144  /***************************************************************************
145  locals
146  ***************************************************************************/
147  int main_loop = 1; /* main loop switch, set to 0 to exit */
148  timeval stamp1, stamp2, delta; /* used to determine startup time */
149  timeval TriggerTimer;
150 
151  /***************************************************************************
152  initialize application (e.g. timer clocks, PLL settings, EMIF etc.)
153  (ref. \Common\Common.c)
154  ***************************************************************************/
155  AppInit (GET_CLOCK);
156 
157  /***************************************************************************
158  select output device for CPrintf (ref. \Common\cprintf.c)
159  possible settings:
160  CPRINTF_UART_OUTPUT -> output to UART
161  CPRINTF_CCS_OUTPUT -> output to CCS
162  CPRINTF_UART_OUTPUT | CPRINTF_CCS_OUTPUT -> output to UART and CCS
163  ***************************************************************************/
164  CPrintf_select_output (CPRINTF_DEFAULT_OUTPUT); /* default outputs */
165 
166  /***************************************************************************
167  print a start up message
168  ***************************************************************************/
169  START_UP_MESSAGE (BLANK_REV NETLIB_REV);
170 
171  /**************************************************************************/
172  // CPrintfProgress (" Heap check ");
173  // at least 0x2000 bytes required for this app
174  /**************************************************************************/
175  ASSERT_HEAP (initial_heap_size, 0x2000);
176  // CPrintfProgressSuccess();
177 
178  /**************************************************************************/
179  CPrintfProgress (" Setup system time ");
180  // 1 milli seconds resolution
181  /**************************************************************************/
184  CPrintf (" *** timer %d mapped to CPU int %d ***\r\n",
186 
187  /**************************************************************************/
188  CPrintfProgress (" Enable interrupts ");
189  /**************************************************************************/
192 
193  /**************************************************************************/
194  CPrintfProgress (" Start system timer ");
195  /**************************************************************************/
196  StartSystemTimer ();
198  CPrintf (" *** timer %d running at %"PRId32" Hz ***\r\n", SystemTimerDev, RES_SECONDS/GetSystemTimerRes());
199 
200  /***************************************************************************
201  measure network initialization time
202  ***************************************************************************/
203  stamp1 = GetTimeStamp();
204 
205  /**************************************************************************/
206  CPrintfProgress (" Initialize network ");
207  /**************************************************************************/
208  InitializeNetwork ( 64); // 64 bytes for ping
209 
210  /***************************************************************************
211  define callback function for received TCP packets
212  ***************************************************************************/
215  stamp2 = GetTimeStamp();
216 
217  tv_interval (&delta, &stamp1, &stamp2);
218  CPuts (" network startup time [sec]: ");
220  "%"PRId32".%03"PRId32"\r\n"
222  delta.tv_sec,
223  delta.tv_usec/1000);
224 
225  LED_on (0);
226  TriggerTimer = GetTimeStamp();
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 (); // process ISQ
238 
239  /***********************************************************************
240  monitor link status
241  ***********************************************************************/
243 
244  /***********************************************************************
245  try to detect IP assignment
246  if DHCP is used, the assigned IP address may change
247  ***********************************************************************/
249 
250  /***********************************************************************
251  a ping request only makes sense when a link is established
252  ***********************************************************************/
253  if (_link && get_ip_address (0))
254  {
255  /*******************************************************************
256  toggle LEDs
257  *******************************************************************/
258  LED_toggle(0);
259  LED_toggle(1);
260 
261  if ( tv_elapsed (&TriggerTimer, 1, 0, TRUE) )
262  {
263  send_ping_request (target_ip);
264  }
265  }
266  }
267 
268  /***************************************************************************
269  exit program, shut down peripherals
270  ***************************************************************************/
271  return (0);
272 }
void BoardEnableInterrupts(void)
global enable interrupts
Definition: BoardSpecific.c:365
void socket_define_callback(SOCKET *so, int32_t(*call_back_function)(SOCKET *, void *, uint32_t, uint32_t), void *data, uint16_t maxdata)
Install a user callback function for a specific socket.
void StartSystemTimer(void)
start system timer
Definition: timer.c:447
volatile uint16_t _link
Definition: BoardSpecific.c:143
#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
#define MAX_PING_DATA
Definition: ping.c:145
void LED_on(unsigned int ledNum)
Definition: BoardSpecific.c:1302
time_t GetSystemTimerRes(void)
Definition: timer.c:160
#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
#define VT100_DEFAULT
Definition: cprintf.h:150
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
SOCKET * icmp_so
Definition: BoardSpecific.c:148
uint32_t initial_heap_size
Definition: Common.c:140
void * socket_get_data_pointer(SOCKET *so)
Retrieve a data pointer from socket.
#define CPRINTF_DEFAULT_OUTPUT
Definition: BoardSpecific.h:129
#define VT100_RED
Definition: cprintf.h:143
int InitializeNetwork(uint16_t icmp_size)
Initialize MAC, sockets and protocols.
Definition: BoardSpecific.c:597
char target_ip[16]
Definition: ping2.c:125
Definition: timer.h:75
#define GetTimeStamp()
Definition: timer.h:81
void tv_interval(timeval *e, timeval *t1, timeval *t2)
compute elapsed time
Definition: timer.c:336
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
uint32_t get_ip_address(uint16_t dev_nr)
Get configured IP address.
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
uint16_t monitor_ip_address(tpOutputFunc pLog)
monitor IP assignment
Definition: BoardSpecific.c:545
#define START_UP_MESSAGE(rev)
Definition: BoardSpecific.h:192
#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
time_t tv_sec
Definition: timer.h:77
#define CPrintfProgress(s)
Definition: cprintf.h:230
time_t tv_usec
Definition: timer.h:78
#define CPrintfProgressSuccess()
Definition: cprintf.h:263

Variable Documentation

char* program_name = "Ping2"
char target_ip[16] = "192.168.168.111"
Examples:
Ping2.c.