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 @file MODSERIAL.h
pspatel321 31:7eaa5e881b56 23 @purpose Extends Serial to provide fully buffered IO
pspatel321 31:7eaa5e881b56 24 @version 1.6
pspatel321 31:7eaa5e881b56 25 @date Nov 2010
pspatel321 31:7eaa5e881b56 26 @author Andy Kirkham
pspatel321 31:7eaa5e881b56 27 */
pspatel321 31:7eaa5e881b56 28
pspatel321 31:7eaa5e881b56 29 #include "MODSERIAL.h"
pspatel321 31:7eaa5e881b56 30 #include "MACROS.h"
pspatel321 31:7eaa5e881b56 31
pspatel321 31:7eaa5e881b56 32 namespace AjK {
pspatel321 31:7eaa5e881b56 33
pspatel321 31:7eaa5e881b56 34 MODSERIAL::MODSERIAL( PinName tx, PinName rx, const char* name ) : Serial( tx, rx, name )
pspatel321 31:7eaa5e881b56 35 {
pspatel321 31:7eaa5e881b56 36 init( MODSERIAL_DEFAULT_TX_BUFFER_SIZE, MODSERIAL_DEFAULT_RX_BUFFER_SIZE, rx );
pspatel321 31:7eaa5e881b56 37 }
pspatel321 31:7eaa5e881b56 38
pspatel321 31:7eaa5e881b56 39 MODSERIAL::MODSERIAL( PinName tx, PinName rx, int bufferSize, const char* name ) : Serial( tx, rx, name )
pspatel321 31:7eaa5e881b56 40 {
pspatel321 31:7eaa5e881b56 41 init( bufferSize, bufferSize, rx );
pspatel321 31:7eaa5e881b56 42 }
pspatel321 31:7eaa5e881b56 43
pspatel321 31:7eaa5e881b56 44 MODSERIAL::MODSERIAL( PinName tx, PinName rx, int txSize, int rxSize, const char* name ) : Serial( tx, rx, name )
pspatel321 31:7eaa5e881b56 45 {
pspatel321 31:7eaa5e881b56 46 init( txSize, rxSize, rx );
pspatel321 31:7eaa5e881b56 47 }
pspatel321 31:7eaa5e881b56 48
pspatel321 31:7eaa5e881b56 49 MODSERIAL::~MODSERIAL()
pspatel321 31:7eaa5e881b56 50 {
pspatel321 31:7eaa5e881b56 51 disableIrq();
pspatel321 31:7eaa5e881b56 52 if ( buffer[0] != NULL) free((char *)buffer[0] );
pspatel321 31:7eaa5e881b56 53 if ( buffer[1] != NULL) free((char *)buffer[1] );
pspatel321 31:7eaa5e881b56 54 }
pspatel321 31:7eaa5e881b56 55
pspatel321 31:7eaa5e881b56 56 bool
pspatel321 31:7eaa5e881b56 57 MODSERIAL::txBufferFull( void )
pspatel321 31:7eaa5e881b56 58 {
pspatel321 31:7eaa5e881b56 59 return MODSERIAL_TX_BUFFER_FULL;
pspatel321 31:7eaa5e881b56 60 }
pspatel321 31:7eaa5e881b56 61
pspatel321 31:7eaa5e881b56 62 bool
pspatel321 31:7eaa5e881b56 63 MODSERIAL::rxBufferFull( void )
pspatel321 31:7eaa5e881b56 64 {
pspatel321 31:7eaa5e881b56 65 return MODSERIAL_RX_BUFFER_FULL;
pspatel321 31:7eaa5e881b56 66 }
pspatel321 31:7eaa5e881b56 67
pspatel321 31:7eaa5e881b56 68 bool
pspatel321 31:7eaa5e881b56 69 MODSERIAL::txBufferEmpty( void )
pspatel321 31:7eaa5e881b56 70 {
pspatel321 31:7eaa5e881b56 71 return MODSERIAL_TX_BUFFER_EMPTY;
pspatel321 31:7eaa5e881b56 72 }
pspatel321 31:7eaa5e881b56 73
pspatel321 31:7eaa5e881b56 74 bool
pspatel321 31:7eaa5e881b56 75 MODSERIAL::rxBufferEmpty( void )
pspatel321 31:7eaa5e881b56 76 {
pspatel321 31:7eaa5e881b56 77 return MODSERIAL_RX_BUFFER_EMPTY;
pspatel321 31:7eaa5e881b56 78 }
pspatel321 31:7eaa5e881b56 79
pspatel321 31:7eaa5e881b56 80 bool
pspatel321 31:7eaa5e881b56 81 MODSERIAL::txIsBusy( void )
pspatel321 31:7eaa5e881b56 82 {
pspatel321 31:7eaa5e881b56 83 return ( _LSR & ( 3UL << 5 ) == 0 ) ? true : false;
pspatel321 31:7eaa5e881b56 84 }
pspatel321 31:7eaa5e881b56 85
pspatel321 31:7eaa5e881b56 86 void
pspatel321 31:7eaa5e881b56 87 MODSERIAL::disableIrq( void )
pspatel321 31:7eaa5e881b56 88 {
pspatel321 31:7eaa5e881b56 89
pspatel321 31:7eaa5e881b56 90 #ifdef __LPC11UXX_H__
pspatel321 31:7eaa5e881b56 91 NVIC_DisableIRQ( UART_IRQn );
pspatel321 31:7eaa5e881b56 92 #else
pspatel321 31:7eaa5e881b56 93 switch( _serial.index ) {
pspatel321 31:7eaa5e881b56 94 case 0: NVIC_DisableIRQ( UART0_IRQn ); break;
pspatel321 31:7eaa5e881b56 95 case 1: NVIC_DisableIRQ( UART1_IRQn ); break;
pspatel321 31:7eaa5e881b56 96 case 2: NVIC_DisableIRQ( UART2_IRQn ); break;
pspatel321 31:7eaa5e881b56 97 case 3: NVIC_DisableIRQ( UART3_IRQn ); break;
pspatel321 31:7eaa5e881b56 98 }
pspatel321 31:7eaa5e881b56 99 #endif
pspatel321 31:7eaa5e881b56 100 }
pspatel321 31:7eaa5e881b56 101
pspatel321 31:7eaa5e881b56 102 void
pspatel321 31:7eaa5e881b56 103 MODSERIAL::enableIrq(void)
pspatel321 31:7eaa5e881b56 104 {
pspatel321 31:7eaa5e881b56 105 #ifdef __LPC11UXX_H__
pspatel321 31:7eaa5e881b56 106 NVIC_EnableIRQ( UART_IRQn );
pspatel321 31:7eaa5e881b56 107 #else
pspatel321 31:7eaa5e881b56 108 switch( _serial.index ) {
pspatel321 31:7eaa5e881b56 109 case 0: NVIC_EnableIRQ( UART0_IRQn ); break;
pspatel321 31:7eaa5e881b56 110 case 1: NVIC_EnableIRQ( UART1_IRQn ); break;
pspatel321 31:7eaa5e881b56 111 case 2: NVIC_EnableIRQ( UART2_IRQn ); break;
pspatel321 31:7eaa5e881b56 112 case 3: NVIC_EnableIRQ( UART3_IRQn ); break;
pspatel321 31:7eaa5e881b56 113 }
pspatel321 31:7eaa5e881b56 114 #endif
pspatel321 31:7eaa5e881b56 115 }
pspatel321 31:7eaa5e881b56 116
pspatel321 31:7eaa5e881b56 117 int
pspatel321 31:7eaa5e881b56 118 MODSERIAL::rxDiscardLastChar( void )
pspatel321 31:7eaa5e881b56 119 {
pspatel321 31:7eaa5e881b56 120 // This function can only be called indirectly from
pspatel321 31:7eaa5e881b56 121 // an rxCallback function. Therefore, we know we
pspatel321 31:7eaa5e881b56 122 // just placed a char into the buffer.
pspatel321 31:7eaa5e881b56 123 char c = buffer[RxIrq][buffer_in[RxIrq]];
pspatel321 31:7eaa5e881b56 124
pspatel321 31:7eaa5e881b56 125 if (buffer_count[RxIrq]) {
pspatel321 31:7eaa5e881b56 126 buffer_count[RxIrq]--;
pspatel321 31:7eaa5e881b56 127 buffer_in[RxIrq]--;
pspatel321 31:7eaa5e881b56 128 if (buffer_in[RxIrq] < 0) {
pspatel321 31:7eaa5e881b56 129 buffer_in[RxIrq] = buffer_size[RxIrq] - 1;
pspatel321 31:7eaa5e881b56 130 }
pspatel321 31:7eaa5e881b56 131 }
pspatel321 31:7eaa5e881b56 132
pspatel321 31:7eaa5e881b56 133 return (int)c;
pspatel321 31:7eaa5e881b56 134 }
pspatel321 31:7eaa5e881b56 135
pspatel321 31:7eaa5e881b56 136
pspatel321 31:7eaa5e881b56 137 }; // namespace AjK ends