Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Committer:
AntonLS
Date:
Mon Apr 13 07:23:58 2015 +0000
Revision:
0:28ca4562fe1a
Child:
3:388e441be8df
ARGH

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 0:28ca4562fe1a 19 using namespace mts;
AntonLS 0:28ca4562fe1a 20
AntonLS 0:28ca4562fe1a 21 MTSSerial::MTSSerial(PinName TXD, PinName RXD, int txBufferSize, int rxBufferSize)
AntonLS 0:28ca4562fe1a 22 : MTSBufferedIO(txBufferSize, rxBufferSize)
AntonLS 0:28ca4562fe1a 23 , serial(TXD,RXD)
AntonLS 0:28ca4562fe1a 24 {
AntonLS 0:28ca4562fe1a 25 serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq);
AntonLS 0:28ca4562fe1a 26 //serial.attach(this, &MTSSerial::handleWrite, Serial::TxIrq);
AntonLS 0:28ca4562fe1a 27 }
AntonLS 0:28ca4562fe1a 28
AntonLS 0:28ca4562fe1a 29 MTSSerial::~MTSSerial()
AntonLS 0:28ca4562fe1a 30 {
AntonLS 0:28ca4562fe1a 31
AntonLS 0:28ca4562fe1a 32 }
AntonLS 0:28ca4562fe1a 33
AntonLS 0:28ca4562fe1a 34 void MTSSerial::baud(int baudrate)
AntonLS 0:28ca4562fe1a 35 {
AntonLS 0:28ca4562fe1a 36 serial.baud(baudrate);
AntonLS 0:28ca4562fe1a 37 }
AntonLS 0:28ca4562fe1a 38
AntonLS 0:28ca4562fe1a 39 void MTSSerial::format(int bits, SerialBase::Parity parity, int stop_bits)
AntonLS 0:28ca4562fe1a 40 {
AntonLS 0:28ca4562fe1a 41 serial.format(bits, parity, stop_bits);
AntonLS 0:28ca4562fe1a 42 }
AntonLS 0:28ca4562fe1a 43
AntonLS 0:28ca4562fe1a 44 void MTSSerial::handleRead()
AntonLS 0:28ca4562fe1a 45 {
AntonLS 0:28ca4562fe1a 46 char byte = serial.getc();
AntonLS 0:28ca4562fe1a 47 if(rxBuffer.write(byte) != 1) {
AntonLS 0:28ca4562fe1a 48 printf("[ERROR] Serial Rx Byte Dropped [%c][0x%02X]\r\n", byte, byte);
AntonLS 0:28ca4562fe1a 49 }
AntonLS 0:28ca4562fe1a 50 }
AntonLS 0:28ca4562fe1a 51
AntonLS 0:28ca4562fe1a 52 // Currently uses Non-Irq based blocking write calls
AntonLS 0:28ca4562fe1a 53 void MTSSerial::handleWrite()
AntonLS 0:28ca4562fe1a 54 {
AntonLS 0:28ca4562fe1a 55 while(txBuffer.size() != 0) {
AntonLS 0:28ca4562fe1a 56 if (serial.writeable()) {
AntonLS 0:28ca4562fe1a 57 char byte;
AntonLS 0:28ca4562fe1a 58 if(txBuffer.read(byte) == 1) {
AntonLS 0:28ca4562fe1a 59 serial.attach(NULL, Serial::RxIrq);
AntonLS 0:28ca4562fe1a 60 serial.putc(byte);
AntonLS 0:28ca4562fe1a 61 serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq);
AntonLS 0:28ca4562fe1a 62 }
AntonLS 0:28ca4562fe1a 63 } else {
AntonLS 0:28ca4562fe1a 64 return;
AntonLS 0:28ca4562fe1a 65 }
AntonLS 0:28ca4562fe1a 66 }
AntonLS 0:28ca4562fe1a 67 }
AntonLS 0:28ca4562fe1a 68
AntonLS 0:28ca4562fe1a 69