EtherCAT slave that reads 3 Xsens IMU's connected to a Xbus Master
Dependencies: MODSERIAL mbed KL25Z_ClockControl
Fork of EtherCAT by
Diff: soes.cpp
- Revision:
- 20:ad13d4f5fd98
- Parent:
- 19:8ead12aec8d5
- Child:
- 21:6150ca891301
--- a/soes.cpp Fri Mar 06 08:11:15 2015 +0000 +++ b/soes.cpp Fri Mar 06 08:27:52 2015 +0000 @@ -173,38 +173,7 @@ } -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_t *)&xbus_master, (uint8_t)copydata); - if(xbus_master.rx.message_complete && xbus_master.rx.checksum_ok) - { - xbus_master.rx.checksum_ok = 0; - if(xbus_master.rx.buffer[2] == 0x32) - { - copy_new_data = 1; - } - } - - // 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(); - PLOEP; - -} + int main(void) { @@ -235,10 +204,18 @@ // application run loop while (1) { - if(copy_new_data) - { - memcpy(&Rb.first.acc[0],&xbus_master.rx.buffer[4],60); - copy_new_data = 0; + while(xbus_serial.readable()) + { + XbusReceiveState(&xbus_master, xbus_serial.getc()); + if(xbus_master.rx.checksum_ok) + { + if(xbus_master.rx.buffer[2] == 0x32) + { + memcpy(&Rb.first.acc[0],&xbus_master.rx.buffer[4],60); + } + xbus_master.rx.checksum_ok = 0; + PLOEP; + } } ESC_read(ESCREG_LOCALTIME, &ESCvar.Time, sizeof(ESCvar.Time), &ESCvar.ALevent); ESC_ALevent();