diff --git a/armsrc/appmain.c b/armsrc/appmain.c index fd0d4cafc..223bd2155 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1136,7 +1136,7 @@ void UsbPacketReceived(uint8_t *packet, int len) { uint8_t my_rx[sizeof(UsbCommand)]; while (!BUTTON_PRESS() && !usb_poll_validate_length()) { LED_B_INV(); - if (usart_readbuffer(my_rx, sizeof(UsbCommand)) ) { + if (usart_readbuffer(my_rx) ) { //UsbPacketReceived(my_rx, sizeof(my_rx)); UsbCommand *my = (UsbCommand *)my_rx; @@ -1565,10 +1565,11 @@ void __attribute__((noreturn)) AppMain(void) { } #ifdef WITH_FPC_HOST // Check if there is a FPC packet available - if (usart_readcommand(rx) > 0) { + if (usart_readbuffer(rx)) { reply_via_fpc = 1; UsbPacketReceived(rx, sizeof(rx)); } + usart_readcheck(rx, sizeof(rx)); #endif // Press button for one second to enter a possible standalone mode diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index b70bad2e4..2474d7026 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -449,6 +449,9 @@ void FpgaWriteConfWord(uint8_t v) { // the samples from the ADC always flow through the FPGA. //----------------------------------------------------------------------------- void SetAdcMuxFor(uint32_t whichGpio) { + +#ifndef WITH_FPC + // When compiled without FPC support AT91C_BASE_PIOA->PIO_OER = GPIO_MUXSEL_HIPKD | GPIO_MUXSEL_LOPKD | @@ -463,9 +466,15 @@ void SetAdcMuxFor(uint32_t whichGpio) { LOW(GPIO_MUXSEL_HIPKD); LOW(GPIO_MUXSEL_LOPKD); -#ifndef WITH_FPC LOW(GPIO_MUXSEL_HIRAW); LOW(GPIO_MUXSEL_LORAW); + +#else + // FPC serial uses HIRAW/LOWRAW pins, so they are excluded here. + AT91C_BASE_PIOA->PIO_OER = GPIO_MUXSEL_HIPKD | GPIO_MUXSEL_LOPKD; + AT91C_BASE_PIOA->PIO_PER = GPIO_MUXSEL_HIPKD | GPIO_MUXSEL_LOPKD; + LOW(GPIO_MUXSEL_HIPKD); + LOW(GPIO_MUXSEL_LOPKD); #endif HIGH(whichGpio); diff --git a/client/cmddata.c b/client/cmddata.c index 0112565a7..1a38fc00f 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -1314,12 +1314,12 @@ static int CmdRawDemod(const char *Cmd) { str_lower((char *)Cmd); - if (str_startswith(Cmd, "fs")) ans = CmdFSKrawdemod(Cmd + 2); + if (str_startswith(Cmd, "fs") || Cmd[0] == 'f' ) ans = CmdFSKrawdemod(Cmd+2); else if (str_startswith(Cmd, "ab")) ans = Cmdaskbiphdemod(Cmd + 2); else if (str_startswith(Cmd, "am")) ans = Cmdaskmandemod(Cmd + 2); else if (str_startswith(Cmd, "ar")) ans = Cmdaskrawdemod(Cmd + 2); - else if (str_startswith(Cmd, "nr")) ans = CmdNRZrawDemod(Cmd + 2); - else if (str_startswith(Cmd, "p1")) ans = CmdPSK1rawDemod(Cmd + 2); + else if (str_startswith(Cmd, "nr") || Cmd[0] == 'n') ans = CmdNRZrawDemod(Cmd+2); + else if (str_startswith(Cmd, "p1") || Cmd[0] == 'p') ans = CmdPSK1rawDemod(Cmd + 2); else if (str_startswith(Cmd, "p2")) ans = CmdPSK2rawDemod(Cmd + 2); else PrintAndLogEx(WARNING, "Unknown modulation entered - see help ('h') for parameter structure"); diff --git a/client/cmdlf.c b/client/cmdlf.c index 9dfa16640..3243d60af 100644 --- a/client/cmdlf.c +++ b/client/cmdlf.c @@ -189,9 +189,6 @@ int CmdLFCommandRead(const char *Cmd) { int CmdFlexdemod(const char *Cmd) { (void)Cmd; // Cmd is not used so far - if (GraphTraceLen < 0) - return 0; - #ifndef LONG_WAIT #define LONG_WAIT 100 #endif diff --git a/client/proxguiqt.cpp b/client/proxguiqt.cpp index 2cf2d0200..e2ef546f6 100644 --- a/client/proxguiqt.cpp +++ b/client/proxguiqt.cpp @@ -276,9 +276,11 @@ QColor Plot::getColor(int graphNum) { void Plot::setMaxAndStart(int *buffer, size_t len, QRect plotRect) { if (len == 0) return; - startMax = (len - (int)((plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint)); - if (startMax < 0) { - startMax = 0; + startMax = 0; + if (plotRect.right() >= plotRect.left() + 40) { + uint32_t t = (plotRect.right() - plotRect.left() - 40) / GraphPixelsPerPoint; + if (len >= t) + startMax = len - t; } if (GraphStart > startMax) { GraphStart = startMax; @@ -470,9 +472,6 @@ void Plot::paintEvent(QPaintEvent *event) { painter.setFont(QFont("Courier New", 10)); - if (GraphStart < 0) - GraphStart = 0; - if (CursorAPos > GraphTraceLen) CursorAPos = 0; if (CursorBPos > GraphTraceLen) diff --git a/client/proxmark3.c b/client/proxmark3.c index 600d975e3..ffb8b295f 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -364,8 +364,13 @@ int main(int argc, char *argv[]) { } } + // default speed for USB 460800, USART(FPC serial) 115200 baud if (speed == 0) +#ifdef WITH_FPC + speed = 115200; +#else speed = 460800; +#endif // If the user passed the filename of the 'script' to execute, get it from last parameter if (lastarg) { diff --git a/common/usart.c b/common/usart.c index 8680d500a..cd657a2b1 100644 --- a/common/usart.c +++ b/common/usart.c @@ -42,7 +42,7 @@ void usart_close(void) { static uint8_t us_inbuf[sizeof(UsbCommand)]; static uint8_t us_outbuf[sizeof(UsbCommand)]; - +/* // transfer from client to device inline int16_t usart_readbuffer(uint8_t *data) { uint32_t rcr = pUS1->US_RCR; @@ -58,6 +58,38 @@ inline int16_t usart_readbuffer(uint8_t *data) { return 0; } } +*/ + +uint8_t check = 0; +inline int16_t usart_readbuffer(uint8_t *data) { + // Check if the first PDC bank is free + if (pUS1->US_RCR == 0) { + pUS1->US_RPR = (uint32_t)data; + pUS1->US_RCR = sizeof(UsbCommand); + pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN; + check = 0; + return 2; + } else { + return 0; + } +} + +void usart_readcheck(uint8_t *data,size_t len) { + if (pUS1->US_RCR 300000){ + pUS1->US_RPR = (uint32_t)data; + pUS1->US_RCR = len; + check = 0; + } + } else { + check = 0; + } +} inline bool usart_dataavailable(void) { return pUS1->US_RCR < sizeof(us_inbuf); @@ -66,14 +98,14 @@ inline bool usart_dataavailable(void) { inline int16_t usart_readcommand(uint8_t *data) { if (pUS1->US_RCR == 0) return usart_readbuffer(data); - else + return 0; } inline bool usart_commandavailable(void) { - return pUS1->US_RCR == 0; + return (pUS1->US_RCR == 0); } - +/* // transfer from device to client inline int16_t usart_writebuffer(uint8_t *data, size_t len) { @@ -90,6 +122,31 @@ inline int16_t usart_writebuffer(uint8_t *data, size_t len) { return 0; } } +*/ + +// transfer from device to client +inline int16_t usart_writebuffer(uint8_t *data, size_t len) { + + while (pUS1->US_TCR && pUS1->US_TNCR) {}; + + // Check if the first PDC bank is free + if (pUS1->US_TCR == 0) { + memcpy(us_outbuf, data, len); + pUS1->US_TPR = (uint32_t)us_outbuf; + pUS1->US_TCR = sizeof(us_outbuf); + pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; + } + // Check if the second PDC bank is free + else if (pUS1->US_TNCR == 0) { + memcpy(us_outbuf, data, len); + pUS1->US_TNPR = (uint32_t)us_outbuf; + pUS1->US_TNCR = sizeof(us_outbuf); + pUS1->US_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN; + } + //wait until finishing transfer + while (pUS1->US_TCR && pUS1->US_TNCR) {}; + return 0; +} void usart_init(void) { @@ -141,11 +198,12 @@ void usart_init(void) { pUS1->US_RNPR = (uint32_t)0; pUS1->US_RNCR = 0; - // re-enable receiver / transmitter pUS1->US_CR = (AT91C_US_RXEN | AT91C_US_TXEN); + // ready to receive pUS1->US_RPR = (uint32_t)us_inbuf; - pUS1->US_RCR = sizeof(us_inbuf); + pUS1->US_RCR = 0; + pUS1->US_RNCR = 0; pUS1->US_PTCR = AT91C_PDC_RXTEN; } diff --git a/common/usart.h b/common/usart.h index f98424841..f01968055 100644 --- a/common/usart.h +++ b/common/usart.h @@ -3,6 +3,9 @@ #include #include "proxmark3.h" +#include "../armsrc/ticks.h" // startcountus + +#define AT91_BAUD_RATE 115200 void usart_init(void); void usart_close(void); @@ -11,5 +14,7 @@ int16_t usart_readbuffer(uint8_t *data); int16_t usart_writebuffer(uint8_t *data, size_t len); bool usart_dataavailable(void); int16_t usart_readcommand(uint8_t *data); +void usart_readcheck(uint8_t *data,size_t len); + bool usart_commandavailable(void); #endif