//! HCS12/HCS08/RS08/CFV1 -  Reset Target
//!
//! @note
//!  commandBuffer                                          \n
//!   - [2] => 8-bit reset control [see \ref TargetMode_t]
//!
//! @return
//!    == \ref BDM_RC_OK => success       \n
//!    != \ref BDM_RC_OK => error         \n
//!
U8 f_CMD_RESET(void) {
register U8 mode = commandBuffer[2]&RESET_MODE_MASK;
U8 rc = BDM_RC_OK;

   // This may take a while
   setBDMBusy();
   
   rc = optionalReconnect(AUTOCONNECT_STATUS);
   if (rc != BDM_RC_OK) {
      return rc;
   }
   cable_status.bdmpprValue = 0x00;
   
   // ToDo - check more
   switch (commandBuffer[2] & RESET_TYPE_MASK) {
#if (HW_CAPABILITY&CAP_RST_IO)   
      case RESET_HARDWARE :
         rc = bdm_hardwareReset(mode);
         break;
#endif         
      case RESET_SOFTWARE :
         rc = bdm_softwareReset(mode);
         break;
#if (HW_CAPABILITY&CAP_VDDCONTROL)   
      case RESET_POWER :
         rc =  bdm_cycleTargetVdd(mode);
         break;
#endif         
      case RESET_ALL :
      default:
         rc = bdm_targetReset(mode);
   }
   if (cable_status.speed != SPEED_USER_SUPPLIED) {
	   // Assume we have lost connection after reset attempt
      cable_status.speed  = SPEED_NO_INFO;
      bdm_rx_ptr          = bdm_rxEmpty;       // Clear the Tx/Rx pointers
      bdm_tx_ptr          = bdm_txEmpty;       //    i.e. no routines found
   }
   cable_status.reset  = NO_RESET_ACTIVITY; // BDM resetting the target doesn't count as a reset!
   cable_status.ackn   = WAIT;              // ACKN feature is disabled after reset

#if 0
   if (rc != BDM_RC_OK) {
     return rc;
   }
   if (cable_status.speed == SPEED_USER_SUPPLIED) {          // User specified speed?
      (void)bdmHC12_confirmSpeed(cable_status.sync_length);  // Confirm we can still operate at that speed
      // ToDo - check what should be done with rc
      (void)bdm_enableBDM();                                 //  & enable BDM mode
      }
   else if ((bdm_option.autoReconnect) || (cable_status.speed == SPEED_SYNC))
      // Re-connect if Auto re-connect enabled or it's quick to do (ACKN was found previously)
      (void)bdm_connect();             //    Done even if no SYNC feature - may be slow!
   else  {
      cable_status.speed  = SPEED_NO_INFO;   // Indicate we no longer have a connection
   }
#endif

   return rc;
}
Exemplo n.º 2
0
//!  Cycle power to target
//!
//! @param mode
//!    - \ref RESET_SPECIAL => Power on in special mode,
//!    - \ref RESET_NORMAL  => Power on in normal mode
//!
//!  BKGD/BKPT is held low when power is re-applied to start
//!  target with BDM active if RESET_SPECIAL
//!
//!  @return
//!   \ref BDM_RC_OK                 => No error \n
//!   \ref BDM_RC_VDD_WRONG_MODE     => Target Vdd not controlled by BDM interface \n
//!   \ref BDM_RC_VDD_NOT_REMOVED    => Target Vdd failed to fall \n
//!   \ref BDM_RC_VDD_NOT_PRESENT    => Target Vdd failed to rise \n
//!   \ref BDM_RC_RESET_TIMEOUT_RISE => RESET signal failed to rise \n
//!
uint8_t bdm_cycleTargetVdd(uint8_t mode) {
uint8_t rc;

   // This may take a while
   setBDMBusy();

   rc = bdm_cycleTargetVddOff();
   if (rc != BDM_RC_OK) {
      return rc;
   }
   WAIT_MS(1000);
   rc = bdm_cycleTargetVddOn(mode);
   return rc;
}