/**
* @brief  CDC_InterfaceDeInit 
*         The function DeInit the Host Channels used for the CDC class.
* @param  pdev: Selected device
* @param  hdev: Selected device property
* @retval None
*/
void CDC_InterfaceDeInit ( USB_OTG_CORE_HANDLE *pdev,
                          void *phost)
{
  if ( CDC_Machine.CDC_CommItf.hc_num_in)
  {
    USB_OTG_HC_Halt(pdev, CDC_Machine.CDC_CommItf.hc_num_in);
    USBH_Free_Channel  (pdev,CDC_Machine.CDC_CommItf.hc_num_in);
    CDC_Machine.CDC_CommItf.hc_num_in = 0;     /* Reset the Channel as Free */
  }
  
  if ( CDC_Machine.CDC_DataItf.hc_num_out)
  {
    USB_OTG_HC_Halt(pdev, CDC_Machine.CDC_DataItf.hc_num_out);
    USBH_Free_Channel  (pdev,CDC_Machine.CDC_DataItf.hc_num_out);
    CDC_Machine.CDC_DataItf.hc_num_out = 0;     /* Reset the Channel as Free */
  }
  
  if ( CDC_Machine.CDC_DataItf.hc_num_in)
  {
    USB_OTG_HC_Halt(pdev, CDC_Machine.CDC_DataItf.hc_num_in);
    USBH_Free_Channel  (pdev,CDC_Machine.CDC_DataItf.hc_num_in);
    CDC_Machine.CDC_DataItf.hc_num_in = 0;     /* Reset the Channel as Free */
  } 
//  return USBH_OK;
}
/**
* @brief  USBH_MSC_InterfaceDeInit 
*         De-Initialize interface by freeing host channels allocated to interface
* @param  pdev: Selected device
* @param  hdev: Selected device property
* @retval None
*/
void USBH_MSC_InterfaceDeInit ( USB_OTG_CORE_HANDLE *pdev,
							   void *phost)
{	
	if ( MSC_Machine.hc_num_out)
	{
		USB_OTG_HC_Halt(pdev, MSC_Machine.hc_num_out);
		USBH_Free_Channel  (pdev, MSC_Machine.hc_num_out);
		MSC_Machine.hc_num_out = 0;     /* Reset the Channel as Free */
	}

	if ( MSC_Machine.hc_num_in)
	{
		USB_OTG_HC_Halt(pdev, MSC_Machine.hc_num_in);
		USBH_Free_Channel  (pdev, MSC_Machine.hc_num_in);
		MSC_Machine.hc_num_in = 0;     /* Reset the Channel as Free */
	} 
}
Beispiel #3
0
/**
  * @brief  USBH_MSC_InterfaceDeInit 
  *         De-Initialize interface by freeing host channels allocated to interface
  * @param  pdev: Selected device
  * @param  hdev: Selected device property
  * @retval None
  */
