From 39224664865222dcd46a39aa4a70d65e4b412d8e Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Thu, 16 May 2002 21:28:21 +0000 Subject: Added mutex protection git-svn-id: svn://svn.rockbox.org/rockbox/trunk@608 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/ata.c | 80 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 11 deletions(-) (limited to 'firmware/drivers/ata.c') diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index 0e0c48833c..716af74ae2 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -54,6 +54,8 @@ #define CMD_SLEEP 0xE6 #define CMD_SECURITY_FREEZE_LOCK 0xF5 +struct mutex ata_mtx; + static int wait_for_bsy(void) { int timeout = current_tick + HZ*4; @@ -96,9 +98,15 @@ int ata_read_sectors(unsigned long start, void* buf) { int i; + int ret = 0; + mutex_lock(&ata_mtx); + if (!wait_for_rdy()) + { + mutex_unlock(&ata_mtx); return -1; + } led(true); @@ -112,7 +120,10 @@ int ata_read_sectors(unsigned long start, for (i=0; i 255) + { + mutex_unlock(&ata_mtx); return -1; + } ATA_NSECTOR = time & 0xff; ATA_COMMAND = CMD_STANDBY; } if (!wait_for_rdy()) - return -1; + ret = -1; - return 0; + mutex_unlock(&ata_mtx); + return ret; } int ata_hard_reset(void) { + int ret; + + mutex_lock(&ata_mtx); + PADR &= ~0x0002; sleep(2); PADR |= 0x0002; - return wait_for_rdy(); + ret = wait_for_rdy(); + + mutex_unlock(&ata_mtx); + return ret; } int ata_soft_reset(void) { + int ret; + + mutex_lock(&ata_mtx); + ATA_SELECT = SELECT_LBA; ATA_CONTROL = CONTROL_nIEN|CONTROL_SRST; sleep(HZ/20000); /* >= 5us */ @@ -243,11 +296,16 @@ int ata_soft_reset(void) ATA_CONTROL = CONTROL_nIEN; sleep(HZ/400); /* >2ms */ - return wait_for_rdy(); + ret = wait_for_rdy(); + + mutex_unlock(&ata_mtx); + return ret; } int ata_init(void) { + mutex_init(&ata_mtx); + led(false); /* activate ATA */ -- cgit v1.2.3