...
Todos estos tiempos los medí con un osciloscopio que se conecta a un led que indica mediante ceros y unos la ejecución del usb (a modo de breakpoint).
...
do{
output_high(USBOK);
MideMCP3201(); //Hace medición de los 5 ADC's
output_low(USBOK);
transOK=0; //No ha enviado paquete
while(transOK==0) //No pudo enviar, intenta de nuevo
transOK=usb_put_packet(1, doutprima, 12, USB_DTS_TOGGLE);
}while(ByteRec[1]--);
if(usb_cdc_kbhit()) //Si se recibe petición
{
comando=usb_cdc_getc();
//Si el comando es 'a'
if(comando=='a')
{
while(1)
{
//Para medir el tiempo desde la medición hasta que ya se envió por USB
//enciendo la terminal RB7 (solo para debug)
//Tiempo en alto = Medición ADC (se espera que sea 10us)
//Tiempo en bajo = Lectura y envío USB (se espera que sea 40.2us)
output_high(USBOK);
MideMCP3201(); //Hace medición de los 5 ADC's
output_low(USBOK);
usb_cdc_putc(doutprima[0]);
usb_cdc_putc(doutprima[1]);
usb_cdc_putc(doutprima[2]);
usb_cdc_putc(doutprima[3]);
usb_cdc_putc(doutprima[4]);
usb_cdc_putc(doutprima[5]);
usb_cdc_putc(doutprima[6]);
usb_cdc_putc(doutprima[7]);
usb_cdc_putc(doutprima[8]);
usb_cdc_putc(doutprima[9]);
usb_cdc_putc(doutprima[10]);
usb_cdc_putc(doutprima[11]);
}
}
}No se supone que USB 2.0 funciona a 10 o 12 Mbit/seg ??? :shock: :shock: :shock:
#INCLUDE <18F4550.h>
#FUSES HSPLL, PLL5, CPUDIV1, USBDIV, VREGEN, NOWDT, PUT, NOBROWNOUT, MCLR, NOPROTECT, NOLVP
#USE DELAY (CLOCK = 48 000 000)
#DEFINE USB_HID_DEVICE FALSE //Deshabilitar el uso de las directivas HID o Dispositivos de Interacion Humana.
#DEFINE USB_CDC_DEVICE FALSE //Deshabilitar el uso de las directivas para simulacion de serial con USB.
#DEFINE USB_USE_FULL_SPEED TRUE //Velocidad: Full Speed 12 Mb/s.
#DEFINE USB_EP1_TX_ENABLE USB_ENABLE_BULK //Habilitar la transferencia en el EndPoint 1.
#DEFINE USB_EP1_RX_ENABLE USB_ENABLE_BULK //Habilitar el recivimiento en el EndPoint1.
#DEFINE USB_EP1_TX_SIZE 64 //Tamaño de bytes maximos que se enviara por el EndPoint1 (maximo 64 bytes).
#DEFINE USB_EP1_RX_SIZE 64 //Tamñao de bytes maximos que se recibira del EndPoint1 (maximo 64 bytes).
#DEFINE USB_EP2_TX_ENABLE USB_ENABLE_BULK //Habilitar la transferencia en el EndPoint 1.
#DEFINE USB_EP2_TX_SIZE 64 //Tamaño de bytes maximos que se enviara por el EndPoint1 (maximo 64 bytes).
#DEFINE USB_EP3_TX_ENABLE USB_ENABLE_BULK //Habilitar la transferencia en el EndPoint 1.
#DEFINE USB_EP3_TX_SIZE 64 //Tamaño de bytes maximos que se enviara por el EndPoint1 (maximo 64 bytes).
#DEFINE USB_EP4_TX_ENABLE USB_ENABLE_BULK //Habilitar la transferencia en el EndPoint 1.
#DEFINE USB_EP4_TX_SIZE 64 //Tamaño de bytes maximos que se enviara por el EndPoint1 (maximo 64 bytes).
#DEFINE USB_EP5_TX_ENABLE USB_ENABLE_BULK //Habilitar la transferencia en el EndPoint 1.
#DEFINE USB_EP5_TX_SIZE 64 //Tamaño de bytes maximos que se enviara por el EndPoint1 (maximo 64 bytes).
#DEFINE USB_EP6_TX_ENABLE USB_ENABLE_BULK //Habilitar la transferencia en el EndPoint 1.
#DEFINE USB_EP6_TX_SIZE 64 //Tamaño de bytes maximos que se enviara por el EndPoint1 (maximo 64 bytes).
#DEFINE USB_EP7_TX_ENABLE USB_ENABLE_BULK //Habilitar la transferencia en el EndPoint 1.
#DEFINE USB_EP7_TX_SIZE 64 //Tamaño de bytes maximos que se enviara por el EndPoint1 (maximo 64 bytes).
#DEFINE USB_EP8_TX_ENABLE USB_ENABLE_BULK //Habilitar la transferencia en el EndPoint 1.
#DEFINE USB_EP8_TX_SIZE 64 //Tamaño de bytes maximos que se enviara por el EndPoint1 (maximo 64 bytes).
#DEFINE USB_EP9_TX_ENABLE USB_ENABLE_BULK //Habilitar la transferencia en el EndPoint 1.
#DEFINE USB_EP9_TX_SIZE 64 //Tamaño de bytes maximos que se enviara por el EndPoint1 (maximo 64 bytes).
#DEFINE USB_CON_SENSE_PIN PIN_A1
#INCLUDE "INC/pic18_usb.h" // Libreria con funciones para los pic 18Fxx5x para el uso del USB 2.0.
#INCLUDE "INC/USB_descriptores.h" // Configuración de los descriptores para este dispositivo
#INCLUDE "INC/usb.c" // Funciones para el uso del Universal System Bulk o Systema Universal de paquetes (USB).
void Main (void)
{
usb_init();
while (true)
{
usb_task();
if (usb_enumerated() == true)
{
if (usb_kbhit(1) == true)
{
}
}
}
}
void Main (void)
{
unsigned int16 i1;
unsigned int8 BufferUSBSalida[64];
output_low(PIN_D0); // D1
printf("\r\n\nUSB\r\n");
usb_init();
while (true)
{
usb_task();
if (usb_enumerated() == true)
{
if (input(PIN_B4) == false) // S2
{
delay_ms(400);
while (input(PIN_B4 == false))
{
}
output_high(PIN_D0); // D1
for (i1 = 0; i1 < 2730; i1++) //2730 24576
{
printf("%u ", usb_put_packet(1, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("%u ", usb_put_packet(2, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("%u ", usb_put_packet(3, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("%u ", usb_put_packet(4, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("%u ", usb_put_packet(5, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("%u ", usb_put_packet(6, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("%u ", usb_put_packet(7, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("%u ", usb_put_packet(8, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("%u ", usb_put_packet(9, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("|| *");
}
output_low(PIN_D0); // D1
}
if (usb_kbhit(1) == true)
{
}
}
}
}
for (i1 = 0; i1 < 24576; i1++) //2730 24576
{
printf("%u ", usb_put_packet(1, BufferUSBSalida, 64, USB_DTS_TOGGLE));
printf("|| *");
}
Que hace uso solamente de un endpoint de salida, enviando otra vez 12Mb (1.5MB) pero en 11 segundos aproximadamente.
Bueno, no puedo asegurar esto del todo, yaque los printf's me retornan 1 la primera vez, pero despues me retornan 0. Esto, debido a que no estoy usando ningun programa de software en la PC para leer estos datos. Asique que estos tiempos quiza puedan ser mayores, pero con esto parece que realmente usar mas endpoints acelera la transferencia aunque paresca lo mismo.
Bueno, seguire revisando.
Salu2.
while(transOK==0) //No pudo enviar, intenta de nuevo
transOK=usb_put_packet(1, doutprima, 12, USB_DTS_TOGGLE); while(transOK==0) //No pudo enviar, intenta de nuevo
transOK=usb_put_packet(1, doutprima, 12, USB_DTS_TOGGLE); //Recibe el byte medido
picusb.RecibePaquetes(rec_buf);
//Función RecibePaquetes
//Entrega en variable BufferRec los 12 bytes enviados por el pic
public void RecibePaquetes(byte* BufferRec)
{
DWORD RecvLength = 2;
ReceivePacketHandle(BufferRec, &RecvLength);
}
//Función ReceivePacketHandle
//Debe existir un handle abierto en myInPipe antes de llamarla
public void ReceivePacketHandle(byte* ReceiveData, DWORD* ReceiveLength)
{
uint ReceiveDelay = 1000;
DWORD ExpectedReceiveLength = *ReceiveLength;
_MPUSBRead(myInPipe, (void*)ReceiveData, ExpectedReceiveLength, ReceiveLength, ReceiveDelay);
}
int1 usb_put_packet(int8 endpoint, int8 * ptr, int16 len, USB_DTS_BIT tgl) { //done
int16 j;
int8 i;
int8 * buff_add;
i=EP_BDxST_I(endpoint);
if (!bit_test(i,7)) {
buff_add=EP_BDxADR_I(endpoint);
for (j=0;j<len;j++) {
*buff_add=*ptr;
buff_add++;
ptr++;
}
return(usb_flush_in(endpoint, len, tgl));
}
else {
debug_usb(debug_putc,"\r\nPUT ERR");
}
return(0);
}
i=EP_BDxST_I(endpoint);#if (USB_PING_PONG_MODE==USB_PING_PONG_MODE_OFF)
#define EP_BDxST_O(x) *(BD0STAT_LOC + x*8)
#define EP_BDxCNT_O(x) *(BD0CNT_LOC + x*8)
#define EP_BDxADR_O(x) *(int16 *)(BD0ADRL_LOC + x*8)
#define EP_BDxST_I(x) *(BD0STAT_LOC + 4 + x*8)
#define EP_BDxCNT_I(x) *(BD0CNT_LOC + 4 + x*8)
#define EP_BDxADR_I(x) *(int16 *)(BD0ADRL_LOC + 4 + x*8)
#else
#error Right now this driver only supports no ping pong
#endif
------PICUSBAPI.cs
//Función OpenPipes
//Regresa un handle a un endpoint con un PID VID específico
public void OpenPipes()
{
DWORD selection = 0;
myOutPipe = _MPUSBOpen(selection, vid_pid_norm, out_pipe, 0, 0);
myInPipe = _MPUSBOpen(selection, vid_pid_norm, in_pipe, 1, 0);
}
------Form1.cs
picusb.OpenPipes();
while(TRUE)
{
if(usb_enumerated())
{
//Si la pc ya pidió el paquete
if(usb_kbhit(1))
{
usb_get_packet(1, buffer_in, 2);
//Si el comando es envío de muestras 0xee
if(buffer_in[0]==0xee)
envio_pend=1;
}
//Si hay envío pendiente y ya hay paquete de 50 bytes armado
if((envio_pend)&&(apunta>49))
{
//Envía arreglo de mediciones
usb_put_packet(1, buffer_out, 64, USB_DTS_TOGGLE);
//En último byte de paquete indica las muestras que contiene
buffer_out[63]=apunta;
apunta=0;
envio_pend=0;
}
}
}
Estoy haciendo la prueba con el modo HID y el programa para el pic ya funciona. El problema que tengo es que no he podido comunicarme con el PIC usando la mpusbapi.dll. Me ha funcionado bien con el modo bulk pero ahora con HID no sé qué pasa.
...
....¿Hay algún otro detalle sobre el modo HID que yo esté ignorando? ¿Hay que hacer envíos en todo momento para mantener viva la conexión usb?
migsantiago, has cambiado los drivers en el pic para configurarlo de Bulk a HID ?? Me refiero al archivo descriptor y el uso de los endpoints como USB_ENABLE_INTERRUPT y esas cosas.
Prueba tb modificando los pid y reinstalando todo d nuevo.
salu2.
#DEFINE USB_HID_DEVICE TRUE
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 64 //allocate 8 bytes in the hardware for transmission
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 8 //allocate 8 bytes in the hardware for reception const char USB_CLASS_SPECIFIC_DESC[] = {
6, 0, 255, // Usage Page = Vendor Defined
9, 1, // Usage = IO device
0xa1, 1, // Collection = Application
0x19, 1, // Usage minimum
0x29, 8, // Usage maximum
0x15, 0x80, // Logical minimum (-128)
0x25, 0x7F, // Logical maximum (127)
0x75, 8, // Report size = 8 (bits)
//0x95, 2, // Report count = 16 bits (2 bytes)
0x95, 64, // Report count = 64 bytes (MODIFICACION)
0x81, 2, // Input (Data, Var, Abs)
0x19, 1, // Usage minimum
0x29, 8, // Usage maximum
0x75, 8, // Report size = 8 (bits)
//0x95, 2, // Report count = 16 bits (2 bytes)
0x95, 8, // Report count = 8 bytes (MODIFICACION)
0x91, 2, // Output (Data, Var, Abs)
0xc0 // End Collection
}; //debug
output_high(USBOK);
//Pone el buffer en el endpoint y espera hasta que se haya enviado
while(!(usb_put_packet(1, buffer_out, 64, USB_DTS_TOGGLE)));
//debug
output_low(USBOK);int1 usb_put_packet(int8 endpoint, int8 * ptr, int16 len, USB_DTS_BIT tgl) { //done
int16 j;
int8 i;
int8 * buff_add;
i=EP_BDxST_I(endpoint);
if (!bit_test(i,7)) {
buff_add=EP_BDxADR_I(endpoint);
for (j=0;j<len;j++) {
*buff_add=*ptr;
buff_add++;
ptr++;
}
return(usb_flush_in(endpoint, len, tgl));
}
else {
debug_usb(debug_putc,"\r\nPUT ERR");
}
return(0);
}int1 usb_flush_in(int8 endpoint, int16 len, USB_DTS_BIT tgl) {
int8 i;
debug_usb(debug_putc,"\r\nPUT %X %U %LU",endpoint, tgl, len);
i=EP_BDxST_I(endpoint);
if (!bit_test(i,7)) {
EP_BDxCNT_I(endpoint)=len;
debug_display_ram(len, EP_BDxADR_I(endpoint));
#if USB_IGNORE_TX_DTS
i=0x80;
#else
if (tgl == USB_DTS_TOGGLE) {
i=EP_BDxST_I(endpoint);
if (bit_test(i,6))
tgl=USB_DTS_DATA0; //was DATA1, goto DATA0
else
tgl=USB_DTS_DATA1; //was DATA0, goto DATA1
}
else if (tgl == USB_DTS_USERX) {
i=EP_BDxST_O(endpoint);
if (bit_test(i,6))
tgl=USB_DTS_DATA1;
else
tgl=USB_DTS_DATA0;
}
if (tgl == USB_DTS_DATA1) {
i=0xC8; //DATA1, UOWN
}
else if (tgl == USB_DTS_DATA0) {
i=0x88; //DATA0, UOWN
}
#endif
//set BC8 and BC9
if (bit_test(len,8)) {bit_set(i,0);}
if (bit_test(len,9)) {bit_set(i,1);}
debug_usb(debug_putc," %X",i);
EP_BDxST_I(endpoint)=i;//save changes
return(1);
}
else {
debug_usb(debug_putc,"\r\nPUT ERR");
}
return(0);
}a eso es lo que microchip le llama overhead, todo el código que tiene que procesar de forma tranasparente al programador. siempre habrá overhead, la pregunta es si con los otros modos, podrás disminuir ese tiempo. :(
The following macros define the default line coding settings
that the CDC serial driver reports in response to
the hosts GET_LINE_CODING request. Keep in mind
that, in a USB environment, communication occurs at
speeds defined by the USB protocol and most hosts
will set the line coding parameters as desired. None the
less, the default values reported can be changed by
changing the following macros.
// Bit Rate
CDC_DEFAULT_BPS 115200
// 1 stop bit
CDC_DEFAULT_FORMAT 0
// No parity
CDC_DEFAULT_PARITY 0
// 8-bits per word
CDC_DEFAULT_NUM_BITS 8
void usb_cdc_init(void) {
usb_cdc_line_coding.dwDTERrate=921600;
usb_cdc_line_coding.bCharFormat=0;
usb_cdc_line_coding.bParityType=0;
usb_cdc_line_coding.bDataBits=8;
(int8)usb_cdc_carrier=0;
usb_cdc_got_set_line_coding=FALSE;
usb_cdc_break=0;
usb_cdc_put_buffer_nextin=0;
usb_cdc_get_buffer_status.got=0;
usb_cdc_put_buffer_free=TRUE;
}
Esta discusión está interesante y la he seguido con atención aunque no la he entendido 100% ya que no estoy tan versado en USB como ustedes...
/*
Librería USB Fast
Santiago Villafuerte
http://www.migsantiago.com
*/
#define STATUS_EP1_IN 0x040C
#define UOWN 7
#define DTS 6
#define CNT_EP1_IN 0x040D
#define ADRL_EP1_IN 0x040E
#define ADRH_EP1_IN 0x040F
////////////////////////////////////////////////////////////////////////////////
//Función put_usb_fast1
//Ejecuta put_usb_packet de forma rápida para el endpoint 1
//
//Requisitos:
//- Solo debe haberse configurado el EP0 y EP1
//- Paquete debe ser de hasta 64bytes de largo
//- El buffer a enviar deberá iniciar en 0x05C0 (banco 5)
//- El paquete lleva toggle DATA0 y DATA1
//
void usb_put_fast_1(int8 *buffer, int8 len)
{
int8 i;
int8 *buffer_ep1;
//Copia la dirección del buffer ep1
buffer_ep1 = *(int16 *)ADRL_EP1_IN;
//Espera a que la SIE deje de manipular el endpoint
while(bit_test(*(STATUS_EP1_IN),UOWN));
//Copia los bytes del buffer al endpoint
//Es recomendable que buffer esté ubicado en las 64 últimas posiciones del
//banco 5 para reducir tiempo entre saltos de banco
for(i=0; i<len; ++i)
{
*buffer_ep1 = *buffer;
++buffer_ep1;
++buffer;
}
//Indica cuántos bytes de enviarán (no hace falta escribir BC9:BC8)
*(CNT_EP1_IN) = len;
//Invierte el bit de datos de paquete DTS (data toggle sync) y
//activa el envío del endpoint levantando UOWN
if(bit_test(*(STATUS_EP1_IN),DTS))
*(STATUS_EP1_IN)= 0b10001000; //UOWN=1, DTS=0, DTSEN=1
else
*(STATUS_EP1_IN)= 0b11001000; //UOWN=1, DTS=1, DTSEN=1
}
////////////////////////////////////////////////////////////////////////////////
#INCLUDE <18F4550.h>
#FUSES XTPLL, PLL1, CPUDIV1, VREGEN, USBDIV, NOMCLR, NOWDT, PROTECT, NOLVP, NODEBUG
#USE DELAY(CLOCK = 48000000)
#DEFINE USB_HID_DEVICE TRUE
#DEFINE USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
#DEFINE USB_EP1_TX_SIZE 8
#DEFINE USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT
#DEFINE USB_EP1_RX_SIZE 8
#DEFINE USB_CON_SENSE_PIN PIN_C2
#DEFINE LED_TEST_1 PIN_A0
#DEFINE LED_TEST_2 PIN_A1
#INCLUDE <pic18_usb.h>
#INCLUDE "usb_desc_hid.h"
#INCLUDE <usb.c>
unsigned int8 Recibe[64], Envia[64];
void Main(void)
{
int16 Cont = 0;
usb_init_cs();
while (true)
{
usb_task();
if (Cont++ > 10000) {output_toggle(LED_TEST_1); Cont = 0;}
if (usb_enumerated() == true)
{
if (usb_kbhit(1) == true)
{
output_high(LED_TEST_2);
usb_get_packet(1, Recibe, 2);
}
}
}
}
Nunca pude usar HID con mpusbapi.dll.Nadie hombre. He estado buscando info en el foro, en san google y nada, no he encontrado nada. Tan dificil o algo asi es xD!
MessageBox.Show(MyHid.Capabilities.OutputReportByteLength.ToString());
0x75, 8, // Report size = 8 (bits)
//0x95, 2, // Report count = 16 bits (2 bytes)
0x95, 64, // Report count = 64 bytes (MODIFICACION)
0x81, 2, // Input (Data, Var, Abs)
0x19, 1, // Usage minimum
0x29, 8, // Usage maximum
0x75, 8, // Report size = 8 (bits)
//0x95, 2, // Report count = 16 bits (2 bytes)
0x95, 8, // Report count = 8 bytes (MODIFICACION)
0x91, 2, // Output (Data, Var, Abs)
0xc0 // End Collection MessageBox.Show(MyHid.Capabilities.OutputReportByteLength.ToString()); me seguie mandando 3 nomas =S#DEFINE USB_HID_DEVICE TRUE
#DEFINE USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
#DEFINE USB_EP1_TX_SIZE 8
#DEFINE USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT
#DEFINE USB_EP1_RX_SIZE 8
usb_get_packet(1, Recibe, 2);
Nunca pude usar HID con mpusbapi.dll.Nadie hombre. He estado buscando info en el foro, en san google y nada, no he encontrado nada. Tan dificil o algo asi es xD!
Salu2
void usb_put_fast_1(int8 buffer, int8 len)
{
//Espera a que la SIE deje de manipular el endpoint
while(bit_test(*(STATUS_EP1_IN),UOWN));
//Indica cuántos bytes se enviarán (no hace falta escribir BC9:BC8)
*(CNT_EP1_IN) = len;
//Indica el comienzo del buffer a la SIE
//El byte alto siempre es 0x06
*(ADRH_EP1_IN) = 0x06; //primer buffer
//El byte bajo sí cambia
switch(buffer)
{
case 1:
*(ADRL_EP1_IN) = 0x00; break;
case 2:
*(ADRL_EP1_IN) = 0x32; break;
case 3:
*(ADRL_EP1_IN) = 0x64; break;
case 4:
*(ADRL_EP1_IN) = 0x96; break;
}
//Invierte el bit de datos de paquete DTS (data toggle sync) y
//activa el envío del endpoint levantando UOWN
if(bit_test(*(STATUS_EP1_IN),DTS))
*(STATUS_EP1_IN)= 0b10001000; //UOWN=1, DTS=0, DTSEN=1
else
*(STATUS_EP1_IN)= 0b11001000; //UOWN=1, DTS=1, DTSEN=1
}...La ventaja de usar 4 buffers clones es que mientras la SIE está manipulando los 50 bytes de un buffer, yo me doy el lujo de estar preparando otro buffer para enviarlo. Esto es similar al modo ping pong, pero con trampa :D
...
...Recuerdo el asunto del buffer circular, me lo recomendaste en este mismo tema... al parecer me sirvió de mucho :D La pregunta es ¿para qué lo piensas usar?
...
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern Boolean ReadFile(
SafeFileHandle hFile,
byte[] buffer, //IntPtr lpBuffer,
Int32 nNumberOfBytesToRead,
ref Int32 lpNumberOfBytesRead,
IntPtr lpOverlapped);
//Investiga tamaño del ring buffer de input reports
[DllImport("hid.dll", SetLastError = true)]
public static extern Boolean HidD_GetNumInputBuffers(
SafeFileHandle HidDeviceObject,
ref Int32 NumberBuffers);
//Establece tamaño del ring buffer de input reports
[DllImport("hid.dll", SetLastError = true)]
public static extern Boolean HidD_SetNumInputBuffers(
SafeFileHandle HidDeviceObject,
Int32 NumberBuffers);jajaja
No es para tanto Pedro, la magia la hace la Sra. Jan Axelson con sus tutoriales mega excelentes. ;-)
...
#DEFINE USB_TOTAL_CONFIG_LEN 46 //config+interface+class+endpoint
char const USB_CONFIG_DESC[] = {
//config_descriptor for config index 1
USB_DESC_CONFIG_LEN, //length of descriptor size =1
USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (0x02)
USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==3,4
1, //number of interfaces this device supports
0x01, //identifier for this configuration. (IF we had more than one configurations)
0x00, //index of string descriptor for this configuration
0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 reserved and bit7=1
0x32, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) =9
//interface descriptor 0 alt 0
USB_DESC_INTERFACE_LEN, //length of descriptor ==10
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (0x04)
0x00, //number defining this interface (IF we had more than one interface)
0x00, //alternate setting
4, //number of endpoints, not counting endpoint 0.-------------------------------------------------------------------------->NOTA1
0xFF, //class code, FF = vendor defined
0xFF, //subclass code, FF = vendor
0xFF, //protocol code, FF = vendor
0x00, //index of string descriptor for interface =18
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x81, //endpoint number and direction (0x81 = EP1 IN)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP1_TX_SIZE,0x00, //maximum packet size supported =23,24
0x01, //polling interval in ms. (for interrupt transfers ONLY)=25
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==26
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x01, //endpoint number and direction (0x01 = EP1 OUT)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP1_RX_SIZE,0x00, //maximum packet size supported =30,31
0x01, //polling interval in ms. (for interrupt transfers ONLY) =32
//endpoint descriptor ////AGREGADO
USB_DESC_ENDPOINT_LEN, //length of descriptor == 33
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x82, //endpoint number and direction (0x82 = EP2 IN)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP2_TX_SIZE,0x00, //maximum packet size supported ==37,38
0x01, //polling interval in ms. (for interrupt transfers ONLY) ==39
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==40
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (0x05)
0x02, //endpoint number and direction (0x02 = EP2 OUT)
0x02, //transfer type supported (0 is control, 1 is iso, 2 is bulk, 3 is interrupt)
USB_EP2_RX_SIZE,0x00, //maximum packet size supported ==44,45
0x01 //polling interval in ms. (for interrupt transfers ONLY) == 46[/b]
};
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK // turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK // turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP2_TX_ENABLE USB_ENABLE_BULK // turn on EP2(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP2_RX_ENABLE USB_ENABLE_BULK // turn on EP2(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 5 // size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 1 // size to allocate for the rx endpoint 1 buffer
#define USB_EP2_TX_SIZE 5 // size to allocate for the tx endpoint 2 buffer
#define USB_EP2_RX_SIZE 1
#region Definición de los Strings: EndPoint y VID_PID
string vid_pid_norm = "vid_04d8&pid_0011";
string out_pipe = "\\MCHP_EP2";
string in_pipe = "\\MCHP_EP2";
#endregion
Del lado de la PC.
Hacer un programa que sea capaz de leer los 15 endpoints en modo bulk del PIC sin retrasos, preferentemente en modo kernel. Si se logra, el PIC enviaría constantemente datos en los endpoints (sin usar ping-pong) y como mínimo la PC los leería a 1Mbps.
while(condicion[0])
{
while(usb_put_packet(2, condicion, 24,USB_DTS_TOGGLE)==0);
}
Alguien sabe como hacer una aplicacion CDC que maneje las lineas de control del port serial, ademas de RX y TX ??
Perdon si no es el lugar de consulta, por favor moverlo a donde crean conveniente... :)