/* It waits for the communication sequence with the device is completed.  */
static USBPD_StatusTypeDef HW_IF_COMM_WAIT(uint8_t PortNum, int16_t Timeout)
/* It waits for the communication sequence with the device is completed.  */
static USBPD_StatusTypeDef HW_IF_COMM_WAIT(uint8_t PortNum, int16_t Timeout)
{
  USBPD_StatusTypeDef ret = USBPD_ERROR;
  int16_t timeout = Timeout;
  while (1)
  {
    if (Ports[PortNum].CommLock == 0)
    {
      Ports[PortNum].CommLock = 1;
      ret = USBPD_OK;
      break;
    }
    if (timeout == 0)
    {
      ret = USBPD_TIMEOUT;
      break;
    }
    if (timeout > 0)
    {
      timeout--;
    }
  }
  return ret;
}