Link Status Callback

Functions

void link_status (uint8_t mode)
 link status change callback function More...
 
uint16_t monitor_link_status (tpOutputFunc pLog)
 monitor link status change More...
 
uint16_t monitor_ip_address (tpOutputFunc pLog)
 monitor IP assignment More...
 

Detailed Description

The link status callback function is called from net_isq() any time the link status has changed. Use this function to print a message, switch LED's, set global variables (e.g. _link) to enable/ disable specific sections of code.

Install this callback by passing this function as parameter to DM2_EmacInit() during initialization.

You shouldn't make use of long operation functions (like stdio printf) within this callback. Use global flags instead.

In case of DHCP configuration the internal IP address should be reset, if no link is available and the DHCP request should be re-triggered if a link is established. Optionally the ARP cache can be cleared (arp_clear_cache()) to avoid long response times if a destination route has changed.

Function Documentation

void link_status ( uint8_t  mode)
Parameters
mode- HDX_10, HDX_100, FDX_10, FDX_100, FDX1000
Returns
nothing
See also
DM2_EmacInit
Hardware Initialization, _link, BoardSpecific.c
HDX_10, HDX_100, FDX_10, FDX_100, FDX_1000
Examples:
BoardSpecific.c.
435 {
436  _link_mode = mode;
437  switch (mode)
438  {
439  case 0xff:
440  /*******************************************************************
441  reset global link status
442  *******************************************************************/
443  _link = 0;
444 
445  /*******************************************************************
446  in case of DHCP reset IP address
447  *******************************************************************/
448  if (!((eth.ip[0]-'0')<=9))
449  {
450  set_ip_address (0, "0.0.0.0");
451  }
452  break;
453 
454  default:
455  /*******************************************************************
456  set global link status
457  *******************************************************************/
458  _link |= 1;
459 
460  /*******************************************************************
461  clear ARP cache
462  *******************************************************************/
463  arp_clear_cache();
464 
465  /*******************************************************************
466  in case of DHCP re-trigger DHCP request
467  *******************************************************************/
468  if ((!((eth.ip[0]-'0')<=9)) && eth.dhcp_setting)
469  {
470  eth.dhcp_setting (eth.ip, 0);
471  }
472  break;
473  }
474 }
uint8_t _link_mode
Definition: BoardSpecific.c:138
volatile uint16_t _link
Definition: BoardSpecific.c:143
uint32_t(* dhcp_setting)(char *, uint16_t)
Definition: net.h:168
char ip[31]
Definition: net.h:170
adapter_t eth
Definition: netconfig.c:62
void arp_clear_cache(void)
Invalidate ARP cache.
uint32_t set_ip_address(uint16_t dev_nr, char *addr_str)
Set IP address.
uint16_t monitor_link_status ( tpOutputFunc  pLog)
Parameters
pLog- printf function or NULL
Returns
TRUE (1) - link status changed
FALSE (0) - link status not changed

Use this function in your main loop to detect a link status change. Global flag _link_mode is monitored and in case of change a LED can be toggled or a message can be printed on the default output terminal. Parameter pLog can be a standard formatted print function like printf or CPrintf. If this parameter is NULL, no output is printed. The return value can be used for event processing in case of a status change.

Note
_link_mode is only valid, if a link_status callback function is used and the _link_mode is set.
See also
DHCPTest.c
Examples:
BoardSpecific.c.
498 {
499  /***************************************************************************
500  locals
501  ***************************************************************************/
502  static uint8_t _link_mode_old = 0xff;
503 
504  if (_link_mode_old != _link_mode)
505  {
506  _link_mode_old = _link_mode;
507  if (pLog) pLog ("\n\r Link status changed: ");
508  switch (_link_mode)
509  {
510  case 0xff:
511  LED_off (2);
512  if (pLog) pLog ("No Link\r\n");
513  break;
514 
515  default:
516  LED_on (2);
517  if (pLog) pLog ("Linked at %d%sMbit %s duplex\r\n",
518  (_link_mode & SPEED_100) ? 100:10,
519  (_link_mode & SPEED_1000) ? "00 ":" ",
520  (_link_mode & FULL_DUPLEX) ? "full":"half");
521  break;
522  }
523  return (1);
524  }
525  return (0);
526 }
uint8_t _link_mode
Definition: BoardSpecific.c:138
void LED_on(unsigned int ledNum)
Definition: BoardSpecific.c:1302
#define SPEED_1000
Definition: net.h:254
unsigned char uint8_t
Definition: stdint.h:43
void LED_off(unsigned int ledNum)
Definition: BoardSpecific.c:1284
#define SPEED_100
Definition: net.h:246
#define FULL_DUPLEX
Definition: net.h:231
uint16_t monitor_ip_address ( tpOutputFunc  pLog)
Parameters
pLog- printf function or NULL
Returns
TRUE (1) - IP address assigned
FALSE (0) - IP address not changed

Use this function to monitor IP assignment. Useful when the IP address is assigned dynamically by DHCP. The return value can be used for event processing, e.g. send a welcome message or email. Parameter pLog can be a standard formatted print function like printf or CPrintf. If this parameter is NULL, no output is printed.

See also
DHCPTest.c
Examples:
BoardSpecific.c.
546 {
547  /***************************************************************************
548  locals
549  ***************************************************************************/
550  static uint16_t wait_for_ip = 1;
551  uint16_t ret = 0;
552  uint32_t ip;
553 
554  /***************************************************************************
555  try to detect IP assignment
556  ***************************************************************************/
557  if ((ip=get_ip_address (0)) == UINT32_C(0)) // no IP address assigned
558  {
559  wait_for_ip = 1;
560  return(ret);
561  }
562 
563  if (wait_for_ip)
564  {
565  wait_for_ip = 0;
566  ret = 1;
567 
568  if (pLog)
569  {
570  if (IS_LINKLOCAL(ip))
571  {
572  pLog (" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n");
573  pLog (" !!! warning: no DHCP server available !!!\r\n");
574  pLog (" !!! assigned IP address is a link-local address !!!\r\n");
575  pLog (" !!! make sure your host is in the same local !!!\r\n");
576  pLog (" !!! subnet: 169.254.x.x !!!\r\n");
577  pLog (" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n");
578  }
579 
580  pLog ("\r\n network configuration:");
581  net_print_stat (0, pLog);
582  }
583  }
584 
585  return (ret);
586 }
unsigned short uint16_t
Definition: stdint.h:45
#define UINT32_C(value)
Definition: stdint.h:210
unsigned int uint32_t
Definition: stdint.h:47
uint32_t get_ip_address(uint16_t dev_nr)
Get configured IP address.
void net_print_stat(uint16_t dev_nr, tpOutputFunc pLog)
Print statistic TCP stack information.
#define IS_LINKLOCAL(a)
Definition: net.h:746