Add a bunch of APNs

Fork of C027_Support by Xinlei Cao

Committer:
mazgch
Date:
Wed May 14 09:12:47 2014 +0000
Revision:
70:0a87d256cd24
Parent:
45:ebc2fd8dcf21
Child:
74:208e3e32d263
serial tx isr should now work on all platforms, moved some code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 9:e7a5959ffae1 1 #pragma once
mazgch 9:e7a5959ffae1 2
mazgch 9:e7a5959ffae1 3 #include "SerialPipe.h"
mazgch 9:e7a5959ffae1 4
mazgch 15:5eda64e5b9d1 5 SerialPipe::SerialPipe(PinName tx, PinName rx, int rxSize, int txSize)
mazgch 15:5eda64e5b9d1 6 : _SerialPipeBase(tx,rx), _pipeRx(rxSize), _pipeTx(txSize)
mazgch 9:e7a5959ffae1 7 {
mazgch 9:e7a5959ffae1 8 attach(this, &SerialPipe::rxIrqBuf, RxIrq);
mazgch 9:e7a5959ffae1 9 }
mazgch 9:e7a5959ffae1 10
mazgch 9:e7a5959ffae1 11 SerialPipe::~SerialPipe(void)
mazgch 9:e7a5959ffae1 12 {
mazgch 9:e7a5959ffae1 13 attach(NULL, RxIrq);
mazgch 9:e7a5959ffae1 14 attach(NULL, TxIrq);
mazgch 9:e7a5959ffae1 15 }
mazgch 9:e7a5959ffae1 16
mazgch 9:e7a5959ffae1 17 // tx channel
mazgch 13:e2446fcdc246 18 int SerialPipe::writeable(void)
mazgch 13:e2446fcdc246 19 {
mazgch 13:e2446fcdc246 20 return _pipeTx.free();
mazgch 13:e2446fcdc246 21 }
mazgch 13:e2446fcdc246 22
mazgch 13:e2446fcdc246 23 int SerialPipe::putc(int c)
mazgch 13:e2446fcdc246 24 {
mazgch 15:5eda64e5b9d1 25 c = _pipeTx.putc(c);
mazgch 15:5eda64e5b9d1 26 txStart();
mazgch 15:5eda64e5b9d1 27 return c;
mazgch 13:e2446fcdc246 28 }
mazgch 13:e2446fcdc246 29
mazgch 13:e2446fcdc246 30 int SerialPipe::put(const void* buffer, int length, bool blocking)
mazgch 9:e7a5959ffae1 31 {
mazgch 13:e2446fcdc246 32 int count = length;
mazgch 13:e2446fcdc246 33 const char* ptr = (const char*)buffer;
mazgch 15:5eda64e5b9d1 34 if (count)
mazgch 9:e7a5959ffae1 35 {
mazgch 15:5eda64e5b9d1 36 do
mazgch 15:5eda64e5b9d1 37 {
mazgch 15:5eda64e5b9d1 38 int written = _pipeTx.put(ptr, count, false);
mazgch 15:5eda64e5b9d1 39 ptr += written;
mazgch 15:5eda64e5b9d1 40 count -= written;
mazgch 15:5eda64e5b9d1 41 txStart();
mazgch 15:5eda64e5b9d1 42 }
mazgch 15:5eda64e5b9d1 43 while (count && blocking);
mazgch 9:e7a5959ffae1 44 }
mazgch 13:e2446fcdc246 45 return (length - count);
mazgch 13:e2446fcdc246 46 }
mazgch 13:e2446fcdc246 47
mazgch 70:0a87d256cd24 48 void SerialPipe::txCopy(void)
mazgch 9:e7a5959ffae1 49 {
mazgch 15:5eda64e5b9d1 50 while (_SerialPipeBase::writeable() && _pipeTx.readable())
mazgch 11:b084552b03fe 51 {
mazgch 13:e2446fcdc246 52 char c = _pipeTx.getc();
mazgch 15:5eda64e5b9d1 53 _SerialPipeBase::_base_putc(c);
mazgch 11:b084552b03fe 54 }
mazgch 9:e7a5959ffae1 55 }
mazgch 9:e7a5959ffae1 56
mazgch 70:0a87d256cd24 57 void SerialPipe::txIrqBuf(void)
mazgch 70:0a87d256cd24 58 {
mazgch 70:0a87d256cd24 59 txCopy();
mazgch 70:0a87d256cd24 60 // detach tx isr if we are done
mazgch 70:0a87d256cd24 61 if (!_pipeTx.readable())
mazgch 70:0a87d256cd24 62 attach(NULL, TxIrq);
mazgch 70:0a87d256cd24 63 }
mazgch 70:0a87d256cd24 64
mazgch 13:e2446fcdc246 65 void SerialPipe::txStart(void)
mazgch 13:e2446fcdc246 66 {
mazgch 70:0a87d256cd24 67 // disable the tx isr to avoid interruption
mazgch 70:0a87d256cd24 68 attach(NULL, TxIrq);
mazgch 70:0a87d256cd24 69 txCopy();
mazgch 70:0a87d256cd24 70 // attach the tx isr to handle the remaining data
mazgch 70:0a87d256cd24 71 if (_pipeTx.readable())
mazgch 70:0a87d256cd24 72 attach(this, &SerialPipe::txIrqBuf, TxIrq);
mazgch 13:e2446fcdc246 73 }
mazgch 13:e2446fcdc246 74
mazgch 9:e7a5959ffae1 75 // rx channel
mazgch 9:e7a5959ffae1 76 int SerialPipe::readable(void)
mazgch 9:e7a5959ffae1 77 {
mazgch 9:e7a5959ffae1 78 return _pipeRx.readable();
mazgch 9:e7a5959ffae1 79 }
mazgch 9:e7a5959ffae1 80
mazgch 9:e7a5959ffae1 81 int SerialPipe::getc(void)
mazgch 9:e7a5959ffae1 82 {
mazgch 15:5eda64e5b9d1 83 if (!_pipeRx.readable())
mazgch 15:5eda64e5b9d1 84 return EOF;
mazgch 15:5eda64e5b9d1 85 return _pipeRx.getc();
mazgch 13:e2446fcdc246 86 }
mazgch 13:e2446fcdc246 87
mazgch 13:e2446fcdc246 88 int SerialPipe::get(void* buffer, int length, bool blocking)
mazgch 13:e2446fcdc246 89 {
mazgch 13:e2446fcdc246 90 return _pipeRx.get((char*)buffer,length,blocking);
mazgch 13:e2446fcdc246 91 }
mazgch 13:e2446fcdc246 92
mazgch 9:e7a5959ffae1 93 void SerialPipe::rxIrqBuf(void)
mazgch 9:e7a5959ffae1 94 {
mazgch 15:5eda64e5b9d1 95 while (_SerialPipeBase::readable())
mazgch 9:e7a5959ffae1 96 {
mazgch 15:5eda64e5b9d1 97 char c = _SerialPipeBase::_base_getc();
mazgch 9:e7a5959ffae1 98 if (_pipeRx.writeable())
mazgch 13:e2446fcdc246 99 _pipeRx.putc(c);
mazgch 9:e7a5959ffae1 100 else
mazgch 9:e7a5959ffae1 101 /* overflow */;
mazgch 9:e7a5959ffae1 102 }
mazgch 9:e7a5959ffae1 103 }
mazgch 9:e7a5959ffae1 104