From dfdc14f583aa7690e11957ccba788237d7012b7e Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 6 Dec 2012 11:02:28 -0800 Subject: [PATCH] AP_HAL_AVR: Console uses only sized int types --- libraries/AP_HAL_AVR/Console.cpp | 28 ++++++++++++++-------------- libraries/AP_HAL_AVR/Console.h | 18 +++++++++--------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libraries/AP_HAL_AVR/Console.cpp b/libraries/AP_HAL_AVR/Console.cpp index e3346348e0..cc5281d4f3 100644 --- a/libraries/AP_HAL_AVR/Console.cpp +++ b/libraries/AP_HAL_AVR/Console.cpp @@ -27,9 +27,9 @@ void AVRConsoleDriver::backend_close() { _user_backend = false; } -int AVRConsoleDriver::backend_read(uint8_t *data, int len) { - for (int i = 0; i < len; i++) { - int b = _txbuf.pop(); +size_t AVRConsoleDriver::backend_read(uint8_t *data, size_t len) { + for (size_t i = 0; i < len; i++) { + int16_t b = _txbuf.pop(); if (b != -1) { data[i] = (uint8_t) b; } else { @@ -39,8 +39,8 @@ int AVRConsoleDriver::backend_read(uint8_t *data, int len) { return len; } -int AVRConsoleDriver::backend_write(const uint8_t *data, int len) { - for (int i = 0; i < len; i++) { +size_t AVRConsoleDriver::backend_write(const uint8_t *data, size_t len) { + for (size_t i = 0; i < len; i++) { bool valid = _rxbuf.push(data[i]); if (!valid) { return i; @@ -78,7 +78,7 @@ void AVRConsoleDriver::_printf_P(const prog_char *fmt, ...) { } // Stream method implementations ///////////////////////////////////////// -int AVRConsoleDriver::available(void) { +int16_t AVRConsoleDriver::available(void) { if (_user_backend) { return _rxbuf.bytes_used(); } else { @@ -86,7 +86,7 @@ int AVRConsoleDriver::available(void) { } } -int AVRConsoleDriver::txspace(void) { +int16_t AVRConsoleDriver::txspace(void) { if (_user_backend) { return _rxbuf.bytes_free(); } else { @@ -94,7 +94,7 @@ int AVRConsoleDriver::txspace(void) { } } -int AVRConsoleDriver::read() { +int16_t AVRConsoleDriver::read() { if (_user_backend) { return _rxbuf.pop(); } else { @@ -102,7 +102,7 @@ int AVRConsoleDriver::read() { } } -int AVRConsoleDriver::peek() { +int16_t AVRConsoleDriver::peek() { if (_user_backend) { return _rxbuf.peek(); } else { @@ -126,7 +126,7 @@ size_t AVRConsoleDriver::write(uint8_t c) { * A synchronous nonblocking ring buffer, based on the AVRUARTDriver::Buffer */ -bool AVRConsoleDriver::Buffer::allocate(int size) { +bool AVRConsoleDriver::Buffer::allocate(uint16_t size) { _head = 0; _tail = 0; uint8_t shift; @@ -158,21 +158,21 @@ bool AVRConsoleDriver::Buffer::push(uint8_t b) { return true; } -int AVRConsoleDriver::Buffer::pop() { +int16_t AVRConsoleDriver::Buffer::pop() { if ( _tail == _head ) { return -1; } uint8_t b = _bytes[_tail]; _tail = ( _tail + 1 ) & _mask; - return (int) b; + return (int16_t) b; } -int AVRConsoleDriver::Buffer::peek() { +int16_t AVRConsoleDriver::Buffer::peek() { if ( _tail == _head ) { return -1; } uint8_t b = _bytes[_tail]; - return (int) b; + return (int16_t) b; } uint16_t AVRConsoleDriver::Buffer::bytes_used() { diff --git a/libraries/AP_HAL_AVR/Console.h b/libraries/AP_HAL_AVR/Console.h index 56b5a63ac3..6b64fbbaa4 100644 --- a/libraries/AP_HAL_AVR/Console.h +++ b/libraries/AP_HAL_AVR/Console.h @@ -13,8 +13,8 @@ public: void init(void* baseuartdriver); void backend_open(); void backend_close(); - int backend_read(uint8_t *data, int len); - int backend_write(const uint8_t *data, int len); + size_t backend_read(uint8_t *data, size_t len); + size_t backend_write(const uint8_t *data, size_t len); /* Implementations of BetterStream virtual methods */ void print_P(const prog_char_t *s); @@ -25,20 +25,20 @@ public: __attribute__ ((format(__printf__, 2, 3))); /* Implementations of Stream virtual methods */ - int available(); - int txspace(); - int read(); - int peek(); + int16_t available(); + int16_t txspace(); + int16_t read(); + int16_t peek(); /* Implementations of Print virtual methods */ size_t write(uint8_t c); private: struct Buffer { /* public methods:*/ - bool allocate(int size); + bool allocate(uint16_t size); bool push(uint8_t b); - int pop(); - int peek(); + int16_t pop(); + int16_t peek(); uint16_t bytes_free(); uint16_t bytes_used();