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

📄 00da51b65f84001d1708b124f72c3963

📁 nios ii sopc关于ISP1362和DM9000A的工程
💻
📖 第 1 页 / 共 2 页
字号:
  OSStart();
  
  while(1); /* Correct Program Flow never gets here. */

  return -1;
}

static void handle_button_interrupts(void* context, alt_u32 id)
{
  /* Cast context to edge_capture's type.
   * It is important to keep this volatile,
   * to avoid compiler optimization issues.
   */
  volatile int* edge_capture_ptr = (volatile int*) context;
  /* Store the value in the Button's edge capture register in *context. */
  *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE);
  /* Reset the Button's edge capture register. */
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);
}

/* Initialize the button_pio. */

static void init_button_pio()
{
  /* Recast the edge_capture pointer to match the alt_irq_register() function
  * prototype. */
  void* edge_capture_ptr = (void*) &edge_capture;
  /* Enable all 4 button interrupts. */
  IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf);
  /* Reset the edge capture register. */
  IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0);
  /* Register the interrupt handler. */
  alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr, handle_button_interrupts ); 
}


static void WSCreateTasks()
{
  INT8U error_code = OS_NO_ERR;
  
  /* Start board control routines/tasks. */
  
  init_button_pio();
  
  /* Start LED Task. */
  
  error_code = OSTaskCreateExt(LED_task,
                             NULL,
                             (void *)&LEDTaskStk[TASK_STACKSIZE],
                             LED_PRIO,
                             LED_PRIO,
                             LEDTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);
  
  /* Start SSD Task. */
  
  error_code = OSTaskCreateExt(SSD_task,
                             NULL,
                             (void *)&SSDTaskStk[TASK_STACKSIZE],
                             SSD_PRIO,
                             SSD_PRIO,
                             SSDTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);
  
  /* Start Board Control Task. */
  
  error_code = OSTaskCreateExt(board_control_task,
                             NULL,
                             (void *)&BCTaskStk[TASK_STACKSIZE],
                             BOARD_PRIO,
                             BOARD_PRIO,
                             BCTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);
  
  /* Suspend both the LED and SSD tasks on start. */
  
  OSTaskSuspend(LED_PRIO);
  OSTaskSuspend(SSD_PRIO);

  /* The web server task is started by the Interniche stack, as the "main" network servicing task. */
  
}

void lcd_output_text( char text[20] )
{
  /* If the incoming string is "ip_address" (case insensitive)
   * output the IP Address.  Otherwise, dump whatever's passed
   * into the text[] array.
   */
  if ( stricmp( text, "ip_address" ) == 0 )
  {
    lcd_ip_addr();
  }
#ifdef RECONFIG_REQUEST_PIO_NAME
  else if ( stricmp( text, "reset" ) == 0 )
  {
    trigger_reset();
  }
#endif
  else
  {
    lcdDevice = fopen( "/dev/lcd_display", "w" ); 
    fprintf(lcdDevice, "\n\n%s", text);
    fclose( lcdDevice );
  }
}

void board_control_task(void *pdata)
{
  INT8U error_code = OS_NO_ERR;
  board_control_mbox = OSMboxCreate((void *)NULL);

  struct http_form_data* board_control_mbox_contents;
  
  while(1)
  {
      board_control_mbox_contents = (void*)OSMboxPend(board_control_mbox, 0, &error_code);
      
      if (board_control_mbox_contents->LED_ON)
      {
        OSTaskResume(LED_PRIO);
      }
      else
      {
        /* Suspend the task and clear the LED. */
        OSTaskSuspend(LED_PRIO);
        IOWR_ALTERA_AVALON_PIO_DATA( LED_PIO_BASE, 0 );
      }
      
      if (board_control_mbox_contents->SSD_ON)
      {
        OSTaskResume(SSD_PRIO);
      }
      else
      {
        /* Suspend the task and set SSD to all zeros. */
        OSTaskSuspend(SSD_PRIO);
        sevenseg_set_hex(0); 
      }  

      /* Always dump text to the LCD... */
      lcd_output_text( board_control_mbox_contents->LCD_TEXT );
  }
}

void LED_task(void* pdata)
{
  
  alt_u8 led = 0x2;
  alt_u8 dir = 0;
     
  /* 
   * Infinitely shift a variable with one bit set back and forth, and write
   * it to the LED PIO.  Software loop provides delay element.
   */
  while (1) 
  {
    if (led & 0x81) 
    {
      dir = (dir ^ 0x1);
    }

    if (dir) 
    {
      led = led >> 1;
    } 
    else 
    {
      led = led << 1;
    }
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);
    OSTimeDlyHMSM(0,0,0,50);
  }
}

static void sevenseg_set_hex(alt_u8 hex)
{
  static alt_u8 segments[16] = {
    0x81, 0xCF, 0x92, 0x86, 0xCC, 0xA4, 0xA0, 0x8F, 0x80, 0x84, /* 0-9 */
    0x88, 0xE0, 0xF2, 0xC2, 0xB0, 0xB8 };                       /* a-f */

  alt_u32 data = segments[hex & 15] | (segments[(hex >> 4) & 15] << 8);

  IOWR_ALTERA_AVALON_PIO_DATA(SEVEN_SEG_PIO_BASE, data);
}

void SSD_task(void* pdata)
{
  alt_u32 count;
  
  while (1)
  {
    for (count = 0; count <= 0xff; count++)
    {
      sevenseg_set_hex(count);
      OSTimeDlyHMSM(0,0,0,50);
    }
  }
}

/******************************************************************************
*                                                                             *
* License Agreement                                                           *
*                                                                             *
* Copyright (c) 2006 Altera Corporation, San Jose, California, USA.           *
* All rights reserved.                                                        *
*                                                                             *
* Permission is hereby granted, free of charge, to any person obtaining a     *
* copy of this software and associated documentation files (the "Software"),  *
* to deal in the Software without restriction, including without limitation   *
* the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
* and/or sell copies of the Software, and to permit persons to whom the       *
* Software is furnished to do so, subject to the following conditions:        *
*                                                                             *
* The above copyright notice and this permission notice shall be included in  *
* all copies or substantial portions of the Software.                         *
*                                                                             *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
* DEALINGS IN THE SOFTWARE.                                                   *
*                                                                             *
* This agreement shall be governed in all respects by the laws of the State   *
* of California and by the laws of the United States of America.              *
* Altera does not recommend, suggest or require that this reference design    *
* file be used in conjunction or combination with any other product.          *
******************************************************************************/

⌨️ 快捷键说明

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