@@ -4802,31 +4802,19 @@ static int write_memory_bus_v1(struct target *target, target_addr_t address,
48024802
48034803 /* Execute the batch of writes */
48044804 result = batch_run (target , batch );
4805- riscv_batch_free ( batch );
4806- if ( result != ERROR_OK )
4805+ if ( result != ERROR_OK ) {
4806+ riscv_batch_free ( batch );
48074807 return result ;
4808+ }
48084809
4809- /* Read sbcs value.
4810- * At the same time, detect if DMI busy has occurred during the batch write. */
4811- bool dmi_busy_encountered ;
4812- if (dm_op (target , & sbcs , & dmi_busy_encountered , DMI_OP_READ ,
4813- DM_SBCS , 0 , false, true) != ERROR_OK )
4814- return ERROR_FAIL ;
4810+ bool dmi_busy_encountered = riscv_batch_was_batch_busy (batch );
4811+ riscv_batch_free (batch );
48154812 if (dmi_busy_encountered )
48164813 LOG_TARGET_DEBUG (target , "DMI busy encountered during system bus write." );
48174814
4818- /* Wait until sbbusy goes low */
4819- time_t start = time (NULL );
4820- while (get_field (sbcs , DM_SBCS_SBBUSY )) {
4821- if (time (NULL ) - start > riscv_command_timeout_sec ) {
4822- LOG_TARGET_ERROR (target , "Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
4823- "Increase the timeout with riscv set_command_timeout_sec." ,
4824- riscv_command_timeout_sec , sbcs );
4825- return ERROR_FAIL ;
4826- }
4827- if (dm_read (target , & sbcs , DM_SBCS ) != ERROR_OK )
4828- return ERROR_FAIL ;
4829- }
4815+ result = read_sbcs_nonbusy (target , & sbcs );
4816+ if (result != ERROR_OK )
4817+ return result ;
48304818
48314819 if (get_field (sbcs , DM_SBCS_SBBUSYERROR )) {
48324820 /* We wrote while the target was busy. */
0 commit comments