Beispiel #1
0
/*******************************************************************************
* Function Name  : In0_Process
* Description    : Process the IN token on all default endpoint.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
uint8_t In0_Process(void) {
    uint32_t ControlState = pInformation->ControlState;

    if((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA)) {
        DataStageIn();
        /* ControlState may be changed outside the function */
        ControlState = pInformation->ControlState;
    }

    else if(ControlState == WAIT_STATUS_IN) {
        if((pInformation->USBbRequest == SET_ADDRESS) && (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))) {
            SetDeviceAddress(pInformation->USBwValue0);
            pUser_Standard_Requests->User_SetDeviceAddress();
        }
        (*pProperty->Process_Status_IN)();
        ControlState = STALLED;
    }

    else {
        ControlState = STALLED;
    }

    pInformation->ControlState = ControlState;

    return Post0_Process();
}
Beispiel #2
0
/*******************************************************************************
* Function Name  : Out0_Process
* Description    : Process the OUT token on all default endpoint.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
uint8_t Out0_Process(void) {
    uint32_t ControlState = pInformation->ControlState;

    if((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA)) {
        /* host aborts the transfer before finish */
        ControlState = STALLED;
    } else if((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA)) {
        DataStageOut();
        ControlState = pInformation->ControlState; /* may be changed outside the function */
    }

    else if(ControlState == WAIT_STATUS_OUT) {
        (*pProperty->Process_Status_OUT)();
#ifndef STM32F10X_CL
        ControlState = STALLED;
#endif /* STM32F10X_CL */
    }


    /* Unexpect state, STALL the endpoint */
    else {
        ControlState = STALLED;
    }

    pInformation->ControlState = ControlState;

    return Post0_Process();
}
Beispiel #3
0
/*******************************************************************************
* Function Name  : Setup0_Process
* Description    : Get the device request data and dispatch to individual process.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
uint8_t Setup0_Process(void) {
    union {
        uint8_t* b;
        uint16_t* w;
    } pBuf;
    
    uint16_t offset = 1;
  
    pBuf.b = PMAAddr + (uint8_t *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */

    if (pInformation->ControlState != PAUSE) {
        pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
        pInformation->USBbRequest = *pBuf.b++; /* bRequest */
        pBuf.w += offset;  /* word not accessed because of 32 bits addressing */
        pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
        pBuf.w += offset;  /* word not accessed because of 32 bits addressing */
        pInformation->USBwIndex  = ByteSwap(*pBuf.w++); /* wIndex */
        pBuf.w += offset;  /* word not accessed because of 32 bits addressing */
        pInformation->USBwLength = *pBuf.w; /* wLength */
    }

    pInformation->ControlState = SETTING_UP;
    if (pInformation->USBwLength == 0) {
        /* Setup with no data stage */
        NoData_Setup0();
    }
    else {
        /* Setup with data stage */
        Data_Setup0();
    }
    
    return Post0_Process();
}
Beispiel #4
0
/*******************************************************************************
* Function Name  : Setup0_Process
* Description    : Get the device request data and dispatch to individual process.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
uint8_t Setup0_Process(void) {
	union {
		uint8_t* b;
		uint16_t* w;
	} pBuf;
	uint16_t offset = 1;
  
	pBuf.b = USB_PMAADDR + (uint8_t *)(GetEPRxAddr(ENDP0) * 2); // *2 for 32 bits addr

	if (pInformation->ControlState != PAUSE) {
		pInformation->USBbmRequestType = *pBuf.b++; // bmRequestType
		pInformation->USBbRequest = *pBuf.b++; // bRequest
		pBuf.w += offset;  // word not accessed because of 32 bits addressing
		pInformation->USBwValue = ByteSwap(*pBuf.w++); // wValue
		pBuf.w += offset;  // word not accessed because of 32 bits addressing
		pInformation->USBwIndex  = ByteSwap(*pBuf.w++); // wIndex
		pBuf.w += offset;  // word not accessed because of 32 bits addressing
		pInformation->USBwLength = *pBuf.w; // wLength
	}
	pInformation->ControlState = SETTING_UP;
	if (pInformation->USBwLength == 0) {
		// Setup with no data stage
		NoData_Setup0();
	} else {
		// Setup with data stage
		Data_Setup0();
	}

	return Post0_Process();
}
/*******************************************************************************
* Function Name  : Setup0_Process
* Description    : Get the device request data and dispatch to individual process.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
uint8_t Setup0_Process(void)
{

  union
  {
    uint8_t* b;
    uint16_t* w;
  } pBuf;

#ifdef STM32F10X_CL
  USB_OTG_EP *ep;
  uint16_t offset = 0;
 
  ep = PCD_GetOutEP(ENDP0);
  pBuf.b = ep->xfer_buff;
  
  OTGD_FS_EP0StartXfer(ep);
#else  
  uint16_t offset = 1;
  
  pBuf.b = PMAAddr + (uint8_t *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */
#endif /* STM32F10X_CL */

  if (pInformation->ControlState != PAUSE)
  {
    pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
    pInformation->USBbRequest = *pBuf.b++; /* bRequest */
    pBuf.w += offset;  /* word not accessed because of 32 bits addressing */
    pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
    pBuf.w += offset;  /* word not accessed because of 32 bits addressing */
    pInformation->USBwIndex  = ByteSwap(*pBuf.w++); /* wIndex */
    pBuf.w += offset;  /* word not accessed because of 32 bits addressing */
    pInformation->USBwLength = *pBuf.w; /* wLength */
  }

  pInformation->ControlState = SETTING_UP;
  if (pInformation->USBwLength == 0)
  {
    /* Setup with no data stage */
    NoData_Setup0();
  }
  else
  {
    /* Setup with data stage */
    Data_Setup0();
  }
  return Post0_Process();
}
Beispiel #6
0
/*******************************************************************************
* Function Name  : Out0_Process
* Description    : Process the OUT token on all default endpoint.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
uint8_t Out0_Process(void) {
	uint32_t ControlState = pInformation->ControlState;

	if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA)) {
		// host aborts the transfer before finish
		ControlState = STALLED;
	} else if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA)) {
		DataStageOut();
		ControlState = pInformation->ControlState; // may be changed outside the function
	} else if (ControlState == WAIT_STATUS_OUT) {
		(*pProperty->Process_Status_OUT)();
		ControlState = STALLED;
	} else {
		// Unexpect state, STALL the endpoint
		ControlState = STALLED;
	}
	pInformation->ControlState = ControlState;

	return Post0_Process();
}
Beispiel #7
0
/*******************************************************************************
* Function Name  : Out0_Process
* Description    : Process the OUT token on all default endpoint.
* Input          : None.
* Output         : None.
* Return         : Post0_Process.
*******************************************************************************/
u8 Out0_Process(void)
{

  u32 ControlState = pInformation->ControlState;
                  #ifdef DEBUG_EP0
    putchar('U');
    #endif

                  #ifdef DEBUG_EP0
    putchar('q');
    #endif
  if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA))
  {
    DataStageOut();
    ControlState = pInformation->ControlState; /* may be changed outside the function */
  }
  else if (ControlState == WAIT_STATUS_OUT)
  {
    (*pProperty->Process_Status_OUT)();
    ControlState = STALLED;
  }

  else if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
  {
    /* host aborts the transfer before finish */
    ControlState = STALLED;
  }

  /* Unexpect state, STALL the endpoint */
  else
  {
    ControlState = STALLED;
  }

  pInformation->ControlState = ControlState;

  return Post0_Process();
}