void USBH_MSC_InterfaceDeInit ( USB_OTG_CORE_HANDLE *pdev,
                                USBH_DeviceProp_TypeDef *hdev)
{	
  if ( MSC_Machine.hc_num_out)
  {
    USB_OTG_HC_Halt((&USB_OTG_FS_dev), MSC_Machine.hc_num_out);
    USBH_Free_Channel  (pdev, MSC_Machine.hc_num_out);
    MSC_Machine.hc_num_out = 0;     /* Reset the Channel as Free */
  }
   
  if ( MSC_Machine.hc_num_in)
  {
    USB_OTG_HC_Halt((&USB_OTG_FS_dev), MSC_Machine.hc_num_in);
    USBH_Free_Channel  (pdev, MSC_Machine.hc_num_in);
    MSC_Machine.hc_num_in = 0;     /* Reset the Channel as Free */
  } 
}
Beispiel #4
0
static uint32_t USB_OTG_USBH_handle_nptxfempty_ISR(USB_OTG_CORE_HANDLE*pdev)
{
	USB_OTG_GINTMSK_TypeDef intmsk;
	USB_OTG_HNPTXSTS_TypeDef hnptxsts;
	uint16_t len_words, len;

	hnptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->HNPTXSTS);
	
	#ifdef DEBUG
	if (hnptxsts.b.chnum > 0)
		p_err("nptxfempty:%d\n", hnptxsts.b.nptxfspcavail);

	if (pdev->host.hc[hnptxsts.b.chnum].xfer_len == 0)
	{
		p_err("%s xfer_len == 0, %d\n", __FUNCTION__, hnptxsts.b.chnum);
		USB_OTG_HC_Halt(pdev, hnptxsts.b.chnum); //test
		return 0;
	}
	#endif

	

	len_words = (pdev->host.hc[hnptxsts.b.chnum].xfer_len + 3) / 4;

	while ((hnptxsts.b.nptxfspcavail > len_words) && (pdev
	->host.hc[hnptxsts.b.chnum].xfer_len != 0))
	{

		len = hnptxsts.b.nptxfspcavail * 4;

		if (len > pdev->host.hc[hnptxsts.b.chnum].xfer_len)
		{
			/* Last packet */
			len = pdev->host.hc[hnptxsts.b.chnum].xfer_len;

			intmsk.d32 = 0;
			intmsk.b.nptxfempty = 1;
			USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, intmsk.d32, 0);
		}

		len_words = (pdev->host.hc[hnptxsts.b.chnum].xfer_len + 3) / 4;

		USB_OTG_WritePacket(pdev, pdev->host.hc[hnptxsts.b.chnum].xfer_buff,
	hnptxsts.b.chnum, len);

		pdev->host.hc[hnptxsts.b.chnum].xfer_buff += len;
		pdev->host.hc[hnptxsts.b.chnum].xfer_len -= len;
		pdev->host.hc[hnptxsts.b.chnum].xfer_count += len;
		hnptxsts.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->HNPTXSTS);
	}

	return 1;
}
Beispiel #5
0
/**
* @brief  USBH_HID_InterfaceDeInit 
*         The function DeInit the Host Channels used for the HID class.
* @param  pdev: Selected device
* @param  hdev: Selected device property
* @retval None
*/
void USBH_HID_InterfaceDeInit ( USB_OTG_CORE_HANDLE *pdev,
                               void *phost)
{	
   //USBH_HOST *pphost = phost;
    
  if(HID_Machine.hc_num_in != 0x00)
  {   
    USB_OTG_HC_Halt(pdev, HID_Machine.hc_num_in);
    USBH_Free_Channel  (pdev, HID_Machine.hc_num_in);
    HID_Machine.hc_num_in = 0;     /* Reset the Channel as Free */  
  }
  
  if(HID_Machine.hc_num_out != 0x00)
  {   
    USB_OTG_HC_Halt(pdev, HID_Machine.hc_num_out);
    USBH_Free_Channel  (pdev, HID_Machine.hc_num_out);
    HID_Machine.hc_num_out = 0;     /* Reset the Channel as Free */  
  }
 
  start_toggle = 0;
}
Beispiel #6
0
// The function DeInit the Host Channels used for the HID class.
void USBH_HID_InterfaceDeInit ( USB_OTG_CORE_HANDLE *pdev,
                               void *phost)
{
  HID_Machine_TypeDef *HID_Machine = &HID_Machines[pdev->cfg.coreID];	
   //USBH_HOST *pphost = phost;
    
  if(HID_Machine->hc_num_in != 0x00)
  {   
    USB_OTG_HC_Halt(pdev, HID_Machine->hc_num_in);
    USBH_Free_Channel  (pdev, HID_Machine->hc_num_in);
    HID_Machine->hc_num_in = 0;     /* Reset the Channel as Free */  
  }
  
  if(HID_Machine->hc_num_out != 0x00)
  {   
    USB_OTG_HC_Halt(pdev, HID_Machine->hc_num_out);
    USBH_Free_Channel  (pdev, HID_Machine->hc_num_out);
    HID_Machine->hc_num_out = 0;     /* Reset the Channel as Free */  
  }
 
  start_toggles[pdev->cfg.coreID] = 0;
}
Beispiel #7
0
uint32_t USB_OTG_USBH_handle_hc_n_In_ISR(USB_OTG_CORE_HANDLE *pdev, uint32_t
	num)
{
	USB_OTG_HCINTn_TypeDef hcint;
	USB_OTG_HCGINTMSK_TypeDef hcintmsk;
	USB_OTG_HCCHAR_TypeDef hcchar;
	USB_OTG_HCTSIZn_TypeDef hctsiz;
	USB_OTG_HC_REGS *hcreg;
	int ret = 0;

	hcreg = pdev->regs.HC_REGS[num];
	hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT);
	hcintmsk.d32 = USB_OTG_READ_REG32(&hcreg->HCGINTMSK);
	hcint.d32 = hcint.d32 &hcintmsk.d32;
	hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCCHAR);
	hcintmsk.d32 = 0;


	if (hcint.b.ahberr)
	{
		CLEAR_HC_INT(hcreg, ahberr);
		UNMASK_HOST_INT_CHH(num);
	}
	else if (hcint.b.ack)
	{
		CLEAR_HC_INT(hcreg, ack);
	}

	else if (hcint.b.stall)
	{
		UNMASK_HOST_INT_CHH(num);
		pdev->host.HC_Status[num] = HC_STALL;
		CLEAR_HC_INT(hcreg, nak); /* Clear the NAK Condition */
		CLEAR_HC_INT(hcreg, stall); /* Clear the STALL Condition */
		hcint.b.nak = 0; /* NOTE: When there is a 'stall', reset also nak,
		else, the pdev->host.HC_Status = HC_STALL
		will be overwritten by 'nak' in code below */
		USB_OTG_HC_Halt(pdev, num);
	}
	else if (hcint.b.datatglerr)
	{
		UNMASK_HOST_INT_CHH(num);
		USB_OTG_HC_Halt(pdev, num);
		CLEAR_HC_INT(hcreg, nak);
		pdev->host.HC_Status[num] = HC_DATATGLERR;
		CLEAR_HC_INT(hcreg, datatglerr);
	}

	if (hcint.b.frmovrun)
	{
		UNMASK_HOST_INT_CHH(num);
		USB_OTG_HC_Halt(pdev, num);
		CLEAR_HC_INT(hcreg, frmovrun);
	}

	else if (hcint.b.xfercompl)
	{
		pdev->host.HC_Status[num] = HC_XFRC;
		pdev->host.ErrCnt[num] = 0;
		CLEAR_HC_INT(hcreg, xfercompl);
		CLEAR_HC_INT(hcreg , nak);

		if (hcchar.b.eptype == EP_TYPE_BULK)
		{
			if (pdev->cfg.dma_enable == 1)
			{
				hctsiz.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCTSIZ);
				pdev->host.XferCnt[num] = pdev->host.hc[num].xfer_len - hctsiz.b.xfersize;

				pdev->host.hc[num].packet_count = (pdev->host.XferCnt[num] + 63) / 64;
			}
		
			if (pdev->host.hc[num].packet_count & 1)
				pdev->host.hc[num].toggle_in ^= 1;
		}
		else if (hcchar.b.eptype == EP_TYPE_CTRL)
		{
			pdev->host.hc[num].toggle_in ^= 1;
		}
		else if (hcchar.b.eptype == EP_TYPE_INTR)
		{
			hcchar.b.oddfrm = 1;
			USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
			pdev->host.URB_State[num] = URB_DONE;
		}

		UNMASK_HOST_INT_CHH(num);
		USB_OTG_HC_Halt(pdev, num);

	}
	else if (hcint.b.chhltd)
	{
		ret = 1;
		MASK_HOST_INT_CHH(num);

		if (pdev->host.HC_Status[num] == HC_XFRC)
		{
			pdev->host.URB_State[num] = URB_DONE;
		}
		else if (pdev->host.HC_Status[num] == HC_STALL)
		{
			pdev->host.URB_State[num] = URB_STALL;
		}
		else if ((pdev->host.HC_Status[num] == HC_XACTERR) || (pdev
	->host.HC_Status[num] == HC_DATATGLERR))
		{
			pdev->host.ErrCnt[num] = 0;
			pdev->host.URB_State[num] = URB_ERROR;
		}else
			ret = 0;
		/*
		else if (pdev->host.HC_Status[num] == HC_NAK)
		{
		pdev->host.URB_State[num] = URB_NAK;
		need_wake_up = 1;
		} */
		

		CLEAR_HC_INT(hcreg, chhltd);

	}
	else if (hcint.b.xacterr)
	{
		UNMASK_HOST_INT_CHH(num);
		pdev->host.ErrCnt[num]++;
		pdev->host.HC_Status[num] = HC_XACTERR;
		USB_OTG_HC_Halt(pdev, num);
		CLEAR_HC_INT(hcreg, xacterr);

	}
	else if (hcint.b.nak)
	{
		if (hcchar.b.eptype == EP_TYPE_CTRL)
		{
			CLEAR_HC_INT(hcreg, nak);
			hcchar.b.chen = 1;
			hcchar.b.chdis = 0;
			USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
		}
		else
		{
			UNMASK_HOST_INT_CHH(num);
			USB_OTG_HC_Halt(pdev, num);
			CLEAR_HC_INT(hcreg, nak);
		}
		pdev->host.HC_Status[num] = HC_NAK;
	}
	else
	{
		p_err("unkown in isr:%08x\n", hcint.d32);
	}


	return ret;

}
Beispiel #8
0
uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR(USB_OTG_CORE_HANDLE *pdev, uint32_t
	num)
{

	USB_OTG_HCINTn_TypeDef hcint;
	USB_OTG_HCGINTMSK_TypeDef hcintmsk;
	USB_OTG_HC_REGS *hcreg;
	USB_OTG_HCCHAR_TypeDef hcchar;
	int ret = 0;
	hcreg = pdev->regs.HC_REGS[num];
	hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT);
	hcintmsk.d32 = USB_OTG_READ_REG32(&hcreg->HCGINTMSK);
	hcint.d32 = hcint.d32 &hcintmsk.d32;
	hcchar.d32 = USB_OTG_READ_REG32(&hcreg->HCCHAR);

	USB_OTG_WRITE_REG32(&hcreg->HCINT, hcint.d32 | 0x7f); //clear 0-10bit

	if (hcint.b.chhltd)
	{
		hcint.b.chhltd = 0;
		ret = 1;
		if (pdev->host.HC_Status[num] == HC_XFRC)
		{
			pdev->host.URB_State[num] = URB_DONE;
			if (hcchar.b.eptype == EP_TYPE_BULK)
			{
				
				if (pdev->host.hc[num].packet_count &1)
					pdev->host.hc[num].toggle_out ^= 1;

			}
		}
		else if (pdev->host.HC_Status[num] == HC_NAK)
		{
			pdev->host.URB_State[num] = URB_NOTREADY;
		}
		else if (pdev->host.HC_Status[num] == HC_NYET)
		{
			if (pdev->host.hc[num].do_ping == 1)
			{
				USB_OTG_HC_DoPing(pdev, num);
			}
			pdev->host.URB_State[num] = URB_NOTREADY;
		}
		else if (pdev->host.HC_Status[num] == HC_STALL)
		{
			pdev->host.URB_State[num] = URB_STALL;
		}
		else if (pdev->host.HC_Status[num] == HC_XACTERR)
		{
			if (pdev->host.ErrCnt[num] == 3)
			{
				pdev->host.URB_State[num] = URB_ERROR;
				pdev->host.ErrCnt[num] = 0;
			}
		}
		else if (pdev->host.HC_Status[num] == HC_HALTED)
		{
			pdev->host.URB_State[num] = URB_ERROR;
			pdev->host.ErrCnt[num] = 0;
		}
		else{
			ret = 0;
			p_err("unkown out chhltd:%d\n", pdev->host.HC_Status[num]);
		}
		
	}

	if (hcint.b.xfercompl)
	{
		hcint.b.xfercompl = 0;

		if (num > 0)
			pdev->host.ErrCnt[num] = 0;
		USB_OTG_HC_Halt(pdev, num);
		pdev->host.HC_Status[num] = HC_XFRC;
	}

	if(hcint.d32 == 0)
		goto end;


	if (hcint.b.ahberr)
	{
		p_err("ahberr in:%08x\n", USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCDMA))
	;
	}

	if (hcint.b.ack)
	{
		p_err("ack\n");
	}

	if (hcint.b.stall)
	{
		USB_OTG_HC_Halt(pdev, num);
		pdev->host.HC_Status[num] = HC_STALL;
	}

	if (hcint.b.nak)
	{
		pdev->host.ErrCnt[num] = 0;
		USB_OTG_HC_Halt(pdev, num);
		pdev->host.HC_Status[num] = HC_NAK;
	}

	if (hcint.b.xacterr)
	{
		USB_OTG_HC_Halt(pdev, num);
		pdev->host.ErrCnt[num]++;
		pdev->host.HC_Status[num] = HC_XACTERR;
	}
	if (hcint.b.nyet)
	{
		pdev->host.ErrCnt[num] = 0;
		USB_OTG_HC_Halt(pdev, num);
		pdev->host.HC_Status[num] = HC_NYET;
	}
	if (hcint.b.datatglerr)
	{
		USB_OTG_HC_Halt(pdev, num);
		pdev->host.HC_Status[num] = HC_DATATGLERR;
	}

