master/fsm.c
changeset 397 c5d2fb08e43f
parent 395 8b1194e51cf2
child 398 ff37601361a8
equal deleted inserted replaced
396:189909f92019 397:c5d2fb08e43f
   263     unsigned int i;
   263     unsigned int i;
   264     ec_slave_t *slave;
   264     ec_slave_t *slave;
   265     ec_master_t *master = fsm->master;
   265     ec_master_t *master = fsm->master;
   266 
   266 
   267     if (datagram->state != EC_DATAGRAM_RECEIVED) {
   267     if (datagram->state != EC_DATAGRAM_RECEIVED) {
   268         EC_ERR("Failed tor receive broadcast datagram.\n");
   268         EC_ERR("Failed to receive broadcast datagram.\n");
   269         fsm->master_state = ec_fsm_error;
   269         fsm->master_state = ec_fsm_error;
   270         return;
   270         return;
   271     }
   271     }
   272 
   272 
   273     EC_INFO("Scanning bus.\n");
   273     EC_INFO("Scanning bus.\n");
  1611         EC_ERR("SII: Reception of read datagram failed.\n");
  1611         EC_ERR("SII: Reception of read datagram failed.\n");
  1612         fsm->sii_state = ec_fsm_error;
  1612         fsm->sii_state = ec_fsm_error;
  1613         return;
  1613         return;
  1614     }
  1614     }
  1615 
  1615 
       
  1616     fsm->sii_check_once_more = 1;
  1616     fsm->sii_start = get_cycles();
  1617     fsm->sii_start = get_cycles();
  1617 
  1618 
  1618     // issue check/fetch datagram
  1619     // issue check/fetch datagram
  1619     if (fsm->sii_mode) {
  1620     if (fsm->sii_mode) {
  1620         ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 10);
  1621         ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 10);
  1647 
  1648 
  1648     // check "busy bit"
  1649     // check "busy bit"
  1649     if (EC_READ_U8(datagram->data + 1) & 0x81) {
  1650     if (EC_READ_U8(datagram->data + 1) & 0x81) {
  1650         // still busy... timeout?
  1651         // still busy... timeout?
  1651         if (get_cycles() - fsm->sii_start >= (cycles_t) 10 * cpu_khz) {
  1652         if (get_cycles() - fsm->sii_start >= (cycles_t) 10 * cpu_khz) {
  1652             EC_ERR("SII: Read timeout.\n");
  1653             if (!fsm->sii_check_once_more) {
  1653             fsm->sii_state = ec_fsm_error;
  1654                 EC_ERR("SII: Read timeout.\n");
       
  1655                 fsm->sii_state = ec_fsm_error;
  1654 #if 0
  1656 #if 0
  1655             EC_DBG("SII busy: %02X %02X %02X %02X\n",
  1657                 EC_DBG("SII busy: %02X %02X %02X %02X\n",
  1656                    EC_READ_U8(datagram->data + 0),
  1658                        EC_READ_U8(datagram->data + 0),
  1657                    EC_READ_U8(datagram->data + 1),
  1659                        EC_READ_U8(datagram->data + 1),
  1658                    EC_READ_U8(datagram->data + 2),
  1660                        EC_READ_U8(datagram->data + 2),
  1659                    EC_READ_U8(datagram->data + 3));
  1661                        EC_READ_U8(datagram->data + 3));
  1660 #endif
  1662 #endif
  1661             return;
  1663                 return;
       
  1664             }
       
  1665             fsm->sii_check_once_more = 0;
  1662         }
  1666         }
  1663 
  1667 
  1664         // issue check/fetch datagram again
  1668         // issue check/fetch datagram again
  1665         if (fsm->sii_mode) {
  1669         if (fsm->sii_mode) {
  1666             ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 10);
  1670             ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 10);