EtherCAT slave that reads 3 Xsens IMU's connected to a Xbus Master

Dependencies:   MODSERIAL mbed KL25Z_ClockControl

Fork of EtherCAT by First Last

Revision:
17:c5946a0fde83
Parent:
16:bfc7ea6bd1af
Child:
18:6629e8c5d59e
--- a/soes.cpp	Tue Mar 03 15:01:29 2015 +0000
+++ b/soes.cpp	Thu Mar 05 22:22:47 2015 +0000
@@ -40,6 +40,7 @@
 #include "utypes.h"
 #include "esc.h"
 #include "MODSERIAL.h"
+#include "xbus.h"
 
 /* Private typedef -----------------------------------------------------------*/
 /* Private define ------------------------------------------------------------*/
@@ -63,7 +64,7 @@
 DigitalOut et1100_ss(ET1100_SS);
 DigitalIn  et1100_miso(ET1100_MISO);
 SPI et1100_spi(ET1100_MOSI,ET1100_MISO,ET1100_SCK);
-MODSERIAL xbus(PTA1,PTA2);
+MODSERIAL xbus(PTC4,PTC3);
 struct xbus_struct xbus_master;
 
 /* Private function prototypes -----------------------------------------------*/
@@ -164,6 +165,37 @@
     } 
 }
 
+
+void rxCallback(MODSERIAL_IRQ_INFO *info) {
+ 
+    // Get the pointer to our MODSERIAL object that invoked this callback.
+    MODSERIAL *pc = info->serial;
+    
+    // info->serial points at the MODSERIAL instance so we can use it to call
+    // any of the public MODSERIAL functions that are normally available. So
+    // there's now no need to use the global version (pc in our case) inside
+    // callback functions.    
+    char c = pc->rxGetLastChar(); // Where local pc variable is a pointer to the global MODSERIAL pc object.
+    // The following is rather daft but demos the point.
+    // Don't allow the letter "A" go into the RX buffer.
+    // Basically acts as a filter to remove the letter "A" 
+    // if it goes into the RX buffer.
+    XbusReceiveState(&xbus_master,c);
+        // Note, we call the MODSERIAL_IRQ_INFO::rxDiscardLastChar() public function which
+        // is permitted access to the protected version of MODSERIAL::rxDiscardLastChar()
+        // within MODSERIAL (because they are friends). This ensures rxDiscardLastChar()
+        // can only be called within an rxCallback function. 
+    info->rxDiscardLastChar(); 
+    if(xbus_master.rx.message_complete && xbus_master.rx.checksum_ok)
+    {
+    	xbus_master.rx.checksum_ok = 0;
+    	if(xbus_master.rx.buffer[2] == 0x32)
+    	{
+    		memcpy(&Rb.first.acc[0],&buffer[4],60);
+    	}
+    }
+}
+
 int main(void)
 {
     /*!< At this stage the microcontroller clock setting is already configured,