This commit is contained in:
iceman1001 2019-04-14 11:14:55 +02:00
commit 62f1c82fda
8 changed files with 95 additions and 21 deletions

View file

@ -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

View file

@ -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);

View file

@ -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");

View file

@ -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

View file

@ -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)

View file

@ -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) {

View file

@ -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<len){
if (check == 0){
StartCountUS();
check = 1;
}
//300ms
if (GetCountUS() > 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;
}

View file

@ -3,6 +3,9 @@
#include <stddef.h>
#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