⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 00da51b65f84001d1708b124f72c3963

📁 nios ii sopc关于ISP1362和DM9000A的工程
💻
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA.           *
* All rights reserved. All use of this software and documentation is          *
* subject to the License Agreement located at the end of this file below.     *
*******************************************************************************
*                                                                             *
* Modified to work with Interniche (week of 9/22/06) - BjR                    *
*                                                                             *
* This is an example webserver using NicheStack on the MicroC/OS-II RTOS.     *
* It is in no way a complete implementation of a webserver, it is enough to   *
* serve up our demo pages and control a few board elements and that's it.     *
*                                                                             *
* This example uses the sockets interface. A good introduction to sockets     *
* programming is the book Unix Network Programming by Richard Stevens.        *
*                                                                             *
* Please refer to file ReadMe.txt for notes on this software example.         *
******************************************************************************
* NicheStack TCP/IP stack initialization and Operating System Start in main()
* for this example. 
* 
* This example demonstrates the use of MicroC/OS-II running on NIOS II.       
* In addition it is to serve as a good starting point for designs using       
* MicroC/OS-II and Altera NicheStack TCP/IP Stack - NIOS II Edition.                                                                                           
*      
* Please refer to the Altera NicheStack Tutorial documentation for details on 
* this software example, as well as details on how to configure the NicheStack
* TCP/IP networking stack and MicroC/OS-II Real-Time Operating System.  
*/

/* MicroC/OS-II definitions */
#include "includes.h"

#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include <unistd.h>

/* Web Server definitions */
#include "alt_error_handler.h"
#include "web_server.h"

/* Nichestack definitions */
#include "ipport.h"
#include "libport.h"
#include "osport.h"
#include "tcpport.h"
#include "net.h"

#ifndef ALT_INICHE
  #error This Web Server requires the Interniche IP Stack Software Component.
#endif

#ifndef __ucosii__
  #error This Web Server requires the UCOS II IP Software Component.
#endif

#ifndef  RO_ZIPFS
  #error This Web Server requires the Altera Read only Zip file system.
#endif

#ifdef LCD_DISPLAY_NAME  
FILE* lcdDevice;
#endif /* LCD_DISPLAY_NAME */

extern int current_flash_block;

extern void WSTask();
static void WSCreateTasks();

/* NicheStack network structure. */
extern struct net netstatic[STATIC_NETS];


/* Declarations for creating a task with TK_NEWTASK.  
 * All tasks which use NicheStack (those that use sockets) must be created this way.
 * TK_OBJECT macro creates the static task object used by NicheStack during operation.
 * TK_ENTRY macro corresponds to the entry point, or defined function name, of the task.
 * inet_taskinfo is the structure used by TK_NEWTASK to create the task.
 */

TK_OBJECT(to_wstask);
TK_ENTRY(WSTask);

struct inet_taskinfo wstask = {
      &to_wstask,
      "web server",
      WSTask,
      HTTP_PRIO,
      APP_STACK_SIZE,
};

/* Function which displays the obtained (or assigned) IP
 * Address on the LCD Display.
 */

void lcd_ip_addr()
{
  /* Declare local ipaddr variable. */
  ip_addr* ipaddr;
  
  /* Assign ipaddr to the network interface's IP Address. 
   * NOTE:  This code assumes that only a single network
   * interface exists
   */
  ipaddr = &nets[0]->n_ipaddr;
  
  /* Display the IP Address (initially) on the LCD Display. */
  lcdDevice = fopen( "/dev/lcd_display", "w" ); 
  fprintf(lcdDevice, "\nIP Address\n%d.%d.%d.%d\n",
        ip4_addr1(*ipaddr),
        ip4_addr2(*ipaddr),
        ip4_addr3(*ipaddr),
        ip4_addr4(*ipaddr));
  fclose( lcdDevice );
}

/* Function which resets the system.  Initiated by sending a string to the "LCD"
 * or through the Reset web form.
 */
#ifdef RECONFIG_REQUEST_PIO_NAME 
void trigger_reset()
{
  /* Drive a 0 out to the configuration PLD reconfig_request pin. */
  IOWR_ALTERA_AVALON_PIO_DATA( RECONFIG_REQUEST_PIO_BASE, 0x0 );
  /* Set BIDIR PIO to drive out. */
  IOWR_ALTERA_AVALON_PIO_DIRECTION( RECONFIG_REQUEST_PIO_BASE, 1 );
  usleep ( 1000000 );
  /* Drive out a 1....probably won't reach this point!!! */
  IOWR_ALTERA_AVALON_PIO_DATA( RECONFIG_REQUEST_PIO_BASE, 0x1 );
}
#endif

/* WSInitialTask will initialize the NichStack TCP/IP stack and then initialize
 * the rest of the web server example tasks.
 */

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. */
  
  lcd_ip_addr();

  /*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.*/
}
/*
 * A MicroC/OS-II message box will be used to communicate between telnet
 * and board LED control tasks.
 */

//static void board_control_init();
void LED_task(void* pdata);
void SSD_task(void* pdata);
static void sevenseg_set_hex(alt_u8 hex);
void board_control_task(void *pdata);
static void handle_button_interrupts(void* context, alt_u32 id);
static void init_button_pio();

/* Definition of Task Stacks for tasks not using networking.*/


OS_STK    WSInitialTaskStk[TASK_STACKSIZE];
OS_STK    LEDTaskStk[TASK_STACKSIZE];
OS_STK    SSDTaskStk[TASK_STACKSIZE];
OS_STK    BCTaskStk[TASK_STACKSIZE];


volatile int edge_capture;

/*
 * Mailbox to control board features 
 * 
 */
OS_EVENT *board_control_mbox;

int main (int argc, char* argv[], char* envp[])
{
  /* Initialize the current flash block, for flash programming. */
  
  current_flash_block = -1;
  
  INT8U error_code;

  /* Clear the RTOS timer */
  OSTimeSet(0);
  
  /* WSInitialTask will initialize the NicheStack TCP/IP Stack and then 
   * initialize the rest of the web server's tasks.
   */ 

  error_code = OSTaskCreateExt(WSInitialTask,
                             NULL,
                             (void *)&WSInitialTaskStk[TASK_STACKSIZE],
                             WS_INITIAL_TASK_PRIO,
                             WS_INITIAL_TASK_PRIO,
                             WSInitialTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);


  /*
   * As with all MicroC/OS-II designs, once the initial thread(s) and 
   * associated RTOS resources are declared, we start the RTOS. That's it!
   */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -