AP_HAL_AVR: Finished implementation of AVRConsoleDriver

This commit is contained in:
Pat Hickey 2012-09-14 17:30:39 -07:00 committed by Andrew Tridgell
parent 98f86d0288
commit 52adb462a9
2 changed files with 24 additions and 7 deletions

View File

@ -80,8 +80,7 @@ void AVRConsoleDriver::_printf_P(const prog_char *fmt, ...) {
// Stream method implementations /////////////////////////////////////////
int AVRConsoleDriver::available(void) {
if (_user_backend) {
// XXX TODO
return INT_MAX;
return _rxbuf.bytes_used();
} else {
return _base_uart->available();
}
@ -89,8 +88,7 @@ int AVRConsoleDriver::available(void) {
int AVRConsoleDriver::txspace(void) {
if (_user_backend) {
// XXX TODO
return INT_MAX;
return _rxbuf.bytes_free();
} else {
return _base_uart->txspace();
}
@ -106,8 +104,7 @@ int AVRConsoleDriver::read() {
int AVRConsoleDriver::peek() {
if (_user_backend) {
// XXX TODO
return -1;
return _rxbuf.peek();
} else {
return _base_uart->peek();
}
@ -169,3 +166,19 @@ int AVRConsoleDriver::Buffer::pop() {
return (int) b;
}
int AVRConsoleDriver::Buffer::peek() {
if ( _tail == _head ) {
return -1;
}
uint8_t b = _bytes[_tail];
return (int) b;
}
uint16_t AVRConsoleDriver::Buffer::bytes_free() {
return ((_head - _tail) & _mask);
}
uint16_t AVRConsoleDriver::Buffer::bytes_used() {
return ((_mask+1) - ((_head - _tail) & _mask));
}

View File

@ -38,7 +38,11 @@ private:
/* public methods:*/
bool allocate(int size);
bool push(uint8_t b);
int pop();
int pop();
int peek();
uint16_t bytes_free();
uint16_t bytes_used();
private:
uint16_t _head, _tail; /* Head and tail indicies */
uint16_t _mask; /* Buffer size mask for index wrap */