void SSSCreateTasks(void)
{
   INT8U error_code;
  
   error_code = OSTaskCreateExt(LED7SegLightshowTask,
                             NULL,
                             (void *)&LED7SegLightshowTaskStk[TASK_STACKSIZE-1],
                             LED_7SEG_LIGHTSHOW_TASK_PRIORITY,
                             LED_7SEG_LIGHTSHOW_TASK_PRIORITY,
                             LED7SegLightshowTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
   
   alt_uCOSIIErrorHandler(error_code, 0);
  
   error_code = OSTaskCreateExt(LEDManagementTask,
                              NULL,
                              (void *)&LEDManagementTaskStk[TASK_STACKSIZE-1],
                              LED_MANAGEMENT_TASK_PRIORITY,
                              LED_MANAGEMENT_TASK_PRIORITY,
                              LEDManagementTaskStk,
                              TASK_STACKSIZE,
                              NULL,
                              0);

   alt_uCOSIIErrorHandler(error_code, 0);

}
static void WSCreateTasks()
{
  INT8U error_code = OS_NO_ERR;
  
  /* Start LED Task. */
  
  error_code = OSTaskCreateExt(LED_task,
                             NULL,
                             (void *)&LEDTaskStk[TASK_STACKSIZE-1],
                             LED_PRIO,
                             LED_PRIO,
                             LEDTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);
  
  /* Start SSD Task. */
  #ifdef SEG7_NAME
  error_code = OSTaskCreateExt(SSD_task,
                             NULL,
                             (void *)&SSDTaskStk[TASK_STACKSIZE-1],
                             SSD_PRIO,
                             SSD_PRIO,
                             SSDTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);
  #endif
  
  /* Start Board Control Task. */
  
  error_code = OSTaskCreateExt(board_control_task,
                             NULL,
                             (void *)&BCTaskStk[TASK_STACKSIZE-1],
                             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. */
  
}
Esempio n. 3
0
int main (int argc, char* argv[], char* envp[])
{

  INT8U error_code;

  /* Clear the RTOS timer */
  OSTimeSet(0);

  /* 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.
   */
  error_code = OSTaskCreateExt(SSSInitialTask,
                             NULL,
                             (void *)&SSSInitialTaskStk[TASK_STACKSIZE],
                             SSS_INITIAL_TASK_PRIORITY,
                             SSS_INITIAL_TASK_PRIORITY,
                             SSSInitialTaskStk,
                             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!
   */
  OSStart();


  while(1); /* Correct Program Flow never gets here. */

  return -1;
}
Esempio n. 4
0
int main (int argc, char* argv[], char* envp[])
{
  
  INT8U error_code;
  int rc;

  /* Clear the RTOS timer */
  OSTimeSet(0);

  /* Flash LEDs and reset ethernet PHY - $M$*/
#ifdef LED_PIO_BASE
   IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xaa);
   printf("LEDs set to 0xAA\n");
#endif
   rc = usleep(1000000);  // Delay 1 sec

#ifdef NENET_REG_RESET_BASE
  /* Reset the Ethernet PHY */
   printf("Reseting Ethernet PHY...");
   IOWR_ALTERA_AVALON_PIO_DATA(NENET_REG_RESET_BASE, 0x1);  // Be sure it's hi first
   rc = usleep(250000);  // Delay .25 sec
   IOWR_ALTERA_AVALON_PIO_DATA(NENET_REG_RESET_BASE, 0x0);  // Go low for reset
   rc = usleep(250000);  // Delay .25 sec
   IOWR_ALTERA_AVALON_PIO_DATA(NENET_REG_RESET_BASE, 0x1);  // Back to hi - inactive
   printf(" Done\n");
   rc = usleep(250000);  // Delay .25 sec
#endif
#ifdef LED_PIO_BASE
   IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xaa);
   printf("LEDs set to 0x55\n");
#endif

  /* SSSInitialTask will initialize the NicheStack
   * TCP/IP Stack and then initialize the rest of the Simple Socket Server example 
   * RTOS structures and tasks. 
   */  
  error_code = OSTaskCreateExt(SSSInitialTask,
                             NULL,
                             (void *)&SSSInitialTaskStk[TASK_STACKSIZE],
                             SSS_INITIAL_TASK_PRIORITY,
                             SSS_INITIAL_TASK_PRIORITY,
                             SSSInitialTaskStk,
                             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!
   */
  OSStart();

  
  while(1); /* Correct Program Flow never gets here. */

  return -1;
}
/*
 * Create our MicroC/OS-II resources. All of the resources beginning with 
 * "SSS" are declared in this file, and created in this function.
 */
void SSSCreateOSDataStructs(void)
{
  INT8U error_code;
  
  /*
  * Create the resource for our MicroC/OS-II Queue for sending commands 
  * received on the TCP/IP socket from the SSSSimpleSocketServerTask()
  * to the LEDManagementTask().
  */
  SSSLEDCommandQ = OSQCreate(&SSSLEDCommandQTbl[0], SSS_LED_COMMAND_Q_SIZE);
  if (!SSSLEDCommandQ)
  {
     alt_uCOSIIErrorHandler(EXPANDED_DIAGNOSIS_CODE, 
     "Failed to create SSSLEDCommandQ.\n");
  }
  
 /* Create our MicroC/OS-II LED Lightshow Semaphore.  The semaphore is checked 
  * by the SSSLEDLightshowTask each time it updates 7 segment LED displays, 
  * U8 and U9.  The LEDTask grabs the semaphore away from the lightshow task to
  * toggle the lightshow off, and gives up the semaphore to turn the lightshow
  * back on.  The LEDTask does this in response to the CMD_LEDS_LIGHTSHOW
  * command sent from the SSSSimpleSocketServerTask when the user sends the 
  * toggle lightshow command over the TCPIP socket.
  */
  SSSLEDLightshowSem = OSSemCreate(1);
  if (!SSSLEDLightshowSem)
  {
     alt_uCOSIIErrorHandler(EXPANDED_DIAGNOSIS_CODE, 
                            "Failed to create SSSLEDLightshowSem.\n");
  }
  
 /*
  * Create our MicroC/OS-II LED Event Flag.  Each flag corresponds to one of
  * the LEDs on the Nios Development board, D0 - D7. 
  */   
  SSSLEDEventFlag = OSFlagCreate(0, &error_code);
  if (!SSSLEDEventFlag)
  {
     alt_uCOSIIErrorHandler(error_code, 0);
  }
}
Esempio n. 6
0
/* 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 */
}
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.*/
}
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-1],
                             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!
   */
  OSStart();
  
  while(1); /* Correct Program Flow never gets here. */

  return -1;
}
Esempio n. 9
0
/* 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 */
}
Esempio n. 10
0
void alt_uCOSIIErrorHandler(INT8U error_code, void *expanded_diagnosis_ptr)
{
   FAULT_LEVEL fault_level;
   
   if(error_code == OS_NO_ERR)
   {
      return;
   }
   
   fault_level = SYSTEM;  
   OSSchedLock();  /* Disable Task Switching but still service other IRQs */
      
   switch (error_code)
   {  
      case OS_PRIO_EXIST:
         fprintf(stderr, "Attempted to assign task priority aready in use.\n");
         break;
      case OS_PRIO_INVALID:
         fprintf(stderr, "Specified task priority higher than allowed max.\n");
         fprintf(stderr, "Task can't be assigned a priority higher than %d\n",
            OS_LOWEST_PRIO);
         break;
      case OS_NO_MORE_TCB:
         fprintf(stderr, "Task Control Blocks have been exhausted\n");
         fprintf(stderr, "Current max number of tasks is %d\n",OS_MAX_TASKS);
         break;
      case OS_MBOX_FULL:
         fault_level = NONE;
         fprintf(stderr, "Attempted Post to Mailbox already holding message\n");
         break;
      case OS_ERR_EVENT_TYPE:
         fault_level = TASK;
         fprintf(stderr, 
"Attempted to access a resource with no match for the required data type.\n");
         break;
      case OS_ERR_PEVENT_NULL:
         fprintf(stderr, "Attempting to access a resource pointing to NULL\n");
         break;
      case OS_ERR_POST_NULL_PTR:
         fault_level = TASK;
         fprintf(stderr, "Attempted to Post a NULL to a resource. \n");
         break;
      case OS_TIMEOUT:
         fault_level = NONE;
         fprintf(stderr, "Resource not received in specified time\n");
         break;
      case OS_ERR_PEND_ISR:
         fprintf(stderr, "Attempting to pend for a resource in an ISR\n");
         break;
      case OS_TASK_DEL_IDLE:
         fprintf(stderr, "Attempted to delete the IDLE task\n");
         break;
      case OS_TASK_DEL_ERR:
         fault_level = NONE;
         fprintf(stderr, "Attempted to delete a task that does not exist\n");
         break;
      case OS_TASK_DEL_ISR:
         fprintf(stderr, "Attempted to delete a task from an ISR\n");
         break;
      case OS_Q_FULL:
         fault_level = NONE;
         fprintf(stderr, "Attempted to post to a full message queue\n");
         break;
      case OS_ERR_NOT_MUTEX_OWNER:
         fault_level = TASK;
         fprintf(stderr, "Attempted to post a mutex not owned by the task\n");
         break;
      case EXPANDED_DIAGNOSIS_CODE:      
         fault_level = SYSTEM;
         printf(
"\n[MicroC/OS-II]: See STDERR for expanded diagnosis translation.");    
         fprintf(stderr, "\n[MicroC/OS-II]: Expanded Diagnosis: %s.", 
                 (char *)expanded_diagnosis_ptr);
         break;           
      default:
         printf("\n[MicroC/OS-II]: (Not a MicroC/OS-II error) See STDERR.\n");    
         fprintf(stderr, "\n[MicroC/OS-II]:");
         fprintf(stderr, "\nError_code %d.\n", error_code);
         perror("\n[MicroC/OS-II]: (Not a MicroC/OS-II error), ERRNO: ");
         break;

   }

   /* Process the error based on the fault level, 
    * reenable scheduler if appropriate. */  
   switch (fault_level) {
      case TASK:
         /* Error can be isolated by killing the task */
         printf("\n[MicroC/OS-II]: See STDERR (FAULT_LEVEL is TASK).");
         fprintf(stderr, "\n[MicroC/OS-II]: FAULT_LEVEL is TASK");
         fprintf(stderr, "\n[MicroC/OS-II]: Task is being deleted.\n");
         OSSchedUnlock(); /* Reenable Task Switching */
         OSTaskDel(OS_PRIO_SELF);
         /* Reinvoke uCOSII error handler in case task deletion fails, in 
          * which case fault_level for this secondary error will be SYSTEM. */
         alt_uCOSIIErrorHandler(error_code, 0);         
         break;
      case SYSTEM:
         /* Total System Failure, Restart Required */
         printf("\n[MicroC/OS-II]: See STDERR (FAULT_LEVEL is SYSTEM).");    
         fprintf(stderr, "\n[MicroC/OS-II]: FAULT_LEVEL is SYSTEM");
         fprintf(stderr, "\n[MicroC/OS-II]: FATAL Error, Restart required.");
         fprintf(stderr, "\n[MicroC/OS-II]: Locking scheduler - endless loop.\n");
         while(1); /* Since scheduler is locked,loop halts all task activity.*/
         break;
      case NONE:
         fprintf(stderr, "\n[MicroC/OS-II]: FAULT_LEVEL is NONE");
         fprintf(stderr, "\n[MicroC/OS-II]: Informational error only, control"); 
         fprintf(stderr, 
            "returned to task to complete processing at application level.\n");
         OSSchedUnlock(); /* Reenable Task Switching */
         return;   
         break;      
      default:
         printf("\n[MicroC/OS-II]: See STDERR (FAULT_LEVEL is Unknown).\n");
         fprintf(stderr, "\n[MicroC/OS-II]: FAULT_LEVEL is unknown!?!\n");
   }
   while(1); /* Correct Program Flow never gets here. */
}
Esempio n. 11
0
void alt_SSSErrorHandler(INT8U error_code, 
                         void *expanded_diagnosis_ptr)
{
   FAULT_LEVEL fault_level;
   
   if   (error_code == OS_NO_ERR)
   {
      return;
   }

   fault_level = (error_code == OS_NO_ERR) ? NONE : SYSTEM;
   
   OSSchedLock();  /* Disable Task Switching but still service other IRQs */
   switch (error_code)
   {
      case EXPANDED_DIAGNOSIS_CODE:      
         fault_level = SYSTEM;
         printf("\n[SSS]: See STDERR for expanded diagnosis translation.");    
         fprintf(stderr, "\n[SSS]: %s", (char *)expanded_diagnosis_ptr);
         break;
         
      case OS_Q_FULL:
         fault_level = NONE;
         fprintf(stderr,"\n[SSS]: Attempted to post to a full message queue.");
         break;
      
      default:
         fault_level = SYSTEM;
         printf("\n[SSS]: See STDERR.\n");    
         fprintf(stderr, "\n[SSS]: Error_code %d!", error_code);        
         perror("\n[SSS]:  ERRNO: ");
   }

   /* Process the error based on the fault level, 
    * reenable scheduler if appropriate. */     
   switch (fault_level) 
   {
      case TASK:
         /* Error can be isolated by killing the task */
         printf("\n[SSS]: See STDERR (FAULT_LEVEL is TASK).");
         fprintf(stderr, "\n[SSS]: FAULT_LEVEL is TASK");
         fprintf(stderr, "\n[SSS]: Task is being deleted.\n");
         OSSchedUnlock(); /* Reenable Task Switching */
         OSTaskDel(OS_PRIO_SELF);
         /* Invoke uCOSII error handler in case task deletion fails, in 
          * which case fault_level for this secondary error will be SYSTEM. */
         alt_uCOSIIErrorHandler(error_code, 0);         
         break;
      case SYSTEM:
          /* Total System Failure, Restart Required */
         printf("\n[SSS]: See STDERR (FAULT_LEVEL is SYSTEM).");    
         fprintf(stderr, "\n[SSS]: FAULT_LEVEL is SYSTEM.");
         fprintf(stderr, "\n[SSS]: FATAL Error, Restart required.");
         fprintf(stderr, "\n[SSS]: Locking scheduler - endless loop.\n");
         while(1); /* Since scheduler is locked, loop halts all task activity.*/
         break;
      case NONE:
         fprintf(stderr, "\n[SSS] FAULT_LEVEL is NONE.");
         fprintf(stderr, 
            "\n[SSS] Informational error only, control returned to task to ");
         fprintf(stderr,
            "complete processing at the application level.\n");
         OSSchedUnlock(); /* Reenable Task Switching */ 
         return;         
         break;
      default:
         printf("\n[SSS]: See STDERR (FAULT_LEVEL is Unknown).\n");
         fprintf(stderr, "\n[SSS] FAULT_LEVEL is unknown!?!\n");
   }
   while(1); /* Correct Program Flow never gets here. */
}