Lab 1 Program C
Fork of mbed by
Diff: Serial.h
- Revision:
- 15:d1a9de3f4fe0
- Parent:
- 11:1c1ebd0324fa
- Child:
- 20:029aa53d7323
diff -r 20a79241b4a0 -r d1a9de3f4fe0 Serial.h --- a/Serial.h Wed Oct 28 17:43:46 2009 +0000 +++ b/Serial.h Mon Nov 16 17:23:08 2009 +0000 @@ -10,6 +10,7 @@ #include "PinNames.h" #include "PeripheralNames.h" #include "Stream.h" +#include "FunctionPointer.h" namespace mbed { @@ -122,6 +123,27 @@ */ int writeable(); + /* Function: attach + * Attach a function to call whenever a serial interrupt is generated + * + * Variables: + * fptr - A pointer to a void function, or 0 to set as none + */ + void attach(void (*fptr)(void)); + + /* Function: attach + * Attach a member function to call whenever a serial interrupt is generated + * + * Variables: + * tptr - pointer to the object to call the member function on + * mptr - pointer to the member function to be called + */ + template<typename T> + void attach(T* tptr, void (T::*mptr)(void)) { + _irq.attach(tptr, mptr); + setup_interrupt(); + } + #ifdef MBED_RPC virtual const struct rpc_method *get_rpc_methods(); static struct rpc_class *get_rpc_class(); @@ -129,10 +151,14 @@ protected: + void setup_interrupt(); + void remove_interrupt(); + virtual int _getc(); virtual int _putc(int c); UARTName _uart; + FunctionPointer _irq; };