Refactoring uart interface (#341)

* uart: Major cleanups
- Adds documentation to the uart API.
- Fixes a buffer overflow issue in `uart_receive`, where the maximum parameter was ignored.
- Splits the maximum length and bytes recieved variables in `uart_receive`.
- Downsizes the receive buffer to the minimum required, saving 16MiB of RAM at runtime.
- Refactors the POSIX and Win32 implementations of uart into separate files.
- Removes the unused `uart_{get,set}_parity` functions, which were not implemented on Win32.
This commit is contained in:
Michael Farrell 2017-07-06 04:22:02 +10:00 committed by pwpiwi
parent 52244230d3
commit 067bfc8b76
7 changed files with 315 additions and 270 deletions

View file

@ -19,6 +19,8 @@
#ifdef _WIN32
# define unlink(x)
#else
# include <unistd.h>
#endif
static serial_port sp;
@ -52,8 +54,7 @@ void ReceiveCommand(UsbCommand* rxcmd) {
byte_t* prx = prxcmd;
size_t rxlen;
while (true) {
rxlen = sizeof(UsbCommand) - (prx-prxcmd);
if (uart_receive(sp,prx,&rxlen)) {
if (uart_receive(sp, prx, sizeof(UsbCommand) - (prx-prxcmd), &rxlen)) {
prx += rxlen;
if ((prx-prxcmd) >= sizeof(UsbCommand)) {
return;
@ -129,7 +130,7 @@ int main(int argc, char **argv)
fprintf(stderr,"Waiting for Proxmark to appear on %s",serial_port_name);
do {
sleep(1);
msleep(1000);
fprintf(stderr, ".");
} while (!OpenProxmark(0));
fprintf(stderr," Found.\n");