2016-02-17 21:25:25 -04:00
|
|
|
#pragma once
|
2012-08-20 15:37:46 -03:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "AP_HAL_Namespace.h"
|
2012-08-20 20:54:01 -03:00
|
|
|
#include "utility/BetterStream.h"
|
2012-08-20 15:37:46 -03:00
|
|
|
|
|
|
|
/* Pure virtual UARTDriver class */
|
2012-08-20 20:54:01 -03:00
|
|
|
class AP_HAL::UARTDriver : public AP_HAL::BetterStream {
|
2012-08-20 15:37:46 -03:00
|
|
|
public:
|
|
|
|
UARTDriver() {}
|
2018-06-20 06:00:00 -03:00
|
|
|
// begin() implicitly clears rx/tx buffers, even if the port was already open (unless the UART is the console UART)
|
2012-12-06 14:55:13 -04:00
|
|
|
virtual void begin(uint32_t baud) = 0;
|
2012-08-23 21:22:46 -03:00
|
|
|
/// Extended port open method
|
|
|
|
///
|
|
|
|
/// Allows for both opening with specified buffer sizes, and re-opening
|
|
|
|
/// to adjust a subset of the port's settings.
|
|
|
|
///
|
|
|
|
/// @note Buffer sizes greater than ::_max_buffer_size will be rounded
|
|
|
|
/// down.
|
|
|
|
///
|
|
|
|
/// @param baud Selects the speed that the port will be
|
|
|
|
/// configured to. If zero, the port speed is left
|
|
|
|
/// unchanged.
|
|
|
|
/// @param rxSpace Sets the receive buffer size for the port. If zero
|
|
|
|
/// then the buffer size is left unchanged if the port
|
|
|
|
/// is open, or set to ::_default_rx_buffer_size if it is
|
|
|
|
/// currently closed.
|
|
|
|
/// @param txSpace Sets the transmit buffer size for the port. If zero
|
|
|
|
/// then the buffer size is left unchanged if the port
|
|
|
|
/// is open, or set to ::_default_tx_buffer_size if it
|
|
|
|
/// is currently closed.
|
|
|
|
///
|
2012-12-06 14:55:13 -04:00
|
|
|
virtual void begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace) = 0;
|
2012-08-21 18:11:24 -03:00
|
|
|
virtual void end() = 0;
|
|
|
|
virtual void flush() = 0;
|
|
|
|
virtual bool is_initialized() = 0;
|
|
|
|
virtual void set_blocking_writes(bool blocking) = 0;
|
|
|
|
virtual bool tx_pending() = 0;
|
2014-02-10 20:22:08 -04:00
|
|
|
|
2018-04-02 03:00:13 -03:00
|
|
|
// lock a port for exclusive use. Use a key of 0 to unlock
|
2018-12-19 07:23:40 -04:00
|
|
|
virtual bool lock_port(uint32_t write_key, uint32_t read_key) { return false; }
|
2018-04-02 03:00:13 -03:00
|
|
|
|
|
|
|
// write to a locked port. If port is locked and key is not correct then 0 is returned
|
|
|
|
// and write is discarded
|
|
|
|
virtual size_t write_locked(const uint8_t *buffer, size_t size, uint32_t key) { return 0; }
|
2018-11-10 05:45:12 -04:00
|
|
|
|
2018-12-19 07:23:40 -04:00
|
|
|
// read from a locked port. If port is locked and key is not correct then 0 is returned
|
|
|
|
virtual int16_t read_locked(uint32_t key) { return -1; }
|
|
|
|
|
2018-11-10 05:45:12 -04:00
|
|
|
// control optional features
|
2020-01-02 21:50:22 -04:00
|
|
|
virtual bool set_options(uint16_t options) { return options==0; }
|
2019-08-27 04:43:43 -03:00
|
|
|
virtual uint8_t get_options(void) const { return 0; }
|
2018-11-10 05:45:12 -04:00
|
|
|
|
|
|
|
enum {
|
2020-01-02 21:50:22 -04:00
|
|
|
OPTION_RXINV = (1U<<0), // invert RX line
|
|
|
|
OPTION_TXINV = (1U<<1), // invert TX line
|
|
|
|
OPTION_HDPLEX = (1U<<2), // half-duplex (one-wire) mode
|
|
|
|
OPTION_SWAP = (1U<<3), // swap RX and TX pins
|
|
|
|
OPTION_PULLDOWN_RX = (1U<<4), // apply pulldown to RX
|
|
|
|
OPTION_PULLUP_RX = (1U<<5), // apply pullup to RX
|
|
|
|
OPTION_PULLDOWN_TX = (1U<<6), // apply pulldown to TX
|
|
|
|
OPTION_PULLUP_TX = (1U<<7), // apply pullup to TX
|
|
|
|
OPTION_NODMA_RX = (1U<<8), // don't use DMA for RX
|
|
|
|
OPTION_NODMA_TX = (1U<<9), // don't use DMA for TX
|
2018-11-10 05:45:12 -04:00
|
|
|
};
|
|
|
|
|
2014-02-10 20:22:08 -04:00
|
|
|
enum flow_control {
|
|
|
|
FLOW_CONTROL_DISABLE=0, FLOW_CONTROL_ENABLE=1, FLOW_CONTROL_AUTO=2
|
|
|
|
};
|
2014-02-11 19:51:58 -04:00
|
|
|
virtual void set_flow_control(enum flow_control flow_control_setting) {};
|
2016-07-01 02:35:07 -03:00
|
|
|
virtual enum flow_control get_flow_control(void) { return FLOW_CONTROL_DISABLE; }
|
2013-09-21 23:20:59 -03:00
|
|
|
|
2017-11-22 13:38:34 -04:00
|
|
|
virtual void configure_parity(uint8_t v){};
|
|
|
|
virtual void set_stop_bits(int n){};
|
|
|
|
|
|
|
|
/* unbuffered writes bypass the ringbuffer and go straight to the
|
|
|
|
* file descriptor
|
|
|
|
*/
|
|
|
|
virtual bool set_unbuffered_writes(bool on){ return false; };
|
|
|
|
|
2018-01-05 03:07:23 -04:00
|
|
|
/*
|
|
|
|
wait for at least n bytes of incoming data, with timeout in
|
|
|
|
milliseconds. Return true if n bytes are available, false if
|
|
|
|
timeout
|
|
|
|
*/
|
|
|
|
virtual bool wait_timeout(uint16_t n, uint32_t timeout_ms) { return false; }
|
2018-01-21 15:44:53 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Optional method to control the update of the motors. Derived classes
|
|
|
|
* can implement it if their HAL layer requires.
|
|
|
|
*/
|
|
|
|
virtual void _timer_tick(void) { }
|
2018-05-15 21:42:14 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
2018-05-21 00:48:04 -03:00
|
|
|
virtual uint64_t receive_time_constraint_us(uint16_t nbytes) { return 0; }
|
2018-04-05 22:58:09 -03:00
|
|
|
|
|
|
|
virtual uint32_t bw_in_kilobytes_per_second() const {
|
|
|
|
return 57;
|
|
|
|
}
|
2012-08-20 20:54:01 -03:00
|
|
|
};
|