@@ -229,6 +229,7 @@ static uint16_t dap_swj_pins(struct dap_context *const ctx,
229229 uint8_t value = request [0 ];
230230 uint8_t select = request [1 ];
231231 uint32_t wait = sys_get_le32 (& request [2 ]);
232+ int64_t timeout_ticks ;
232233 uint8_t state ;
233234
234235 if (!atomic_test_bit (& ctx -> state , DAP_STATE_CONNECTED )) {
@@ -242,10 +243,17 @@ static uint16_t dap_swj_pins(struct dap_context *const ctx,
242243 api -> swdp_set_pins (ctx -> swdp_dev , select , value );
243244 }
244245
245- /* TODO: implement wait */
246- api -> swdp_get_pins (ctx -> swdp_dev , & state );
247- LOG_ERR ("select 0x%02x, value 0x%02x, wait %u, state 0x%02x" ,
248- select , value , wait , state );
246+ timeout_ticks = k_uptime_ticks () + (CONFIG_SYS_CLOCK_TICKS_PER_SEC / 1000000 * wait );
247+
248+ do {
249+ api -> swdp_get_pins (ctx -> swdp_dev , & state );
250+ LOG_INF ("select 0x%02x, value 0x%02x, wait %u, state 0x%02x" ,
251+ select , value , wait , state );
252+ if ((value & select ) == (state & select )) {
253+ LOG_DBG ("swdp_get_pins succeeded before timeout" );
254+ break ;
255+ }
256+ } while (k_uptime_ticks () - timeout_ticks > 0 );
249257
250258 response [0 ] = state ;
251259
0 commit comments