2018-08-27 03:28:24 +00:00
|
|
|
// Copyright 2016 Rob Riggs <rob@mobilinkd.com>
|
|
|
|
// All rights reserved.
|
|
|
|
|
|
|
|
#ifndef MOBILINKD__TNC__PORT_INTERFACE_HPP_
|
|
|
|
#define MOBILINKD__TNC__PORT_INTERFACE_HPP_
|
|
|
|
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
|
|
|
|
#include "HdlcFrame.hpp"
|
|
|
|
#include "PortInterface.h"
|
|
|
|
|
|
|
|
namespace mobilinkd { namespace tnc {
|
|
|
|
|
2018-10-29 02:02:14 +00:00
|
|
|
const uint32_t TX_BUFFER_SIZE = 64; // Cannot be larger that USB_FS_MAX_PACKET_SIZE.
|
2018-08-27 03:28:24 +00:00
|
|
|
extern uint8_t TxBuffer[TX_BUFFER_SIZE];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This interface defines the semi-asynchronous interface used for reading
|
|
|
|
* and writing. The write interface is synchronous. The read interface
|
|
|
|
* is asynchronous. The call to open() starts a task that reads from port
|
|
|
|
* and puts that data on the read_queue, one byte at a time.
|
|
|
|
*/
|
|
|
|
struct PortInterface {
|
|
|
|
virtual ~PortInterface() {}
|
|
|
|
virtual bool open() = 0;
|
|
|
|
virtual bool isOpen() const = 0;
|
|
|
|
virtual void close() = 0;
|
|
|
|
virtual osMessageQId queue() const = 0;
|
|
|
|
virtual bool write(const uint8_t* data, uint32_t size, uint8_t type,
|
|
|
|
uint32_t timeout) = 0;
|
|
|
|
virtual bool write(const uint8_t* data, uint32_t size, uint32_t timeout) = 0;
|
|
|
|
virtual bool write(hdlc::IoFrame* frame, uint32_t timeout = osWaitForever) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern PortInterface* ioport;
|
|
|
|
|
|
|
|
int write(hdlc::IoFrame* frame, uint32_t timeout = osWaitForever);
|
|
|
|
|
|
|
|
}} // mobilinkd::tnc
|
|
|
|
|
|
|
|
#endif // MOBILINKD__TNC__PORT_INTERFACE_HPP_
|