Add a bunch of APNs

Fork of C027_Support by Xinlei Cao

Committer:
mazgch
Date:
Mon May 05 15:42:49 2014 +0000
Revision:
45:ebc2fd8dcf21
Parent:
35:9275215a3a5b
Child:
70:0a87d256cd24
make more portable to other cpus

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 45:ebc2fd8dcf21 9 #if defined(TARGET_UBLOX_C027) || defined(TARGET_LPC1768)
mazgch 45:ebc2fd8dcf21 10 // the lpc1768 supports interrupt driven tx
mazgch 9:e7a5959ffae1 11 attach(this, &SerialPipe::txIrqBuf, TxIrq);
mazgch 45:ebc2fd8dcf21 12 #endif
mazgch 9:e7a5959ffae1 13 }
mazgch 9:e7a5959ffae1 14
mazgch 9:e7a5959ffae1 15 SerialPipe::~SerialPipe(void)
mazgch 9:e7a5959ffae1 16 {
mazgch 9:e7a5959ffae1 17 attach(NULL, RxIrq);
mazgch 45:ebc2fd8dcf21 18 #if defined(TARGET_UBLOX_C027) || defined(TARGET_LPC1768)
mazgch 9:e7a5959ffae1 19 attach(NULL, TxIrq);
mazgch 45:ebc2fd8dcf21 20 #endif
mazgch 9:e7a5959ffae1 21 }
mazgch 9:e7a5959ffae1 22
mazgch 9:e7a5959ffae1 23 // tx channel
mazgch 13:e2446fcdc246 24 int SerialPipe::writeable(void)
mazgch 13:e2446fcdc246 25 {
mazgch 13:e2446fcdc246 26 return _pipeTx.free();
mazgch 13:e2446fcdc246 27 }
mazgch 13:e2446fcdc246 28
mazgch 13:e2446fcdc246 29 int SerialPipe::putc(int c)
mazgch 13:e2446fcdc246 30 {
mazgch 15:5eda64e5b9d1 31 c = _pipeTx.putc(c);
mazgch 15:5eda64e5b9d1 32 txStart();
mazgch 15:5eda64e5b9d1 33 return c;
mazgch 13:e2446fcdc246 34 }
mazgch 13:e2446fcdc246 35
mazgch 13:e2446fcdc246 36 int SerialPipe::put(const void* buffer, int length, bool blocking)
mazgch 9:e7a5959ffae1 37 {
mazgch 13:e2446fcdc246 38 int count = length;
mazgch 13:e2446fcdc246 39 const char* ptr = (const char*)buffer;
mazgch 15:5eda64e5b9d1 40 if (count)
mazgch 9:e7a5959ffae1 41 {
mazgch 15:5eda64e5b9d1 42 do
mazgch 15:5eda64e5b9d1 43 {
mazgch 15:5eda64e5b9d1 44 int written = _pipeTx.put(ptr, count, false);
mazgch 15:5eda64e5b9d1 45 ptr += written;
mazgch 15:5eda64e5b9d1 46 count -= written;
mazgch 15:5eda64e5b9d1 47 txStart();
mazgch 15:5eda64e5b9d1 48 }
mazgch 15:5eda64e5b9d1 49 while (count && blocking);
mazgch 9:e7a5959ffae1 50 }
mazgch 13:e2446fcdc246 51 return (length - count);
mazgch 13:e2446fcdc246 52 }
mazgch 13:e2446fcdc246 53
mazgch 9:e7a5959ffae1 54 void SerialPipe::txIrqBuf(void)
mazgch 9:e7a5959ffae1 55 {
mazgch 15:5eda64e5b9d1 56 while (_SerialPipeBase::writeable() && _pipeTx.readable())
mazgch 11:b084552b03fe 57 {
mazgch 13:e2446fcdc246 58 char c = _pipeTx.getc();
mazgch 15:5eda64e5b9d1 59 _SerialPipeBase::_base_putc(c);
mazgch 11:b084552b03fe 60 }
mazgch 9:e7a5959ffae1 61 }
mazgch 9:e7a5959ffae1 62
mazgch 13:e2446fcdc246 63 void SerialPipe::txStart(void)
mazgch 13:e2446fcdc246 64 {
mazgch 45:ebc2fd8dcf21 65 #if defined(TARGET_UBLOX_C027) || defined(TARGET_LPC1768)
mazgch 13:e2446fcdc246 66 __disable_irq();
mazgch 13:e2446fcdc246 67 txIrqBuf();
mazgch 13:e2446fcdc246 68 __enable_irq();
mazgch 45:ebc2fd8dcf21 69 #else
mazgch 45:ebc2fd8dcf21 70 while (_pipeTx.readable())
mazgch 45:ebc2fd8dcf21 71 {
mazgch 45:ebc2fd8dcf21 72 char c = _pipeTx.getc();
mazgch 45:ebc2fd8dcf21 73 while (!_SerialPipeBase::writeable())
mazgch 45:ebc2fd8dcf21 74 /*wait*/;
mazgch 45:ebc2fd8dcf21 75 _SerialPipeBase::_base_putc(c);
mazgch 45:ebc2fd8dcf21 76 }
mazgch 45:ebc2fd8dcf21 77 #endif
mazgch 13:e2446fcdc246 78 }
mazgch 13:e2446fcdc246 79
mazgch 9:e7a5959ffae1 80 // rx channel
mazgch 9:e7a5959ffae1 81 int SerialPipe::readable(void)
mazgch 9:e7a5959ffae1 82 {
mazgch 9:e7a5959ffae1 83 return _pipeRx.readable();
mazgch 9:e7a5959ffae1 84 }
mazgch 9:e7a5959ffae1 85
mazgch 9:e7a5959ffae1 86 int SerialPipe::getc(void)
mazgch 9:e7a5959ffae1 87 {
mazgch 15:5eda64e5b9d1 88 if (!_pipeRx.readable())
mazgch 15:5eda64e5b9d1 89 return EOF;
mazgch 15:5eda64e5b9d1 90 return _pipeRx.getc();
mazgch 13:e2446fcdc246 91 }
mazgch 13:e2446fcdc246 92
mazgch 13:e2446fcdc246 93 int SerialPipe::get(void* buffer, int length, bool blocking)
mazgch 13:e2446fcdc246 94 {
mazgch 13:e2446fcdc246 95 return _pipeRx.get((char*)buffer,length,blocking);
mazgch 13:e2446fcdc246 96 }
mazgch 13:e2446fcdc246 97
mazgch 9:e7a5959ffae1 98 void SerialPipe::rxIrqBuf(void)
mazgch 9:e7a5959ffae1 99 {
mazgch 15:5eda64e5b9d1 100 while (_SerialPipeBase::readable())
mazgch 9:e7a5959ffae1 101 {
mazgch 15:5eda64e5b9d1 102 char c = _SerialPipeBase::_base_getc();
mazgch 9:e7a5959ffae1 103 if (_pipeRx.writeable())
mazgch 13:e2446fcdc246 104 _pipeRx.putc(c);
mazgch 9:e7a5959ffae1 105 else
mazgch 9:e7a5959ffae1 106 /* overflow */;
mazgch 9:e7a5959ffae1 107 }
mazgch 9:e7a5959ffae1 108 }
mazgch 9:e7a5959ffae1 109