@@ -158,9 +158,9 @@ impl Qspi {
158158 } ) ;
159159 }
160160
161- /// Checks for QSPI timeout and transfer bits, and resets the interrupts
162- /// if all is fine .
163- fn check_qspi_errors ( & self ) -> Result < ( ) , QspiError > {
161+ /// Returns the number of valid bytes being held in the FIFO queue if a
162+ /// QSPI timeout or transfer error hasn't occurred .
163+ fn get_fifo_level ( & self ) -> Result < usize , QspiError > {
164164 let sr = self . reg . sr . read ( ) ;
165165
166166 // Check timeout bit.
@@ -180,7 +180,7 @@ impl Qspi {
180180 self . reg
181181 . cr
182182 . modify ( |_, w| w. teie ( ) . set_bit ( ) . toie ( ) . set_bit ( ) ) ;
183- Ok ( ( ) )
183+ Ok ( usize :: from ( sr . flevel ( ) . bits ( ) ) )
184184 }
185185
186186 /// Wait for the Transfer Complete flag to get set.
@@ -260,10 +260,9 @@ impl Qspi {
260260 let mut data = data;
261261 while !data. is_empty ( ) {
262262 // Check for any errors
263- self . check_qspi_errors ( ) ?;
263+ let fl = self . get_fifo_level ( ) ?;
264264
265265 // How much space is in the FIFO?
266- let fl = usize:: from ( sr. flevel ( ) . bits ( ) ) ;
267266 let ffree = FIFO_SIZE - fl;
268267 if ffree >= FIFO_THRESH . min ( data. len ( ) ) {
269268 // Calculate the write size. Note that this may be bigger than
@@ -366,11 +365,10 @@ impl Qspi {
366365 // perform transfers.
367366 let mut out = out;
368367 while !out. is_empty ( ) {
369- // Check for any errors
370- self . check_qspi_errors ( ) ?;
368+ // Get the FIFO level if no errors have occurred.
369+ let fl = self . get_fifo_level ( ) ?;
371370
372371 // Is there enough to read that we want to bother with it?
373- let fl = usize:: from ( sr. flevel ( ) . bits ( ) ) ;
374372 if fl < FIFO_THRESH . min ( out. len ( ) ) {
375373 // Nope! Let's wait for more bytes.
376374
0 commit comments