Add attach

Fork of SerialHalfDuplex by Aimen Al-Refai

Files at this revision

API Documentation at this revision

Comitter:
yusuke_kyo
Date:
Sun May 03 16:17:06 2015 +0000
Parent:
2:5ecc72a47df0
Commit message:
add attach

Changed in this revision

SerialHalfDuplex.cpp Show annotated file Show diff for this revision Revisions of this file
SerialHalfDuplex.h Show annotated file Show diff for this revision Revisions of this file
diff -r 5ecc72a47df0 -r a5021aaf31d9 SerialHalfDuplex.cpp
--- a/SerialHalfDuplex.cpp	Tue Apr 01 06:50:02 2014 +0000
+++ b/SerialHalfDuplex.cpp	Sun May 03 16:17:06 2015 +0000
@@ -28,6 +28,10 @@
 #include "pinmap.h"
 #include "serial_api.h"
 #include "gpio_api.h"
+
+#include "mbed.h"
+
+DigitalOut led4(LED4);
  
 namespace mbed {
  
@@ -49,11 +53,25 @@
 //    transmit has occurred, and also clears the byte from the buffer.
 // 5. Return pin to input mode
 // 6. Re-enable interrupts
- 
+
+Timeout en;
+
+void SerialHalfDuplex::enable(){
+//    printf("timeout enable/n");
+    __enable_irq();
+//    led4 = 1;
+//    wait(0.5);
+//    led4 = 0;
+}
+
 int SerialHalfDuplex::_putc(int c) {
+
     int retc;
     
+    en.attach(this, &SerialHalfDuplex::enable, 1.0);
+    
     // TODO: We should not disable all interrupts
+//    printf("disable_irq/n");
     __disable_irq();
     
     serial_pinout_tx(_txpin);
@@ -61,10 +79,12 @@
     Serial::_putc(c);
     retc = Serial::getc();       // reading also clears any interrupt
     
+
     pin_function(_txpin, 0);
     
     __enable_irq();
-    
+//    printf("enable/n");
+        
     return retc;
 }
  
diff -r 5ecc72a47df0 -r a5021aaf31d9 SerialHalfDuplex.h
--- a/SerialHalfDuplex.h	Tue Apr 01 06:50:02 2014 +0000
+++ b/SerialHalfDuplex.h	Sun May 03 16:17:06 2015 +0000
@@ -115,8 +115,7 @@
 Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None)
      *  stop - The number of stop bits (1 or 2; default = 1)
      */
-    void format(int bits = 8, Parity parity = Serial::None, int stop_bits 
-= 1);
+    void format(int bits = 8, Parity parity = Serial::None, int stop_bits = 1);
  
     /* Function: putc
      *  Write a character
@@ -189,7 +188,8 @@
      */
     template<typename T>
     void attach(T* tptr, void (T::*mptr)(void));
- 
+
+
 #endif
  
 protected:
@@ -197,6 +197,8 @@
  
     virtual int _putc(int c);
     virtual int _getc(void);
+    
+    void enable(void);
  
 }; // End class SerialHalfDuplex