usart_writebuffer_sync simplified as we're always sending in blocking mode anyway

This commit is contained in:
Philippe Teuwen 2019-04-22 00:30:01 +02:00
commit cdd4177968
3 changed files with 13 additions and 23 deletions

View file

@ -72,7 +72,7 @@ int16_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, voi
if (reply_via_fpc) {
#ifdef WITH_FPC_HOST
sendlen = usart_writebuffer((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
sendlen = usart_writebuffer_sync((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
// Dbprintf_usb("Sent %i bytes over usart", len);
#else
return PM3_EDEVNOTSUPP;
@ -124,7 +124,7 @@ static int16_t reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, si
if (reply_via_fpc) {
#ifdef WITH_FPC_HOST
sendlen = usart_writebuffer((uint8_t *)&txBufferNG, txBufferNGLen);
sendlen = usart_writebuffer_sync((uint8_t *)&txBufferNG, txBufferNGLen);
// Dbprintf_usb("Sent %i bytes over usart", len);
#else
return PM3_EDEVNOTSUPP;

View file

@ -129,25 +129,15 @@ uint32_t usart_read_ng(uint8_t *data, size_t len) {
}
// transfer from device to client
inline int16_t usart_writebuffer(uint8_t *data, size_t len) {
inline int16_t usart_writebuffer_sync(uint8_t *data, size_t len) {
// Wait for one free PDC bank
while (pUS1->US_TCR && pUS1->US_TNCR) {};
// Check if the current PDC bank is free
if (pUS1->US_TCR == 0) {
pUS1->US_TPR = (uint32_t)data;
pUS1->US_TCR = len;
}
// Check if the backup PDC bank is free
else if (pUS1->US_TNCR == 0) {
pUS1->US_TNPR = (uint32_t)data;
pUS1->US_TNCR = len;
} else {
// we shouldn't be here
return 0;
}
//wait until finishing all transfers
// Wait for current PDC bank to be free
// (and check next bank too, in case there will be a usart_writebuffer_async)
while (pUS1->US_TNCR || pUS1->US_TCR) {};
pUS1->US_TPR = (uint32_t)data;
pUS1->US_TCR = len;
// Wait until finishing all transfers to make sure "data" buffer can be discarded
// (if we don't wait here, bulk send as e.g. "hw status" will fail)
while (pUS1->US_TNCR || pUS1->US_TCR) {};
return len;
}