mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-18 06:08:31 +03:00
Renamed main folder to firmware
This commit is contained in:
@@ -0,0 +1,237 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**\file
|
||||
* Implementation of a single CDC serial port function for USB device.
|
||||
*/
|
||||
|
||||
/** \addtogroup usbd_cdc
|
||||
*@{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Headers
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#include "CDCDSerial.h"
|
||||
|
||||
#include <USBLib_Trace.h>
|
||||
#include <USBDDriver.h>
|
||||
#include <USBD_HAL.h>
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Types
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal variables
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/** Serial Port instance list */
|
||||
static CDCDSerialPort cdcdSerial;
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* USB CDC Serial Port Event Handler.
|
||||
* \param event Event code.
|
||||
* \param param Event parameter.
|
||||
*/
|
||||
static uint32_t CDCDSerial_EventHandler(uint32_t event,
|
||||
uint32_t param)
|
||||
{
|
||||
switch (event) {
|
||||
case CDCDSerialPortEvent_SETCONTROLLINESTATE:
|
||||
{
|
||||
if (CDCDSerial_ControlLineStateChanged) {
|
||||
CDCDSerial_ControlLineStateChanged(
|
||||
(param & CDCControlLineState_DTR) > 0,
|
||||
(param & CDCControlLineState_RTS) > 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CDCDSerialPortEvent_SETLINECODING:
|
||||
{
|
||||
if (CDCDSerial_LineCodingIsToChange) {
|
||||
event = CDCDSerial_LineCodingIsToChange(
|
||||
(CDCLineCoding*)param);
|
||||
if (event != USBRC_SUCCESS)
|
||||
return event;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return USBRC_SUCCESS;
|
||||
}
|
||||
|
||||
return USBRC_SUCCESS;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Initializes the USB Device CDC serial driver & USBD Driver.
|
||||
* \param pUsbd Pointer to USBDDriver instance.
|
||||
* \param bInterfaceNb Interface number for the function.
|
||||
*/
|
||||
void CDCDSerial_Initialize(
|
||||
USBDDriver *pUsbd, uint8_t bInterfaceNb)
|
||||
{
|
||||
CDCDSerialPort *pCdcd = &cdcdSerial;
|
||||
|
||||
TRACE_INFO("CDCDSerial_Initialize\n\r");
|
||||
|
||||
/* Initialize serial port function */
|
||||
CDCDSerialPort_Initialize(
|
||||
pCdcd, pUsbd,
|
||||
(CDCDSerialPortEventHandler)CDCDSerial_EventHandler,
|
||||
0,
|
||||
bInterfaceNb, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked whenever the device is changed by the
|
||||
* host.
|
||||
* \pDescriptors Pointer to the descriptors for function configure.
|
||||
* \wLength Length of descriptors in number of bytes.
|
||||
*/
|
||||
void CDCDSerial_ConfigureFunction(USBGenericDescriptor *pDescriptors,
|
||||
uint16_t wLength)
|
||||
{
|
||||
CDCDSerialPort *pCdcd = &cdcdSerial;
|
||||
CDCDSerialPort_ParseInterfaces(pCdcd,
|
||||
(USBGenericDescriptor*)pDescriptors,
|
||||
wLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles CDC-specific SETUP requests. Should be called from a
|
||||
* re-implementation of USBDCallbacks_RequestReceived() method.
|
||||
* \param request Pointer to a USBGenericRequest instance.
|
||||
*/
|
||||
uint32_t CDCDSerial_RequestHandler(const USBGenericRequest *request)
|
||||
{
|
||||
CDCDSerialPort * pCdcd = &cdcdSerial;
|
||||
|
||||
TRACE_INFO_WP("Cdcf ");
|
||||
return CDCDSerialPort_RequestHandler(pCdcd, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives data from the host through the virtual COM port created by
|
||||
* the CDC device serial driver. This function behaves like USBD_Read.
|
||||
* \param data Pointer to the data buffer to put received data.
|
||||
* \param size Size of the data buffer in bytes.
|
||||
* \param callback Optional callback function to invoke when the transfer
|
||||
* finishes.
|
||||
* \param argument Optional argument to the callback function.
|
||||
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
|
||||
* otherwise, the corresponding error code.
|
||||
*/
|
||||
uint32_t CDCDSerial_Read(void *data,
|
||||
uint32_t size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
CDCDSerialPort * pCdcd = &cdcdSerial;
|
||||
return CDCDSerialPort_Read(pCdcd, data, size, callback, argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a data buffer through the virtual COM port created by the CDC
|
||||
* device serial driver. This function behaves exactly like USBD_Write.
|
||||
* \param data Pointer to the data buffer to send.
|
||||
* \param size Size of the data buffer in bytes.
|
||||
* \param callback Optional callback function to invoke when the transfer
|
||||
* finishes.
|
||||
* \param argument Optional argument to the callback function.
|
||||
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
|
||||
* otherwise, the corresponding error code.
|
||||
*/
|
||||
uint32_t CDCDSerial_Write(void *data,
|
||||
uint32_t size,
|
||||
TransferCallback callback,
|
||||
void *argument)
|
||||
{
|
||||
CDCDSerialPort * pCdcd = &cdcdSerial;
|
||||
return CDCDSerialPort_Write(pCdcd, data, size, callback, argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current control line state of the RS-232 line.
|
||||
*/
|
||||
uint8_t CDCDSerial_GetControlLineState(void)
|
||||
{
|
||||
CDCDSerialPort * pCdcd = &cdcdSerial;
|
||||
return CDCDSerialPort_GetControlLineState(pCdcd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy current line coding settings to pointered space.
|
||||
* \param pLineCoding Pointer to CDCLineCoding instance.
|
||||
*/
|
||||
void CDCDSerial_GetLineCoding(CDCLineCoding* pLineCoding)
|
||||
{
|
||||
CDCDSerialPort * pCdcd = &cdcdSerial;
|
||||
CDCDSerialPort_GetLineCoding(pCdcd, pLineCoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current status of the RS-232 line.
|
||||
*/
|
||||
uint16_t CDCDSerial_GetSerialState(void)
|
||||
{
|
||||
CDCDSerialPort * pCdcd = &cdcdSerial;
|
||||
return CDCDSerialPort_GetSerialState(pCdcd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current serial state of the device to the given value.
|
||||
* \param serialState New device state.
|
||||
*/
|
||||
void CDCDSerial_SetSerialState(uint16_t serialState)
|
||||
{
|
||||
CDCDSerialPort * pCdcd = &cdcdSerial;
|
||||
CDCDSerialPort_SetSerialState(pCdcd, serialState);
|
||||
}
|
||||
|
||||
WEAK uint8_t CDCDSerial_LineCodingIsToChange(CDCLineCoding * pLineCoding)
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
WEAK void CDCDSerial_ControlLineStateChanged(uint8_t DTR,uint8_t RTS)
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
/**@}*/
|
||||
@@ -0,0 +1,116 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**\file
|
||||
* Title: CDCDSerialDriver implementation
|
||||
*
|
||||
* About: Purpose
|
||||
* Implementation of the CDCDSerialDriver class methods.
|
||||
*/
|
||||
|
||||
/** \addtogroup usbd_cdc
|
||||
*@{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Headers
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#include "CDCDSerialDriver.h"
|
||||
|
||||
#include <USBLib_Trace.h>
|
||||
#include <USBDDriver.h>
|
||||
#include <USBD_HAL.h>
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Types
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal variables
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Initializes the USB Device CDC serial driver & USBD Driver.
|
||||
* \param pDescriptors Pointer to Descriptors list for CDC Serial Device.
|
||||
*/
|
||||
void CDCDSerialDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
|
||||
{
|
||||
USBDDriver *pUsbd = USBD_GetDriver();
|
||||
|
||||
/* Initialize the standard driver */
|
||||
USBDDriver_Initialize(pUsbd,
|
||||
pDescriptors,
|
||||
0); /* Multiple settings for interfaces not supported */
|
||||
|
||||
CDCDSerial_Initialize(pUsbd, CDCDSerialDriver_CC_INTERFACE);
|
||||
|
||||
/* Initialize the USB driver */
|
||||
USBD_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked whenever the active configuration of device is changed by the
|
||||
* host.
|
||||
* \param cfgnum Configuration number.
|
||||
*/
|
||||
void CDCDSerialDriver_ConfigurationChangedHandler(uint8_t cfgnum)
|
||||
{
|
||||
USBDDriver *pUsbd = USBD_GetDriver();
|
||||
USBConfigurationDescriptor *pDesc;
|
||||
if (cfgnum) {
|
||||
pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
|
||||
CDCDSerial_ConfigureFunction((USBGenericDescriptor *)pDesc,
|
||||
pDesc->wTotalLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles CDC-specific SETUP requests. Should be called from a
|
||||
* re-implementation of USBDCallbacks_RequestReceived() method.
|
||||
* \param request Pointer to a USBGenericRequest instance.
|
||||
*/
|
||||
void CDCDSerialDriver_RequestHandler(const USBGenericRequest *request)
|
||||
{
|
||||
USBDDriver *pUsbd = USBD_GetDriver();
|
||||
TRACE_INFO_WP("NewReq ");
|
||||
if (CDCDSerial_RequestHandler(request))
|
||||
USBDDriver_RequestHandler(pUsbd, request);
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2010, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Headers
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/* These headers were introduced in C99
|
||||
by working group ISO/IEC JTC1/SC22/WG14. */
|
||||
#include <stdint.h>
|
||||
|
||||
#include "CDCDSerialDriver.h"
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Default callback functions
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Invoked when the CDC LineCoding is requested to changed
|
||||
* \param port Port number.
|
||||
* \param pLineCoding Pointer to new LineCoding settings.
|
||||
*/
|
||||
extern WEAK uint8_t CDCDSerialDriver_LineCodingIsToChange(
|
||||
CDCLineCoding * pLineCoding)
|
||||
{
|
||||
/* Accept any of linecoding settings */
|
||||
return USBD_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the CDC ControlLineState is changed
|
||||
* \param port Port number.
|
||||
* \param DTR New DTR value.
|
||||
* \param RTS New RTS value.
|
||||
*/
|
||||
extern WEAK void CDCDSerialDriver_ControlLineStateChanged(uint8_t DTR,
|
||||
uint8_t RTS)
|
||||
{
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
@@ -0,0 +1,455 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* Copyright (c) 2008, Atmel Corporation
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**\file
|
||||
* Implementation of the CDCDSerialPort class methods.
|
||||
*/
|
||||
|
||||
/** \addtogroup usbd_cdc
|
||||
*@{
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Headers
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
#include <CDCDSerialPort.h>
|
||||
#include <CDCDescriptors.h>
|
||||
#include <USBLib_Trace.h>
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Types
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/** Parse data extention for descriptor parsing */
|
||||
typedef struct _CDCDParseData {
|
||||
/** Pointer to CDCDSerialPort instance */
|
||||
CDCDSerialPort * pCdcd;
|
||||
/** Pointer to found interface descriptor */
|
||||
USBInterfaceDescriptor * pIfDesc;
|
||||
|
||||
} CDCDParseData;
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal variables
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/** Line coding values */
|
||||
static CDCLineCoding lineCoding;
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Internal functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Parse descriptors: Interface, Bulk IN/OUT, Interrupt IN.
|
||||
* \param desc Pointer to descriptor list.
|
||||
* \param arg Argument, pointer to AUDDParseData instance.
|
||||
*/
|
||||
static uint32_t _Interfaces_Parse(USBGenericDescriptor *pDesc,
|
||||
CDCDParseData * pArg)
|
||||
{
|
||||
CDCDSerialPort *pCdcd = pArg->pCdcd;
|
||||
|
||||
/* Not a valid descriptor */
|
||||
if (pDesc->bLength == 0)
|
||||
return USBRC_PARAM_ERR;
|
||||
|
||||
/* Find interface descriptor */
|
||||
if (pDesc->bDescriptorType == USBGenericDescriptor_INTERFACE) {
|
||||
USBInterfaceDescriptor *pIf = (USBInterfaceDescriptor*)pDesc;
|
||||
|
||||
/* Obtain interface from descriptor */
|
||||
if (pCdcd->bInterfaceNdx == 0xFF) {
|
||||
/* First interface is communication */
|
||||
if (pIf->bInterfaceClass ==
|
||||
CDCCommunicationInterfaceDescriptor_CLASS) {
|
||||
pCdcd->bInterfaceNdx = pIf->bInterfaceNumber;
|
||||
pCdcd->bNumInterface = 2;
|
||||
}
|
||||
/* Only data interface */
|
||||
else if(pIf->bInterfaceClass == CDCDataInterfaceDescriptor_CLASS) {
|
||||
pCdcd->bInterfaceNdx = pIf->bInterfaceNumber;
|
||||
pCdcd->bNumInterface = 1;
|
||||
}
|
||||
pArg->pIfDesc = pIf;
|
||||
}
|
||||
else if (pCdcd->bInterfaceNdx <= pIf->bInterfaceNumber
|
||||
&& pCdcd->bInterfaceNdx + pCdcd->bNumInterface
|
||||
> pIf->bInterfaceNumber) {
|
||||
pArg->pIfDesc = pIf;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse valid interfaces */
|
||||
if (pArg->pIfDesc == 0)
|
||||
return 0;
|
||||
|
||||
/* Find endpoint descriptors */
|
||||
if (pDesc->bDescriptorType == USBGenericDescriptor_ENDPOINT) {
|
||||
USBEndpointDescriptor *pEp = (USBEndpointDescriptor*)pDesc;
|
||||
switch(pEp->bmAttributes & 0x3) {
|
||||
case USBEndpointDescriptor_INTERRUPT:
|
||||
if (pEp->bEndpointAddress & 0x80)
|
||||
pCdcd->bIntInPIPE = pEp->bEndpointAddress & 0x7F;
|
||||
break;
|
||||
case USBEndpointDescriptor_BULK:
|
||||
if (pEp->bEndpointAddress & 0x80)
|
||||
pCdcd->bBulkInPIPE = pEp->bEndpointAddress & 0x7F;
|
||||
else
|
||||
pCdcd->bBulkOutPIPE = pEp->bEndpointAddress;
|
||||
}
|
||||
}
|
||||
|
||||
if ( pCdcd->bInterfaceNdx != 0xFF
|
||||
&& pCdcd->bBulkInPIPE != 0
|
||||
&& pCdcd->bBulkOutPIPE != 0)
|
||||
return USBRC_FINISHED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function which should be invoked after the data of a
|
||||
* SetLineCoding request has been retrieved. Sends a zero-length packet
|
||||
* to the host for acknowledging the request.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
*/
|
||||
static void _SetLineCodingCallback(CDCDSerialPort * pCdcd)
|
||||
{
|
||||
uint32_t exec = 1;
|
||||
if (pCdcd->fEventHandler) {
|
||||
uint32_t rc = pCdcd->fEventHandler(
|
||||
CDCDSerialPortEvent_SETLINECODING,
|
||||
(uint32_t)(&lineCoding),
|
||||
pCdcd->pArg);
|
||||
if (rc == USBD_STATUS_SUCCESS) {
|
||||
pCdcd->lineCoding.dwDTERate = lineCoding.dwDTERate;
|
||||
pCdcd->lineCoding.bCharFormat = lineCoding.bCharFormat;
|
||||
pCdcd->lineCoding.bParityType = lineCoding.bParityType;
|
||||
pCdcd->lineCoding.bDataBits = lineCoding.bDataBits;
|
||||
}
|
||||
else
|
||||
exec = 0;
|
||||
}
|
||||
if (exec) USBD_Write(0, 0, 0, 0, 0);
|
||||
else USBD_Stall(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives new line coding information from the USB host.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
*/
|
||||
static void _SetLineCoding(CDCDSerialPort * pCdcd)
|
||||
{
|
||||
TRACE_INFO_WP("sLineCoding ");
|
||||
|
||||
USBD_Read(0,
|
||||
(void *) & (lineCoding),
|
||||
sizeof(CDCLineCoding),
|
||||
(TransferCallback)_SetLineCodingCallback,
|
||||
(void*)pCdcd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the current line coding information to the host through Control
|
||||
* endpoint 0.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
*/
|
||||
static void _GetLineCoding(CDCDSerialPort * pCdcd)
|
||||
{
|
||||
TRACE_INFO_WP("gLineCoding ");
|
||||
|
||||
USBD_Write(0,
|
||||
(void *) &(pCdcd->lineCoding),
|
||||
sizeof(CDCLineCoding),
|
||||
0,
|
||||
0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the state of the serial driver according to the information
|
||||
* sent by the host via a SetControlLineState request, and acknowledges
|
||||
* the request with a zero-length packet.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
* \param request Pointer to a USBGenericRequest instance.
|
||||
*/
|
||||
static void _SetControlLineState(
|
||||
CDCDSerialPort * pCdcd,
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
uint8_t DTR, RTS;
|
||||
|
||||
DTR = ((request->wValue & CDCControlLineState_DTR) > 0);
|
||||
RTS = ((request->wValue & CDCControlLineState_RTS) > 0);
|
||||
TRACE_INFO_WP("sControlLineState(%d, %d) ", DTR, RTS);
|
||||
|
||||
pCdcd->bControlLineState = (uint8_t)request->wValue;
|
||||
USBD_Write(0, 0, 0, 0, 0);
|
||||
|
||||
if (pCdcd->fEventHandler)
|
||||
pCdcd->fEventHandler(CDCDSerialPortEvent_SETCONTROLLINESTATE,
|
||||
|
||||
(uint32_t)pCdcd->bControlLineState,
|
||||
pCdcd->pArg);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Exported functions
|
||||
*------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Initializes the USB Device CDC serial port function.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
* \param pUsbd Pointer to USBDDriver instance.
|
||||
* \param fEventHandler Pointer to event handler function.
|
||||
* \param firstInterface First interface index for the function
|
||||
* (0xFF to parse from descriptors).
|
||||
* \param numInterface Number of interfaces for the function.
|
||||
*/
|
||||
void CDCDSerialPort_Initialize(CDCDSerialPort * pCdcd,
|
||||
USBDDriver * pUsbd,
|
||||
CDCDSerialPortEventHandler fEventHandler,
|
||||
void * pArg,
|
||||
uint8_t firstInterface,uint8_t numInterface)
|
||||
{
|
||||
TRACE_INFO("CDCDSerialPort_Initialize\n\r");
|
||||
|
||||
/* Initialize event handler */
|
||||
pCdcd->fEventHandler = fEventHandler;
|
||||
pCdcd->pArg = pArg;
|
||||
|
||||
/* Initialize USB Device Driver interface */
|
||||
pCdcd->pUsbd = pUsbd;
|
||||
pCdcd->bInterfaceNdx = firstInterface;
|
||||
pCdcd->bNumInterface = numInterface;
|
||||
pCdcd->bIntInPIPE = 0;
|
||||
pCdcd->bBulkInPIPE = 0;
|
||||
pCdcd->bBulkOutPIPE = 0;
|
||||
|
||||
/* Initialize Abstract Control Model attributes */
|
||||
pCdcd->bControlLineState = 0;
|
||||
pCdcd->wSerialState = 0;
|
||||
CDCLineCoding_Initialize(&(pCdcd->lineCoding),
|
||||
115200,
|
||||
CDCLineCoding_ONESTOPBIT,
|
||||
CDCLineCoding_NOPARITY,
|
||||
8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse CDC Serial Port information for CDCDSerialPort instance.
|
||||
* Accepted interfaces:
|
||||
* - Communication Interface + Data Interface
|
||||
* - Data Interface ONLY
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
* \param pDescriptors Pointer to descriptor list.
|
||||
* \param dwLength Descriptor list size in bytes.
|
||||
*/
|
||||
USBGenericDescriptor *CDCDSerialPort_ParseInterfaces(
|
||||
CDCDSerialPort *pCdcd,
|
||||
USBGenericDescriptor *pDescriptors,
|
||||
uint32_t dwLength)
|
||||
{
|
||||
CDCDParseData parseData;
|
||||
|
||||
parseData.pCdcd = pCdcd;
|
||||
parseData.pIfDesc = 0;
|
||||
|
||||
return USBGenericDescriptor_Parse(
|
||||
pDescriptors, dwLength,
|
||||
(USBDescriptorParseFunction)_Interfaces_Parse,
|
||||
&parseData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles CDC-specific SETUP requests. Should be called from a
|
||||
* re-implementation of USBDCallbacks_RequestReceived() method.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
* \param request Pointer to a USBGenericRequest instance.
|
||||
* \return USBRC_SUCCESS if request handled, otherwise error.
|
||||
*/
|
||||
uint32_t CDCDSerialPort_RequestHandler(
|
||||
CDCDSerialPort *pCdcd,
|
||||
const USBGenericRequest *request)
|
||||
{
|
||||
if (USBGenericRequest_GetType(request) != USBGenericRequest_CLASS)
|
||||
return USBRC_PARAM_ERR;
|
||||
|
||||
TRACE_INFO_WP("Cdcs ");
|
||||
|
||||
/* Validate interface */
|
||||
if (request->wIndex >= pCdcd->bInterfaceNdx &&
|
||||
request->wIndex < pCdcd->bInterfaceNdx + pCdcd->bNumInterface) {
|
||||
}
|
||||
else {
|
||||
return USBRC_PARAM_ERR;
|
||||
}
|
||||
|
||||
/* Handle the request */
|
||||
switch (USBGenericRequest_GetRequest(request)) {
|
||||
|
||||
case CDCGenericRequest_SETLINECODING:
|
||||
|
||||
_SetLineCoding(pCdcd);
|
||||
break;
|
||||
|
||||
case CDCGenericRequest_GETLINECODING:
|
||||
|
||||
_GetLineCoding(pCdcd);
|
||||
break;
|
||||
|
||||
case CDCGenericRequest_SETCONTROLLINESTATE:
|
||||
|
||||
_SetControlLineState(pCdcd, request);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
return USBRC_PARAM_ERR;
|
||||
}
|
||||
|
||||
return USBRC_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives data from the host through the virtual COM port created by
|
||||
* the CDC device serial driver. This function behaves like USBD_Read.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
* \param pData Pointer to the data buffer to put received data.
|
||||
* \param dwSize Size of the data buffer in bytes.
|
||||
* \param fCallback Optional callback function to invoke when the transfer
|
||||
* finishes.
|
||||
* \param pArg Optional argument to the callback function.
|
||||
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
|
||||
* otherwise, the corresponding error code.
|
||||
*/
|
||||
uint32_t CDCDSerialPort_Read(const CDCDSerialPort * pCdcd,
|
||||
void * pData,uint32_t dwSize,
|
||||
TransferCallback fCallback,void * pArg)
|
||||
{
|
||||
if (pCdcd->bBulkOutPIPE == 0)
|
||||
return USBRC_PARAM_ERR;
|
||||
|
||||
return USBD_Read(pCdcd->bBulkOutPIPE,
|
||||
pData, dwSize,
|
||||
fCallback, pArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a data buffer through the virtual COM port created by the CDC
|
||||
* device serial driver. This function behaves exactly like USBD_Write.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
* \param pData Pointer to the data buffer to send.
|
||||
* \param dwSize Size of the data buffer in bytes.
|
||||
* \param fCallback Optional callback function to invoke when the transfer
|
||||
* finishes.
|
||||
* \param pArg Optional argument to the callback function.
|
||||
* \return USBD_STATUS_SUCCESS if the read operation has been started normally;
|
||||
* otherwise, the corresponding error code.
|
||||
*/
|
||||
uint32_t CDCDSerialPort_Write(const CDCDSerialPort * pCdcd,
|
||||
void * pData, uint32_t dwSize,
|
||||
TransferCallback fCallback, void * pArg)
|
||||
{
|
||||
if (pCdcd->bBulkInPIPE == 0)
|
||||
return USBRC_PARAM_ERR;
|
||||
|
||||
return USBD_Write(pCdcd->bBulkInPIPE,
|
||||
pData, dwSize,
|
||||
fCallback, pArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current control line state of the RS-232 line.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
*/
|
||||
uint8_t CDCDSerialPort_GetControlLineState(const CDCDSerialPort * pCdcd)
|
||||
{
|
||||
return pCdcd->bControlLineState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy current line coding settings to pointered space.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
* \param pLineCoding Pointer to CDCLineCoding instance.
|
||||
*/
|
||||
void CDCDSerialPort_GetLineCoding(const CDCDSerialPort * pCdcd,
|
||||
CDCLineCoding* pLineCoding)
|
||||
{
|
||||
if (pLineCoding) {
|
||||
pLineCoding->dwDTERate = pCdcd->lineCoding.dwDTERate;
|
||||
pLineCoding->bCharFormat = pCdcd->lineCoding.bCharFormat;
|
||||
pLineCoding->bParityType = pCdcd->lineCoding.bParityType;
|
||||
pLineCoding->bDataBits = pCdcd->lineCoding.bDataBits;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current status of the RS-232 line.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
*/
|
||||
uint16_t CDCDSerialPort_GetSerialState(const CDCDSerialPort * pCdcd)
|
||||
{
|
||||
return pCdcd->wSerialState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current serial state of the device to the given value.
|
||||
* \param pCdcd Pointer to CDCDSerialPort instance.
|
||||
* \param wSerialState New device state.
|
||||
*/
|
||||
void CDCDSerialPort_SetSerialState(CDCDSerialPort * pCdcd,
|
||||
uint16_t wSerialState)
|
||||
{
|
||||
if (pCdcd->bIntInPIPE == 0)
|
||||
return;
|
||||
|
||||
/* If new state is different from previous one, send a notification to the
|
||||
host */
|
||||
if (pCdcd->wSerialState != wSerialState) {
|
||||
|
||||
pCdcd->wSerialState = wSerialState;
|
||||
USBD_Write(pCdcd->bIntInPIPE,
|
||||
&(pCdcd->wSerialState),
|
||||
2,
|
||||
0,
|
||||
0);
|
||||
|
||||
/* Reset one-time flags */
|
||||
pCdcd->wSerialState &= ~(CDCSerialState_OVERRUN
|
||||
| CDCSerialState_PARITY
|
||||
| CDCSerialState_FRAMING
|
||||
| CDCSerialState_RINGSIGNAL
|
||||
| CDCSerialState_BREAK);
|
||||
}
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
@@ -0,0 +1,45 @@
|
||||
; $Id: 6119.inf,v 1.1.2.1 2006/12/05 08:33:25 danielru Exp $
|
||||
|
||||
[Version] ; Version section
|
||||
Signature="$Chicago$" ; All Windows versions
|
||||
Class=Ports ; This is a serial port driver
|
||||
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} ; Associated GUID
|
||||
Provider=%ATMEL% ; Driver is provided by ATMEL
|
||||
DriverVer=09/12/2006,1.1.1.5 ; Driver version 1.1.1.5 published on 23 February 2007
|
||||
|
||||
[DestinationDirs] ; DestinationDirs section
|
||||
DefaultDestDir=12 ; Default install directory is \drivers or \IOSubSys
|
||||
|
||||
[Manufacturer] ; Manufacturer section
|
||||
%ATMEL%=AtmelMfg ; Only one manufacturer (ATMEL), models section is named
|
||||
; AtmelMfg
|
||||
|
||||
[AtmelMfg] ; Models section corresponding to ATMEL
|
||||
%USBtoSerialConverter%=USBtoSer.Install,USB\VID_03EB&PID_6119 ; Identifies a device with ATMEL Vendor ID (03EBh) and
|
||||
; Product ID equal to 6119h. Corresponding Install section
|
||||
; is named USBtoSer.Install
|
||||
|
||||
[USBtoSer.Install] ; Install section
|
||||
include=mdmcpq.inf
|
||||
CopyFiles=FakeModemCopyFileSection
|
||||
AddReg=USBtoSer.AddReg ; Registry keys to add are listed in USBtoSer.AddReg
|
||||
|
||||
[USBtoSer.AddReg] ; AddReg section
|
||||
HKR,,DevLoader,,*ntkern ;
|
||||
HKR,,NTMPDriver,,usbser.sys
|
||||
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
|
||||
|
||||
[USBtoSer.Install.Services] ; Services section
|
||||
AddService=usbser,0x00000002,USBtoSer.AddService ; Assign usbser as the PnP driver for the device
|
||||
|
||||
[USBtoSer.AddService] ; Service install section
|
||||
DisplayName=%USBSer% ; Name of the serial driver
|
||||
ServiceType=1 ; Service kernel driver
|
||||
StartType=3 ; Driver is started by the PnP manager
|
||||
ErrorControl=1 ; Warn about errors
|
||||
ServiceBinary=%12%\usbser.sys ; Driver filename
|
||||
|
||||
[Strings] ; Strings section
|
||||
ATMEL="ATMEL Corp." ; String value for the ATMEL symbol
|
||||
USBtoSerialConverter="AT91 USB to Serial Converter" ; String value for the USBtoSerialConverter symbol
|
||||
USBSer="USB Serial Driver" ; String value for the USBSer symbol
|
||||
Reference in New Issue
Block a user