UAVX Multicopter Flight Controller.

Dependencies:   mbed

Committer:
gke
Date:
Tue Apr 26 12:12:29 2011 +0000
Revision:
2:90292f8bd179
Parent:
1:1e3318a30ddd
Not flightworthy. Posted for others to make use of the I2C SW code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gke 1:1e3318a30ddd 1 /*
gke 1:1e3318a30ddd 2 Copyright (c) 2010 Andy Kirkham
gke 1:1e3318a30ddd 3
gke 1:1e3318a30ddd 4 Permission is hereby granted, free of charge, to any person obtaining a copy
gke 1:1e3318a30ddd 5 of this software and associated documentation files (the "Software"), to deal
gke 1:1e3318a30ddd 6 in the Software without restriction, including without limitation the rights
gke 1:1e3318a30ddd 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
gke 1:1e3318a30ddd 8 copies of the Software, and to permit persons to whom the Software is
gke 1:1e3318a30ddd 9 furnished to do so, subject to the following conditions:
gke 1:1e3318a30ddd 10
gke 1:1e3318a30ddd 11 The above copyright notice and this permission notice shall be included in
gke 1:1e3318a30ddd 12 all copies or substantial portions of the Software.
gke 1:1e3318a30ddd 13
gke 1:1e3318a30ddd 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
gke 1:1e3318a30ddd 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
gke 1:1e3318a30ddd 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
gke 1:1e3318a30ddd 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
gke 1:1e3318a30ddd 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
gke 1:1e3318a30ddd 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
gke 1:1e3318a30ddd 20 THE SOFTWARE.
gke 1:1e3318a30ddd 21 */
gke 1:1e3318a30ddd 22
gke 1:1e3318a30ddd 23 #include "../SerialBuffered.h"
gke 1:1e3318a30ddd 24 #include "../sb_globals.h"
gke 1:1e3318a30ddd 25
gke 1:1e3318a30ddd 26 int SerialBuffered::putc(int c, bool blocking) {
gke 1:1e3318a30ddd 27 if ((GET_REGISTER(SERIALBUFFERED_LSR) & 0x20) && (_tx_buffer_in[uart_number] == _tx_buffer_out[uart_number] && !_tx_buffer_full[uart_number])) {
gke 1:1e3318a30ddd 28 SET_REGISTER(SERIALBUFFERED_THR, (uint8_t)c);
gke 1:1e3318a30ddd 29 }
gke 1:1e3318a30ddd 30 else {
gke 1:1e3318a30ddd 31 if (_tx_buffer_full[uart_number]) {
gke 1:1e3318a30ddd 32 if (blocking) while (_tx_buffer_full[uart_number]) ; /* Blocks!!! */
gke 1:1e3318a30ddd 33 else {
gke 1:1e3318a30ddd 34 _tx_buffer_overflow[uart_number] = true;
gke 1:1e3318a30ddd 35 return -1;
gke 1:1e3318a30ddd 36 }
gke 1:1e3318a30ddd 37 }
gke 1:1e3318a30ddd 38 _tx_buffer[uart_number][_tx_buffer_in[uart_number]++] = (char)c;
gke 1:1e3318a30ddd 39 if (_tx_buffer_in[uart_number] >= _tx_buffer_size[uart_number]) {
gke 1:1e3318a30ddd 40 _tx_buffer_in[uart_number] = 0;
gke 1:1e3318a30ddd 41 }
gke 1:1e3318a30ddd 42 if (_tx_buffer_in[uart_number] == _tx_buffer_out[uart_number] && !_tx_buffer_full[uart_number]) _tx_buffer_full[uart_number] = true;
gke 1:1e3318a30ddd 43 SET_REGISTER(SERIALBUFFERED_IER, 0x3);
gke 1:1e3318a30ddd 44 }
gke 1:1e3318a30ddd 45 return 0;
gke 1:1e3318a30ddd 46 }
gke 1:1e3318a30ddd 47
gke 1:1e3318a30ddd 48 /** putc
gke 1:1e3318a30ddd 49 */
gke 1:1e3318a30ddd 50 int SerialBuffered::putc(int c) {
gke 1:1e3318a30ddd 51 return putc(c, true);
gke 1:1e3318a30ddd 52 }
gke 1:1e3318a30ddd 53
gke 1:1e3318a30ddd 54 int SerialBuffered::writeable(void) {
gke 1:1e3318a30ddd 55 return (!_tx_buffer_full[uart_number] && !_tx_buffer_overflow[uart_number]) ? 1 : 0;
gke 1:1e3318a30ddd 56 }