[En-Nut-Discussion] Thread Switching Problem

Julian Dohle JD at REMBE.de
Wed Apr 4 22:25:19 CEST 2007


Hello,

As far as i understand a thread can only be switched if a function like NutSleep or something else is called.
Your Thread Service_thread only contains a function call to TCPservice. If theres no call to a nutsleep or a simmilar function, then the thread would'nt switch. You may try to insert an NutSleep(100) Call in your thread service_thread or in TCPservice. Maybe this will solve your problem.

Viele Grüße / With best regards

i.A. Julian Dohle 
IT Department
 
REMBE® GmbH SAFETY + CONTROL
Gallbergweg 21
59929 Brilon / Germany
T:  + 49 2961 7405 - 517
F:  + 49 2961 50714
www.rembe.de


-----Ursprüngliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de [mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von MUHAMMAD AZEEM AZAM
Gesendet: Mittwoch, 4. April 2007 16:45
An: en-nut-discussion at egnite.de
Betreff: [En-Nut-Discussion] Thread Switching Problem

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.
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion



More information about the En-Nut-Discussion mailing list