LoadCalendarFromRTC (developers)

39 views
Skip to first unread message

xiaogui972

unread,
Mar 7, 2011, 8:30:23 AM3/7/11
to ml-d...@googlegroups.com
Hi,

Does anyone know a way to get the actual RTC tick count from the processor? Since LoadCalendarFromRTC  exists I assume it must get the tick count internally.. I am wondering if anyone reversed it for 550D 1.09?

It's a great way to measure time ticks, looking for something like rdtsc on x86..

Thanks!

Alex

unread,
Mar 7, 2011, 8:57:10 AM3/7/11
to Magic Lantern firmware development
Try looking around 0x26B8 with mem spy.

Alex

unread,
Jun 7, 2011, 11:17:33 AM6/7/11
to Magic Lantern firmware development
At first sight, 0xc0242014 (550D) seems to be a timer with 10us
resolution, which rolls over every 1 second.

Credits goto AJ: AJ_guess_get_DIGIC_time :)

> --
> http://magiclantern.wikia.com/
>
> To post to this group, send email to ml-d...@googlegroups.com
> To unsubscribe from this group, send email to ml-devel+u...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/ml-devel?hl=en

Antony Newman

unread,
Jun 7, 2011, 12:05:17 PM6/7/11
to ml-d...@googlegroups.com
This are a couple of test routines - two versions.  that I penned to allow 'stopwatches' to be started.

+) Version 1 => I discovered - probably much in the same way that TH did - that the DIGIC_clock is not synced with the RTC.
                    => That if you get the RTC too soon after DryOs startup -> DryOs freaks out.
                    => That if you poll (call) the RTC 'too frequently' -> DryOs gets upset

+) Version 2 => Before I finished the code I removed it (found another way of doing what I wanted)
                    => The idea I had was to record the DIGIC_TIME offset when you call it, and take this as Zero.
                          then combine this with the RTC value to give you the actual ms Value.
                    => I think I removed it due to drift of the DIGIC_TIME - can't remember.

AJ



/*********************************************************************************
VERSION 1                                                                     *
*  aj_stopwatch()   What is the time?    Seconds + microseconds                  *                                                               
*                   Pass the address of you parameter storing your stopwatch     *
*                   Set it to Zero on the first call - and it will be updated    *
*                   with the current ms time                                     *                                                             
*********************************************************************************/

#define MAX_DIGIC_TIME (0xFFFFF)

unsigned int aj_stopwatch(unsigned int *start_time_ms)
{
   if (start_time_ms==NULL)
      return ( 0 );  // Oops


   /***********************************************************
   *  What is the absolute number of ms since time started ?? *
   ***********************************************************/

   unsigned int digic_time = AJ_guess_get_DIGIC_time();   

   struct tm now;


   LoadCalendarFromRTC( &now );     // get time.

   //hack Comment out the following line if you're calling this at startup  (causes ERROR70)
   now.tm_gmtoff = 0;

   unsigned int time_ms = (999 * digic_time) / MAX_DIGIC_TIME;
 
   time_ms = time_ms + now.tm_gmtoff * 1000;


   /***********************************************
   *  If user set variable as Zero - reset clock  *
   ***********************************************/
   
   if ( *start_time_ms == 0)
      *start_time_ms = time_ms;



   /***********************************************
   *  How many milliseconds so far?               *
   ***********************************************/
   
   return(  time_ms - *start_time_ms );
 
} /* end of aj_stopwatch() */




/*********************************************************************************
VERSION 1   - unfinished                                                      *
*  aj_stopwatch()   What is the time?    Seconds + microseconds                  *                                                              
*                   Pass the address of you parameter storing your stopwatch     *
*                   Set it to Zero on the first call - and it will be updated    *
*                   with the current ms time                                     *                                                            
*********************************************************************************/

#define MAX_DIGIC_TIME (0xFFFFF)

unsigned int aj_stopwatch(unsigned int *start_time_ms)
{
   if (start_time_ms==NULL)
      return ( 0 );  // Oops


   /***********************************************************
   *  What is the asolute number of ms since time started ??  *
   ***********************************************************/
 
   static unsigned int old_digic_time=0;
   static unsigned int old_seconds=0;

   unsigned int digic_time = AJ_guess_get_DIGIC_time();

   struct tm now;

   if ( *start_time_ms == 0)
   {
      old_digic_time = digic_time;

      LoadCalendarFromRTC( &now );     // get time.
      old_seconds = now.tm_gmtoff;
   }


   if (old_digic_time >  digic_time)
   {
      LoadCalendarFromRTC( &now );     // get time.
      old_seconds = now.tm_gmtoff;
   }

// hack
now.tm_gmtoff = 0;

   unsigned int time_ms = (999 * digic_time) / MAX_DIGIC_TIME;
 
   time_ms = time_ms + now.tm_gmtoff * 1000;



   /***********************************************
   *  If user set variable as Zero - reset clock  *
   ***********************************************/
  
   if ( *start_time_ms == 0)
      *start_time_ms = time_ms;



   /***********************************************
   *  How many milliseconds so far?               *
   ***********************************************/
  
   return(  time_ms - *start_time_ms );
 
} /* end of aj_stopwatch() */


Reply all
Reply to author
Forward
0 new messages