2016-02-17 21:25:26 -04:00
|
|
|
#pragma once
|
2013-01-02 20:03:05 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include "AP_HAL_PX4.h"
|
2013-01-24 00:01:48 -04:00
|
|
|
#include <systemlib/perf_counter.h>
|
2013-01-02 20:03:05 -04:00
|
|
|
|
|
|
|
class PX4::PX4UARTDriver : public AP_HAL::UARTDriver {
|
|
|
|
public:
|
2013-01-24 00:01:48 -04:00
|
|
|
PX4UARTDriver(const char *devpath, const char *perf_name);
|
2013-01-02 20:03:05 -04:00
|
|
|
/* PX4 implementations of UARTDriver virtual methods */
|
|
|
|
void begin(uint32_t b);
|
|
|
|
void begin(uint32_t b, uint16_t rxS, uint16_t txS);
|
|
|
|
void end();
|
|
|
|
void flush();
|
|
|
|
bool is_initialized();
|
|
|
|
void set_blocking_writes(bool blocking);
|
|
|
|
bool tx_pending();
|
|
|
|
|
|
|
|
/* PX4 implementations of Stream virtual methods */
|
2016-08-02 10:42:50 -03:00
|
|
|
uint32_t available() override;
|
|
|
|
uint32_t txspace() override;
|
|
|
|
int16_t read() override;
|
2013-01-02 20:03:05 -04:00
|
|
|
|
|
|
|
/* PX4 implementations of Print virtual methods */
|
|
|
|
size_t write(uint8_t c);
|
2013-01-21 19:50:26 -04:00
|
|
|
size_t write(const uint8_t *buffer, size_t size);
|
2013-01-02 22:16:41 -04:00
|
|
|
|
2013-01-14 00:59:54 -04:00
|
|
|
void set_device_path(const char *path) {
|
|
|
|
_devpath = path;
|
|
|
|
}
|
|
|
|
|
2013-01-22 05:11:12 -04:00
|
|
|
void _timer_tick(void);
|
|
|
|
|
2013-02-07 00:03:54 -04:00
|
|
|
int _get_fd(void) {
|
|
|
|
return _fd;
|
|
|
|
}
|
|
|
|
|
2014-02-10 20:22:08 -04:00
|
|
|
void set_flow_control(enum flow_control flow_control);
|
2014-02-13 22:15:24 -04:00
|
|
|
enum flow_control get_flow_control(void) { return _flow_control; }
|
2014-02-09 21:54:50 -04:00
|
|
|
|
2013-01-02 22:16:41 -04:00
|
|
|
private:
|
2013-01-03 06:12:10 -04:00
|
|
|
const char *_devpath;
|
|
|
|
int _fd;
|
2013-10-05 02:47:28 -03:00
|
|
|
uint32_t _baudrate;
|
|
|
|
volatile bool _initialised;
|
|
|
|
volatile bool _in_timer;
|
2013-01-21 19:34:04 -04:00
|
|
|
|
2013-01-22 06:52:21 -04:00
|
|
|
bool _nonblocking_writes;
|
|
|
|
|
2013-01-22 05:11:12 -04:00
|
|
|
// we use in-task ring buffers to reduce the system call cost
|
|
|
|
// of ::read() and ::write() in the main loop
|
2013-01-21 19:34:04 -04:00
|
|
|
uint8_t *_readbuf;
|
2013-01-22 05:11:12 -04:00
|
|
|
uint16_t _readbuf_size;
|
|
|
|
|
|
|
|
// _head is where the next available data is. _tail is where new
|
|
|
|
// data is put
|
|
|
|
volatile uint16_t _readbuf_head;
|
|
|
|
volatile uint16_t _readbuf_tail;
|
|
|
|
|
|
|
|
uint8_t *_writebuf;
|
|
|
|
uint16_t _writebuf_size;
|
|
|
|
volatile uint16_t _writebuf_head;
|
|
|
|
volatile uint16_t _writebuf_tail;
|
2013-01-24 00:01:48 -04:00
|
|
|
perf_counter_t _perf_uart;
|
2013-02-18 21:02:46 -04:00
|
|
|
|
|
|
|
int _write_fd(const uint8_t *buf, uint16_t n);
|
2013-03-20 01:41:52 -03:00
|
|
|
int _read_fd(uint8_t *buf, uint16_t n);
|
2015-07-13 20:52:48 -03:00
|
|
|
uint64_t _first_write_time;
|
2013-02-18 21:02:46 -04:00
|
|
|
uint64_t _last_write_time;
|
2013-10-05 02:47:28 -03:00
|
|
|
|
|
|
|
void try_initialise(void);
|
|
|
|
uint32_t _last_initialise_attempt_ms;
|
2014-02-10 20:22:08 -04:00
|
|
|
|
2015-07-13 20:52:48 -03:00
|
|
|
uint32_t _os_start_auto_space;
|
2014-02-10 20:22:08 -04:00
|
|
|
uint32_t _total_read;
|
|
|
|
uint32_t _total_written;
|
|
|
|
enum flow_control _flow_control;
|
2014-09-06 13:24:41 -03:00
|
|
|
|
|
|
|
pid_t _uart_owner_pid;
|
|
|
|
|
2013-01-02 20:03:05 -04:00
|
|
|
};
|