end:
	return ret;
}
Beispiel #9
0
uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR(USB_OTG_CORE_HANDLE *pdev, uint32_t
	num)
{

	USB_OTG_HCINTn_TypeDef hcint;
	USB_OTG_HCGINTMSK_TypeDef hcintmsk;
	USB_OTG_HC_REGS *hcreg;
	USB_OTG_HCCHAR_TypeDef hcchar;
	int ret = 0;
	hcreg = pdev->regs.HC_REGS[num];
	hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT);
	hcintmsk.d32 = USB_OTG_READ_REG32(&hcreg->HCGINTMSK);
	hcint.d32 = hcint.d32 &hcintmsk.d32;
	hcchar.d32 = USB_OTG_READ_REG32(&hcreg->HCCHAR);

	//	USB_OTG_WRITE_REG32(&hcreg->HCINT, hcint.d32|0x7f);	//clear 0-10bit

	if (hcint.b.ahberr)
	{
		CLEAR_HC_INT(hcreg, ahberr);
		UNMASK_HOST_INT_CHH(num);
	}
	else if (hcint.b.ack)
	{
		CLEAR_HC_INT(hcreg, ack);
	}

	else if (hcint.b.xfercompl)
	{
		pdev->host.ErrCnt[num] = 0;
		UNMASK_HOST_INT_CHH(num);
		USB_OTG_HC_Halt(pdev, num);
		CLEAR_HC_INT(hcreg, xfercompl);
		pdev->host.HC_Status[num] = HC_XFRC;
	}

	else if (hcint.b.stall)
	{
		CLEAR_HC_INT(hcreg, stall);
		UNMASK_HOST_INT_CHH(num);
		USB_OTG_HC_Halt(pdev, num);
		pdev->host.HC_Status[num] = HC_STALL;
	}

	else if (hcint.b.nak)
	{
		pdev->host.ErrCnt[num] = 0;
		UNMASK_HOST_INT_CHH(num);
		USB_OTG_HC_Halt(pdev, num);
		CLEAR_HC_INT(hcreg, nak);
		pdev->host.HC_Status[num] = HC_NAK;
	}

	else if (hcint.b.xacterr)
	{
		UNMASK_HOST_INT_CHH(num);
		USB_OTG_HC_Halt(pdev, num);
		pdev->host.ErrCnt[num]++;
		pdev->host.HC_Status[num] = HC_XACTERR;
		CLEAR_HC_INT(hcreg, xacterr);
	}
	else if (hcint.b.nyet)
	{
		pdev->host.ErrCnt[num] = 0;
		UNMASK_HOST_INT_CHH(num);
		USB_OTG_HC_Halt(pdev, num);
		CLEAR_HC_INT(hcreg, nyet);
		pdev->host.HC_Status[num] = HC_NYET;
	}
	else if (hcint.b.datatglerr)
	{
		UNMASK_HOST_INT_CHH(num);
		USB_OTG_HC_Halt(pdev, num);
		CLEAR_HC_INT(hcreg, nak);
		pdev->host.HC_Status[num] = HC_DATATGLERR;

		CLEAR_HC_INT(hcreg, datatglerr);
	}
	else if (hcint.b.chhltd)
	{
		MASK_HOST_INT_CHH(num);
		ret = 1;
		if (pdev->host.HC_Status[num] == HC_XFRC)
		{
			pdev->host.URB_State[num] = URB_DONE;
			if (hcchar.b.eptype == EP_TYPE_BULK)
			{
				
				if (pdev->host.hc[num].packet_count & 1)
					pdev->host.hc[num].toggle_out ^= 1;
			}
		}
		else if (pdev->host.HC_Status[num] == HC_NAK)
		{
			pdev->host.URB_State[num] = URB_NOTREADY;
		}
		else if (pdev->host.HC_Status[num] == HC_NYET)
		{
			if (pdev->host.hc[num].do_ping == 1)
			{
				USB_OTG_HC_DoPing(pdev, num);
			}
			pdev->host.URB_State[num] = URB_NOTREADY;
		}
		else if (pdev->host.HC_Status[num] == HC_STALL)
		{
			pdev->host.URB_State[num] = URB_STALL;
		}
		else if (pdev->host.HC_Status[num] == HC_XACTERR)
		{
			if (pdev->host.ErrCnt[num] == 3)
			{
				pdev->host.URB_State[num] = URB_ERROR;
				pdev->host.ErrCnt[num] = 0;
			}
		}else
			ret = 0;
		
		CLEAR_HC_INT(hcreg, chhltd);
	}
	else
	{
		p_err("unkown out isr:%08x\n", hcint.d32);
	}


	return ret;
}
Beispiel #10
0
uint32_t USB_OTG_USBH_handle_hc_n_In_ISR(USB_OTG_CORE_HANDLE *pdev, uint32_t
	num)
{
	USB_OTG_HCINTn_TypeDef hcint;
	USB_OTG_HCGINTMSK_TypeDef hcintmsk;
	USB_OTG_HCCHAR_TypeDef hcchar;
	USB_OTG_HCTSIZn_TypeDef hctsiz;
	USB_OTG_HC_REGS *hcreg;
	int ret = 0;

	hcreg = pdev->regs.HC_REGS[num];
	hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT);
	hcintmsk.d32 = USB_OTG_READ_REG32(&hcreg->HCGINTMSK);
	hcint.d32 = hcint.d32 &hcintmsk.d32;
	hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCCHAR);
	hcintmsk.d32 = 0;

	USB_OTG_WRITE_REG32(&hcreg->HCINT, hcint.d32 | 0x7f); //clear 0-10bit

	if (hcint.b.chhltd)
	{
		//      MASK_HOST_INT_CHH(num);
		hcint.b.chhltd = 0;
		
		ret = 1;
		if (pdev->host.HC_Status[num] == HC_XFRC)
		{
			pdev->host.URB_State[num] = URB_DONE;
		}
		else if (pdev->host.HC_Status[num] == HC_NAK)
		//mark nak作为正常的接收
		{
			pdev->host.URB_State[num] = URB_DONE;
		}
		else if (pdev->host.HC_Status[num] == HC_STALL)
		{
			pdev->host.URB_State[num] = URB_STALL;
		}

		else if ((pdev->host.HC_Status[num] == HC_XACTERR) || (pdev
	->host.HC_Status[num] == HC_DATATGLERR))
		{
			pdev->host.ErrCnt[num] = 0;
			pdev->host.URB_State[num] = URB_ERROR;

		}
		else if (pdev->host.HC_Status[num] == HC_HALTED)
		{
			pdev->host.URB_State[num] = URB_ERROR;
			pdev->host.ErrCnt[num] = 0;
		}
		else{
			ret = 0;
			p_err("unkown hltd:%d\n", pdev->host.HC_Status[num]);
		}
		

	}

	if (hcint.b.xfercompl)
	{
		hcint.b.xfercompl = 0;

		pdev->host.HC_Status[num] = HC_XFRC;
		pdev->host.ErrCnt[num] = 0;

		if (hcchar.b.eptype == EP_TYPE_BULK)
		{
			if (pdev->cfg.dma_enable == 1)
			{
				hctsiz.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCTSIZ);
				pdev->host.XferCnt[num] = pdev->host.hc[num].xfer_len - hctsiz.b.xfersize;

				pdev->host.hc[num].packet_count = (pdev->host.XferCnt[num] + pdev
	->host.hc[num].max_packet - 1) / pdev->host.hc[num].max_packet;
			}
			if (pdev->host.hc[num].packet_count &1)
				pdev->host.hc[num].toggle_in ^= 1;
			USB_OTG_HC_Halt(pdev, num);
		}
		else if (hcchar.b.eptype == EP_TYPE_CTRL)
		{
			pdev->host.hc[num].toggle_in ^= 1;
			USB_OTG_HC_Halt(pdev, num);
		}
		else if (hcchar.b.eptype == EP_TYPE_INTR)
		{
			hcchar.b.oddfrm = 1;
			USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
			pdev->host.URB_State[num] = URB_DONE;
		}

	}

	if (hcint.b.nak)
	{
		hcint.b.nak = 0;

		pdev->host.HC_Status[num] = HC_NAK;

		if (hcchar.b.eptype == EP_TYPE_CTRL)
		{
			hcchar.b.chen = 1;
			hcchar.b.chdis = 0;
			USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
		}
		else
			USB_OTG_HC_Halt(pdev, num);
	}

	if(hcint.d32 == 0)
		goto end;


	if (hcint.b.ahberr)
	{
		p_err("ahberr\n");
	}

	if (hcint.b.ack)
	{
		p_err("ack\n");
	}

	if (hcint.b.stall)
	{
		pdev->host.HC_Status[num] = HC_STALL;
		hcint.b.nak = 0; /* NOTE: When there is a 'stall', reset also nak,
		else, the pdev->host.HC_Status = HC_STALL
		will be overwritten by 'nak' in code below */
		USB_OTG_HC_Halt(pdev, num);
	}

	if (hcint.b.datatglerr)
	{
		pdev->host.HC_Status[num] = HC_DATATGLERR;
		USB_OTG_HC_Halt(pdev, num);
	}

	if (hcint.b.frmovrun)
	{
		USB_OTG_HC_Halt(pdev, num);
	}

	if (hcint.b.xacterr)
	{
		pdev->host.ErrCnt[num]++;
		pdev->host.HC_Status[num] = HC_XACTERR;
		USB_OTG_HC_Halt(pdev, num);
	}
	
