Hello,
Firstly, with the use of a fast SPI clock, there would be little point in attemptiing to use SPI interrupts because the cycle overheads associated with the entry to, and exit from the ISR will be greater than the byte transmission cycles of the SPI. For these clock rates, it is more efficient to use polling.
The polling loops used, whilst waiting for a flag to become set, have a five cycle period. For a 16 cycle byte transmission period, this would mean that the polling loop would repeat four times, for a total of 20 cycles. There would be a small saving of maybe 3 or 4 cycles with the inclusion of one or two NOP instructions prior to the polling loop, so that the loop would repeat only three times, instead of four.
I have my doubts about using double buffering capability for a SPI master (it is of more use for a slave application). If you are sending N bytes in succession, the transmission time for all bytes will always be 16*N. Any differences in the total period will depend on the overhead required between each byte.
In usual circumstances, a SPI transmission is a bi-directional process, and the aim of the code is to prevent receive overrun, and subsequent loss of receive data. To achieve this, the SPRF flag must be polled and cleared after each byte. If this is done, timing is non-critical and interrupts occurring during code execution will not be a problem - they will simply delay the completion of code execution in the usual manner.
Once you choose to use the double buffering capability by polling the SPTEF flag instead, the timing becomes critical to prevent a receive overrun condition, and interrupts would usually be globally disabled to alleviate timing problems. In this case, if it is not permissible to disable interrupts, it is not permissible to use double buffering, especially for very high SPI clock frequencies.
For the SD card case, where you appear to have no interest in the returned data, even though receive overrun is not an issue, interrupts can still play havoc because when you eventually clear the SPRF flag preparatory to detecting the completion of the final byte, there is the uncertainty that you have described. Since you cannot disable interrupts for your application, the uncertainty seems only to be eliminated by clearing the SPRF flag at the conclusion of each byte. If this is done, the status of the SPTEF flag is unimportant (since the flag will always be set when SPRF becomes set). The timing penalty would appear to be an additional four cycles between each byte, for the purpose of clearing the SPRF flag.
SPITXB: MOV X+,SPID ;(5) SEND DATA. NOP ;(1) BRCLR SPRF,SPIS,* ;(5*N) WAIT FOR SEND COMPLETE TST SPID ;(4) CLEAR FLAG DBNZA SPITXB ;(4) LOOP FOR ACC BYTES RTS
Regards,
Mac