Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
elmbed
Date:
Sun Nov 29 13:52:53 2015 +0000
Revision:
18:affef3a7db2a
Parent:
15:b86c4b798aa1
Device to phone comms working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AntonLS 0:28ca4562fe1a 1 /* Universal Socket Modem Interface Library
AntonLS 0:28ca4562fe1a 2 * Copyright (c) 2013 Multi-Tech Systems
AntonLS 0:28ca4562fe1a 3 *
AntonLS 0:28ca4562fe1a 4 * Licensed under the Apache License, Version 2.0 (the "License");
AntonLS 0:28ca4562fe1a 5 * you may not use this file except in compliance with the License.
AntonLS 0:28ca4562fe1a 6 * You may obtain a copy of the License at
AntonLS 0:28ca4562fe1a 7 *
AntonLS 0:28ca4562fe1a 8 * http://www.apache.org/licenses/LICENSE-2.0
AntonLS 0:28ca4562fe1a 9 *
AntonLS 0:28ca4562fe1a 10 * Unless required by applicable law or agreed to in writing, software
AntonLS 0:28ca4562fe1a 11 * distributed under the License is distributed on an "AS IS" BASIS,
AntonLS 0:28ca4562fe1a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AntonLS 0:28ca4562fe1a 13 * See the License for the specific language governing permissions and
AntonLS 0:28ca4562fe1a 14 * limitations under the License.
AntonLS 0:28ca4562fe1a 15 */
AntonLS 0:28ca4562fe1a 16
AntonLS 0:28ca4562fe1a 17 #include "MTSSerial.h"
AntonLS 0:28ca4562fe1a 18
AntonLS 3:388e441be8df 19 // Added new RTS CTS args. ALS 20150413
AntonLS 3:388e441be8df 20
AntonLS 0:28ca4562fe1a 21 using namespace mts;
AntonLS 0:28ca4562fe1a 22
AntonLS 3:388e441be8df 23 MTSSerial::MTSSerial( PinName TXD, PinName RXD, int txBufferSize, int rxBufferSize,
AntonLS 3:388e441be8df 24 PinName RTS, PinName CTS )
AntonLS 0:28ca4562fe1a 25 : MTSBufferedIO(txBufferSize, rxBufferSize)
AntonLS 3:388e441be8df 26 , serial( TXD, RXD, NULL, RTS, CTS )
AntonLS 0:28ca4562fe1a 27 {
AntonLS 10:72ceef287b0f 28 enableRxIrq();
AntonLS 10:72ceef287b0f 29 // serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq);
AntonLS 10:72ceef287b0f 30 enableTxIrq();
AntonLS 0:28ca4562fe1a 31 //serial.attach(this, &MTSSerial::handleWrite, Serial::TxIrq);
AntonLS 0:28ca4562fe1a 32 }
AntonLS 0:28ca4562fe1a 33
AntonLS 0:28ca4562fe1a 34 MTSSerial::~MTSSerial()
AntonLS 0:28ca4562fe1a 35 {
AntonLS 0:28ca4562fe1a 36
AntonLS 0:28ca4562fe1a 37 }
AntonLS 0:28ca4562fe1a 38
AntonLS 0:28ca4562fe1a 39 void MTSSerial::baud(int baudrate)
AntonLS 0:28ca4562fe1a 40 {
AntonLS 0:28ca4562fe1a 41 serial.baud(baudrate);
AntonLS 0:28ca4562fe1a 42 }
AntonLS 0:28ca4562fe1a 43
AntonLS 0:28ca4562fe1a 44 void MTSSerial::format(int bits, SerialBase::Parity parity, int stop_bits)
AntonLS 0:28ca4562fe1a 45 {
AntonLS 0:28ca4562fe1a 46 serial.format(bits, parity, stop_bits);
AntonLS 0:28ca4562fe1a 47 }
AntonLS 0:28ca4562fe1a 48
elmbed 18:affef3a7db2a 49 //extern DigitalOut led0; // ALS
AntonLS 10:72ceef287b0f 50
AntonLS 0:28ca4562fe1a 51 void MTSSerial::handleRead()
AntonLS 0:28ca4562fe1a 52 {
AntonLS 0:28ca4562fe1a 53 char byte = serial.getc();
AntonLS 0:28ca4562fe1a 54 if(rxBuffer.write(byte) != 1) {
AntonLS 5:1b9734e68327 55 // printf("[ERROR] Serial Rx Byte Dropped [%c][0x%02X]\r\n", byte, byte);
AntonLS 11:d3aa5fca2330 56 printf( " ! " );
AntonLS 0:28ca4562fe1a 57 }
elmbed 18:affef3a7db2a 58 // led0 = !led0; // Toggle LED on char in. ALS
AntonLS 0:28ca4562fe1a 59 }
AntonLS 0:28ca4562fe1a 60
AntonLS 10:72ceef287b0f 61 // Currently uses Non-Irq based blocking write calls -- Now uses TXDRDY IRQ ALS 20150419
AntonLS 0:28ca4562fe1a 62 void MTSSerial::handleWrite()
AntonLS 0:28ca4562fe1a 63 {
AntonLS 10:72ceef287b0f 64 /* while */ if(txBuffer.size() != 0) {
AntonLS 0:28ca4562fe1a 65 if (serial.writeable()) {
AntonLS 0:28ca4562fe1a 66 char byte;
AntonLS 0:28ca4562fe1a 67 if(txBuffer.read(byte) == 1) {
AntonLS 11:d3aa5fca2330 68 //serial.attach(NULL, Serial::RxIrq);
AntonLS 11:d3aa5fca2330 69 disableRxIrq();
AntonLS 0:28ca4562fe1a 70 serial.putc(byte);
AntonLS 11:d3aa5fca2330 71 //serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq);
AntonLS 11:d3aa5fca2330 72 enableRxIrq();
AntonLS 0:28ca4562fe1a 73 }
AntonLS 0:28ca4562fe1a 74 } else {
AntonLS 0:28ca4562fe1a 75 return;
AntonLS 0:28ca4562fe1a 76 }
AntonLS 10:72ceef287b0f 77 } else if( serial.writeable() ) disableTxIrq(); // Prevent needless IRQs, but keep TXDRDY set. ALS
AntonLS 10:72ceef287b0f 78 }
AntonLS 10:72ceef287b0f 79
AntonLS 10:72ceef287b0f 80 // TXDRDY IRQ enable/disable ALS 20150419
AntonLS 10:72ceef287b0f 81 void MTSSerial::disableTxIrq()
AntonLS 10:72ceef287b0f 82 {
AntonLS 10:72ceef287b0f 83 serial.attach( NULL, Serial::TxIrq );
AntonLS 0:28ca4562fe1a 84 }
AntonLS 0:28ca4562fe1a 85
AntonLS 10:72ceef287b0f 86 void MTSSerial::enableTxIrq()
AntonLS 10:72ceef287b0f 87 {
AntonLS 10:72ceef287b0f 88 serial.attach( this, &MTSSerial::handleWrite, Serial::TxIrq );
AntonLS 0:28ca4562fe1a 89
AntonLS 10:72ceef287b0f 90 handleWrite(); // Start the ball rolling if necessary.
AntonLS 10:72ceef287b0f 91 }
AntonLS 10:72ceef287b0f 92
AntonLS 10:72ceef287b0f 93 // RXDRDY IRQ enable/disable ALS 20150420
AntonLS 10:72ceef287b0f 94 void MTSSerial::disableRxIrq()
AntonLS 10:72ceef287b0f 95 {
AntonLS 10:72ceef287b0f 96 serial.attach( NULL, Serial::RxIrq );
AntonLS 10:72ceef287b0f 97 }
AntonLS 10:72ceef287b0f 98
AntonLS 10:72ceef287b0f 99 void MTSSerial::enableRxIrq()
AntonLS 10:72ceef287b0f 100 {
AntonLS 10:72ceef287b0f 101 serial.attach( this, &MTSSerial::handleRead, Serial::RxIrq );
AntonLS 10:72ceef287b0f 102 }
AntonLS 10:72ceef287b0f 103