38 #include <boost/thread.hpp> 61 this->page_ = page & 0xffff;
67 this->page_ = page & 0xffff;
73 this->page_ = (length-1) & 0xffff;
128 if (!readSpiEepromCmd(com, mbx, cmd))
130 ROS_ERROR(
"Error reading SPI Eeprom Cmd busy bit");
140 }
while (tries <= 10);
142 ROS_ERROR(
"Timed out waiting for SPI state machine to be idle (%d)", tries);
158 if (!waitForSpiEepromReady(com, mbx))
166 ROS_ERROR(
"Error writing SPI EEPROM command");
177 if (!readSpiEepromCmd(com, mbx, stat))
193 ROS_WARN(
"Eeprom state machine took %d cycles", tries);
198 fprintf(stderr,
"eeprom busy reading again, waiting...\n");
200 }
while (++tries < 10);
202 ROS_ERROR(
"Eeprom SPI state machine busy after %d cycles", tries);
223 boost::lock_guard<boost::mutex> lock(mutex_);
225 if (length > MAX_EEPROM_PAGE_SIZE)
227 ROS_ERROR(
"Eeprom read length %d > %d", length, MAX_EEPROM_PAGE_SIZE);
231 if (page >= NUM_EEPROM_PAGES)
233 ROS_ERROR(
"Eeprom read page %d > %d", page, NUM_EEPROM_PAGES-1);
240 memset(data,0,length);
243 ROS_ERROR(
"Error zeroing eeprom data buffer");
251 memset(&cmd,0,
sizeof(cmd));
253 if (!sendSpiEepromCmd(com, mbx, cmd))
255 ROS_ERROR(
"Error sending SPI read command");
265 ROS_ERROR(
"Error reading eeprom data from buffer");
289 boost::lock_guard<boost::mutex> lock(mutex_);
293 ROS_ERROR(
"Eeprom write length %d > %d", length, MAX_EEPROM_PAGE_SIZE);
297 if (page >= NUM_EEPROM_PAGES)
299 ROS_ERROR(
"Eeprom write page %d > %d", page, NUM_EEPROM_PAGES-1);
304 if (!waitForSpiEepromReady(com, mbx))
309 const void *write_buf = data;
312 uint8_t buf[MAX_EEPROM_PAGE_SIZE];
313 if (length < MAX_EEPROM_PAGE_SIZE)
315 memcpy(buf, data, length);
316 memset(buf+length, 0xFF, MAX_EEPROM_PAGE_SIZE-length);
323 ROS_ERROR(
"Write of SPI EEPROM buffer failed");
330 if (!sendSpiEepromCmd(com, mbx, cmd))
332 ROS_ERROR(
"Error giving SPI EEPROM write command");
337 if (!waitForEepromReady(com, mbx))
363 if (!readEepromStatusReg(com, mbx, status_reg))
372 }
while (++tries < 20);
376 ROS_ERROR(
"Eeprom still busy after %d cycles", tries);
382 ROS_WARN(
"EEPROM took %d cycles to be ready", tries);
408 unsigned char data[2] = {0xD7, 0x00};
409 BOOST_STATIC_ASSERT(
sizeof(data) == 2);
419 if (!sendSpiEepromCmd(com, mbx, cmd))
421 ROS_ERROR(
"Sending SPI abitrary command");
429 ROS_ERROR(
"Reading status register data from SPI buffer");
459 ROS_ERROR(
"Reading SPI command register with mailbox");
bool waitForEepromReady(EthercatCom *com, WGMailbox *mbx)
Waits for EEPROM to become ready.
bool sendSpiEepromCmd(EthercatCom *com, WGMailbox *mbx, const WG0XSpiEepromCmd &cmd)
Sends command to SPI EEPROM state machine.
static const unsigned SPI_WRITE_OP
bool readSpiEepromCmd(EthercatCom *com, WGMailbox *mbx, WG0XSpiEepromCmd &cmd)
Reads SPI state machine command register.
bool writeEepromPage(EthercatCom *com, WGMailbox *mbx, unsigned page, const void *data, unsigned length)
Write data to single eeprom page.
void build_arbitrary(unsigned length)
int writeMailbox(EthercatCom *com, unsigned address, void const *data, unsigned length)
Write data to WG0X local bus using mailbox communication.
bool readEepromPage(EthercatCom *com, WGMailbox *mbx, unsigned page, void *data, unsigned length)
Read data from single eeprom page.
void build_write(unsigned page)
void build_read(unsigned page)
static const unsigned SPI_ARBITRARY_OP
bool readEepromStatusReg(EthercatCom *com, WGMailbox *mbx, EepromStatusReg ®)
Reads EEPROM status register.
int readMailbox(EthercatCom *com, unsigned address, void *data, unsigned length)
Read data from WG0X local bus using mailbox communication.
union ethercat_hardware::WG0XSpiEepromCmd::@53 __attribute__
static const unsigned SPI_COMMAND_ADDR
bool waitForSpiEepromReady(EthercatCom *com, WGMailbox *mbx)
Waits for SPI eeprom state machine to be idle.
static const unsigned SPI_BUFFER_ADDR
static const unsigned SPI_READ_OP