ardupilot/libraries/AP_HAL_Linux/UARTDriver.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
3.0 KiB
C
Raw Permalink Normal View History

#pragma once
2013-09-22 03:01:24 -03:00
#include <AP_HAL/utility/OwnPtr.h>
#include <AP_HAL/utility/RingBuffer.h>
2013-09-22 03:01:24 -03:00
#include "AP_HAL_Linux.h"
#include "SerialDevice.h"
#include "Semaphores.h"
namespace Linux {
class UARTDriver : public AP_HAL::UARTDriver {
2013-09-22 03:01:24 -03:00
public:
UARTDriver(bool default_console);
static UARTDriver *from(AP_HAL::UARTDriver *uart) {
return static_cast<UARTDriver*>(uart);
}
bool is_initialized() override;
bool tx_pending() override;
2013-09-22 03:01:24 -03:00
uint32_t txspace() override;
2013-09-22 03:01:24 -03:00
void set_device_path(const char *path);
2013-09-22 03:01:24 -03:00
bool _write_pending_bytes(void);
virtual void _timer_tick(void) override;
virtual enum flow_control get_flow_control(void) override
{
return _device->get_flow_control();
}
void configure_parity(uint8_t v) override;
virtual void set_flow_control(enum flow_control flow_control_setting) override
{
_device->set_flow_control(flow_control_setting);
}
/*
return timestamp estimate in microseconds for when the start of
a nbytes packet arrived on the uart. This should be treated as a
time constraint, not an exact time. It is guaranteed that the
packet did not start being received after this time, but it
could have been in a system buffer before the returned time.
This takes account of the baudrate of the link. For transports
that have no baudrate (such as USB) the time estimate may be
less accurate.
A return value of zero means the HAL does not support this API
*/
uint64_t receive_time_constraint_us(uint16_t nbytes) override;
uint32_t bw_in_bytes_per_second() const override;
virtual uint32_t get_baud_rate() const override { return _baudrate; }
2024-02-28 02:11:31 -04:00
2013-09-22 03:01:24 -03:00
private:
AP_HAL::OwnPtr<SerialDevice> _device;
bool _console;
volatile bool _in_timer;
uint16_t _base_port;
uint32_t _baudrate;
char *_ip;
char *_flag;
bool _connected; // true if a client has connected
bool _packetise; // true if writes should try to be on mavlink boundaries
void _allocate_buffers(uint16_t rxS, uint16_t txS);
void _deallocate_buffers();
AP_HAL::OwnPtr<SerialDevice> _parseDevicePath(const char *arg);
// timestamp for receiving data on the UART, avoiding a lock
uint64_t _receive_timestamp[2];
uint8_t _receive_timestamp_idx;
protected:
const char *device_path;
volatile bool _initialised;
// we use in-task ring buffers to reduce the system call cost
// of ::read() and ::write() in the main loop
ByteBuffer _readbuf{0};
ByteBuffer _writebuf{0};
virtual int _write_fd(const uint8_t *buf, uint16_t n);
virtual int _read_fd(uint8_t *buf, uint16_t n);
Linux::Semaphore _write_mutex;
bool _discard_input() override;
void _begin(uint32_t b, uint16_t rxS, uint16_t txS) override;
void _end() override;
void _flush() override;
uint32_t _available() override;
size_t _write(const uint8_t *buffer, size_t size) override;
ssize_t _read(uint8_t *buffer, uint16_t count) override WARN_IF_UNUSED;
2013-09-22 03:01:24 -03:00
};
}