Hi Gordon,

Gordon Henderson schrieb:
> void mathTest (uint16_t x)
> {
>    uint32_t y ;
>    uint32_t i = 0 ;
> 
>    for (;;)
>    {
> 
>      y = (uint32_t)x * 9668 + 500 ;
>      if (y != 4225416L)
>      {
>        serialPuts ("Curruption @ ") ;
>       ...
>      }
>      ++i ;
> 
>    }
> 
> works fine with interrupts off, or with the math code in the interrupt 
> routine commented out, but sees random coruptions with them on:

[..]

> That's the first I've noticed int and I've not even dived into floating 
> point land yet...

This does not really come as a surprise:
The manual has a special section (3.9.1.4) Common interrupt pitfall
which specifically mentions 16 bit and 32 bit arithmetics...

> Any thoughts, anyone?

First thought would be not to use math code within interrupts:)
Second thought, if you just need a multiply within interrupt,
you could (taking multiply with 9668 (= 0x25c4) and add with 500 as example)
get to the intended y by:

   uint32_t xx = x;
   y = 500;
   xx <<= 2; // 0x0004
   y += xx;
   xx <<= 3; // 0x0040
   y += xx;
   xx <<= 1; // 0x0080
   y += xx;
   xx <<= 1; // 0x0100
   y += xx;
   xx <<= 2; // 0x0400
   ...

(bugs are mine, also check that the addition does not cause diving
into a nonreentrant function)

Greetings,
Frieder

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to