DHCPtest.c File Reference

Receiving DSP IP-address from DHCP-server. 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>

Macros

#define USE_DHCP   1
 
#define MAX_PING_DATA   100
 

Functions

int main (void)
 

Variables

char * program_name = "DHCP"
 
far char * host_name
 
far char * domain_name
 

Detailed Description

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

The terminal-window should print on success:

 DSP IP-address before initializing: 0.0.0.0

 Link status changed: Linked at 100Mbit full duplex
 assigned DSP IP-address:192.168.168.123
 success

 DHCP demo running on address 192.168.168.123

 MAC address: 02-00-c1-31-00-34
 IP address:  192.168.168.123
 Host name:   mydemo
 Domain name: dsignt.net
 DNS Server:  192.168.168.1
 Gateway:     192.168.168.1
 Subnetmask:  255.255.255.0
 now ping the dsp:
>ping 192.168.168.123    or
>ping mydemo

The real assigned IP address depends on your DHCP configuration. If the DSP hangs for a while after the first line, your DHCP configuration may be wrong or no DHCP-server is reachable. In this case after about 20-30 seconds (and a few retries) a link-local address is assigned and a warning should appear on the screen:

 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !!! warning: no DHCP server available           !!!
 !!! assigned IP address is a link-local address !!!
 !!! make sure your host is in the same local    !!!
 !!! subnet: 169.254.x.x                         !!!
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Macro Definition Documentation

#define USE_DHCP   1
#define MAX_PING_DATA   100

Function Documentation

