windows port: implement abort mecanism in pn532_uart driver (Based on provided patch: many thanks to Edwin Evans)
This commit is contained in:
parent
c808511694
commit
7bb4f4597d
2 changed files with 25 additions and 7 deletions
|
@ -144,15 +144,33 @@ uart_get_speed (const serial_port sp)
|
|||
int
|
||||
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p)
|
||||
{
|
||||
// TODO Test me with abort_p
|
||||
DWORD dwBytesToGet = (DWORD)szRx;
|
||||
DWORD dwBytesReceived = 0;
|
||||
DWORD dwTotalBytesReceived = 0;
|
||||
BOOL res;
|
||||
|
||||
volatile bool * abort_flag_p = (volatile bool *)abort_p;
|
||||
DWORD dwRxLen = szRx;
|
||||
do {
|
||||
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, dwRxLen, &dwRxLen, NULL)) {
|
||||
res = ReadFile (((serial_port_windows *) sp)->hPort, pbtRx + received_bytes_count,
|
||||
dwBytesToGet,
|
||||
&dwBytesReceived, NULL);
|
||||
|
||||
dwTotalBytesReceived += dwBytesReceived;
|
||||
|
||||
if (!res) {
|
||||
WARN("ReadFile returned error\n");
|
||||
return DEIO;
|
||||
}
|
||||
} while ( (dwRxLen != (DWORD) szRx) && ((abort_flag_p) && !(*abort_flag_p)) );
|
||||
return (dwRxLen == (DWORD) szRx) ? 0 : DEIO;
|
||||
if (((DWORD)szRx) > dwTotalBytesReceived) {
|
||||
dwBytesToGet -= dwBytesReceived;
|
||||
}
|
||||
|
||||
if (abort_flag_p != NULL && (*abort_flag_p) && dwTotalBytesReceived == 0) {
|
||||
return DEABORT;
|
||||
}
|
||||
} while (((DWORD)szRx) > dwTotalBytesReceived);
|
||||
|
||||
return (dwTotalBytesReceived == (DWORD) szRx) ? 0 : DEIO;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -182,7 +182,7 @@ pn532_uart_connect (const nfc_device_desc_t * pndd)
|
|||
// pipe-based abort mecanism
|
||||
pipe (DRIVER_DATA (pnd)->iAbortFds);
|
||||
#else
|
||||
abort_flag = false;
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
#endif
|
||||
|
||||
pn53x_init(pnd);
|
||||
|
@ -288,7 +288,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
|||
#ifndef WIN32
|
||||
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
|
||||
#else
|
||||
abort_p = &(DRIVER_DATA (pnd)->abort_flag);
|
||||
abort_p = (void*)&(DRIVER_DATA (pnd)->abort_flag);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue