Hi,
El Mon, Oct 27, 2008 at 04:44:17PM +0100 Leon Ljunggren ha dit:
> Hi,
> I working on a driver for a embedded system running Linux 2.6.20.3 and
> I'm having a bit of problem getting spin_lock to work as I'd expect it
> to.
>
> The driver reads from an AVR and before it does that one need do a
> write to tell it were to read is to take place. The problem is that I
> have a interupt function that will also perform such a read and if it
> interupts the user induced read after i2c_write but before i2c_read it
> can cause the read to happen in the wrong place.
>
> To ensure that this doesn't happen I'm trying to use
> spin_lock_irqsave, but I'm getting rather unexpected results. First of
> all it doesn't seem to disable the interupt, the interupt function is
> still called and secondly it just seems to ignore the lock. Even if
> avr_read has aquired lock2 and then gets interupted (which it
> shouldn't since interupts should be disabled, right?) avr_interupt
> will not care and still call the write/read functions instead of
> blocking as expected.
>
> Any pointers to what I might be doing wrong?
>
> Thanks
> /Leon Ljunggren
>
> ----- pseudo code ----
>
> spinlock_t lock1 = SPIN_LOCK_UNLOCKED;
> spinlock_t lock2 = SPIN_LOCK_UNLOCKED;
>
> i2c_read()
> {
> spin_lock_irqsave(&lock1, lock1_flag);
> ...
> spin_unlock_irqrestore(&lock2, lock2_flag);
> }
>
> i2c_write()
> {
> spin_lock_irqsave(&lock1, lock1_flag);
> ...
> spin_unlock_irqrestore(&lock2, lock2_flag);
> }
>
>
> i2c_irq_read()
> {
> spin_lock_irqsave(&lock1, lock1_flag);
> ...
> spin_unlock_irqrestore(&lock2, lock2_flag);
> }
>
> i2c_irq_write()
> {
> spin_lock_irqsave(&lock1, lock1_flag);
> ...
> spin_unlock_irqrestore(&lock2, lock2_flag);
> }
i there any special reason why you acquire lock1 but release lock2
('restoring' lock2_flags) in these functions? doesn't look good to me
--
Matthias Kaehlcke
Embedded Linux Engineer
Barcelona
La posibilidad de realizar un suenyo es lo
que hace que la vida sea interesante
.''`.
using free software / Debian GNU/Linux | http://debian.org : :' :
`. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4 `-
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