HAL_PX4: added UART performance counters

This commit is contained in:
Andrew Tridgell 2013-01-24 15:01:48 +11:00
parent 6cf1d5e1ff
commit fc8065b50f
2 changed files with 12 additions and 4 deletions

View File

@ -19,9 +19,11 @@ using namespace PX4;
extern const AP_HAL::HAL& hal;
PX4UARTDriver::PX4UARTDriver(const char *devpath) {
_devpath = devpath;
}
PX4UARTDriver::PX4UARTDriver(const char *devpath, const char *perf_name) :
_devpath(devpath),
_perf_uart(perf_alloc(PC_ELAPSED, perf_name))
{}
extern const AP_HAL::HAL& hal;
@ -316,6 +318,7 @@ void PX4UARTDriver::_timer_tick(void)
uint16_t _tail;
n = BUF_AVAILABLE(_writebuf);
if (n > 0) {
perf_begin(_perf_uart);
if (_tail > _writebuf_head) {
// do as a single write
int ret = ::write(_fd, &_writebuf[_writebuf_head], n);
@ -336,12 +339,14 @@ void PX4UARTDriver::_timer_tick(void)
}
}
}
perf_end(_perf_uart);
}
// try to fill the read buffer
uint16_t _head;
n = BUF_SPACE(_readbuf);
if (n > 0) {
perf_begin(_perf_uart);
if (_readbuf_tail < _head) {
// one read will do
int ret = ::read(_fd, &_readbuf[_readbuf_tail], n);
@ -361,6 +366,7 @@ void PX4UARTDriver::_timer_tick(void)
}
}
}
perf_end(_perf_uart);
}
_in_timer = false;

View File

@ -3,10 +3,11 @@
#define __AP_HAL_PX4_UARTDRIVER_H__
#include <AP_HAL_PX4.h>
#include <systemlib/perf_counter.h>
class PX4::PX4UARTDriver : public AP_HAL::UARTDriver {
public:
PX4UARTDriver(const char *devpath);
PX4UARTDriver(const char *devpath, const char *perf_name);
/* PX4 implementations of UARTDriver virtual methods */
void begin(uint32_t b);
void begin(uint32_t b, uint16_t rxS, uint16_t txS);
@ -65,6 +66,7 @@ private:
uint16_t _writebuf_size;
volatile uint16_t _writebuf_head;
volatile uint16_t _writebuf_tail;
perf_counter_t _perf_uart;
};
#endif // __AP_HAL_PX4_UARTDRIVER_H__