Serial Lib for Process-Visualisation with SvVis3

Dependents:   ProcVisDemo1 bluetooth_0110 Ansteuerung_motor_2509 bluetooth_0110 ... more

Committer:
hollegha2
Date:
Thu Apr 07 09:50:12 2016 +0000
Revision:
1:1a03b6d5226f
Parent:
0:b958bdf108cf
V 1.2

Who changed what in which revision?

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