int main ( void  )
183 {
184  /***************************************************************************
185  locals
186  ***************************************************************************/
187  int main_loop = 1; /* main loop switch, set to 0 to exit */
188  uint32_t ip;
189  char buffer[20]; /* small buffer for ip-address conversion */
190 
191  /***************************************************************************
192  initialize application (e.g. timer clocks, PLL settings, EMIF etc.)
193  (ref. \Common\Common.c)
194  ***************************************************************************/
195  AppInit (GET_CLOCK);
196 
197  /***************************************************************************
198  select output device for CPrintf (ref. \Common\cprintf.c)
199  possible settings:
200  CPRINTF_UART_OUTPUT -> output to UART
201  CPRINTF_CCS_OUTPUT -> output to CCS
202  CPRINTF_UART_OUTPUT | CPRINTF_CCS_OUTPUT -> output to UART and CCS
203  ***************************************************************************/
204  CPrintf_select_output (CPRINTF_DEFAULT_OUTPUT); /* default outputs */
205 
206  /***************************************************************************
207  print a start up message
208  ***************************************************************************/
209  START_UP_MESSAGE (BLANK_REV NETLIB_REV);
210 
211  /**************************************************************************/
212  // CPrintfProgress (" Heap check ");
213  // at least 0x2000 bytes required for this app
214  /**************************************************************************/
215  ASSERT_HEAP (initial_heap_size, 0x2000);
216  // CPrintfProgressSuccess();
217 
218  /**************************************************************************/
219  CPrintfProgress (" Setup system time ");
220  // 1 milli seconds resolution
221  /**************************************************************************/
224  CPrintf (" *** timer %d mapped to CPU int %d ***\r\n",
226 
227  /**************************************************************************/
228  CPrintfProgress (" Enable interrupts ");
229  /**************************************************************************/
232 
233  /**************************************************************************/
234  CPrintfProgress (" Start system timer ");
235  /**************************************************************************/
236  StartSystemTimer ();
238  CPrintf (" *** timer %d running at %"PRId32" Hz ***\r\n", SystemTimerDev, RES_SECONDS/GetSystemTimerRes());
239 
240  /***************************************************************************
241  print DSP IP address before initializing sockets:
242  ***************************************************************************/
243  ip = get_ip_address (0);
244  CPrintf ("\r\n DSP IP-address before initializing: %s\r\n", inet_ntoa (ip, buffer));
245 
246  /***************************************************************************
247  initialize network
248  ***************************************************************************/
249  CPrintfProgress (" Initialize network ");
250 
251  /***************************************************************************
252  The default network configuration for all examples are configured in file
253  \BoardSupport\netconfig.c. eth.ip contains either a fixed local IP address
254  string or a host name depending on switch USE_DHCP. Fill the eth.ip array
255  with a string starting with a letter to force InitializeNetwork() to use
256  DHCP. InitializeNetwork() appends the lower MAC address to form a unique
257  network name
258  ***************************************************************************/
259  strcpy (eth.ip, "mydemo"); /* host name */
260 
261  InitializeNetwork ( 64);
263 
264  CPrintf (" Largest free heap block : %"PRIu32" bytes\r\n", GetFreeHeapSize ());
265 
266  /***************************************************************************
267  main program loop: set main_loop to 0 to exit loop
268  ***************************************************************************/
269  CPrintf ("\r\n Entering main loop ...");
270  while ( main_loop )
271  {
272  /***********************************************************************
273  process net_isq()
274  ***********************************************************************/
275  net_isq (); // process ISQ
276 
277  /***********************************************************************
278  monitor link status
279  ***********************************************************************/
281 
282  /***********************************************************************
283  try to detect IP assignment
284  if DHCP is used, the assigned IP address may change
285  ***********************************************************************/
287  {
288  ip = get_ip_address (0);
289  CPrintf (" now ping the dsp:\r\n>ping %s", inet_ntoa (ip, buffer));
290  if (!IS_LINKLOCAL(ip))
291  {
292  CPrintf (" or\r\n>ping %s", host_name);
293  if (*domain_name)
294  {
295  CPrintf (".%s", domain_name);
296  }
297  }
298  CPuts (CRLF);
299  }
300 
301  /***********************************************************************
302  show that the program is running, perform symbol animation
303  ***********************************************************************/
305  }
306 
307  /***************************************************************************
308  exit program, shut down peripherals
309  ***************************************************************************/
310  return (0);
311 }
void BoardEnableInterrupts(void)
global enable interrupts
Definition: BoardSpecific.c:365
#define ANIMATE_SYMBOLS_COUNT
Definition: BoardSpecific.h:268
void StartSystemTimer(void)
start system timer
Definition: timer.c:447
#define RES_MSECONDS
Definition: timer.h:67
char * inet_ntoa(uint32_t i_addr, char *s)
Convert IP-address from 0xbbaaddcc to "aaa.bbb.ccc.ddd".
uint16_t CPrintf_select_output(uint16_t device)
Definition: cprintf.c:206
#define ASSERT_HEAP(i, h)
Definition: Common.h:262
time_t GetSystemTimerRes(void)
Definition: timer.c:160
#define GET_CLOCK
Definition: BoardSpecific.h:258
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
#define CRLF
Definition: cprintf.h:214
uint32_t initial_heap_size
Definition: Common.c:140
#define CPRINTF_DEFAULT_OUTPUT
Definition: BoardSpecific.h:129
uint32_t GetFreeHeapSize(void)
determine free heap size
Definition: Common.c:1147
uint16_t CPrintAnimatedSymbol(char *c, time_t period, size_t size)
Definition: cprintf.c:816
int InitializeNetwork(uint16_t icmp_size)
Initialize MAC, sockets and protocols.
Definition: BoardSpecific.c:597
unsigned int uint32_t
Definition: stdint.h:47
static char buffer[100]
Definition: blocksend.c:158
char sym_animate[]
Definition: BoardSpecific.c:129
far char * host_name
#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...
char ip[31]
Definition: net.h:170
#define BLANK_REV
Definition: BoardSpecific.h:191
Uint16 SystemTimerDev
adapter_t eth
Definition: netconfig.c:62
uint16_t monitor_ip_address(tpOutputFunc pLog)
monitor IP assignment
Definition: BoardSpecific.c:545
#define START_UP_MESSAGE(rev)
Definition: BoardSpecific.h:192
far char * domain_name
#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 IS_LINKLOCAL(a)
Definition: net.h:746
#define CPrintfProgressSuccess()
Definition: cprintf.h:263

Variable Documentation

char* program_name = "DHCP"
far char* host_name
Examples:
DHCPTest.c.
far char* domain_name
Examples:
Blocksend.c, DHCPTest.c, and Echo.c.