[En-Nut-Discussion] Thread Switching Problem

MUHAMMAD AZEEM AZAM muhammadazeemazam786 at yahoo.com
Wed Apr 4 16:45:29 CEST 2007


I have the following code and my thread is not switching from main() to Compute() Thread except for the first time. All threads have same priority. Service thread is a TCP reuest Thread.
  THanks for help in advance
  Bye
  ------------------
   
  THREAD(service_thread, arg)
{
 //NutThreadSetPriority(61);
      for (;;)
 { 
        PORTD = PORTD & 0xfe;
  //DDRD = 0xff;
  //PORTD = 0x00;  
    TCPservice();
  
  PORTD = PORTD | 0x01;
  //DDRD = 0xff;
  //PORTD = 0xff;
 }
}
  THREAD(compute_thread, arg)
{
 //NutThreadSetPriority(65);
    for (;;)
 {
  NutSleep(500);
        PORTD = PORTD & 0xfd;
  NutSleep(500);
  PORTD = PORTD | 0x02;
  //DDRD = 0xff;
  //PORTD = 0x0f;
  //NutSleep(1000);
 }
}
  /**************************************************************************************
****************************** Initialization Functions *******************************
**************************************************************************************/
  void InitRegisterDevice(void)
{
    NutRegisterDevice(&devEth0, 0x8300, 5);
}
  int InitEthernetDevice(void)
{
    u_long ip_addr = inet_addr(MY_IPADDR);
    u_long ip_mask = inet_addr(MY_IPMASK);
    u_char mac[6] = MY_MAC;
   NutNetIfConfig("eth0", mac, ip_addr, ip_mask);
 
 return 0;
}
  /**************************************************************************************
*********************************** Main **********************************************
**************************************************************************************/
  int main(void)
{
 static char txt_msg0_str[]  = "TCP Server \x0";
   static char txt_msg1_str[]  = "Ethernut Project\x0";
 
 /***************************************************
   * LED & LCD initialization
   *****************************************************/
  
 DevBoardShiftLedOut(ShiftLEDOut);
   strcpy(LCDText,txt_msg0_str);
 strcat(LCDText,txt_msg1_str);
   LCD_Init();
 LCD_Cursor_YX( 0, 0 );
 LCD_Puts(txt_msg0_str);
 LCD_Cursor_YX( 1, 0 );
 LCD_Puts(txt_msg1_str);
 LCD_SendCmd(0x0C);   /* display on, cursor off */
  
//----------------------------------
   InitRegisterDevice();
 
 if (InitEthernetDevice() == 0) 
 {
  
  NutThreadCreate("NET_Thread", service_thread, 0, 512);
  NutThreadCreate("OTH_Thread", compute_thread, 0, 512);
      
  
  //NutThreadSetPriority(254);   /*smallest priority on main program. Default priority is 64*/
      for (;;) 
   {
    NutSleep(1000);
          PORTD = PORTD & 0xfb; 
    NutSleep(1000);
    PORTD = PORTD | 0x04;
    //DDRD = 0xff;
    //PORTD = 0xf0;
    //NutSleep(500);
     }
      }
return 0;
}

  -----------------------

 
---------------------------------
Bored stiff? Loosen up...
Download and play hundreds of games for free on Yahoo! Games.


More information about the En-Nut-Discussion mailing list