diff options
-rw-r--r-- | firmware/drivers/ata.c | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index 4f4fb4c9b3..397cb9ac82 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c | |||
@@ -179,23 +179,22 @@ static int perform_soft_reset(void); | |||
179 | static int set_multiple_mode(int sectors); | 179 | static int set_multiple_mode(int sectors); |
180 | static int set_features(void); | 180 | static int set_features(void); |
181 | 181 | ||
182 | STATICIRAM int wait_for_bsy(void) ICODE_ATTR; | 182 | STATICIRAM ICODE_ATTR int wait_for_bsy(void) |
183 | STATICIRAM int wait_for_bsy(void) | ||
184 | { | 183 | { |
185 | long timeout = current_tick + HZ*30; | 184 | long timeout = current_tick + HZ*30; |
186 | while (TIME_BEFORE(current_tick, timeout) && (ATA_STATUS & STATUS_BSY)) { | 185 | |
186 | do | ||
187 | { | ||
188 | if (!(ATA_STATUS & STATUS_BSY)) | ||
189 | return 1; | ||
187 | last_disk_activity = current_tick; | 190 | last_disk_activity = current_tick; |
188 | yield(); | 191 | yield(); |
189 | } | 192 | } while (TIME_BEFORE(current_tick, timeout)); |
190 | 193 | ||
191 | if (TIME_BEFORE(current_tick, timeout)) | 194 | return 0; /* timeout */ |
192 | return 1; | ||
193 | else | ||
194 | return 0; /* timeout */ | ||
195 | } | 195 | } |
196 | 196 | ||
197 | STATICIRAM int wait_for_rdy(void) ICODE_ATTR; | 197 | STATICIRAM ICODE_ATTR int wait_for_rdy(void) |
198 | STATICIRAM int wait_for_rdy(void) | ||
199 | { | 198 | { |
200 | long timeout; | 199 | long timeout; |
201 | 200 | ||
@@ -203,21 +202,19 @@ STATICIRAM int wait_for_rdy(void) | |||
203 | return 0; | 202 | return 0; |
204 | 203 | ||
205 | timeout = current_tick + HZ*10; | 204 | timeout = current_tick + HZ*10; |
206 | 205 | ||
207 | while (TIME_BEFORE(current_tick, timeout) && | 206 | do |
208 | !(ATA_ALT_STATUS & STATUS_RDY)) { | 207 | { |
208 | if (ATA_ALT_STATUS & STATUS_RDY) | ||
209 | return 1; | ||
209 | last_disk_activity = current_tick; | 210 | last_disk_activity = current_tick; |
210 | yield(); | 211 | yield(); |
211 | } | 212 | } while (TIME_BEFORE(current_tick, timeout)); |
212 | 213 | ||
213 | if (TIME_BEFORE(current_tick, timeout)) | 214 | return 0; /* timeout */ |
214 | return STATUS_RDY; | ||
215 | else | ||
216 | return 0; /* timeout */ | ||
217 | } | 215 | } |
218 | 216 | ||
219 | STATICIRAM int wait_for_start_of_transfer(void) ICODE_ATTR; | 217 | STATICIRAM ICODE_ATTR int wait_for_start_of_transfer(void) |
220 | STATICIRAM int wait_for_start_of_transfer(void) | ||
221 | { | 218 | { |
222 | if (!wait_for_bsy()) | 219 | if (!wait_for_bsy()) |
223 | return 0; | 220 | return 0; |
@@ -225,8 +222,7 @@ STATICIRAM int wait_for_start_of_transfer(void) | |||
225 | return (ATA_ALT_STATUS & (STATUS_BSY|STATUS_DRQ)) == STATUS_DRQ; | 222 | return (ATA_ALT_STATUS & (STATUS_BSY|STATUS_DRQ)) == STATUS_DRQ; |
226 | } | 223 | } |
227 | 224 | ||
228 | STATICIRAM int wait_for_end_of_transfer(void) ICODE_ATTR; | 225 | STATICIRAM ICODE_ATTR int wait_for_end_of_transfer(void) |
229 | STATICIRAM int wait_for_end_of_transfer(void) | ||
230 | { | 226 | { |
231 | if (!wait_for_bsy()) | 227 | if (!wait_for_bsy()) |
232 | return 0; | 228 | return 0; |
@@ -247,8 +243,7 @@ static void ata_led(bool on) | |||
247 | #endif | 243 | #endif |
248 | 244 | ||
249 | #ifndef ATA_OPTIMIZED_READING | 245 | #ifndef ATA_OPTIMIZED_READING |
250 | STATICIRAM void copy_read_sectors(unsigned char* buf, int wordcount) ICODE_ATTR; | 246 | STATICIRAM ICODE_ATTR void copy_read_sectors(unsigned char* buf, int wordcount) |
251 | STATICIRAM void copy_read_sectors(unsigned char* buf, int wordcount) | ||
252 | { | 247 | { |
253 | unsigned short tmp = 0; | 248 | unsigned short tmp = 0; |
254 | 249 | ||
@@ -456,9 +451,8 @@ int ata_read_sectors(IF_MV2(int drive,) | |||
456 | } | 451 | } |
457 | 452 | ||
458 | #ifndef ATA_OPTIMIZED_WRITING | 453 | #ifndef ATA_OPTIMIZED_WRITING |
459 | STATICIRAM void copy_write_sectors(const unsigned char* buf, int wordcount) | 454 | STATICIRAM ICODE_ATTR void copy_write_sectors(const unsigned char* buf, |
460 | ICODE_ATTR; | 455 | int wordcount) |
461 | STATICIRAM void copy_write_sectors(const unsigned char* buf, int wordcount) | ||
462 | { | 456 | { |
463 | if ( (unsigned long)buf & 1) | 457 | if ( (unsigned long)buf & 1) |
464 | { /* not 16-bit aligned, copy byte by byte */ | 458 | { /* not 16-bit aligned, copy byte by byte */ |