end:
	return ret;

}
Beispiel #11
0
/**
* @brief  USB_OTG_USBH_handle_hc_n_Out_ISR 
*         Handles interrupt for a specific Host Channel
* @param  pdev: Selected device
* @param  hc_num: Channel number
* @retval status 
*/
uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t num)
{
  
  USB_OTG_HCINTn_TypeDef     hcint;
  USB_OTG_HCINTMSK_TypeDef  hcintmsk;
  USB_OTG_HC_REGS *hcreg;
  USB_OTG_HCCHAR_TypeDef     hcchar; 
  
  hcreg = pdev->regs.HC_REGS[num];
  hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT);
  hcintmsk.d32 = USB_OTG_READ_REG32(&hcreg->HCINTMSK);
  hcint.d32 = hcint.d32 & hcintmsk.d32;
  
  hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCCHAR);
#ifdef USE_HOST_MODE
  if (hcint.b.ahberr)
  {
    CLEAR_HC_INT(hcreg ,ahberr);
    UNMASK_HOST_INT_CHH (num);
  } 
  else if (hcint.b.ack)
  {
    CLEAR_HC_INT(hcreg , ack);
  }
  else if (hcint.b.frmovrun)
  {
    UNMASK_HOST_INT_CHH (num);
    USB_OTG_HC_Halt(pdev, num);
    CLEAR_HC_INT(hcreg ,frmovrun);
  }
  else if (hcint.b.xfercompl)
  {
    pdev->host.ErrCnt[num] = 0;
    UNMASK_HOST_INT_CHH (num);
    USB_OTG_HC_Halt(pdev, num);
    CLEAR_HC_INT(hcreg , xfercompl);
    pdev->host.HC_Status[num] = HC_XFRC;            
  }
  
  else if (hcint.b.stall)
  {
    CLEAR_HC_INT(hcreg , stall);
    UNMASK_HOST_INT_CHH (num);
    USB_OTG_HC_Halt(pdev, num);
    pdev->host.HC_Status[num] = HC_STALL;      
  }
  
  else if (hcint.b.nak)
  {
    pdev->host.ErrCnt[num] = 0;
    UNMASK_HOST_INT_CHH (num);
    USB_OTG_HC_Halt(pdev, num);
    CLEAR_HC_INT(hcreg , nak);
    pdev->host.HC_Status[num] = HC_NAK;      
  }
  
  else if (hcint.b.xacterr)
  {
    UNMASK_HOST_INT_CHH (num);
    USB_OTG_HC_Halt(pdev, num);
    pdev->host.ErrCnt[num] ++;
    pdev->host.HC_Status[num] = HC_XACTERR;
    CLEAR_HC_INT(hcreg , xacterr);
  }
  else if (hcint.b.nyet)
  {
    pdev->host.ErrCnt[num] = 0;
    UNMASK_HOST_INT_CHH (num);
    USB_OTG_HC_Halt(pdev, num);
    CLEAR_HC_INT(hcreg , nyet);
    pdev->host.HC_Status[num] = HC_NYET;    
  }
  else if (hcint.b.datatglerr)
  {
    
    UNMASK_HOST_INT_CHH (num);
    USB_OTG_HC_Halt(pdev, num);
    CLEAR_HC_INT(hcreg , nak);   
    pdev->host.HC_Status[num] = HC_DATATGLERR;
    
    CLEAR_HC_INT(hcreg , datatglerr);
  }  
  else if (hcint.b.chhltd)
  {
    MASK_HOST_INT_CHH (num);
    
    if(pdev->host.HC_Status[num] == HC_XFRC)
    {
      pdev->host.URB_State[num] = URB_DONE;  
      
      if (hcchar.b.eptype == EP_TYPE_BULK)
      {
        pdev->host.hc[num].toggle_out ^= 1; 
      }
    }
    else if(pdev->host.HC_Status[num] == HC_NAK)
    {
      pdev->host.URB_State[num] = URB_NOTREADY;      
    }    
    else if(pdev->host.HC_Status[num] == HC_NYET)
    {
      if(pdev->host.hc[num].do_ping == 1)
      {
        USB_OTG_HC_DoPing(pdev, num);
      }
      pdev->host.URB_State[num] = URB_NOTREADY;      
    }      
    else if(pdev->host.HC_Status[num] == HC_STALL)
    {
      pdev->host.URB_State[num] = URB_STALL;      
    }  
    else if(pdev->host.HC_Status[num] == HC_XACTERR)
    {
      if (pdev->host.ErrCnt[num] == 3)
      {
        pdev->host.URB_State[num] = URB_ERROR;  
        pdev->host.ErrCnt[num] = 0;
      }
    }
    CLEAR_HC_INT(hcreg , chhltd);    
  }
#endif
  
  return 1;
}
/**
  * @brief  This function send data to the device.
  * @param  fileName : name of the file 
  * @retval the filestate will be returned 
  * FS_SUCCESS : returned to the parent function when the file length become to zero
  */
void  CDC_StopReception( USB_OTG_CORE_HANDLE *pdev)
{
  RX_Enabled = 0; 
  USB_OTG_HC_Halt(pdev, CDC_Machine.CDC_DataItf.hc_num_in);
  USBH_Free_Channel  (pdev,CDC_Machine.CDC_DataItf.hc_num_in);
}