コード例 #1
0
ファイル: iniche_init.c プロジェクト: tisaire/subversion
INT8U wait_on_phy()
{
  int phyadd;
  int phyid;
  int phyid2 = 0;
  np_tse_mac* pmac;

/*
 * Initialize the structure necessary for "pmac" to function.
 */

  pmac = (np_tse_mac*) TSE_MAC_BASE;

/*
 * Find phyid...assuming it's National's PHY....for now.
 */
  for( phyadd = 0x00; phyadd < 0xff; phyadd++ )
  {
    IOWR(&pmac->MDIO_ADDR0, 0, phyadd);
    phyid = IORD(&pmac->mdio0.PHY_ID1, 0);
    phyid2 = IORD(&pmac->mdio0.PHY_ID2, 0);

    if( phyid != phyid2 )
    {
      printf("\n\n\nPHY INFO:  [phyid] 0x%x %x %x\n", phyadd, phyid, phyid2);
      phyadd = 0xff;
    }
  }

/*
 * Issue a PHY reset.
 */
  IOWR(&pmac->mdio0.CONTROL, 0, PCS_CTL_an_enable | PCS_CTL_sw_reset);
  if( ( ( IORD(&pmac->mdio0.CONTROL,0) & PCS_CTL_rx_slpbk) != 0 ) ||
      ( ( IORD(&pmac->mdio0.STATUS,0) & PCS_ST_an_done) == 0) )
  {
    IOWR(&pmac->mdio0.CONTROL, 0, PCS_CTL_an_enable | PCS_CTL_sw_reset);
    printf( "PHY INFO:  Issuing PHY Reset\n" );
  }

/*
 * Holding pattern until autonegotiation completes.
 */

  if(( IORD( &pmac->mdio0.STATUS, 0 ) & PCS_ST_an_done ) == 0 )
  {
    printf( "PHY INFO:  waiting on PHY link...\n" );
    while(( IORD( &pmac->mdio0.STATUS, 0 ) & PCS_ST_an_done ) == 0 )
    {
      OSTimeDlyHMSM( 0, 0, 0, 10 );
    }
    printf( "PHY INFO:  PHY link detected, allowing network to start.\n\n\n\n" );
    resume_network_tasks();
    printf( "SSS INFO:  Connecting...\n\n\n\n" );
  }
  TK_SLEEP(3);
  return( 0 );
}
コード例 #2
0
ファイル: iniche_init.c プロジェクト: keskella/omat
/* SSSInitialTask will initialize the NicheStack
 * TCP/IP Stack and then initialize the rest of the Simple Socket Server example 
 * RTOS structures and tasks. 
 */
void SSSInitialTask(void *task_data)
{
  INT8U error_code;
  
  /*
   * Initialize Altera NicheStack TCP/IP Stack - Nios II Edition specific code.
   * NicheStack is initialized from a task, so that RTOS will have started, and 
   * I/O drivers are available.  Two tasks are created:
   *    "Inet main"  task with priority 2
   *    "clock tick" task with priority 3
   */   
  alt_iniche_init();
  netmain(); 

  /* Wait for the network stack to be ready before proceeding. 
   * iniche_net_ready indicates that TCP/IP stack is ready, and IP address is obtained.
   */
  while (!iniche_net_ready)
    TK_SLEEP(1);

  /* Now that the stack is running, perform the application initialization steps */
  
  /* Application Specific Task Launching Code Block Begin */

  printf("\nSimple Socket Server starting up\n");

  /* Create the main simple socket server task. */
  TK_NEWTASK(&ssstask);
  
  /*create os data structures */
  SSSCreateOSDataStructs(); 

  /* create the other tasks */
  SSSCreateTasks();

  /* Application Specific Task Launching Code Block End */
  
  /*This task is deleted because there is no need for it to run again */
  error_code = OSTaskDel(OS_PRIO_SELF);
  alt_uCOSIIErrorHandler(error_code, 0);
  
  while (1); /* Correct Program Flow should never get here */
}
コード例 #3
0
void WSInitialTask(void* pdata)
{
  INT8U error_code = OS_NO_ERR;

  /*
  * Initialize Altera NicheStack TCP/IP Stack - Nios II Edition specific code.
  * NicheStack is initialized from a task, so that RTOS will have started, and 
  * I/O drivers are available.  Two tasks are created:
  *    "Inet main"  task with priority 2
  *    "clock tick" task with priority 3
  */   
  alt_iniche_init();
  /* Start the Iniche-specific network tasks and initialize the network
   * devices.
   */
  netmain(); 
  /* Wait for the network stack to be ready before proceeding. */
  while (!iniche_net_ready)
    TK_SLEEP(1);

  /* Create the main network task.  In this case, a web server. */
  TK_NEWTASK(&wstask);

  /* Application specific code starts here... */
  
  /*Create Tasks*/
  WSCreateTasks();
  printf("\nWeb Server starting up\n");
  /* Application specific code ends here. */

  /* Display the IP Address on the LCD Display. */
  #ifdef LCD_NAME
  lcd_ip_addr();
  #endif
  /*This task deletes itself, since there's no reason to keep it around, once
   *it's complete.
   */
  error_code = OSTaskDel(OS_PRIO_SELF);
  alt_uCOSIIErrorHandler(error_code, 0);

  while(1); /*Correct Program Flow should not reach here.*/
}
コード例 #4
0
ファイル: iniche_init.c プロジェクト: tisaire/subversion
/* SSSInitialTask will initialize the NicheStack
 * TCP/IP Stack and then initialize the rest of the Nios II Simple Socket Server example
 * RTOS structures and tasks.
 */
