Only imu output

Dependencies:   Servo mbed

Fork of FYDP_Final2 by Mark Vandermeulen

Committer:
tntmarket
Date:
Wed Mar 25 09:58:50 2015 +0000
Revision:
5:d2e955a94940
Parent:
0:21019d94ad33
only imu output

Who changed what in which revision?

UserRevisionLine numberNew contents of line
majik 0:21019d94ad33 1 /*
majik 0:21019d94ad33 2 Copyright (c) 2010 Andy Kirkham
majik 0:21019d94ad33 3
majik 0:21019d94ad33 4 Permission is hereby granted, free of charge, to any person obtaining a copy
majik 0:21019d94ad33 5 of this software and associated documentation files (the "Software"), to deal
majik 0:21019d94ad33 6 in the Software without restriction, including without limitation the rights
majik 0:21019d94ad33 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
majik 0:21019d94ad33 8 copies of the Software, and to permit persons to whom the Software is
majik 0:21019d94ad33 9 furnished to do so, subject to the following conditions:
majik 0:21019d94ad33 10
majik 0:21019d94ad33 11 The above copyright notice and this permission notice shall be included in
majik 0:21019d94ad33 12 all copies or substantial portions of the Software.
majik 0:21019d94ad33 13
majik 0:21019d94ad33 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
majik 0:21019d94ad33 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
majik 0:21019d94ad33 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
majik 0:21019d94ad33 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
majik 0:21019d94ad33 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
majik 0:21019d94ad33 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
majik 0:21019d94ad33 20 THE SOFTWARE.
majik 0:21019d94ad33 21 */
majik 0:21019d94ad33 22
majik 0:21019d94ad33 23 #include "MODSERIAL.h"
majik 0:21019d94ad33 24 #include "MACROS.h"
majik 0:21019d94ad33 25
majik 0:21019d94ad33 26 namespace AjK {
majik 0:21019d94ad33 27
majik 0:21019d94ad33 28 int
majik 0:21019d94ad33 29 MODSERIAL::__putc(int c, bool block) {
majik 0:21019d94ad33 30
majik 0:21019d94ad33 31 // If no buffer is in use fall back to standard TX FIFO usage.
majik 0:21019d94ad33 32 // Note, we must block in this case and ignore bool "block"
majik 0:21019d94ad33 33 // so as to maintain compat with Mbed Serial.
majik 0:21019d94ad33 34 if (buffer[TxIrq] == (char *)NULL || buffer_size[TxIrq] == 0) {
majik 0:21019d94ad33 35 while (! MODSERIAL_WRITABLE) ; // Wait for space in the TX FIFO.
majik 0:21019d94ad33 36 MODSERIAL_WRITE_REG = (uint32_t)c;
majik 0:21019d94ad33 37 return 0;
majik 0:21019d94ad33 38 }
majik 0:21019d94ad33 39
majik 0:21019d94ad33 40 if ( MODSERIAL_WRITABLE && MODSERIAL_TX_BUFFER_EMPTY ) {
majik 0:21019d94ad33 41 MODSERIAL_WRITE_REG = (uint32_t)c;
majik 0:21019d94ad33 42 }
majik 0:21019d94ad33 43 else {
majik 0:21019d94ad33 44 if (block) {
majik 0:21019d94ad33 45 uint32_t irq_reg = MODSERIAL_IRQ_REG; DISABLE_TX_IRQ;
majik 0:21019d94ad33 46 while ( MODSERIAL_TX_BUFFER_FULL ) { // Blocks!
majik 0:21019d94ad33 47 // If putc() is called from an ISR then we are stuffed
majik 0:21019d94ad33 48 // because in an ISR no bytes from the TX buffer will
majik 0:21019d94ad33 49 // get transferred to teh TX FIFOs while we block here.
majik 0:21019d94ad33 50 // So, to work around this, instead of sitting in a
majik 0:21019d94ad33 51 // loop waiting for space in the TX buffer (which will
majik 0:21019d94ad33 52 // never happen in IRQ context), check to see if the
majik 0:21019d94ad33 53 // TX FIFO has space available to move bytes from the
majik 0:21019d94ad33 54 // TX buffer to TX FIFO to make space. The easiest way
majik 0:21019d94ad33 55 // to do this is to poll the isr_tx() function while we
majik 0:21019d94ad33 56 // are blocking.
majik 0:21019d94ad33 57 isr_tx(false);
majik 0:21019d94ad33 58 }
majik 0:21019d94ad33 59 MODSERIAL_IRQ_REG = irq_reg;
majik 0:21019d94ad33 60 }
majik 0:21019d94ad33 61 else if( MODSERIAL_TX_BUFFER_FULL ) {
majik 0:21019d94ad33 62 buffer_overflow[TxIrq] = c; // Oh dear, no room in buffer.
majik 0:21019d94ad33 63 _isr[TxOvIrq].call(&this->callbackInfo);
majik 0:21019d94ad33 64 return -1;
majik 0:21019d94ad33 65 }
majik 0:21019d94ad33 66 DISABLE_TX_IRQ;
majik 0:21019d94ad33 67 buffer[TxIrq][buffer_in[TxIrq]] = c;
majik 0:21019d94ad33 68 __disable_irq();
majik 0:21019d94ad33 69 buffer_count[TxIrq]++;
majik 0:21019d94ad33 70 __enable_irq();
majik 0:21019d94ad33 71 buffer_in[TxIrq]++;
majik 0:21019d94ad33 72 if (buffer_in[TxIrq] >= buffer_size[TxIrq]) {
majik 0:21019d94ad33 73 buffer_in[TxIrq] = 0;
majik 0:21019d94ad33 74 }
majik 0:21019d94ad33 75 ENABLE_TX_IRQ;
majik 0:21019d94ad33 76 }
majik 0:21019d94ad33 77
majik 0:21019d94ad33 78 return 0;
majik 0:21019d94ad33 79 }
majik 0:21019d94ad33 80
majik 0:21019d94ad33 81 }; // namespace AjK ends