Packetizer.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 _Packetizer_h_
#define _Packetizer_h_
#include "bootloader_common.h"
#include "bootloader/bl_peripheral.h"
#include <time.h>
namespace blfwk
{
// Forward declarations.
class Peripheral;
enum _packetizer_status
{
kStatus_NoPingResponse = MAKE_STATUS(kStatusGroup_Packetizer, 0),
kStatus_InvalidPacketType = MAKE_STATUS(kStatusGroup_Packetizer, 1),
kStatus_InvalidCRC = MAKE_STATUS(kStatusGroup_Packetizer, 2),
kStatus_NoCommandResponse = MAKE_STATUS(kStatusGroup_Packetizer, 3)
};
class Packetizer
{
public:
Packetizer(Peripheral *peripheral, uint32_t packetTimeoutMs)
: m_peripheral(peripheral)
, m_packetTimeoutMs(packetTimeoutMs)
, m_version()
, m_options(0)
, m_isAbortEnabled(false)
{
}
virtual ~Packetizer(){};
virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType) = 0;
virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType) = 0;
virtual void abortPacket() = 0;
virtual void sync() = 0;
virtual void finalize() = 0;
virtual void enableSimulatorPump() = 0;
virtual void pumpSimulator() = 0;
virtual void setAborted(bool aborted) = 0;
virtual uint32_t getMaxPacketSize() = 0;
virtual Peripheral *getPeripheral() { return m_peripheral; }
standard_version_t getVersion() { return m_version; }
uint16_t getOptions() { return m_options; }
void setAbortEnabled(bool isEnabled) { m_isAbortEnabled = isEnabled; }
bool isAbortEnabled() { return m_isAbortEnabled; }
protected:
Peripheral *m_peripheral;
standard_version_t m_version;
uint16_t m_options;
clock_t m_startTime;
uint32_t m_packetTimeoutMs;
bool m_isAbortEnabled;
};
} // namespace blfwk
#endif // _Packetizer_h_
// EOF
blfwk::Packetizer::m_startTime
clock_t m_startTime
Beginning time of packet transaction.
Definition: Packetizer.h:116
blfwk::Packetizer
Interface class for packetization of commands and data.
Definition: Packetizer.h:59
blfwk::Packetizer::pumpSimulator
virtual void pumpSimulator()=0
Pump simulator command processor.
blfwk::Packetizer::setAborted
virtual void setAborted(bool aborted)=0
Set aborted flag.
blfwk
Definition: BlfwkErrors.h:16
blfwk::Packetizer::m_isAbortEnabled
bool m_isAbortEnabled
True if allowing abort packet. Not used by all packetizers.
Definition: Packetizer.h:118
blfwk::Packetizer::setAbortEnabled
void setAbortEnabled(bool isEnabled)
Set abort packet check enable.
Definition: Packetizer.h:109
blfwk::Packetizer::abortPacket
virtual void abortPacket()=0
Abort data phase.
blfwk::Packetizer::m_version
standard_version_t m_version
Framing protocol version.
Definition: Packetizer.h:114
blfwk::Packetizer::sync
virtual void sync()=0
Send framing packet ack.
blfwk::Packetizer::writePacket
virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType)=0
Write a packet.
standard_version_t
Definition: qspi_config_block_generator.c:101
blfwk::Packetizer::readPacket
virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType)=0
Read a packet.
blfwk::Packetizer::isAbortEnabled
bool isAbortEnabled()
Check if abort data phase is enabled.
Definition: Packetizer.h:111
blfwk::Packetizer::getMaxPacketSize
virtual uint32_t getMaxPacketSize()=0
Return the max packet size.
blfwk::Packetizer::finalize
virtual void finalize()=0
Finalize.
blfwk::Packetizer::m_options
uint16_t m_options
Framing protocol options bitfield.
Definition: Packetizer.h:115
blfwk::Peripheral
Represents a peripheral.
Definition: Peripheral.h:48
blfwk::Packetizer::getOptions
uint16_t getOptions()
Get Framing Protocol Options.
Definition: Packetizer.h:107
blfwk::Packetizer::getPeripheral
virtual Peripheral * getPeripheral()
Peripheral accessor.
Definition: Packetizer.h:103
blfwk::Packetizer::enableSimulatorPump
virtual void enableSimulatorPump()=0
Enable simulator command processor pump.
blfwk::Packetizer::getVersion
standard_version_t getVersion()
Get Framing Protocol Version.
Definition: Packetizer.h:105
blfwk::Packetizer::m_peripheral
Peripheral * m_peripheral
Peripheral to send/receive bytes on.
Definition: Packetizer.h:113