michael hollegha
/
LineSensTest_B16
LineSensTest for Bertl16
Fork of B16Test4 by
Serial_HL.h@1:a2c68aba6d98, 2017-12-27 (annotated)
- Committer:
- hollegha3
- Date:
- Wed Dec 27 12:15:27 2017 +0000
- Revision:
- 1:a2c68aba6d98
V 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hollegha3 | 1:a2c68aba6d98 | 1 | |
hollegha3 | 1:a2c68aba6d98 | 2 | #ifndef Serial_HL_h |
hollegha3 | 1:a2c68aba6d98 | 3 | #define Serial_HL_h |
hollegha3 | 1:a2c68aba6d98 | 4 | |
hollegha3 | 1:a2c68aba6d98 | 5 | #include "platform.h" |
hollegha3 | 1:a2c68aba6d98 | 6 | // #include "Stream.h" |
hollegha3 | 1:a2c68aba6d98 | 7 | #include "FunctionPointer.h" |
hollegha3 | 1:a2c68aba6d98 | 8 | #include "serial_api.h" |
hollegha3 | 1:a2c68aba6d98 | 9 | #include "SvProtocol.h" |
hollegha3 | 1:a2c68aba6d98 | 10 | |
hollegha3 | 1:a2c68aba6d98 | 11 | namespace mbed { |
hollegha3 | 1:a2c68aba6d98 | 12 | |
hollegha3 | 1:a2c68aba6d98 | 13 | class SerialBLK : public IStreamHL { |
hollegha3 | 1:a2c68aba6d98 | 14 | public: |
hollegha3 | 1:a2c68aba6d98 | 15 | SerialBLK(PinName tx, PinName rx); |
hollegha3 | 1:a2c68aba6d98 | 16 | void baud(int baudrate); |
hollegha3 | 1:a2c68aba6d98 | 17 | |
hollegha3 | 1:a2c68aba6d98 | 18 | virtual void PutChar(int aCh); |
hollegha3 | 1:a2c68aba6d98 | 19 | virtual int GetChar(); |
hollegha3 | 1:a2c68aba6d98 | 20 | virtual void Write(void* aData, uint32_t aLenBytes); |
hollegha3 | 1:a2c68aba6d98 | 21 | virtual void Read(void* aData, uint32_t aLenBytes); |
hollegha3 | 1:a2c68aba6d98 | 22 | |
hollegha3 | 1:a2c68aba6d98 | 23 | enum Parity { |
hollegha3 | 1:a2c68aba6d98 | 24 | None = 0, |
hollegha3 | 1:a2c68aba6d98 | 25 | Odd, |
hollegha3 | 1:a2c68aba6d98 | 26 | Even, |
hollegha3 | 1:a2c68aba6d98 | 27 | Forced1, |
hollegha3 | 1:a2c68aba6d98 | 28 | Forced0 |
hollegha3 | 1:a2c68aba6d98 | 29 | }; |
hollegha3 | 1:a2c68aba6d98 | 30 | enum IrqType { |
hollegha3 | 1:a2c68aba6d98 | 31 | RxIrq = 0, |
hollegha3 | 1:a2c68aba6d98 | 32 | TxIrq |
hollegha3 | 1:a2c68aba6d98 | 33 | }; |
hollegha3 | 1:a2c68aba6d98 | 34 | |
hollegha3 | 1:a2c68aba6d98 | 35 | void format(int bits=8, Parity parity=SerialBLK::None, int stop_bits=1); |
hollegha3 | 1:a2c68aba6d98 | 36 | |
hollegha3 | 1:a2c68aba6d98 | 37 | int readable(); |
hollegha3 | 1:a2c68aba6d98 | 38 | int writeable(); |
hollegha3 | 1:a2c68aba6d98 | 39 | int IsDataAvail() |
hollegha3 | 1:a2c68aba6d98 | 40 | { return readable(); } |
hollegha3 | 1:a2c68aba6d98 | 41 | |
hollegha3 | 1:a2c68aba6d98 | 42 | // fptr A pointer to a void function, or 0 to set as none |
hollegha3 | 1:a2c68aba6d98 | 43 | // type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) |
hollegha3 | 1:a2c68aba6d98 | 44 | void attach(void (*fptr)(void), IrqType type=RxIrq); |
hollegha3 | 1:a2c68aba6d98 | 45 | |
hollegha3 | 1:a2c68aba6d98 | 46 | // tptr pointer to the object to call the member function on |
hollegha3 | 1:a2c68aba6d98 | 47 | // mptr pointer to the member function to be called |
hollegha3 | 1:a2c68aba6d98 | 48 | // type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) |
hollegha3 | 1:a2c68aba6d98 | 49 | template<typename T> |
hollegha3 | 1:a2c68aba6d98 | 50 | void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { |
hollegha3 | 1:a2c68aba6d98 | 51 | if((mptr != NULL) && (tptr != NULL)) { |
hollegha3 | 1:a2c68aba6d98 | 52 | _irq[type].attach(tptr, mptr); |
hollegha3 | 1:a2c68aba6d98 | 53 | serial_irq_set(&_serial, (SerialIrq)type, 1); |
hollegha3 | 1:a2c68aba6d98 | 54 | } |
hollegha3 | 1:a2c68aba6d98 | 55 | } |
hollegha3 | 1:a2c68aba6d98 | 56 | |
hollegha3 | 1:a2c68aba6d98 | 57 | static void _irq_handler(uint32_t id, SerialIrq irq_type); |
hollegha3 | 1:a2c68aba6d98 | 58 | protected: |
hollegha3 | 1:a2c68aba6d98 | 59 | serial_t _serial; |
hollegha3 | 1:a2c68aba6d98 | 60 | FunctionPointer _irq[2]; |
hollegha3 | 1:a2c68aba6d98 | 61 | int _baud; |
hollegha3 | 1:a2c68aba6d98 | 62 | }; |
hollegha3 | 1:a2c68aba6d98 | 63 | |
hollegha3 | 1:a2c68aba6d98 | 64 | } // namespace mbed |
hollegha3 | 1:a2c68aba6d98 | 65 | |
hollegha3 | 1:a2c68aba6d98 | 66 | #endif |
hollegha3 | 1:a2c68aba6d98 | 67 |