int exec_cmd(EcInitCmdDesc *CmdDesc, uint16 slave)
{int wkc,cnt = 0; 
char i; 
 uint32 data=0;
 
 uint16 retry,estat;
 
   retry=CmdDesc->retries;
      if (CmdDesc->ecHead.ADO==0x502||CmdDesc->ecHead.ADO==0x508)
	    {
		  
		  ec_eeprom2master(slave);
		 
         if (ec_eeprom_waitnotbusyAP(CmdDesc->ecHead.ADP, &estat, EC_TIMEOUTEEP))
	        {
		     if (estat & EC_ESTAT_EMASK) /* error bits are set */
		        {
			     estat = htoes(EC_ECMD_NOP); /* clear error bits */
			     wkc=ec_APWR(CmdDesc->ecHead.ADP, ECT_REG_EEPCTL, sizeof(estat), &estat, EC_TIMEOUTRET);
		        }
		
		    do
			wkc=EcatCmdReq(CmdDesc, &data, slave);
			while ((wkc <= 0) && (cnt++ < retry));
	        }
     
	    }
       EC_PRINT("Command: %s\n",CmdDesc->cmt);
 	 else 
	    {
		 do
		 {
Example #2
0
/** Recover slave.
 *
 * @param[in] slave	  = slave to recover
 * @return >0 if successful
 */
int ec_recover_slave(uint16 slave)
{
  int rval;
  uint16 ADPh, configadr;

  rval = 0;
  configadr = ec_slave[slave].configadr;
  /* clear possible slaves at EC_TEMPNODE */
  ec_FPWRw(EC_TEMPNODE, ECT_REG_STADR, htoes(0), 0);
  ADPh = (uint16)(1 - slave);
  /* set temporary node address of slave */
  if (ec_APWRw(ADPh, ECT_REG_STADR, htoes(EC_TEMPNODE), EC_TIMEOUTRET) <= 0)
    return 0; /* slave fails to respond */

  ec_slave[slave].configadr = EC_TEMPNODE; /* temporary config address */
  ec_eeprom2master(slave); /* set Eeprom control to master */

  /* check if slave is the same as configured before */
  if ((ec_FPRDw(EC_TEMPNODE, ECT_REG_ALIAS, EC_TIMEOUTRET) == ec_slave[slave].aliasadr)
      && (ec_readeeprom(slave, ECT_SII_ID, EC_TIMEOUTEEP) == ec_slave[slave].eep_id)
      && (ec_readeeprom(slave, ECT_SII_MANUF, EC_TIMEOUTEEP) == ec_slave[slave].eep_man)
      && (ec_readeeprom(slave, ECT_SII_REV, EC_TIMEOUTEEP) == ec_slave[slave].eep_rev))
  {
    rval = ec_FPWRw(EC_TEMPNODE, ECT_REG_STADR, htoes(configadr), EC_TIMEOUTRET);
    ec_slave[slave].configadr = configadr;
  }
  else
  {
    /* slave is not the expected one, remove config address*/
    ec_FPWRw(EC_TEMPNODE, ECT_REG_STADR, htoes(0), EC_TIMEOUTRET);
    ec_slave[slave].configadr = configadr;
  }

  return rval;
}
/** Read one byte from slave EEPROM via cache.
 *  If the cache location is empty then a read request is made to the slave.
 *  Depending on the slave capabillities the request is 4 or 8 bytes.
 *  @param[in] slave   = slave number
 *  @param[in] address = eeprom address in bytes (slave uses words)
 *  @return requested byte, if not available then 0xff
 */
uint8 ec_siigetbyte(uint16 slave, uint16 address)
{
	uint16 configadr, eadr;
	uint64 *p64;
	uint32 *p32;
	uint64 edat;
	uint16 mapw, mapb;
	int lp,cnt;
	uint8 retval;
	
	retval = 0xff;
	if (slave != esislave) /* not the same slave? */
	{	
		memset(esimap,0x00,EC_MAXEEPBITMAP); /* clear esibuf cache map */
		esislave=slave;
	}	
	if (address < EC_MAXEEPBUF)
	{		
		mapw = address >> 5;
		mapb = address - (mapw << 5);
		if (esimap[mapw] & (uint32)(1 << mapb))
		{
			/* byte is already in buffer */
			retval = esibuf[address];
		}
		else
		{
			/* byte is not in buffer, put it there */
		    configadr = ec_slave[slave].configadr;
			ec_eeprom2master(slave); /* set eeprom control to master */
			eadr = address >> 1;
			edat = ec_readeepromFP (configadr, eadr, EC_TIMEOUTEEP);
			/* 8 byte response */
			if (ec_slave[slave].eep_8byte)
			{	
				p64 = (uint64*)&esibuf[eadr << 1];
				*p64 = edat;
				cnt = 8;
			}
			/* 4 byte response */
			else
			{
				p32 = (uint32*)&esibuf[eadr << 1];
				*p32 = (uint32)edat;
				cnt = 4;
			}
			/* find bitmap location */
			mapw = eadr >> 4;
			mapb = (eadr << 1) - (mapw << 5);
			for(lp = 0 ; lp < cnt ; lp++)
			{
				/* set bitmap for each byte that is read */
				esimap[mapw] |= (1 << mapb);
				mapb++;
				if (mapb > 31)
				{
					mapb = 0;
					mapw++;
				}	
			}	
			retval = esibuf[address];
		}	
	}