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

@ -1100,7 +1100,7 @@ static void PacketReceived(PacketCommandNG *packet) {
strncat(at, s_at, sizeof(at) - strlen(at) - 1); strncat(at, s_at, sizeof(at) - strlen(at) - 1);
DbpString("Try AT baud rate setting"); DbpString("Try AT baud rate setting");
usart_init(); usart_init();
int16_t res = usart_writebuffer((uint8_t*)&at, sizeof(at)); int16_t res = usart_writebuffer_sync((uint8_t*)&at, sizeof(at));
WaitMS(1); WaitMS(1);
Dbprintf("SEND %d | %c%c%c%c%c%c%c%c%c%c%c", res, at[0], at[1], at[2], at[3], at[4], at[5], at[6], at[7], at[8], at[9], at[10]); Dbprintf("SEND %d | %c%c%c%c%c%c%c%c%c%c%c", res, at[0], at[1], at[2], at[3], at[4], at[5], at[6], at[7], at[8], at[9], at[10]);
@ -1122,7 +1122,7 @@ static void PacketReceived(PacketCommandNG *packet) {
} }
static const char *welcome = "Proxmark3 Serial interface via FPC ready\r\n"; static const char *welcome = "Proxmark3 Serial interface via FPC ready\r\n";
usart_writebuffer((uint8_t *)welcome, strlen(welcome)); usart_writebuffer_sync((uint8_t *)welcome, strlen(welcome));
sprintf(dest, "| bytes 0x%02x 0x%02x 0x%02x 0x%02x\r\n" sprintf(dest, "| bytes 0x%02x 0x%02x 0x%02x 0x%02x\r\n"
, packet->data.asBytes[0] , packet->data.asBytes[0]
@ -1130,7 +1130,7 @@ static void PacketReceived(PacketCommandNG *packet) {
, packet->data.asBytes[2] , packet->data.asBytes[2]
, packet->data.asBytes[3] , packet->data.asBytes[3]
); );
usart_writebuffer((uint8_t *)dest, strlen(dest)); usart_writebuffer_sync((uint8_t *)dest, strlen(dest));
LED_A_ON(); LED_A_ON();

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) { if (reply_via_fpc) {
#ifdef WITH_FPC_HOST #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); // Dbprintf_usb("Sent %i bytes over usart", len);
#else #else
return PM3_EDEVNOTSUPP; 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) { if (reply_via_fpc) {
#ifdef WITH_FPC_HOST #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); // Dbprintf_usb("Sent %i bytes over usart", len);
#else #else
return PM3_EDEVNOTSUPP; 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 // 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 // Wait for current PDC bank to be free
while (pUS1->US_TCR && pUS1->US_TNCR) {}; // (and check next bank too, in case there will be a usart_writebuffer_async)
while (pUS1->US_TNCR || pUS1->US_TCR) {};
// Check if the current PDC bank is free pUS1->US_TPR = (uint32_t)data;
if (pUS1->US_TCR == 0) { pUS1->US_TCR = len;
pUS1->US_TPR = (uint32_t)data; // Wait until finishing all transfers to make sure "data" buffer can be discarded
pUS1->US_TCR = len; // (if we don't wait here, bulk send as e.g. "hw status" will fail)
}
// 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
while (pUS1->US_TNCR || pUS1->US_TCR) {}; while (pUS1->US_TNCR || pUS1->US_TCR) {};
return len; return len;
} }