HRESULT Library_spot_hardware_usb_native_Microsoft_SPOT_Hardware_UsbClient_UsbStream::nativeWrite___I4__SZARRAY_U1__I4__I4( CLR_RT_StackFrame& stack ) { TINYCLR_HEADER(); CLR_INT32 retVal = 0; CLR_INT32 controllerIndex, streamIndex, stream; CLR_UINT32 offset, count; CLR_RT_HeapBlock* pThis; CLR_RT_HeapBlock_Array* array; pThis = stack.This(); FAULT_ON_NULL(pThis); controllerIndex = pThis[ Library_spot_hardware_usb_native_Microsoft_SPOT_Hardware_UsbClient_UsbStream::FIELD__m_controllerIndex ].NumericByRef().s4; streamIndex = pThis[ Library_spot_hardware_usb_native_Microsoft_SPOT_Hardware_UsbClient_UsbStream::FIELD__m_streamIndex ].NumericByRef().s4; array = stack.Arg1().DereferenceArray(); FAULT_ON_NULL( array ); offset = stack.Arg2().NumericByRef().u4; count = stack.Arg3().NumericByRef().u4; stream = (controllerIndex << USB_CONTROLLER_SHIFT) + streamIndex; if( array->m_numOfElements < (offset + count) ) { TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER); } else { retVal = USB_Write( stream, (char*)array->GetFirstElement()+offset, count ); } stack.SetResult_I4( retVal ); TINYCLR_NOCLEANUP(); }
//------------------------------------------------------------------------------ // \brief Sends the qualifier descriptor to the host. // // The number of bytes actually sent depends on both the length // requested by the host and the actual length of the descriptor. // \param pClass Pointer to a class driver instance // \param wLength Number of bytes requested by the host //------------------------------------------------------------------------------ static void STD_GetQualifierDescriptor(const S_std_class *pClass, unsigned short wLength) { USB_Write(pClass->pUsb, 0, (void *) pClass->pDescriptors->pQualifier, min(pClass->pDescriptors->pQualifier->bLength, wLength), 0, 0); }
//------------------------------------------------------------------------------ // \brief Sends the device descriptor to the host. // // The number of bytes actually sent depends on both the length // requested by the host and the actual length of the descriptor. // \param pClass Pointer to a class driver instance // \param wLength Number of bytes requested by the host //------------------------------------------------------------------------------ static void STD_GetDeviceDescriptor(const S_std_class *pClass, unsigned short wLength) { USB_Write(pClass->pUsb, 0, (void *) pClass->pDescriptors->pDevice, min(sizeof(S_usb_device_descriptor), wLength), 0, 0); }
//------------------------------------------------------------------------------ // \brief Sends the specified string descriptor to the host // // The number of bytes actually sent depends on both the length // requested by the host and the actual length of the descriptor. // \param pClass Pointer to a class driver instance // \param wLength Number of bytes requested by the host // \param wIndex Index of requested string descriptor //------------------------------------------------------------------------------ static void STD_GetStringDescriptor(const S_std_class *pClass, unsigned short wLength, unsigned char bIndex) { USB_Write(pClass->pUsb, 0, (void *) pClass->pDescriptors->pStrings[bIndex], min( *(pClass->pDescriptors->pStrings[bIndex]), wLength), 0, 0); }
//------------------------------------------------------------------------------ // \brief Sends the other speed configuration descriptor to the host. // // The number of bytes actually sent depends on both the length // requested by the host and the actual length of the descriptor. // \param pClass Pointer to a class driver instance // \param wLength Number of bytes requested by the host //------------------------------------------------------------------------------ static void STD_GetOSCDescriptor(const S_std_class *pClass, unsigned short wLength) { USB_Write(pClass->pUsb, 0, (void *) pClass->pDescriptors->pOtherSpeedConfiguration, min(pClass->pDescriptors->pOtherSpeedConfiguration->wTotalLength, wLength), 0, 0); }
//------------------------------------------------------------------------------ // \brief Sends the current status of specified endpoint to the host. // \param pClass Pointer to a class driver instance // \param bEndpoint Endpoint number //------------------------------------------------------------------------------ static void STD_GetEndpointStatus(S_std_class *pClass, unsigned char bEndpoint) { //! Retrieve the endpoint current status pClass->wData = (unsigned short) USB_Halt(pClass->pUsb, bEndpoint, USB_GET_STATUS); //! Return the endpoint status USB_Write(pClass->pUsb, 0, &(pClass->wData), 2, 0, 0); }
//------------------------------------------------------------------------------ // \brief Sends the currently selected configuration to the host. // \param pClass Pointer to a class driver instance //------------------------------------------------------------------------------ static void STD_GetConfiguration(S_std_class *pClass) { if (ISSET(USB_GetState(pClass->pUsb), USB_STATE_CONFIGURED)) { pClass->wData = 1; } else { pClass->wData = 0; } USB_Write(pClass->pUsb, 0, &(pClass->wData), 1, 0, 0); }
int DebuggerPort_Write( COM_HANDLE ComPortNum, const char* Data, size_t size ) { NATIVE_PROFILE_PAL_COM(); UINT32 transport = ExtractTransport(ComPortNum); const char* dataTmp = Data; INT32 totWrite = 0; int retries = 100; while(size > 0 && retries--) { int ret = 0; switch(transport) { case USART_TRANSPORT: ret = USART_Write( ConvertCOM_ComPort( ComPortNum ), dataTmp, size ); break; case USB_TRANSPORT: ret = USB_Write( ConvertCOM_UsbStream( ComPortNum ), dataTmp, size ); break; case SOCKET_TRANSPORT: ret = SOCKETS_Write( ConvertCOM_SockPort(ComPortNum), dataTmp, size ); break; } if(ret < 0) { break; } else if(ret == 0) { // if interrupts are off and our buffer is full then there is nothing we can do if(!INTERRUPTS_ENABLED_STATE()) break; Events_WaitForEvents(0, 1); } else { retries = 50; // reset retries size -= ret; dataTmp += ret; totWrite += ret; } } return totWrite; }
//------------------------------------------------------------------------------ // \brief Sends the current device status to the host. // \param pClass Pointer to a class driver interface //------------------------------------------------------------------------------ static void STD_GetDeviceStatus(S_std_class *pClass) { // Bus or self-powered ? if (ISSET(pClass->pDescriptors->pConfiguration->bmAttibutes, USB_CONFIG_SELF_NOWAKEUP)) { // Self powered device pClass->wDeviceStatus |= SELF_POWERED; } else { // Bus powered device pClass->wDeviceStatus &= ~SELF_POWERED; } // Return the device status USB_Write(pClass->pUsb, 0, &(pClass->wDeviceStatus), 2, 0, 0); }
/*--------------------------------------------------------------------------- * usbTransmitData() * Function to transmit data. * This function may be called when an HCI packet is sent down. It is also * called when the controller is ready to transmit more data. Unlike other * transports, each packet must be a single IO request to USB so we must * reassemble the header and data fragments. * * Requires: * * Parameters: * * Returns: * */ static void usbTransmitData(void) { /* USTRAN(txBufp) could be on the stack in this function. It was placed * in the context structure because of the size. */ U8 *txBufp = USTRAN(txBuf); UsbEndPoint epType; /* USB endpoint type */ int bytesWritten; U16 len; int i; if (USTRAN(txPacket)) { /* We received an event indicating the packet was sent so notify * the upper layer */ HCI_PacketSent(USTRAN(txPacket)); } /* Get a packet off the transmit queue */ if (IsListEmpty(&USTRAN(txQueue))) { USTRAN(txPacket) = 0; return; } USTRAN(txPacket) = (HciPacket *)RemoveHeadList(&USTRAN(txQueue)); /* * Based upon the type, we will write 'bulk' or 'control' or 'isochronous'. * SCO is the only type for isochronous */ if (USTRAN(txPacket)->flags & HCI_BUFTYPE_COMMAND) { /* COMMAND Data type - use control pipe */ epType = USB_CONTROL_WRITE; len = 3; /* header len = 3 */ } else if (USTRAN(txPacket)->flags & HCI_BUFTYPE_ACL_DATA) { /* ACL Data type - use bulk pipe */ epType = USB_BULK_WRITE; len = 4; /* header len = 4 */ #if (BT_SCO_HCI_DATA == XA_ENABLED) && (NUM_SCO_CONNS > 0) } else if (USTRAN(txPacket)->flags & HCI_BUFTYPE_SCO_DATA) { /* SCO Data type - use isochronous pipe */ epType = USB_ISO_WRITE; len = 3; /* header len = 3 */ #endif } else { Assert(0); return; } /* Copy header to our transmit buffer */ OS_MemCopy((U8 *)txBufp, (U8 *)USTRAN(txPacket)->header, len); txBufp += len; /* Append each fragment to our buffer */ for (i = 0; i < USTRAN(txPacket)->fCount; i++) { len = USTRAN(txPacket)->f[i].len; Assert(len <= (USTRAN(txBuf) + HCI_USB_TX_BUFFER_SIZE) - txBufp); OS_MemCopy(txBufp, USTRAN(txPacket)->f[i].buffer, len); txBufp += len; } /* Write outstanding bytes to the USB driver */ bytesWritten = USB_Write(epType, USTRAN(txBuf), txBufp - USTRAN(txBuf), TRUE); /* If no bytes were written, there was some kind of error */ if (bytesWritten <= 0) { bt_trace(TRACE_GROUP_1,TRANS_USB_COULD_NOT_WRITE_DATA); HCI_TransportError(); } }
void USB_WriteWord(WORD w) { USB_Write(&w, 2); }
void USB_WriteChar(char c) { USB_Write(&c, 1); }