public inbox for ecos-patches@sourceware.org
 help / color / mirror / Atom feed
* cortexm fix rtc
@ 2008-11-04 15:54 simon.kallweit
  2008-11-04 18:23 ` Nick Garnett
  0 siblings, 1 reply; 4+ messages in thread
From: simon.kallweit @ 2008-11-04 15:54 UTC (permalink / raw)
  To: ecos-patches

[-- Attachment #1: Type: text/plain, Size: 151 bytes --]

This patch fixes a small issue with the SysTick reload value (this has 
to be period - 1) and fixed wrap-around in the hal_delay_us() function.

Simon

[-- Attachment #2: cortexm_fix_rtc.patch --]
[-- Type: text/x-diff, Size: 2533 bytes --]

diff -r 88090cc51393 packages/hal/cortexm/arch/current/ChangeLog
--- a/packages/hal/cortexm/arch/current/ChangeLog	Tue Nov 04 13:57:25 2008 +0100
+++ b/packages/hal/cortexm/arch/current/ChangeLog	Tue Nov 04 16:51:48 2008 +0100
@@ -1,3 +1,9 @@
+2008-11-04  Simon Kallweit  <simon.kallweit@intefo.ch>
+	* include/hal_intr.h:
+	Fixed load value of SysTick counter.
+	* src/hal_misc.c:
+	Fixed wrap-around in hal_delay_us().
+
 2008-11-04  Simon Kallweit  <simon.kallweit@intefo.ch>
 
 	* include/hal_intr.h:
diff -r 88090cc51393 packages/hal/cortexm/arch/current/include/hal_intr.h
--- a/packages/hal/cortexm/arch/current/include/hal_intr.h	Tue Nov 04 13:57:25 2008 +0100
+++ b/packages/hal/cortexm/arch/current/include/hal_intr.h	Tue Nov 04 16:51:48 2008 +0100
@@ -326,7 +326,7 @@
 #define HAL_CLOCK_INITIALIZE( __period )                                \
 {                                                                       \
     cyg_uint32 __p = __period;                                          \
-    __p = hal_cortexm_systick_clock / ( 1000000 / __p );                \
+    __p = hal_cortexm_systick_clock / ( 1000000 / __p ) - 1;            \
     HAL_WRITE_UINT32(CYGARC_REG_SYSTICK_BASE+CYGARC_REG_SYSTICK_RELOAD, \
                      __p );                                             \
     HAL_WRITE_UINT32(CYGARC_REG_SYSTICK_BASE+CYGARC_REG_SYSTICK_CSR,    \
@@ -345,8 +345,8 @@
     cyg_uint32 __period, __value;                                       \
     HAL_READ_UINT32(CYGARC_REG_SYSTICK_BASE+CYGARC_REG_SYSTICK_RELOAD, __period ); \
     HAL_READ_UINT32(CYGARC_REG_SYSTICK_BASE+CYGARC_REG_SYSTICK_VALUE, __value ); \
-    __value = __period - __value;                                       \
-    __value /= (hal_cortexm_systick_clock/ 1000000 );                   \
+    __value = ( __period + 1 ) - __value;                               \
+    __value /= (hal_cortexm_systick_clock / 1000000 );                  \
     *(__pvalue) = __value;                                              \
 }
 
diff -r 88090cc51393 packages/hal/cortexm/arch/current/src/hal_misc.c
--- a/packages/hal/cortexm/arch/current/src/hal_misc.c	Tue Nov 04 13:57:25 2008 +0100
+++ b/packages/hal/cortexm/arch/current/src/hal_misc.c	Tue Nov 04 16:51:48 2008 +0100
@@ -500,8 +500,9 @@
     {
         HAL_CLOCK_READ( &t1 );
         if( t1 < t0 )
-            t1 += CYGNUM_HAL_RTC_PERIOD;
-        us -= t1-t0;
+            us -= (t1 + CYGNUM_HAL_RTC_PERIOD - t0);
+        else
+        	us -= t1 - t0;
         t0 = t1;
     }
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: cortexm fix rtc
  2008-11-04 15:54 cortexm fix rtc simon.kallweit
@ 2008-11-04 18:23 ` Nick Garnett
  2008-11-04 18:53   ` Simon Kallweit
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Garnett @ 2008-11-04 18:23 UTC (permalink / raw)
  To: simon.kallweit; +Cc: ecos-patches

"simon.kallweit@intefo.ch" <simon.kallweit@intefo.ch> writes:

> This patch fixes a small issue with the SysTick reload value (this has
> to be period - 1) and fixed wrap-around in the hal_delay_us() function.

The -1 on the period is OK.

However, I don't see the point in the change to HAL_DELAY_US(). As far
as I can tell it has exactly the same effect, or am I missing
something?


-- 
Nick Garnett                                      eCos Kernel Architect
eCosCentric Limited    http://www.eCosCentric.com      The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.     Tel: +44 1223 245571
Registered in England and Wales:                        Reg No: 4422071

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: cortexm fix rtc
  2008-11-04 18:23 ` Nick Garnett
@ 2008-11-04 18:53   ` Simon Kallweit
  2008-11-05 10:02     ` Nick Garnett
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Kallweit @ 2008-11-04 18:53 UTC (permalink / raw)
  To: Nick Garnett; +Cc: ecos-patches

Nick Garnett schrieb:
> "simon.kallweit@intefo.ch" <simon.kallweit@intefo.ch> writes:
>
>   
>> This patch fixes a small issue with the SysTick reload value (this has
>> to be period - 1) and fixed wrap-around in the hal_delay_us() function.
>>     
>
> The -1 on the period is OK.
>   

Fine.

> However, I don't see the point in the change to HAL_DELAY_US(). As far
> as I can tell it has exactly the same effect, or am I missing
> something?
>   

Do a series on paper, it's not the same. When the wrap around occures, 
you will add to the us counter. The 100ms delay on a redboot reboot 
never returned. With this fix, it actually takes 100ms :)

Simon

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: cortexm fix rtc
  2008-11-04 18:53   ` Simon Kallweit
@ 2008-11-05 10:02     ` Nick Garnett
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Garnett @ 2008-11-05 10:02 UTC (permalink / raw)
  To: Simon Kallweit; +Cc: ecos-patches

Simon Kallweit <simon.kallweit@intefo.ch> writes:

> Nick Garnett schrieb:
> > However, I don't see the point in the change to HAL_DELAY_US(). As far
> > as I can tell it has exactly the same effect, or am I missing
> > something?
> >
> 
> Do a series on paper, it's not the same. When the wrap around occures,
> you will add to the us counter. The 100ms delay on a redboot reboot
> never returned. With this fix, it actually takes 100ms :)

I'm still not convinced. However, there is no reason not to make the
change so I've applied it.


-- 
Nick Garnett                                      eCos Kernel Architect
eCosCentric Limited    http://www.eCosCentric.com      The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.     Tel: +44 1223 245571
Registered in England and Wales:                        Reg No: 4422071

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-11-05 10:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-04 15:54 cortexm fix rtc simon.kallweit
2008-11-04 18:23 ` Nick Garnett
2008-11-04 18:53   ` Simon Kallweit
2008-11-05 10:02     ` Nick Garnett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).