Add a bunch of APNs
Fork of C027_Support by
SerialPipe.h@93:2b5478693c20, 2014-06-12 (annotated)
- Committer:
- mazgch
- Date:
- Thu Jun 12 07:17:38 2014 +0000
- Revision:
- 93:2b5478693c20
- Parent:
- 70:0a87d256cd24
make destructor virtual (base class has changed)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mazgch | 0:cb2d45baaca3 | 1 | #pragma once |
mazgch | 0:cb2d45baaca3 | 2 | |
mazgch | 2:b6012cd91657 | 3 | #include "mbed.h" |
mazgch | 0:cb2d45baaca3 | 4 | #include "Pipe.h" |
mazgch | 0:cb2d45baaca3 | 5 | |
mazgch | 42:6786401ba18c | 6 | #define _SerialPipeBase SerialBase //!< base class used by this class |
mazgch | 15:5eda64e5b9d1 | 7 | |
mazgch | 42:6786401ba18c | 8 | /** Buffered serial interface (rtos capable/interrupt driven) |
mazgch | 42:6786401ba18c | 9 | */ |
mazgch | 15:5eda64e5b9d1 | 10 | class SerialPipe : public _SerialPipeBase |
mazgch | 0:cb2d45baaca3 | 11 | { |
mazgch | 9:e7a5959ffae1 | 12 | public: |
mazgch | 42:6786401ba18c | 13 | /** Constructor |
mazgch | 42:6786401ba18c | 14 | \param tx the trasmitting pin |
mazgch | 42:6786401ba18c | 15 | \param rx the receiving pin |
mazgch | 42:6786401ba18c | 16 | \param rxSize the size of the receiving buffer |
mazgch | 42:6786401ba18c | 17 | \param txSize the size of the transmitting buffer |
mazgch | 42:6786401ba18c | 18 | */ |
mazgch | 15:5eda64e5b9d1 | 19 | SerialPipe(PinName tx, PinName rx, int rxSize = 128, int txSize = 128); |
mazgch | 42:6786401ba18c | 20 | |
mazgch | 42:6786401ba18c | 21 | /** Destructor |
mazgch | 42:6786401ba18c | 22 | */ |
mazgch | 93:2b5478693c20 | 23 | virtual ~SerialPipe(void); |
mazgch | 42:6786401ba18c | 24 | |
mazgch | 9:e7a5959ffae1 | 25 | // tx channel |
mazgch | 42:6786401ba18c | 26 | //---------------------------------------------------- |
mazgch | 42:6786401ba18c | 27 | |
mazgch | 42:6786401ba18c | 28 | /** check if writable |
mazgch | 42:6786401ba18c | 29 | return the number of free bytes |
mazgch | 42:6786401ba18c | 30 | */ |
mazgch | 13:e2446fcdc246 | 31 | int writeable(void); |
mazgch | 42:6786401ba18c | 32 | |
mazgch | 42:6786401ba18c | 33 | /** send a character (blocking) |
mazgch | 42:6786401ba18c | 34 | \param c the character to send |
mazgch | 42:6786401ba18c | 35 | \return c |
mazgch | 42:6786401ba18c | 36 | */ |
mazgch | 42:6786401ba18c | 37 | int putc(int c); |
mazgch | 42:6786401ba18c | 38 | |
mazgch | 42:6786401ba18c | 39 | /** send a buffer |
mazgch | 42:6786401ba18c | 40 | \param buffer the buffer to send |
mazgch | 42:6786401ba18c | 41 | \param length the size of the buffer to send |
mazgch | 42:6786401ba18c | 42 | \param blocking, if true this function will block |
mazgch | 42:6786401ba18c | 43 | until all bytes placed in the buffer. |
mazgch | 42:6786401ba18c | 44 | \return the number of bytes written |
mazgch | 42:6786401ba18c | 45 | */ |
mazgch | 15:5eda64e5b9d1 | 46 | int put(const void* buffer, int length, bool blocking); |
mazgch | 42:6786401ba18c | 47 | |
mazgch | 9:e7a5959ffae1 | 48 | // rx channel |
mazgch | 42:6786401ba18c | 49 | //---------------------------------------------------- |
mazgch | 42:6786401ba18c | 50 | |
mazgch | 42:6786401ba18c | 51 | /** check if readable |
mazgch | 42:6786401ba18c | 52 | \return the size available in the buffer. |
mazgch | 42:6786401ba18c | 53 | */ |
mazgch | 9:e7a5959ffae1 | 54 | int readable(void); |
mazgch | 42:6786401ba18c | 55 | |
mazgch | 42:6786401ba18c | 56 | /** receive one character from the serial port (blocking) |
mazgch | 42:6786401ba18c | 57 | \param the character received |
mazgch | 42:6786401ba18c | 58 | */ |
mazgch | 42:6786401ba18c | 59 | int getc(void); |
mazgch | 42:6786401ba18c | 60 | |
mazgch | 42:6786401ba18c | 61 | /** read a buffer from the serial port |
mazgch | 42:6786401ba18c | 62 | \param pointer to the buffer to read. |
mazgch | 42:6786401ba18c | 63 | \param length number of bytes to read |
mazgch | 42:6786401ba18c | 64 | \param blocking true if all bytes shall be read. false if only the available bytes. |
mazgch | 42:6786401ba18c | 65 | \return the number of bytes read. |
mazgch | 42:6786401ba18c | 66 | */ |
mazgch | 15:5eda64e5b9d1 | 67 | int get(void* buffer, int length, bool blocking); |
mazgch | 42:6786401ba18c | 68 | |
mazgch | 13:e2446fcdc246 | 69 | protected: |
mazgch | 42:6786401ba18c | 70 | //! receive interrupt routine |
mazgch | 9:e7a5959ffae1 | 71 | void rxIrqBuf(void); |
mazgch | 42:6786401ba18c | 72 | //! transmit interrupt woutine |
mazgch | 9:e7a5959ffae1 | 73 | void txIrqBuf(void); |
mazgch | 42:6786401ba18c | 74 | //! start transmission helper |
mazgch | 13:e2446fcdc246 | 75 | void txStart(void); |
mazgch | 70:0a87d256cd24 | 76 | //! move bytes to hardware |
mazgch | 70:0a87d256cd24 | 77 | void txCopy(void); |
mazgch | 42:6786401ba18c | 78 | Pipe<char> _pipeRx; //!< receive pipe |
mazgch | 42:6786401ba18c | 79 | Pipe<char> _pipeTx; //!< transmit pipe |
mazgch | 9:e7a5959ffae1 | 80 | }; |