UsbHidPacketizer.h
/*
* Copyright (c) 2013-14, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _usb_hid_packetizer_h_
#define _usb_hid_packetizer_h_
#include "Packetizer.h"
#include "UsbHidPeripheral.h"
#include "hidapi.h"
#include "bootloader_common.h"
#include "bootloader_hid_report_ids.h"
namespace blfwk
{
class UsbHidPacketizer : public Packetizer
{
public:
enum _usbhid_contants
{
kReadFlushTimeoutMs = 100000,
#if defined(BL_WITHOUT_RECEIVE_SB_FILE_CMD)
kPollAbortTimeoutMs = 0,
#else
kPollAbortTimeoutMs = 10,
#endif
kPollPacketMaxRetryCnt = 50,
kContinuousReadMargin = 2,
};
public:
UsbHidPacketizer(UsbHidPeripheral *peripheral, uint32_t readPacketTimeoutMs);
virtual ~UsbHidPacketizer();
virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType);
virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType);
virtual void abortPacket();
virtual void sync(){};
virtual void finalize(){};
virtual void enableSimulatorPump() {}
virtual void pumpSimulator() {}
virtual void setAborted(bool aborted) {}
virtual uint32_t getMaxPacketSize();
virtual UsbHidPeripheral *getPeripheral() { return (UsbHidPeripheral *)m_peripheral; }
protected:
virtual void flushInput();
bool pollForAbortPacket();
protected:
bl_hid_report_t m_report;
bl_hid_report_t m_abortReport;
private:
uint32_t
m_continuousReadCount;
};
} // namespace blfwk
#endif // _usb_hid_packetizer_h_
// EOF
blfwk::Packetizer
Interface class for packetization of commands and data.
Definition: Packetizer.h:59
blfwk::UsbHidPacketizer::m_abortReport
bl_hid_report_t m_abortReport
Used for received abort report.
Definition: UsbHidPacketizer.h:115
blfwk::UsbHidPacketizer::abortPacket
virtual void abortPacket()
Abort data phase.
Definition: UsbHidPacketizer.cpp:206
blfwk::UsbHidPacketizer::readPacket
virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType)
Read a packet.
Definition: UsbHidPacketizer.cpp:111
blfwk
Definition: BlfwkErrors.h:16
blfwk::UsbHidPacketizer::sync
virtual void sync()
Send framing packet ack/nak.
Definition: UsbHidPacketizer.h:90
blfwk::UsbHidPacketizer::UsbHidPacketizer
UsbHidPacketizer(UsbHidPeripheral *peripheral, uint32_t readPacketTimeoutMs)
Default Constructor.
Definition: UsbHidPacketizer.cpp:47
blfwk::UsbHidPacketizer::getMaxPacketSize
virtual uint32_t getMaxPacketSize()
Returns the max packet size supported.
Definition: UsbHidPacketizer.cpp:232
blfwk::UsbHidPacketizer
Provides source and sink for packets that go over USB HID class.
Definition: UsbHidPacketizer.h:50
blfwk::UsbHidPacketizer::_usbhid_contants
_usbhid_contants
Constants.
Definition: UsbHidPacketizer.h:54
blfwk::UsbHidPacketizer::pollForAbortPacket
bool pollForAbortPacket()
Poll overlapped read for receiver data phase abort.
Definition: UsbHidPacketizer.cpp:213
blfwk::UsbHidPacketizer::setAborted
virtual void setAborted(bool aborted)
Set aborted flag.
Definition: UsbHidPacketizer.h:100
blfwk::UsbHidPacketizer::enableSimulatorPump
virtual void enableSimulatorPump()
Enable simulator command processor pump.
Definition: UsbHidPacketizer.h:96
blfwk::UsbHidPacketizer::getPeripheral
virtual UsbHidPeripheral * getPeripheral()
Peripheral accessor.
Definition: UsbHidPacketizer.h:105
blfwk::UsbHidPacketizer::finalize
virtual void finalize()
Finalize.
Definition: UsbHidPacketizer.h:93
blfwk::UsbHidPacketizer::m_report
bl_hid_report_t m_report
Used for building and receiving the report.
Definition: UsbHidPacketizer.h:114
blfwk::UsbHidPacketizer::flushInput
virtual void flushInput()
Flush input from device.
Definition: UsbHidPacketizer.cpp:196
blfwk::UsbHidPeripheral
Represents a USB HID peripheral.
Definition: UsbHidPeripheral.h:47
blfwk::UsbHidPacketizer::~UsbHidPacketizer
virtual ~UsbHidPacketizer()
Destructor.
Definition: UsbHidPacketizer.cpp:54
blfwk::Packetizer::m_peripheral
Peripheral * m_peripheral
Peripheral to send/receive bytes on.
Definition: Packetizer.h:113
blfwk::UsbHidPacketizer::pumpSimulator
virtual void pumpSimulator()
Pump simulator command processor.
Definition: UsbHidPacketizer.h:98
blfwk::UsbHidPacketizer::writePacket
virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType)
Write a packet.
Definition: UsbHidPacketizer.cpp:60