windows port: implement abort mecanism in pn532_uart driver (Based on provided patch: many thanks to Edwin Evans)

This commit is contained in:
Romuald Conty 2011-05-10 13:26:57 +00:00
parent c808511694
commit 7bb4f4597d
2 changed files with 25 additions and 7 deletions

View file

@ -144,15 +144,33 @@ uart_get_speed (const serial_port sp)
int int
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p) 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; volatile bool * abort_flag_p = (volatile bool *)abort_p;
DWORD dwRxLen = szRx;
do { 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; return DEIO;
} }
} while ( (dwRxLen != (DWORD) szRx) && ((abort_flag_p) && !(*abort_flag_p)) ); if (((DWORD)szRx) > dwTotalBytesReceived) {
return (dwRxLen == (DWORD) szRx) ? 0 : DEIO; 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 int

View file

@ -182,7 +182,7 @@ pn532_uart_connect (const nfc_device_desc_t * pndd)
// pipe-based abort mecanism // pipe-based abort mecanism
pipe (DRIVER_DATA (pnd)->iAbortFds); pipe (DRIVER_DATA (pnd)->iAbortFds);
#else #else
abort_flag = false; DRIVER_DATA (pnd)->abort_flag = false;
#endif #endif
pn53x_init(pnd); pn53x_init(pnd);
@ -288,7 +288,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
#ifndef WIN32 #ifndef WIN32
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]); abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
#else #else
abort_p = &(DRIVER_DATA (pnd)->abort_flag); abort_p = (void*)&(DRIVER_DATA (pnd)->abort_flag);
#endif #endif
break; break;
default: default: