- while (time) {
-
- target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status);
-
- if (status & mg_io_rbit_status_busy)
- {
- if (wait == mg_io_wait_bsy)
- return ERROR_OK;
- } else {
- switch(wait)
- {
- case mg_io_wait_not_bsy:
- return ERROR_OK;
- case mg_io_wait_rdy_noerr:
- if (status & mg_io_rbit_status_ready)
- return ERROR_OK;
- break;
- case mg_io_wait_drq_noerr:
- if (status & mg_io_rbit_status_data_req)
- return ERROR_OK;
- break;
- default:
- break;
- }
-
- // Now we check the error condition!
- if (status & mg_io_rbit_status_error)
- {
- target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error);
-
- if (error & mg_io_rbit_err_bad_sect_num) {
- LOG_ERROR("sector not found");
- return ERROR_FAIL;
- }
- else if (error & (mg_io_rbit_err_bad_block | mg_io_rbit_err_uncorrectable)) {
- LOG_ERROR("bad block");
- return ERROR_FAIL;
- } else {
- LOG_ERROR("disk operation fail");
- return ERROR_FAIL;
- }
- }
-
- switch (wait)
- {
- case mg_io_wait_rdy:
- if (status & mg_io_rbit_status_ready)
- return ERROR_OK;
-
- case mg_io_wait_drq:
- if (status & mg_io_rbit_status_data_req)
- return ERROR_OK;
-
- default:
- break;
- }
- }
-
- duration_stop_measure(&duration, NULL);
-
- t=duration.duration.tv_usec/1000;
- t+=duration.duration.tv_sec*1000;
+ while (time) {
+
+ target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status);
+
+ if (status & mg_io_rbit_status_busy)
+ {
+ if (wait == mg_io_wait_bsy)
+ return ERROR_OK;
+ } else {
+ switch(wait)
+ {
+ case mg_io_wait_not_bsy:
+ return ERROR_OK;
+ case mg_io_wait_rdy_noerr:
+ if (status & mg_io_rbit_status_ready)
+ return ERROR_OK;
+ break;
+ case mg_io_wait_drq_noerr:
+ if (status & mg_io_rbit_status_data_req)
+ return ERROR_OK;
+ break;
+ default:
+ break;
+ }
+
+ /* Now we check the error condition! */
+ if (status & mg_io_rbit_status_error)
+ {
+ target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error);
+
+ if (error & mg_io_rbit_err_bad_sect_num) {
+ LOG_ERROR("sector not found");
+ return ERROR_FAIL;
+ }
+ else if (error & (mg_io_rbit_err_bad_block | mg_io_rbit_err_uncorrectable)) {
+ LOG_ERROR("bad block");
+ return ERROR_FAIL;
+ } else {
+ LOG_ERROR("disk operation fail");
+ return ERROR_FAIL;
+ }
+ }
+
+ switch (wait)
+ {
+ case mg_io_wait_rdy:
+ if (status & mg_io_rbit_status_ready)
+ return ERROR_OK;
+
+ case mg_io_wait_drq:
+ if (status & mg_io_rbit_status_data_req)
+ return ERROR_OK;
+
+ default:
+ break;
+ }
+ }
+
+ duration_stop_measure(&duration, NULL);
+
+ t=duration.duration.tv_usec/1000;
+ t+=duration.duration.tv_sec*1000;