Re: Digest from [email protected]
Bryan Kattwinkel <[email protected]> Mon, 21 Jul 2008 08:35:17 -0400
| Newsgroups | gmane.comp.hardware.motorola.microcontrollers.coldfire |
|---|---|
| Message-ID | <[email protected]> |
Phil Roets wrote:
> I am developing a multitask application on a MFC5282 board and intended to create a semaphore type
> method to control access to some of the common variables. Replacing
the 'tst.b' with 'tas.b' in the
> snippet :
> move.l 4(%sp),%a0
> move.l #128,%d0
> tas.b (%a0)
> jbne .L4
> move.b #-128,(%a0)
> clr.b %d0
> ..L4:
> rts
> causes a 'invalid instruction for the architecture ...
Because the 5282 does not have that instruction. (tas is ISA-B, 5282 is
ISA-A+).
Use bset, which sets 1 bit (by number, not mask!) and sets the z flag to
the *previous* value of the bit:
clr.l D0 /* bit 0 */
bset.b D0,(A0) /* set one bit atomically */
sne D0 /* previous state */
rts
If you need a counting semaphore, you can add/subtract to a long word of
memory atomically (in this case the flags represent the state at the end
of the operation).
These operations generally have to be written in assembly; typical C
compilers will not generate the atomic-memory forms [destination (a0)].
They are atomic with respect to the single 5282 processor; tas would
only be needed with multiple CPUs, which I don't think you can do with
that chip.
---
[email protected] Send a post to the list.
[email protected] Join the list.
[email protected] Join the list in digest mode.
[email protected] Leave the list.