LineSensTest for Bertl16

Dependencies:   mbed

Fork of B16Test4 by michael hollegha

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Serial_HL.h Source File

Serial_HL.h

00001 
00002 #ifndef Serial_HL_h
00003 #define Serial_HL_h
00004 
00005 #include "platform.h"
00006 // #include "Stream.h"
00007 #include "FunctionPointer.h"
00008 #include "serial_api.h"
00009 #include "SvProtocol.h"
00010 
00011 namespace mbed {
00012 
00013 class SerialBLK : public IStreamHL {
00014     public:
00015         SerialBLK(PinName tx, PinName rx);
00016         void baud(int baudrate);
00017   
00018     virtual void PutChar(int aCh);
00019         virtual int GetChar();
00020         virtual void Write(void* aData, uint32_t aLenBytes);
00021         virtual void Read(void* aData, uint32_t aLenBytes);
00022         
00023         enum Parity {
00024         None = 0,
00025         Odd,
00026         Even,
00027         Forced1,
00028         Forced0
00029         };
00030         enum IrqType {
00031         RxIrq = 0,
00032         TxIrq
00033         };
00034     
00035     void format(int bits=8, Parity parity=SerialBLK::None, int stop_bits=1);
00036         
00037         int readable();
00038         int writeable();
00039         int IsDataAvail()
00040             { return readable(); }
00041         
00042         // fptr A pointer to a void function, or 0 to set as none
00043     // type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
00044     void attach(void (*fptr)(void), IrqType type=RxIrq);
00045         
00046         // tptr pointer to the object to call the member function on
00047     // mptr pointer to the member function to be called
00048     // type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
00049         template<typename T>
00050     void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
00051         if((mptr != NULL) && (tptr != NULL)) {
00052             _irq[type].attach(tptr, mptr);
00053             serial_irq_set(&_serial, (SerialIrq)type, 1);
00054         }
00055     }
00056         
00057         static void _irq_handler(uint32_t id, SerialIrq irq_type);
00058     protected:
00059         serial_t        _serial;
00060     FunctionPointer _irq[2];
00061     int             _baud;
00062 };
00063 
00064 } // namespace mbed
00065 
00066 #endif
00067