> > But if interrupt latency is an issue, you can use a different > > method: have the ISR put the 32-bit integer into a temporary > > holding register and set a flag bit somewhere to indicate to the > > main code that a new integer value is available. The main code > > can test the flag and when a new value is available, transfer it > > to the working variable and then reset the flag. The ISR, in > > turn, refrains from updating the holding register unless the flag > > has been cleared by the main code. > I have thought of that, but as there is no instruction to test-and-clear a > variable in a single cycle a racing-condition could occur. Perhaps a > combination of both solutions to keep the disable-interrupt-period as short > as possible. As described it's faily safe as the ISR writes the flag but never resets it. The "main" task will never inspect the data until it is definitely ready. Also the main task will never clear the flag until after it is read. The "semaphore" flag is sepearted in time by the reading andwriting of 4 bytes. If you want a more conventional semaphore then you should be able to overcome the lack of an "indivisible instruction" by a multiple read of the semaphore flag as follows - Main task sees the interupts resource_in_use flag is free, sets its own "I am using the resource" flag THEN reads the interupt's resource_in_use flag for a secind time. IF the interupt has crept in and stolen the resource between the time that the main task saw it was free and then set it's in use flag then the second time around it will find the interupt's flag is set. It then de-asserts it's own flag and tries again. Main task: ; own flag is cleared at this point Do while irq flag is set Clear own flag ; for loop back condition Do while irq flag is set ; second test catchers the irq stealing scenario mumble End Assert own flag End ; stolen resource is detected here - loop back if stolen do task clear own flag ____________ Interupt: Do while main_task flag is set Something else End Set irq flag Do task Clear irq flag. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body