/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Noob question

Username:     
Password:     
             

Forum

# 1   2008-08-02 08:06:11 Noob question

ashesman
New member
Registered: 2008-07-20
Posts: 7

Noob question

Hi there,

  I am new to STM32, Circle OS and all that (but not new to C or embedded stuff).  I just started my first CircleOS application and I am surprised at how slow it is running.  It is doing next to no work.  Currently my application handler seems to be executing at about 5 Hz or 10 Hz if I comment out half the code.  Could someone please help me with my application handler is called so infrequently or is taking so long to execute.  All code is exactly as per a new CircleOS project with this application  handler:

Code:

/*******************************************************************************
* Function Name  : Application_Handler
* Description    : Management of the Circle_App.
*
* Input          : None
* Return         : MENU_CONTINUE
*******************************************************************************/
enum MENU_code Application_Handler ( void )
{
   // TODO: Write your application handling here.
   //       This routine will get called repeatedly by CircleOS, until we
   //       return MENU_LEAVE

   static u32 s_oldSeconds = 0;
   static u32 s_callRateCount = 0;
   static u32 s_callRate = 0; 
   
   // Calculate call rate
   u32 hours, minutes, seconds;
   RTC_GetTime(&hours, &minutes, &seconds); 
   s_callRateCount++;
   if(seconds != s_oldSeconds)
   {
      s_callRate = s_callRateCount;
      s_callRateCount = 0;
   }
   s_oldSeconds = seconds;
   
   // Zero MEMS if button pushed
   if(BUTTON_GetState() == BUTTON_PUSHED) 
   {
      MEMS_SetNeutral();
      BUZZER_SetMode(BUZZER_SHORTBEEP);
   }
   
   // Update screen
   tMEMS_Info * ptrMems;
   ptrMems = MEMS_GetInfo();
   char * tempBuf[10];
   char * tempStr[20];
   UTIL_int2str(tempBuf, ptrMems->OutX_F64 / 64,6 , 0);
   strcpy(tempStr, "X: ");
   strcat(tempStr, tempBuf);
   DRAW_DisplayString(5, 99, tempStr, 17);
   UTIL_int2str(tempBuf, ptrMems->OutY_F64 / 64,6 , 0);
   strcpy(tempStr, "Y: ");
   strcat(tempStr, tempBuf);
   DRAW_DisplayString(5, 88, tempStr, 17);
   UTIL_int2str(tempBuf, ptrMems->OutZ_F64 / 64,6 , 0);
   strcpy(tempStr, "Z: ");
   strcat(tempStr, tempBuf);
   DRAW_DisplayString(5, 77, tempStr, 17);

   UTIL_int2str(tempBuf, s_callRate, 5 , 0);
   strcpy(tempStr, "Rate: ");
   strcat(tempStr, tempBuf);
   DRAW_DisplayString(5, 55, tempStr, 17);
   
   return MENU_CONTINUE;   // Returning MENU_LEAVE will quit to CircleOS
}

Last edited by ashesman (2008-08-02 08:23:39)

Offline

 

# 2   2008-08-02 08:23:08 Noob question

ashesman
New member
Registered: 2008-07-20
Posts: 7

Re: Noob question

OK, so I found some answers here:

http://www.stm32circle.com/forum/viewtopic.php?id=123

But it still doesn't explain why calls to the application handler halve when all code is commented in.  Surely this code could not be taking so long to execute that it skips every second call to the application handler???  The following code executes exactly twice as often as the code above!

o me it would make more sense to call the application handler whenever the OS is not doing something rather than having the processor waiting 100ms or more between calls to the application handler.  You have to add handlers to get any useful performance out of the OS.  It would be more practical if in the application handler you took care of how often parts of your application were called. ie every 10ms do this, every 23ms do that...

Code:

/*******************************************************************************
* Function Name  : Application_Handler
* Description    : Management of the Circle_App.
*
* Input          : None
* Return         : MENU_CONTINUE
*******************************************************************************/
enum MENU_code Application_Handler ( void )
{
   // TODO: Write your application handling here.
   //       This routine will get called repeatedly by CircleOS, until we
   //       return MENU_LEAVE

   static u32 s_oldSeconds = 0;
   static u32 s_callRateCount = 0;
   static u32 s_callRate = 0; 
   
   // Calculate call rate
   u32 hours, minutes, seconds;
   RTC_GetTime(&hours, &minutes, &seconds); 
   if(seconds != s_oldSeconds)
   {
      s_callRate = s_callRateCount;
      s_callRateCount = 0;
   }
   s_oldSeconds = seconds;
   s_callRateCount++;
   
   // Zero MEMS if button pushed
   if(BUTTON_GetState() == BUTTON_PUSHED) 
   {
      MEMS_SetNeutral();
      BUZZER_SetMode(BUZZER_SHORTBEEP);
   }
   
   // Update screen
   tMEMS_Info * ptrMems;
   ptrMems = MEMS_GetInfo();
   char * tempBuf[10];
   char * tempStr[20];
   /*UTIL_int2str(tempBuf, ptrMems->OutX_F64 / 64,6 , 0);
   strcpy(tempStr, "X: ");
   strcat(tempStr, tempBuf);
   DRAW_DisplayString(5, 99, tempStr, 17);
   UTIL_int2str(tempBuf, ptrMems->OutY_F64 / 64,6 , 0);
   strcpy(tempStr, "Y: ");
   strcat(tempStr, tempBuf);
   DRAW_DisplayString(5, 88, tempStr, 17);
   UTIL_int2str(tempBuf, ptrMems->OutZ_F64 / 64,6 , 0);
   strcpy(tempStr, "Z: ");
   strcat(tempStr, tempBuf);
   DRAW_DisplayString(5, 77, tempStr, 17);*/

   UTIL_int2str(tempBuf, s_callRate, 5 , 0);
   strcpy(tempStr, "Rate: ");
   strcat(tempStr, tempBuf);
   DRAW_DisplayString(5, 55, tempStr, 17);
   
   return MENU_CONTINUE;   // Returning MENU_LEAVE will quit to CircleOS
}

Last edited by ashesman (2008-08-02 08:28:06)

Offline

 

# 3   2008-08-04 15:56:17 Noob question

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Noob question

We don't call too often the application handler to avoid saturation. All the tasks (except the MEMS that is handled by a high priority interrupt) are called sequentially from the same systick interrupt. An a long 'application' can be accepted if it is not call at every tick.

Note that if you need to call more often your application handler, you can easily redirect the handler to your application, and eliminate the division. Just restore the original handler when you leave the application (in order to provide the standard behaviour to any other application).

Offline

 

Board footer