Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Tue Apr 21 07:00:55 2015 +0000
Revision:
10:72ceef287b0f
Parent:
5:1b9734e68327
Child:
11:d3aa5fca2330
IRQs and buffers working for serial Tx and Rx.;

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
AntonLS 10:72ceef287b0f 49 extern DigitalOut _led1; // 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 5:1b9734e68327 56 printf( "\r\n! " );
AntonLS 0:28ca4562fe1a 57 }
AntonLS 10:72ceef287b0f 58 _led1 = !_led1; // 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 0:28ca4562fe1a 68 serial.attach(NULL, Serial::RxIrq);
AntonLS 0:28ca4562fe1a 69 serial.putc(byte);
AntonLS 0:28ca4562fe1a 70 serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq);
AntonLS 0:28ca4562fe1a 71 }
AntonLS 0:28ca4562fe1a 72 } else {
AntonLS 0:28ca4562fe1a 73 return;
AntonLS 0:28ca4562fe1a 74 }
AntonLS 10:72ceef287b0f 75 } else if( serial.writeable() ) disableTxIrq(); // Prevent needless IRQs, but keep TXDRDY set. ALS
AntonLS 10:72ceef287b0f 76 }
AntonLS 10:72ceef287b0f 77
AntonLS 10:72ceef287b0f 78 // TXDRDY IRQ enable/disable ALS 20150419
AntonLS 10:72ceef287b0f 79 void MTSSerial::disableTxIrq()
AntonLS 10:72ceef287b0f 80 {
AntonLS 10:72ceef287b0f 81 serial.attach( NULL, Serial::TxIrq );
AntonLS 0:28ca4562fe1a 82 }
AntonLS 0:28ca4562fe1a 83
AntonLS 10:72ceef287b0f 84 void MTSSerial::enableTxIrq()
AntonLS 10:72ceef287b0f 85 {
AntonLS 10:72ceef287b0f 86 serial.attach( this, &MTSSerial::handleWrite, Serial::TxIrq );
AntonLS 0:28ca4562fe1a 87
AntonLS 10:72ceef287b0f 88 handleWrite(); // Start the ball rolling if necessary.
AntonLS 10:72ceef287b0f 89 }
AntonLS 10:72ceef287b0f 90
AntonLS 10:72ceef287b0f 91 // RXDRDY IRQ enable/disable ALS 20150420
AntonLS 10:72ceef287b0f 92 void MTSSerial::disableRxIrq()
AntonLS 10:72ceef287b0f 93 {
AntonLS 10:72ceef287b0f 94 serial.attach( NULL, Serial::RxIrq );
AntonLS 10:72ceef287b0f 95 }
AntonLS 10:72ceef287b0f 96
AntonLS 10:72ceef287b0f 97 void MTSSerial::enableRxIrq()
AntonLS 10:72ceef287b0f 98 {
AntonLS 10:72ceef287b0f 99 serial.attach( this, &MTSSerial::handleRead, Serial::RxIrq );
AntonLS 10:72ceef287b0f 100 }
AntonLS 10:72ceef287b0f 101