SimPacketizer.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 _sim_packetizer_h_
#define _sim_packetizer_h_
#include "Packetizer.h"
#include "SimPeripheral.h"
#include "packet/command_packet.h"
namespace blfwk
{
// Forward declarations.
class Peripheral;
class SimPacketizer : public Packetizer
{
public:
enum _simPacketizer_contants
{
kSimReadTimeoutMs = 5000
};
public:
SimPacketizer(SimPeripheral *peripheral);
virtual ~SimPacketizer();
virtual SimPeripheral *getPeripheral() { return dynamic_cast< SimPeripheral *>(m_peripheral); }
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() { setAborted(true); }
virtual void sync(){};
virtual void finalize();
virtual void enableSimulatorPump() { m_isPumpEnabled = true; }
virtual void pumpSimulator();
virtual void setAborted(bool aborted) { m_isAborted = aborted; }
virtual uint32_t getMaxPacketSize() { return kDefaultMaxPacketSize; }
protected:
bool m_isPumpEnabled;
bool m_isAborted;
uint8_t m_buffer[kDefaultMaxPacketSize];
};
} // namespace blfwk
#endif // _sim_packetizer_h_
// EOF
blfwk::Packetizer
Interface class for packetization of commands and data.
Definition: Packetizer.h:59
blfwk::SimPacketizer::m_isPumpEnabled
bool m_isPumpEnabled
True if simulator pump enabled.
Definition: SimPacketizer.h:98
blfwk
Definition: BlfwkErrors.h:16
blfwk::SimPacketizer::_simPacketizer_contants
_simPacketizer_contants
Constants.
Definition: SimPacketizer.h:50
blfwk::SimPeripheral
Peripheral that operates in the simulation space.
Definition: SimPeripheral.h:45
blfwk::SimPacketizer::sync
virtual void sync()
Send framing packet ack.
Definition: SimPacketizer.h:81
blfwk::SimPacketizer::~SimPacketizer
virtual ~SimPacketizer()
Destructor.
Definition: SimPacketizer.cpp:51
blfwk::SimPacketizer::enableSimulatorPump
virtual void enableSimulatorPump()
Enable simulator command processor pump.
Definition: SimPacketizer.h:87
blfwk::SimPacketizer::m_buffer
uint8_t m_buffer[kDefaultMaxPacketSize]
Buffer for bytes used to build read packet.
Definition: SimPacketizer.h:100
blfwk::SimPacketizer::getPeripheral
virtual SimPeripheral * getPeripheral()
Peripheral accessor.
Definition: SimPacketizer.h:63
blfwk::SimPacketizer::readPacket
virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType)
Read a packet.
Definition: SimPacketizer.cpp:88
blfwk::SimPacketizer::getMaxPacketSize
virtual uint32_t getMaxPacketSize()
Return the max packet size.
Definition: SimPacketizer.h:96
blfwk::SimPacketizer::abortPacket
virtual void abortPacket()
Abort data phase.
Definition: SimPacketizer.h:79
blfwk::SimPacketizer::SimPacketizer
SimPacketizer(SimPeripheral *peripheral)
Default Constructor.
Definition: SimPacketizer.cpp:43
blfwk::SimPacketizer
Provides source and sink for packets in the simulator space.
Definition: SimPacketizer.h:46
blfwk::SimPacketizer::pumpSimulator
virtual void pumpSimulator()
Pump simulator command processor.
Definition: SimPacketizer.cpp:125
blfwk::SimPacketizer::setAborted
virtual void setAborted(bool aborted)
Set aborted flag.
Definition: SimPacketizer.h:94
blfwk::SimPacketizer::writePacket
virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType)
Write a packet.
Definition: SimPacketizer.cpp:62
blfwk::SimPacketizer::m_isAborted
bool m_isAborted
Data phase abort requested by receiver.
Definition: SimPacketizer.h:99
blfwk::Packetizer::m_peripheral
Peripheral * m_peripheral
Peripheral to send/receive bytes on.
Definition: Packetizer.h:113
blfwk::SimPacketizer::finalize
virtual void finalize()
Finalize.
Definition: SimPacketizer.cpp:57