void SSSInitialTask(void *task_data)
{
  INT8U error_code;

  system_dhcp_hostname = "NEEK_1";

  wait_on_phy();

/*
 * Register new DHCP "IP attained" callback function.
 * If DHCP is acquired, ws_ipset will be called instead of dhc_main_ipset().
 */
#ifdef DHCP_CLIENT
  dhc_set_callback( 0, ws_ipset );
#endif


  /*
   * Initialize Altera NicheStack TCP/IP Stack - Nios II Edition specific code.
   * NicheStack is initialized from a task, so that RTOS will have started, and
   * I/O drivers are available.  Two tasks are created:
   *    "Inet main"  task with priority 2
   *    "clock tick" task with priority 3
   */
  alt_iniche_init();

  /* Start the Iniche-specific network tasks and initialize the network
   * devices.
   */
  netmain();

  /* Wait for the network stack to be ready before proceeding. */
  while (!iniche_net_ready)
  {
    TK_SLEEP(1);
 /*
  * Allow other tasks to run, while waiting for network.
  */
    OSTimeDlyHMSM(0, 0, 3, 0);
  }

/*
 * Nichestack is ready.
 */

  /* Application Specific Task Launching Code Block Begin */

  printf("\nNios II Simple Socket Server starting up.\n");

  /* Create the phy monitoring task. */
  TK_NEWTASK(&sssphytask);

  /* Create the main Nios II Simple socket server task. */
  //TK_NEWTASK(&ssstask);

  TK_NEWTASK(&ssspenetask);

  /*create os data structures */
  SSSCreateOSDataStructs();

  /* create the other tasks */
  SSSCreateTasks();

  /* Application Specific Task Launching Code Block End */

  /*This task is deleted because there is no need for it to run again */
  error_code = OSTaskDel(OS_PRIO_SELF);
  alt_uCOSIIErrorHandler(error_code, 0);

  while (1); /* Correct Program Flow should never get here */
}
コード例 #5
0
ファイル: iniche_init.c プロジェクト: tisaire/subversion
/* SSSMonitorPhyTask monitors the status of a single network PHY every 5 seconds
  (approximately) and acts to maintain a "healthy" network connection.
*/
void SSSMonitorPhyTask(void *task_data)
{
  INT8U status;

/*
 * Counter to allow for a brief network disconnect.
 */
  int disconnect_count;

 /*
  * Populate the local pmac structure upon successful network initialization.
  */
  np_tse_mac* pmac = (np_tse_mac*) tse.mi.base;

 /*
  * Clear counter to allow for a brief network disconnect.
  */
  disconnect_count = 0;

 /*
  * Now, start a loop that monitors the status of a single network PHY every 5 seconds
  * (approximately) and acts to maintain a "healthy" network connection.
  * The possible states are:
  *   Connected
  *   Disconnected
  */
  while(1)
  {
    OSTimeDlyHMSM(0, 0, 1, 0);
    status = IORD( &pmac->mdio1.STATUS, 0 );
    if( !(status & 0x20) )
    {
      disconnect_count++;
      if( disconnect_count == MAX_CABLE_DOWN )
      {
        printf( "\nPHY ERROR:  Ethernet Cable Disconnected!\n" );
        if( suspend_network_tasks() != OS_NO_ERR )
        {
          printf( "SSS INFO:  Error suspending network tasks!\n" );
        }
      }
    }
    else
    {

 /*
  * If the cable was previously disconnected, detect this, reset the PHY and
  * initiate the DHCP discovery process to obtain an IP Address.
  */
      if( disconnect_count > 0 )
      {
 /*
  * Issue a PHY Reset.
  */
        wait_on_phy();
        printf( "PHY INFO:  Cable Reconnected!\n" );
        TK_SLEEP(1);
 /*
  * Force re-acquisition of existing IP Address.
  * If that fails, the Iniche DHCP state machine should fall through to DHCP discovery.
  */
#ifdef DHCP_CLIENT
        dhc_set_state( 0, DHCS_INITREBOOT );
#endif
      }
/*
 * Reset the disconnect counter.
 */
      disconnect_count = 0;
    }
  }
}