MbxIn = NULL;
MbxOut = NULL;
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, 0);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, 0);
MbxOut = ecx_getmbx(context);
if(!MbxOut) return wkc;
ec_clearmbx(MbxOut);
MbxIn = NULL;
do
{
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, timeout);
- } while ((wkc > 0) && !MbxIn);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
+ } while ((wkc > 0) && !MbxIn);
aSDOp = (ec_SDOt *)MbxIn;
if ((wkc > 0) && MbxIn) /* succeeded to read slave response ? */
{
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
aSDOp = (ec_SDOt *)MbxIn;
/* has slave responded ? */
if (wkc > 0)
MbxIn = NULL;
MbxOut = NULL;
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, 0);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, 0);
MbxOut = ecx_getmbx(context);
if(!MbxOut) return wkc;
ec_clearmbx(MbxOut);
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, Timeout);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, Timeout);
if (wkc > 0)
{
aSDOp = (ec_SDOt *)MbxIn;
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, Timeout);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, Timeout);
if (wkc > 0)
{
aSDOp = (ec_SDOt *)MbxIn;
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, Timeout);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, Timeout);
if (wkc > 0)
{
aSDOp = (ec_SDOt *)MbxIn;
MbxIn = NULL;
MbxOut = NULL;
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, 0);
- if (MbxIn) ecx_dropmbx(context, MbxIn);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, 0);
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
MbxOut = ecx_getmbx(context);
if(!MbxOut) return wkc;
ec_clearmbx(MbxOut);
MbxIn = NULL;
MbxOut = NULL;
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, 0);
- if (MbxIn) ecx_dropmbx(context, MbxIn);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, 0);
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
MbxOut = ecx_getmbx(context);
if(!MbxOut) return wkc;
ec_clearmbx(MbxOut);
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
if (wkc > 0) /* succeeded to read slave response ? */
{
aSDOp = (ec_SDOt *)MbxIn;
MbxIn = NULL;
MbxOut = NULL;
/* Empty slave out mailbox if something is in. Timout set to 0 */
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, 0);
- if (MbxIn) ecx_dropmbx(context, MbxIn);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, 0);
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
MbxOut = ecx_getmbx(context);
if(!MbxOut) return wkc;
ec_clearmbx(MbxOut);
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, EC_TIMEOUTRXM);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, EC_TIMEOUTRXM);
/* got response ? */
if (wkc > 0)
{
MbxIn = NULL;
MbxOut = NULL;
/* Empty slave out mailbox if something is in. Timout set to 0 */
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, 0);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, 0);
if (MbxIn) ecx_dropmbx(context, MbxIn);
MbxOut = ecx_getmbx(context);
if(!MbxOut) return wkc;
/* mailbox placed in slave ? */
if (wkc > 0)
{
- if (MbxIn) ecx_dropmbx(context, MbxIn);
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, EC_TIMEOUTRXM);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, EC_TIMEOUTRXM);
/* got response ? */
if (wkc > 0)
{
MbxIn = NULL;
MbxOut = NULL;
/* Empty slave out mailbox if something is in. Timout set to 0 */
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, 0);
- if (MbxIn) ecx_dropmbx(context, MbxIn);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, 0);
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
MbxOut = ecx_getmbx(context);
if(!MbxOut) return wkc;
ec_clearmbx(MbxOut);
/* mailbox placed in slave ? */
if (wkc > 0)
{
- if (MbxIn) ecx_dropmbx(context, MbxIn);
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, Slave, &MbxIn, EC_TIMEOUTRXM);
+ wkc = ecx_mbxreceive(context, Slave, &MbxIn, EC_TIMEOUTRXM);
/* got response ? */
if (wkc > 0)
{
position = etohl(context->slavelist[slave].FMMU[FMMUc].LogStart);
context->slavelist[slave].mbxstatus = (uint8 *)(pIOmap) + position;
- position -= context->grouplist[group].Obytes + context->grouplist[group].Ibytes;
- context->grouplist[group].mbxstatuslookup[position] = slave;
+ context->grouplist[group].mbxstatuslookup[context->grouplist[group].mbxstatuslength] = slave;
context->grouplist[group].mbxstatuslength++;
FMMUc++;
/* account for MBXSTATUS wkc increment */
if (segmentsize && diff)
context->grouplist[group].inputsWKC++;
}
-
- ecx_eeprom2pdi(context, slave); /* set Eeprom control to PDI */
- /* User may override automatic state change */
- if (context->manualstatechange == 0)
- {
- /* request safe_op for slave */
- ecx_FPWRw(context->port,
- configadr,
- ECT_REG_ALCTL,
- htoes(EC_STATE_SAFE_OP),
- EC_TIMEOUTRET3); /* set safeop status */
- }
- if (context->slavelist[slave].blockLRW)
- {
- context->grouplist[group].blockLRW++;
- }
- context->grouplist[group].Ebuscurrent += context->slavelist[slave].Ebuscurrent;
}
}
if (BitPos)
context->grouplist[group].nsegments = currentsegment + 1;
context->grouplist[group].inputs = (uint8 *)(pIOmap) + context->grouplist[group].Obytes;
context->grouplist[group].Ibytes = LogAddr -
- context->grouplist[group].logstartaddr -
- context->grouplist[group].Obytes;
+ context->grouplist[group].logstartaddr -
+ context->grouplist[group].Obytes;
/* do mbxstatus mapping of slave and program FMMUs */
for (slave = 1; slave <= *(context->slavecount); slave++)
{
segmentsize += diff;
}
- ecx_eeprom2pdi(context, slave); /* set Eeprom control to PDI */
- ecx_FPWRw(context->port, configadr, ECT_REG_ALCTL, htoes(EC_STATE_SAFE_OP) , EC_TIMEOUTRET3); /* set safeop status */
- if (context->slavelist[slave].blockLRW)
- {
- context->grouplist[group].blockLRW++;
- }
- context->grouplist[group].Ebuscurrent += context->slavelist[slave].Ebuscurrent;
}
}
context->slavelist[0].mbxstatus = (uint8 *)(pIOmap) + context->slavelist[0].Obytes + context->slavelist[0].Ibytes;
}
- EC_PRINT("IOmapSize %d\n", LogAddr - context->grouplist[group].logstartaddr);
- return (LogAddr - context->grouplist[group].logstartaddr);
+ /* Do post mapping actions */
+ for (slave = 1; slave <= *(context->slavecount); slave++)
+ {
+ configadr = context->slavelist[slave].configadr;
+ if (!group || (group == context->slavelist[slave].group))
+ {
+ /* set Eeprom control to PDI */
+ ecx_eeprom2pdi(context, slave);
+ /* User may override automatic state change */
+ if (context->manualstatechange == 0)
+ {
+ /* request safe_op for slave */
+ ecx_FPWRw(context->port,
+ configadr,
+ ECT_REG_ALCTL,
+ htoes(EC_STATE_SAFE_OP),
+ EC_TIMEOUTRET3);
+ }
+
+ /* Store slave properties*/
+ if (context->slavelist[slave].blockLRW)
+ {
+ context->grouplist[group].blockLRW++;
+ }
+ context->grouplist[group].Ebuscurrent += context->slavelist[slave].Ebuscurrent;
+ }
+ }
+
+ EC_PRINT("IOmapSize %d\n", context->grouplist[group].Obytes +
+ context->grouplist[group].Ibytes +
+ context->grouplist[group].mbxstatuslength);
+
+ return (context->grouplist[group].Obytes +
+ context->grouplist[group].Ibytes) +
+ context->grouplist[group].mbxstatuslength;
}
return 0;
context->grouplist[group].inputsWKC += (siLength > 0);
context->grouplist[group].outputsWKC += (soLength > 0);
}
-
- ecx_eeprom2pdi(context, slave); /* set Eeprom control to PDI */
- /* User may override automatic state change */
- if (context->manualstatechange == 0)
- {
- /* request safe_op for slave */
- ecx_FPWRw(context->port,
- configadr,
- ECT_REG_ALCTL,
- htoes(EC_STATE_SAFE_OP),
- EC_TIMEOUTRET3);
- }
- if (context->slavelist[slave].blockLRW)
- {
- context->grouplist[group].blockLRW++;
- }
- context->grouplist[group].Ebuscurrent += context->slavelist[slave].Ebuscurrent;
-
}
}
+ /* Update segment info */
context->grouplist[group].IOsegment[currentsegment] = segmentsize;
context->grouplist[group].nsegments = currentsegment + 1;
context->grouplist[group].Isegment = 0;
context->grouplist[group].mbxstatus = (uint8 *)pIOmap + context->grouplist[group].Obytes + context->grouplist[group].Ibytes;
- /* Move calculated inputs with OBytes offset*/
+ /* Move calculated inputs with OBytes offset */
for (slave = 1; slave <= *(context->slavecount); slave++)
{
if (!group || (group == context->slavelist[slave].group))
}
}
+ /* Do mbxstatus mapping of slave and program FMMUs */
+ for (slave = 1; slave <= *(context->slavecount); slave++)
+ {
+ configadr = context->slavelist[slave].configadr;
+ if (!group || (group == context->slavelist[slave].group))
+ {
+ ecx_config_create_mbxstatus_mappings(context, pIOmap, group, slave, &tempLogAddr);
+ diff = tempLogAddr - mLogAddr;
+ mLogAddr = tempLogAddr;
+ if ((segmentsize + diff) > (EC_MAXLRWDATA - EC_FIRSTDCDATAGRAM))
+ {
+ context->grouplist[group].IOsegment[currentsegment] = segmentsize;
+ if (currentsegment < (EC_MAXIOSEGMENTS - 1))
+ {
+ currentsegment++;
+ segmentsize = diff;
+ }
+ }
+ else
+ {
+ segmentsize += diff;
+ }
+ /* Move calculated mbxstatus with OBytes + Ibytes offset */
+ context->slavelist[slave].mbxstatus += context->grouplist[group].Obytes;
+ context->slavelist[slave].mbxstatus += context->grouplist[group].Ibytes;
+ }
+ }
+
+ /* Update segment info */
+ context->grouplist[group].IOsegment[currentsegment] = segmentsize;
+ context->grouplist[group].nsegments = currentsegment + 1;
+
if (!group)
{
/* store output bytes in master record */
context->slavelist[0].Obytes = soLogAddr - context->grouplist[group].logstartaddr;
context->slavelist[0].inputs = (uint8 *)pIOmap + context->slavelist[0].Obytes;
context->slavelist[0].Ibytes = siLogAddr - context->grouplist[group].logstartaddr;
- context->slavelist[0].mbxstatus = (uint8 *)pIOmap + context->slavelist[0].Obytes + context->slavelist[0].Ibytes;
+ context->slavelist[0].mbxstatus = (uint8 *)pIOmap +
+ context->slavelist[0].Obytes +
+ context->slavelist[0].Ibytes;
+ }
+
+ /* Do post mapping actions */
+ for (slave = 1; slave <= *(context->slavecount); slave++)
+ {
+ configadr = context->slavelist[slave].configadr;
+ if (!group || (group == context->slavelist[slave].group))
+ {
+ /* set Eeprom control to PDI */
+ ecx_eeprom2pdi(context, slave);
+ /* User may override automatic state change */
+ if (context->manualstatechange == 0)
+ {
+ /* request safe_op for slave */
+ ecx_FPWRw(context->port,
+ configadr,
+ ECT_REG_ALCTL,
+ htoes(EC_STATE_SAFE_OP),
+ EC_TIMEOUTRET3);
+ }
+
+ /* Store slave properties*/
+ if (context->slavelist[slave].blockLRW)
+ {
+ context->grouplist[group].blockLRW++;
+ }
+ context->grouplist[group].Ebuscurrent += context->slavelist[slave].Ebuscurrent;
+ }
}
- EC_PRINT("IOmapSize %d\n", context->grouplist[group].Obytes + context->grouplist[group].Ibytes);
+ EC_PRINT("IOmapSize %d\n", context->grouplist[group].Obytes +
+ context->grouplist[group].Ibytes +
+ context->grouplist[group].mbxstatuslength);
- return (context->grouplist[group].Obytes + context->grouplist[group].Ibytes);
+ return (context->grouplist[group].Obytes +
+ context->grouplist[group].Ibytes) +
+ context->grouplist[group].mbxstatuslength;
}
return 0;
*/
int ecx_EOEsetIp(ecx_contextt *context, uint16 slave, uint8 port, eoe_param_t * ipparam, int timeout)
{
- ec_EOEt *EOEp, *aEOEp;
- ec_mbxbuft MbxIn, MbxOut;
+ ec_EOEt *EOEp, *aEOEp;
+ ec_mbxbuft *MbxIn, *MbxOut;
uint16 frameinfo1, result;
uint8 cnt, data_offset;
uint8 flags = 0;
int wkc;
- ec_clearmbx(&MbxIn);
+ MbxIn = NULL;
+ MbxOut = NULL;
/* Empty slave out mailbox if something is in. Timout set to 0 */
- wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, 0);
- ec_clearmbx(&MbxOut);
- aEOEp = (ec_EOEt *)&MbxIn;
- EOEp = (ec_EOEt *)&MbxOut;
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, 0);
+ MbxOut = ecx_getmbx(context);
+ ec_clearmbx(MbxOut);
+ EOEp = (ec_EOEt *)MbxOut;
EOEp->mbxheader.address = htoes(0x0000);
EOEp->mbxheader.priority = 0x00;
data_offset = EOE_PARAM_OFFSET;
EOEp->data[0] = flags;
/* send EoE request to slave */
- wkc = ecx_mbxsend(context, slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM);
+ wkc = ecx_mbxsend(context, slave, MbxOut, EC_TIMEOUTTXM);
+ MbxOut = NULL;
if (wkc > 0) /* succeeded to place mailbox in slave ? */
{
- /* clean mailboxbuffer */
- ec_clearmbx(&MbxIn);
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
+ MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
if (wkc > 0) /* succeeded to read slave response ? */
{
- /* slave response should be FoE */
+ aEOEp = (ec_EOEt*)MbxIn;
+ /* slave response should be EoE */
if ((aEOEp->mbxheader.mbxtype & 0x0f) == ECT_MBXT_EOE)
{
frameinfo1 = etohs(aEOEp->frameinfo1);
}
}
}
+
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
+ if (MbxOut) ecx_dropmbx(context, MbxOut);
+
return wkc;
}
int ecx_EOEgetIp(ecx_contextt *context, uint16 slave, uint8 port, eoe_param_t * ipparam, int timeout)
{
ec_EOEt *EOEp, *aEOEp;
- ec_mbxbuft MbxIn, MbxOut;
+ ec_mbxbuft *MbxIn, *MbxOut;
uint16 frameinfo1, eoedatasize;
uint8 cnt, data_offset;
uint8 flags = 0;
int wkc;
+ MbxIn = NULL;
+ MbxOut = NULL;
/* Empty slave out mailbox if something is in. Timout set to 0 */
- wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, 0);
- ec_clearmbx(&MbxOut);
- aEOEp = (ec_EOEt *)&MbxIn;
- EOEp = (ec_EOEt *)&MbxOut;
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, 0);
+ MbxOut = ecx_getmbx(context);
+ ec_clearmbx(MbxOut);
+ EOEp = (ec_EOEt *)MbxOut;
EOEp->mbxheader.address = htoes(0x0000);
EOEp->mbxheader.priority = 0x00;
data_offset = EOE_PARAM_OFFSET;
EOEp->data[0] = flags;
/* send EoE request to slave */
- wkc = ecx_mbxsend(context, slave, (ec_mbxbuft *)&MbxOut, EC_TIMEOUTTXM);
+ wkc = ecx_mbxsend(context, slave, MbxOut, EC_TIMEOUTTXM);
+ MbxOut = NULL;
if (wkc > 0) /* succeeded to place mailbox in slave ? */
{
- /* clean mailboxbuffer */
- ec_clearmbx(&MbxIn);
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
+ MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
if (wkc > 0) /* succeeded to read slave response ? */
{
+ aEOEp = (ec_EOEt*)MbxIn;
/* slave response should be FoE */
if ((aEOEp->mbxheader.mbxtype & 0x0f) == ECT_MBXT_EOE)
{
}
}
}
+
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
+ if (MbxOut) ecx_dropmbx(context, MbxOut);
+
return wkc;
}
int ecx_EOEsend(ecx_contextt *context, uint16 slave, uint8 port, int psize, void *p, int timeout)
{
ec_EOEt *EOEp;
- ec_mbxbuft MbxOut;
+ ec_mbxbuft *MbxOut;
uint16 frameinfo1, frameinfo2;
uint8 cnt, txfragmentno;
boolean NotLast;
const uint8 * buf = p;
static uint8_t txframeno = 0;
- ec_clearmbx(&MbxOut);
- EOEp = (ec_EOEt *)&MbxOut;
- EOEp->mbxheader.address = htoes(0x0000);
- EOEp->mbxheader.priority = 0x00;
+ MbxOut = NULL;
/* data section=mailbox size - 6 mbx - 4 EoEh */
maxdata = context->slavelist[slave].mbx_l - 0x0A;
txframesize = psize;
do
{
+ MbxOut = ecx_getmbx(context);
+ ec_clearmbx(MbxOut);
+ EOEp = (ec_EOEt*)MbxOut;
+ EOEp->mbxheader.address = htoes(0x0000);
+ EOEp->mbxheader.priority = 0x00;
+
txframesize = psize - txframeoffset;
if (txframesize > maxdata)
{
memcpy(EOEp->data, &buf[txframeoffset], txframesize);
/* send EoE request to slave */
- wkc = ecx_mbxsend(context, slave, (ec_mbxbuft *)&MbxOut, timeout);
+ wkc = ecx_mbxsend(context, slave, MbxOut, timeout);
+ MbxOut = NULL;
if ((NotLast == TRUE) && (wkc > 0))
{
txframeoffset += txframesize;
txfragmentno++;
}
} while ((NotLast == TRUE) && (wkc > 0));
-
+
+ if (MbxOut) ecx_dropmbx(context, MbxOut);
+
return wkc;
}
int ecx_EOErecv(ecx_contextt *context, uint16 slave, uint8 port, int * psize, void *p, int timeout)
{
ec_EOEt *aEOEp;
- ec_mbxbuft MbxIn;
+ ec_mbxbuft *MbxIn;
uint16 frameinfo1, frameinfo2;
uint8 rxfragmentno, rxframeno;
boolean NotLast;
int wkc, buffersize, rxframesize, rxframeoffset, eoedatasize;
uint8 * buf = p;
-
- ec_clearmbx(&MbxIn);
- aEOEp = (ec_EOEt *)&MbxIn;
+
+ MbxIn = NULL;
NotLast = TRUE;
buffersize = *psize;
rxfragmentno = 0;
rxframeoffset = 0;
/* Hang for a while if nothing is in */
- wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
while ((wkc > 0) && (NotLast == TRUE))
{
+ aEOEp = (ec_EOEt*)MbxIn;
/* slave response should be FoE */
if ((aEOEp->mbxheader.mbxtype & 0x0f) == ECT_MBXT_EOE)
{
-
eoedatasize = etohs(aEOEp->mbxheader.length) - 0x00004;
frameinfo1 = etohs(aEOEp->frameinfo1);
frameinfo2 = etohs(aEOEp->frameinfo2);
}
else
{
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
+ MbxIn = NULL;
/* Hang for a while if nothing is in */
- wkc = ecx_mbxreceive(context, slave, (ec_mbxbuft *)&MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
}
}
else
wkc = -EC_ERR_TYPE_PACKET_ERROR;
}
}
+ if (MbxIn) ecx_dropmbx(context, MbxIn);
return wkc;
}
* @return 0= if fragment OK, >0 if last fragment, <0 on error
*/
int ecx_EOEreadfragment(
- ec_mbxbuft * MbxIn,
- uint8 * rxfragmentno,
- uint16 * rxframesize,
- uint16 * rxframeoffset,
- uint16 * rxframeno,
- int * psize,
+ ec_mbxbuft *MbxIn,
+ uint8 *rxfragmentno,
+ uint16 *rxframesize,
+ uint16 *rxframeoffset,
+ uint16 *rxframeno,
+ int *psize,
void *p)
{
uint16 frameinfo1, frameinfo2, eoedatasize;
MbxIn = NULL;
MbxOut = NULL;
/* Empty slave out mailbox if something is in. Timout set to 0 */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, 0);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, 0);
MbxOut = ecx_getmbx(context);
ec_clearmbx(MbxOut);
FOEp = (ec_FOEt *)MbxOut;
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
if (wkc > 0) /* succeeded to read slave response ? */
{
aFOEp = (ec_FOEt *)MbxIn;
MbxIn = NULL;
MbxOut = NULL;
/* Empty slave out mailbox if something is in. Timout set to 0 */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, 0);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, 0);
MbxOut = ecx_getmbx(context);
ec_clearmbx(MbxOut);
FOEp = (ec_FOEt *)MbxOut;
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
if (wkc > 0) /* succeeded to read slave response ? */
{
aFOEp = (ec_FOEt *)MbxIn;
/* handle robust mailbox protocol state machine */
if(slaveitem->mbxrmpstate)
{
- if(slaveitem->islost) slaveitem->mbxrmpstate = 0;
+ if(slaveitem->islost)
+ {
+ slaveitem->mbxrmpstate = 0;
+ }
else
{
switch(slaveitem->mbxrmpstate)
break;
case 3 :
/* wait for repeat ack */
+ SMstatex = htoes(slaveitem->mbxinstateex);
wkc2 = ecx_FPRD(context->port, configadr, ECT_REG_SM1CONTR, sizeof(SMcontr), &SMcontr, EC_TIMEOUTRET);
if((wkc2 > 0) && ((SMcontr & 0x02) == (HI_BYTE(SMstatex) & 0x02)))
{
}
else if ((mbxh->mbxtype & 0x0f) == ECT_MBXT_EOE) /* EoE response? */
{
- if(slaveitem->eoembxin && (slaveitem->eoembxinfull == FALSE))
+ ec_EOEt *eoembx = (ec_EOEt*)mbx;
+ uint16 frameinfo1 = etohs(eoembx->frameinfo1);
+ /* All non fragment data frame types are expected to be handled by
+ * slave send/receive API if the EoE hook is set
+ */
+ if (EOE_HDR_FRAME_TYPE_GET(frameinfo1) == EOE_FRAG_DATA)
+ {
+ if (context->EOEhook)
+ {
+ if (context->EOEhook(context, slave, eoembx) > 0)
+ {
+ /* Fragment handled by EoE hook */
+ wkc = 0;
+ }
+ }
+ }
+ /* Not handled by hook */
+ if((wkc > 0) && slaveitem->eoembxin && (slaveitem->eoembxinfull == FALSE))
{
slaveitem->eoembxin = (uint8 *)mbx;
mbx = NULL;
/* release mailbox to pool if still owner */
if (mbx)
{
- ecx_dropmbx(context, mbx);
+ ecx_dropmbx(context, mbx);
}
}
}
}
if(wkc < 0 ) wkc = 0;
}
- if (mbx) ecx_dropmbx(context, mbx);
- return wkc;
-}
-
-/** Read OUT mailbox from slave.
- * Supports Mailbox Link Layer with repeat requests.
- * @param[in] context = context struct
- * @param[in] slave = Slave number
- * @param[out] mbx = Mailbox data
- * @param[in] timeout = Timeout in us
- * @return Work counter (>0 is success)
- */
-int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout)
-{
- uint16 mbxro,mbxl,configadr;
- int wkc=0;
- int wkc2;
- uint8 SMstat;
- uint16 SMstatex;
- uint8 SMcontr;
- ec_mbxheadert *mbxh;
- ec_emcyt *EMp;
- ec_mbxerrort *MBXEp;
- osal_timert timer;
- ec_slavet *slavelist = &(context->slavelist[slave]);
-
- configadr = slavelist->configadr;
- mbxl = slavelist->mbx_rl;
- if (slavelist->mbxhandlerstate == ECT_MBXH_CYCLIC)
- {
- osal_timer_start(&timer, timeout);
- wkc = 0;
- do
- {
- if (slavelist->coembxinfull == TRUE)
- {
- memcpy(mbx, slavelist->coembxin, mbxl);
- ecx_dropmbx(context, (ec_mbxbuft *)slavelist->coembxin);
- slavelist->coembxin = EC_MBXINENABLE;
- slavelist->coembxinfull = FALSE;
- wkc = 1;
- }
- else if (slavelist->soembxinfull == TRUE)
- {
- memcpy(mbx, slavelist->soembxin, mbxl);
- slavelist->soembxinfull = FALSE;
- wkc = 1;
- }
- else if (slavelist->foembxinfull == TRUE)
- {
- memcpy(mbx, slavelist->foembxin, mbxl);
- slavelist->foembxinfull = FALSE;
- wkc = 1;
- }
- if (!wkc && (timeout > EC_LOCALDELAY))
- {
- osal_usleep(EC_LOCALDELAY);
- }
- }
- while ((wkc <= 0) && (osal_timer_is_expired(&timer) == FALSE));
- }
- else if ((mbxl > 0) && (mbxl <= EC_MAXMBX))
- {
- osal_timer_start(&timer, timeout);
- wkc = 0;
- do /* wait for read mailbox available */
- {
- SMstat = 0;
- wkc = ecx_readmbxstatus(context, slave, &SMstat);
- if (((SMstat & 0x08) == 0) && (timeout > EC_LOCALDELAY))
- {
- osal_usleep(EC_LOCALDELAY);
- }
- }
- while (((wkc <= 0) || ((SMstat & 0x08) == 0)) && (osal_timer_is_expired(&timer) == FALSE));
-
- if ((wkc > 0) && ((SMstat & 0x08) > 0)) /* read mailbox available ? */
- {
- mbxro = slavelist->mbx_ro;
- mbxh = (ec_mbxheadert *)mbx;
- do
- {
- wkc = ecx_FPRD(context->port, configadr, mbxro, mbxl, mbx, EC_TIMEOUTRET); /* get mailbox */
- if ((wkc > 0) && ((mbxh->mbxtype & 0x0f) == 0x00)) /* Mailbox error response? */
- {
- MBXEp = (ec_mbxerrort *)mbx;
- ecx_mbxerror(context, slave, etohs(MBXEp->Detail));
- wkc = 0; /* prevent emergency to cascade up, it is already handled. */
- }
- else if ((wkc > 0) && ((mbxh->mbxtype & 0x0f) == ECT_MBXT_COE)) /* CoE response? */
- {
- EMp = (ec_emcyt *)mbx;
- if ((etohs(EMp->CANOpen) >> 12) == 0x01) /* Emergency request? */
- {
- ecx_mbxemergencyerror(context, slave, etohs(EMp->ErrorCode), EMp->ErrorReg,
- EMp->bData, etohs(EMp->w1), etohs(EMp->w2));
- wkc = 0; /* prevent emergency to cascade up, it is already handled. */
- }
- }
- else if ((wkc > 0) && ((mbxh->mbxtype & 0x0f) == ECT_MBXT_EOE)) /* EoE response? */
- {
- ec_EOEt * eoembx = (ec_EOEt *)mbx;
- uint16 frameinfo1 = etohs(eoembx->frameinfo1);
- /* All non fragment data frame types are expected to be handled by
- * slave send/receive API if the EoE hook is set
- */
- if (EOE_HDR_FRAME_TYPE_GET(frameinfo1) == EOE_FRAG_DATA)
- {
- if (context->EOEhook)
- {
- if (context->EOEhook(context, slave, eoembx) > 0)
- {
- /* Fragment handled by EoE hook */
- wkc = 0;
- }
- }
- }
- }
- else
- {
- if (wkc <= 0) /* read mailbox lost */
- {
- do /* read extended mailbox status */
- {
- wkc2 = ecx_readmbxstatusex(context, slave, &SMstatex);
- } while ((wkc2 <= 0) && (osal_timer_is_expired(&timer) == FALSE));
- SMstatex ^= 0x0200; /* toggle repeat request */
- SMstatex = htoes(SMstatex);
- wkc2 = ecx_FPWR(context->port, configadr, ECT_REG_SM1STAT, sizeof(SMstatex), &SMstatex, EC_TIMEOUTRET);
- SMstatex = etohs(SMstatex);
- do /* wait for toggle ack */
- {
- wkc2 = ecx_FPRD(context->port, configadr, ECT_REG_SM1CONTR, sizeof(SMcontr), &SMcontr, EC_TIMEOUTRET);
- } while (((wkc2 <= 0) || ((SMcontr & 0x02) != (HI_BYTE(SMstatex) & 0x02))) && (osal_timer_is_expired(&timer) == FALSE));
- do /* wait for read mailbox available */
- {
- wkc2 = ecx_readmbxstatusex(context, slave, &SMstatex);
- if (((SMstatex & 0x08) == 0) && (timeout > EC_LOCALDELAY))
- {
- osal_usleep(EC_LOCALDELAY);
- }
- } while (((wkc2 <= 0) || ((SMstatex & 0x08) == 0)) && (osal_timer_is_expired(&timer) == FALSE));
- }
- }
- } while ((wkc <= 0) && (osal_timer_is_expired(&timer) == FALSE)); /* if WKC<=0 repeat */
- }
- else /* no read mailbox available */
- {
- wkc = 0;
- }
- }
-
+ if (mbx) ecx_dropmbx(context, mbx);
return wkc;
}
* @param[in] timeout = Timeout in us
* @return Work counter (>0 is success)
*/
-int ecx_mbxreceive2(ecx_contextt *context, uint16 slave, ec_mbxbuft **mbx, int timeout)
+int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft **mbx, int timeout)
{
uint16 mbxro,mbxl,configadr;
int wkc=0;
slavelist->foembxinfull = FALSE;
wkc = 1;
}
+ else if (slavelist->eoembxinfull == TRUE)
+ {
+ *mbx = (ec_mbxbuft*)slavelist->eoembxin;
+ slavelist->eoembxin = EC_MBXINENABLE;
+ slavelist->eoembxinfull = FALSE;
+ wkc = 1;
+ }
if (!wkc && (timeout > EC_LOCALDELAY))
{
osal_usleep(EC_LOCALDELAY);
mbxin = NULL;
wkc = 0; /* prevent emergency to cascade up, it is already handled. */
}
- else if ((wkc > 0) && ((mbxh->mbxtype & 0x0f) == 0x03)) /* CoE response? */
+ else if ((wkc > 0) && ((mbxh->mbxtype & 0x0f) == ECT_MBXT_COE)) /* CoE response? */
{
EMp = (ec_emcyt *)mbx;
if ((etohs(EMp->CANOpen) >> 12) == 0x01) /* Emergency request? */
mbxin = NULL;
}
}
+ else if ((wkc > 0) && ((mbxh->mbxtype & 0x0f) == ECT_MBXT_EOE)) /* EoE response? */
+ {
+ ec_EOEt* eoembx = (ec_EOEt*)mbx;
+ uint16 frameinfo1 = etohs(eoembx->frameinfo1);
+ /* All non fragment data frame types are expected to be handled by
+ * slave send/receive API if the EoE hook is set
+ */
+ if (EOE_HDR_FRAME_TYPE_GET(frameinfo1) == EOE_FRAG_DATA)
+ {
+ if (context->EOEhook)
+ {
+ if (context->EOEhook(context, slave, eoembx) > 0)
+ {
+ /* Fragment handled by EoE hook */
+ ecx_dropmbx(context, mbxin);
+ mbxin = NULL;
+ wkc = 0;
+ }
+ }
+ }
+ /* Not handled by EoE hook*/
+ if(wkc > 0)
+ {
+ *mbx = mbxin;
+ mbxin = NULL;
+ }
+ }
else
{
if (wkc <= 0) /* read mailbox lost */
/* For overlap IOmap make the frame EQ big to biggest part */
length = (context->grouplist[group].Obytes > context->grouplist[group].Ibytes) ?
context->grouplist[group].Obytes : context->grouplist[group].Ibytes;
+ length += context->grouplist[group].mbxstatuslength;
/* Save the offset used to compensate where to save inputs when frame returns */
iomapinputoffset = context->grouplist[group].Obytes;
}
else
{
- length = context->grouplist[group].Obytes + context->grouplist[group].Ibytes;
+ length = context->grouplist[group].Obytes +
+ context->grouplist[group].Ibytes +
+ context->grouplist[group].mbxstatuslength;
iomapinputoffset = 0;
}
int ecx_mbxhandler(ecx_contextt *context, uint8 group, int limit);
int ecx_mbxempty(ecx_contextt *context, uint16 slave, int timeout);
int ecx_mbxsend(ecx_contextt *context, uint16 slave,ec_mbxbuft *mbx, int timeout);
-int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft *mbx, int timeout);
-int ecx_mbxreceive2(ecx_contextt *context, uint16 slave, ec_mbxbuft **mbx, int timeout);
+int ecx_mbxreceive(ecx_contextt *context, uint16 slave, ec_mbxbuft **mbx, int timeout);
void ecx_esidump(ecx_contextt *context, uint16 slave, uint8 *esibuf);
uint32 ecx_readeeprom(ecx_contextt *context, uint16 slave, uint16 eeproma, int timeout);
int ecx_writeeeprom(ecx_contextt *context, uint16 slave, uint16 eeproma, uint16 data, int timeout);
MbxIn = NULL;
MbxOut = NULL;
/* Empty slave out mailbox if something is in. Timout set to 0 */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, 0);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, 0);
MbxOut = ecx_getmbx(context);
ec_clearmbx(MbxOut);
SoEp = (ec_SoEt *)MbxOut;
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
if (wkc > 0) /* succeeded to read slave response ? */
{
aSoEp = (ec_SoEt *)MbxIn;
MbxIn = NULL;
MbxOut = NULL;
/* Empty slave out mailbox if something is in. Timout set to 0 */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, 0);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, 0);
hp = p;
maxdata = context->slavelist[slave].mbx_l - sizeof(ec_SoEt);
NotLast = TRUE;
if(MbxIn) ecx_dropmbx(context, MbxIn);
MbxIn = NULL;
/* read slave response */
- wkc = ecx_mbxreceive2(context, slave, &MbxIn, timeout);
+ wkc = ecx_mbxreceive(context, slave, &MbxIn, timeout);
if (wkc > 0) /* succeeded to read slave response ? */
{
aSoEp = (ec_SoEt *)MbxIn;