| 652 | //=========================================================================== |
| 653 | |
| 654 | BYTE __stdcall CSuperSerialCard::CommReceive(WORD, WORD, BYTE, BYTE, ULONG) |
| 655 | { |
| 656 | if (!CheckComm()) |
| 657 | return 0; |
| 658 | |
| 659 | BYTE result = 0; |
| 660 | |
| 661 | if (!m_qTcpSerialBuffer.empty()) |
| 662 | { |
| 663 | // NB. See CommTcpSerialReceive() above, for a note explaining why there's no need for a critical section here |
| 664 | |
| 665 | // If receiver is disabled then transmitting device should not send data |
| 666 | // . For COM serial connection this is handled by DTR/DTS flow-control (which enables the receiver) |
| 667 | if ((m_uCommandByte & CMD_DTR) == 0) // Receiver disable, so prevent receiving data |
| 668 | return 0; |
| 669 | |
| 670 | result = m_qTcpSerialBuffer.front(); |
| 671 | m_qTcpSerialBuffer.pop_front(); |
| 672 | |
| 673 | if (m_bRxIrqEnabled && !m_qTcpSerialBuffer.empty()) |
| 674 | { |
| 675 | CpuIrqAssert(IS_SSC); |
| 676 | m_vbRxIrqPending = true; |
| 677 | } |
| 678 | } |
| 679 | else if (m_hCommHandle != INVALID_HANDLE_VALUE) |
| 680 | { |
| 681 | EnterCriticalSection(&m_CriticalSection); |
| 682 | { |
| 683 | const UINT uCOMIdx = m_vuRxCurrBuffer; |
| 684 | const UINT uSSCIdx = uCOMIdx ^ 1; |
| 685 | if (!m_qComSerialBuffer[uSSCIdx].empty()) |
| 686 | { |
| 687 | result = m_qComSerialBuffer[uSSCIdx].front(); |
| 688 | m_qComSerialBuffer[uSSCIdx].pop_front(); |
| 689 | |
| 690 | UINT uNewSSCIdx = uSSCIdx; |
| 691 | if ( m_qComSerialBuffer[uSSCIdx].empty() && // Current SSC buffer is empty |
| 692 | !m_qComSerialBuffer[uCOMIdx].empty() ) // Current COM buffer has data |
| 693 | { |
| 694 | m_vuRxCurrBuffer = uSSCIdx; // Flip buffers |
| 695 | uNewSSCIdx = uCOMIdx; |
| 696 | } |
| 697 | |
| 698 | if (m_bRxIrqEnabled && !m_qComSerialBuffer[uNewSSCIdx].empty()) |
| 699 | { |
| 700 | CpuIrqAssert(IS_SSC); |
| 701 | m_vbRxIrqPending = true; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | LeaveCriticalSection(&m_CriticalSection); |
| 706 | } |
| 707 | |
| 708 | return result; |
| 709 | } |
| 710 | |
| 711 | //=========================================================================== |
no test coverage detected