26 #define MODE_READBIN 1 27 #define MODE_READINTEL 2 28 #define MODE_WRITEBIN 3 29 #define MODE_WRITEINTEL 4 31 #define MAXSLENGTH 256 43 #define IHEXLENGTH 0x20 51 fp = fopen(fname,
"rb");
54 while (((c = fgetc(fp)) != EOF) && (cc <
MAXBUF))
66 int c, sc, retval = 1;
67 int ll, ladr, lt, sn, i, lval;
68 int hstart, hlength, sum;
70 fp = fopen(fname,
"r");
80 while (((c = fgetc(fp)) != EOF) && (c != 0x0A) && (sc < (
MAXSLENGTH -1)))
82 if ((c != EOF) && ((sc < 11) || (
sline[0] !=
':')))
86 printf(
"Invalid Intel Hex format.\n");
90 sn = sscanf(
sline ,
":%2x%4x%2x", &ll, &ladr, <);
91 if ((sn == 3) && ((ladr + ll) <=
MAXBUF) && (lt == 0))
93 sum = ll + (ladr >> 8) + (ladr & 0xff) + lt;
94 if(ladr < hstart) hstart = ladr;
95 for(i = 0; i < ll ; i++)
97 sn = sscanf(&
sline[9 + (i << 1)],
"%2x", &lval);
101 if(((ladr + ll) - hstart) > hlength)
102 hlength = (ladr + ll) - hstart;
103 sum = (0x100 - sum) & 0xff;
104 sn = sscanf(&
sline[9 + (i << 1)],
"%2x", &lval);
105 if (!sn || ((sum - lval) != 0))
109 printf(
"Invalid checksum.\n");
131 fp = fopen(fname,
"wb");
134 for (cc = 0 ; cc < length ; cc++)
135 fputc(
ebuf[cc], fp);
145 int cc = 0, ll, sum, i;
147 fp = fopen(fname,
"w");
154 sum = ll + (cc >> 8) + (cc & 0xff);
155 fprintf(fp,
":%2.2X%4.4X00", ll, cc);
156 for (i = 0; i < ll; i++)
158 fprintf(fp,
"%2.2X",
ebuf[cc + i]);
161 fprintf(fp,
"%2.2X\n", (0x100 - sum) & 0xff);
164 fprintf(fp,
":00000001FF\n");
189 estat =
etohs(estat);
193 for (i = start ; i < (start + length) ; i+=
ainc)
208 for (i = start ; i < (start + length) ; i+=
ainc)
241 for (i = start ; i < (start + length) ; i+=2)
260 int w, rc = 0, estart, esize;
266 printf(
"ec_init on %s succeeded.\n",ifname);
283 printf(
"Slave %d data\n", slave);
284 printf(
" PDI Control : %4.4X\n",*(wbuf + 0x00));
285 printf(
" PDI Config : %4.4X\n",*(wbuf + 0x01));
286 printf(
" Config Alias : %4.4X\n",*(wbuf + 0x04));
287 printf(
" Checksum : %4.4X\n",*(wbuf + 0x07));
288 printf(
" Vendor ID : %8.8X\n",*(
uint32 *)(wbuf + 0x08));
289 printf(
" Product Code : %8.8X\n",*(
uint32 *)(wbuf + 0x0A));
290 printf(
" Revision Number : %8.8X\n",*(
uint32 *)(wbuf + 0x0C));
291 printf(
" Serial Number : %8.8X\n",*(
uint32 *)(wbuf + 0x0E));
292 printf(
" Mailbox Protocol : %4.4X\n",*(wbuf + 0x1C));
293 esize = (*(wbuf + 0x3E) + 1) * 128;
295 printf(
" Size : %4.4X = %d bytes\n",*(wbuf + 0x3E), esize);
296 printf(
" Version : %4.4X\n",*(wbuf + 0x3F));
306 printf(
"\nTotal EEPROM read time :%ldms\n", (tdif.
usec+(tdif.
sec*1000000L)) / 1000);
317 printf(
"Slave %d\n", slave);
318 printf(
" Vendor ID : %8.8X\n",*(
uint32 *)(wbuf + 0x08));
319 printf(
" Product Code : %8.8X\n",*(
uint32 *)(wbuf + 0x0A));
320 printf(
" Revision Number : %8.8X\n",*(
uint32 *)(wbuf + 0x0C));
321 printf(
" Serial Number : %8.8X\n",*(
uint32 *)(wbuf + 0x0E));
330 printf(
"\nTotal EEPROM write time :%ldms\n", (tdif.
usec+(tdif.
sec*1000000L)) / 1000);
333 printf(
"Error reading file, abort.\n");
337 printf(
"Slave number outside range.\n");
340 printf(
"No slaves found!\n");
341 printf(
"End, close socket\n");
346 printf(
"No socket connection on %s\nExcecute as root\n",ifname);
349 int main(
int argc,
char *argv[])
352 printf(
"SOEM (Simple Open EtherCAT Master)\nEEPROM tool\n");
356 slave = atoi(argv[2]);
368 printf(
"Usage: eepromtool ifname slave OPTION fname\n");
369 printf(
"ifname = adapter name\n");
370 printf(
"slave = slave number in EtherCAT order 1..n\n");
371 printf(
" -r read EEPROM, output binary format\n");
372 printf(
" -ri read EEPROM, output Intel Hex format\n");
373 printf(
" -w write EEPROM, input binary format\n");
374 printf(
" -wi write EEPROM, input Intel Hex format\n");
376 printf (
"Available adapters\n");
378 while (adapter != NULL)
380 printf (
"Description : %s, Device to use for wpcap: %s\n", adapter->
desc,adapter->
name);
381 adapter = adapter->
next;
385 printf(
"End program\n");
int ec_writeeepromAP(uint16 aiadr, uint16 eeproma, uint16 data, int timeout)
int ec_APWR(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout)
int ec_APRD(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout)
char name[EC_MAXLEN_ADAPTERNAME]
Headerfile for all ethercat headers.
int ec_init(const char *ifname)
char desc[EC_MAXLEN_ADAPTERNAME]
ec_timet osal_current_time(void)
int ec_BRD(uint16 ADP, uint16 ADO, uint16 length, void *data, int timeout)
void osal_time_diff(ec_timet *start, ec_timet *end, ec_timet *diff)
uint64 ec_readeepromAP(uint16 aiadr, uint16 eeproma, int timeout)
ec_adaptert * ec_find_adapters(void)