diff --git a/source/arm11/hardware/i2c.c b/source/arm11/hardware/i2c.c index 771c767..e9ceae1 100644 --- a/source/arm11/hardware/i2c.c +++ b/source/arm11/hardware/i2c.c @@ -19,7 +19,7 @@ #include "types.h" #include "mem_map.h" #include "arm11/hardware/i2c.h" -#include "arm11/spinlock.h" +#include "arm11/hardware/interrupt.h" #define I2C1_REGS_BASE (IO_MEM_ARM9_ARM11 + 0x61000) @@ -161,15 +161,14 @@ bool I2C_readRegBuf(I2cDevice devId, u8 regAddr, u8 *out, u32 size) { - static u32 lock; - spinlockLock(&lock); // TODO: Don't block interrupts. + const u32 oldState = enterCriticalSection(); // TODO: Don't block interrupts. const u8 busId = i2cDevTable[devId].busId; I2cRegs *const regs = i2cGetBusRegsBase(busId); if(!i2cStartTransfer(devId, regAddr, true, regs)) { - spinlockUnlock(&lock); + leaveCriticalSection(oldState); return false; } @@ -184,21 +183,20 @@ i2cWaitBusy(regs); *out = regs->REG_I2C_DATA; // Last byte - spinlockUnlock(&lock); + leaveCriticalSection(oldState); return true; } bool I2C_writeRegBuf(I2cDevice devId, u8 regAddr, const u8 *in, u32 size) { - static u32 lock; - spinlockLock(&lock); // TODO: Don't block interrupts. + const u32 oldState = enterCriticalSection(); // TODO: Don't block interrupts. const u8 busId = i2cDevTable[devId].busId; I2cRegs *const regs = i2cGetBusRegsBase(busId); if(!i2cStartTransfer(devId, regAddr, false, regs)) { - spinlockUnlock(&lock); + leaveCriticalSection(oldState); return false; } @@ -210,7 +208,7 @@ if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed. { regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP; - spinlockUnlock(&lock); + leaveCriticalSection(oldState); return false; } } @@ -221,11 +219,11 @@ if(!I2C_GET_ACK(regs->REG_I2C_CNT)) // If ack flag is 0 it failed. { regs->REG_I2C_CNT = I2C_ENABLE | I2C_IRQ_ENABLE | I2C_ERROR | I2C_STOP; - spinlockUnlock(&lock); + leaveCriticalSection(oldState); return false; } - spinlockUnlock(&lock); + leaveCriticalSection(oldState); return true; }