Function Generator for TINF 2021

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Serial_HL.h Source File

Serial_HL.h

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