Penn Electric Racing / Mbed 2 deprecated SystemManagement

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Committer:
pspatel321
Date:
Fri Nov 14 06:05:59 2014 +0000
Revision:
31:7eaa5e881b56
Mostly working.  Wrote CAN in/out code.  Xbee still needs work.  My guess is that MODDMA breaks when used with RTOS.

Who changed what in which revision?

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