Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
blfwk::SerialPacketizer Class Reference

Provides source and sink for packets that go over the serial peripherals. More...

#include <SerialPacketizer.h>

+ Inheritance diagram for blfwk::SerialPacketizer:
+ Collaboration diagram for blfwk::SerialPacketizer:

Public Member Functions

 SerialPacketizer (UartPeripheral *peripheral, uint32_t packetTimeoutMs)
 Constructor.
 
virtual ~SerialPacketizer ()
 Destructor.
 
virtual UartPeripheralgetPeripheral ()
 Peripheral accessor.
 
virtual status_t readPacket (uint8_t **packet, uint32_t *packetLength, packet_type_t packetType)
 Read a packet. More...
 
virtual status_t writePacket (const uint8_t *packet, uint32_t byteCount, packet_type_t packetType)
 Write a packet. More...
 
virtual void abortPacket ()
 Abort data phase.
 
virtual void sync ()
 Send framing packet ack.
 
virtual void finalize ()
 Finalize.
 
virtual void enableSimulatorPump ()
 Enable simulator command processor pump.
 
virtual void pumpSimulator ()
 Pump simulator command processor.
 
virtual void setAborted (bool aborted)
 Set aborted flag.
 
virtual uint32_t getMaxPacketSize ()
 Return the max packet size.
 
void host_delay (uint32_t milliseconds)
 Delay milliseconds.
 
virtual status_t ping (int retries, unsigned int delay, ping_response_t *response, int comSpeed)
 Send a ping packet and receive an ack. More...
 
- Public Member Functions inherited from blfwk::Packetizer
 Packetizer (Peripheral *peripheral, uint32_t packetTimeoutMs)
 
standard_version_t getVersion ()
 Get Framing Protocol Version.
 
uint16_t getOptions ()
 Get Framing Protocol Options.
 
void setAbortEnabled (bool isEnabled)
 Set abort packet check enable.
 
bool isAbortEnabled ()
 Check if abort data phase is enabled.
 

Protected Member Functions

status_t send_deferred_ack ()
 Send ACK if needed.
 
status_t serial_packet_read (uint8_t **packet, uint32_t *packetLength, packet_type_t packetType)
 Read packet using serial framing. More...
 
status_t serial_packet_write (const uint8_t *packet, uint32_t byteCount, packet_type_t packetType)
 Write packet using serial framing.
 
void serial_packet_abort ()
 Abort data phase. More...
 
uint32_t serial_packet_get_max_packet_size ()
 Get max packet size.
 
status_t serial_packet_send_sync (uint8_t framingPacketType)
 Send a sync packet of the specified type.
 
status_t serial_send_ping_response ()
 Send a ping message back in response to a ping.
 
status_t wait_for_ack_packet ()
 Wait for an ACK, handling NAKs as needed.
 
status_t read_data_packet (framing_data_packet_t *packet, uint8_t *data, packet_type_t packetType)
 Read from peripheral until entire data framing packet read.
 
status_t read_start_byte (framing_header_t *header)
 Read from peripheral until start byte found.
 
status_t read_header (framing_header_t *header)
 Read from peripheral until packet header found.
 
status_t read_length (framing_data_packet_t *packet)
 Read from peripheral until packet length found.
 
status_t read_crc16 (framing_data_packet_t *packet)
 Read from peripheral until crc16 is found.
 
uint16_t calculate_framing_crc16 (framing_data_packet_t *packet, const uint8_t *data)
 Calculate crc over framing data packet.
 

Protected Attributes

serial_data_t m_serialContext
 
- Protected Attributes inherited from blfwk::Packetizer
Peripheralm_peripheral
 Peripheral to send/receive bytes on.
 
standard_version_t m_version
 Framing protocol version.
 
uint16_t m_options
 Framing protocol options bitfield.
 
clock_t m_startTime
 Beginning time of packet transaction.
 
uint32_t m_packetTimeoutMs
 
bool m_isAbortEnabled
 True if allowing abort packet. Not used by all packetizers.
 

Detailed Description

Provides source and sink for packets that go over the serial peripherals.

Member Function Documentation

status_t SerialPacketizer::ping ( int  retries,
unsigned int  delay,
ping_response_t *  response,
int  comSpeed 
)
virtual

Send a ping packet and receive an ack.

This is a method for host only side pinging of the target. The reponse from the target to a ping packet is a ping response packet. Since the target may or may not be online there is optionally a series of retries to make the best attempt at communication possible

Parameters
retriesThe number of attempts that should be made.
delayThe time in milliseconds between each attempt.
comSpeedThe peripheral baud rate. Used in order to calculate the receive delay in the case of low com speeds such as 100 and 300 which need nearly a second to complete
status_t SerialPacketizer::readPacket ( uint8_t **  packet,
uint32_t *  packetLength,
packet_type_t  packetType 
)
virtual

Read a packet.

Provides the address of a buffer containing the packet.

Parameters
packetPointer location to write packet pointer
packetLengthNumber of bytes in returned packet.

Implements blfwk::Packetizer.

void SerialPacketizer::serial_packet_abort ( )
protected

Abort data phase.

Respond to next host data packet with AckAbort instead of Ack (i.e. receiver data phase abort).

status_t SerialPacketizer::serial_packet_read ( uint8_t **  packet,
uint32_t *  packetLength,
packet_type_t  packetType 
)
protected

Read packet using serial framing.

On return, caller must call flow control method to send AckContinue or AckWait followed by Continue.

status_t SerialPacketizer::writePacket ( const uint8_t *  packet,
uint32_t  byteCount,
packet_type_t  packetType 
)
virtual

Write a packet.

Parameters
packetPointer to packet to write.
byteCountNumber of bytes in packet.

Implements blfwk::Packetizer.


The documentation for this class was generated from the following files: