mirror of
https://github.com/esp-rs/esp-idf-hal.git
synced 2025-10-02 14:44:51 +00:00
Workaround for a problem where pushing to the queue might fail
This commit is contained in:
parent
a2b95b85f2
commit
ac8aff796b
31
src/spi.rs
31
src/spi.rs
@ -2059,10 +2059,9 @@ async fn spi_transmit_async(
|
|||||||
|
|
||||||
let last = queue.back_mut().unwrap();
|
let last = queue.back_mut().unwrap();
|
||||||
last.0.user = &last.1 as *const _ as *mut _;
|
last.0.user = &last.1 as *const _ as *mut _;
|
||||||
match esp!(unsafe { spi_device_queue_trans(handle, &mut last.0, delay::NON_BLOCK) }) {
|
match esp!(unsafe { spi_device_queue_trans(handle, &mut last.0, delay::BLOCK) }) {
|
||||||
Err(e) if e.code() == ESP_ERR_TIMEOUT => Ok(false),
|
Err(e) if e.code() == ESP_ERR_TIMEOUT => unreachable!(),
|
||||||
Err(e) => Err(e)?,
|
other => other,
|
||||||
Ok(()) => Ok(true),
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2087,27 +2086,23 @@ async fn spi_transmit_async(
|
|||||||
};
|
};
|
||||||
|
|
||||||
for transaction in transactions {
|
for transaction in transactions {
|
||||||
if queue.len() == queue_size {
|
while queue.len() == queue_size {
|
||||||
loop {
|
if pop(queue)? {
|
||||||
// If the queue is full, we wait for the first transaction in the queue
|
break;
|
||||||
queue.front_mut().unwrap().1.wait().await;
|
|
||||||
if pop(queue)? {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the queue is full, we wait for the first transaction in the queue
|
||||||
|
queue.front_mut().unwrap().1.wait().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write transaction to a stable memory location
|
// Write transaction to a stable memory location
|
||||||
if !push(queue, transaction)? {
|
push(queue, transaction)?;
|
||||||
// There must be a place in the queue, which we asserted above,
|
|
||||||
// so this should never happen
|
|
||||||
unreachable!();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while !queue.is_empty() {
|
while !queue.is_empty() {
|
||||||
queue.front_mut().unwrap().1.wait().await;
|
if !pop(queue)? {
|
||||||
pop(queue)?;
|
queue.front_mut().unwrap().1.wait().await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user