Selaa lähdekoodia

USB serial use different packet sizes at 12 vs 480

main
PaulStoffregen 5 vuotta sitten
vanhempi
commit
17d02bcaf0
3 muutettua tiedostoa jossa 28 lisäystä ja 16 poistoa
  1. +5
    -5
      teensy4/usb_desc.c
  2. +4
    -2
      teensy4/usb_desc.h
  3. +19
    -9
      teensy4/usb_serial.c

+ 5
- 5
teensy4/usb_desc.c Näytä tiedosto

@@ -662,7 +662,7 @@ PROGMEM const uint8_t usb_config_descriptor_480[CONFIG_DESC_SIZE] = {
5, // bDescriptorType
CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
0x03, // bmAttributes (0x03=intr)
CDC_ACM_SIZE, 0, // wMaxPacketSize
LSB(CDC_ACM_SIZE),MSB(CDC_ACM_SIZE), // wMaxPacketSize
16, // bInterval
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
9, // bLength
@@ -679,14 +679,14 @@ PROGMEM const uint8_t usb_config_descriptor_480[CONFIG_DESC_SIZE] = {
5, // bDescriptorType
CDC_RX_ENDPOINT, // bEndpointAddress
0x02, // bmAttributes (0x02=bulk)
CDC_RX_SIZE, 0, // wMaxPacketSize
LSB(CDC_RX_SIZE_480),MSB(CDC_RX_SIZE_480),// wMaxPacketSize
0, // bInterval
// endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
7, // bLength
5, // bDescriptorType
CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
0x02, // bmAttributes (0x02=bulk)
CDC_TX_SIZE, 0, // wMaxPacketSize
LSB(CDC_TX_SIZE_480),MSB(CDC_TX_SIZE_480),// wMaxPacketSize
0, // bInterval
#endif // CDC_DATA_INTERFACE

@@ -1501,14 +1501,14 @@ PROGMEM const uint8_t usb_config_descriptor_12[CONFIG_DESC_SIZE] = {
5, // bDescriptorType
CDC_RX_ENDPOINT, // bEndpointAddress
0x02, // bmAttributes (0x02=bulk)
CDC_RX_SIZE, 0, // wMaxPacketSize
LSB(CDC_RX_SIZE_12),MSB(CDC_RX_SIZE_12),// wMaxPacketSize
0, // bInterval
// endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
7, // bLength
5, // bDescriptorType
CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
0x02, // bmAttributes (0x02=bulk)
CDC_TX_SIZE, 0, // wMaxPacketSize
LSB(CDC_TX_SIZE_12),MSB(CDC_TX_SIZE_12),// wMaxPacketSize
0, // bInterval
#endif // CDC_DATA_INTERFACE


+ 4
- 2
teensy4/usb_desc.h Näytä tiedosto

@@ -135,8 +135,10 @@ let me know? http://forum.pjrc.com/forums/4-Suggestions-amp-Bug-Reports
#define CDC_RX_ENDPOINT 3
#define CDC_TX_ENDPOINT 4
#define CDC_ACM_SIZE 16
#define CDC_RX_SIZE 64
#define CDC_TX_SIZE 64
#define CDC_RX_SIZE_480 512
#define CDC_TX_SIZE_480 512
#define CDC_RX_SIZE_12 64
#define CDC_TX_SIZE_12 64
#define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
#define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_UNUSED
#define ENDPOINT4_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_BULK

+ 19
- 9
teensy4/usb_serial.c Näytä tiedosto

@@ -49,6 +49,7 @@ volatile uint8_t usb_cdc_transmit_flush_timer=0;
//static usb_packet_t *rx_packet=NULL;
//static usb_packet_t *tx_packet=NULL;
static volatile uint8_t tx_noautoflush=0;
extern volatile uint8_t usb_high_speed;

// TODO: should be 2 different timeouts, high speed (480) vs full speed (12)
#define TRANSMIT_FLUSH_TIMEOUT 75 /* in microseconds */
@@ -59,21 +60,23 @@ static void timer_stop();
static void usb_serial_flush_callback(void);

#define TX_NUM 7
#define TX_SIZE 256 /* should be a multiple of CDC_TX_SIZE */
#define TX_SIZE 1024 /* should be a multiple of CDC_TX_SIZE */
static transfer_t tx_transfer[TX_NUM] __attribute__ ((used, aligned(32)));
static uint8_t txbuffer[TX_SIZE * TX_NUM];
static uint8_t tx_head=0;
static uint16_t tx_available=0;
static uint16_t tx_packet_size=0;

#define RX_NUM 3
static transfer_t rx_transfer[RX_NUM] __attribute__ ((used, aligned(32)));
static uint8_t rx_buffer[RX_NUM * CDC_RX_SIZE];
static uint8_t rx_buffer[RX_NUM * CDC_RX_SIZE_480];
static uint16_t rx_count[RX_NUM];
static uint16_t rx_index[RX_NUM];
static uint16_t rx_packet_size=0;

static void rx_event(transfer_t *t)
{
int len = CDC_RX_SIZE - ((t->status >> 16) & 0x7FFF);
int len = rx_packet_size - ((t->status >> 16) & 0x7FFF);
int index = t->callback_param;
//printf("rx event, len=%d, i=%d\n", len, index);
rx_count[index] = len;
@@ -89,16 +92,23 @@ void usb_serial_reset(void)
void usb_serial_configure(void)
{
printf("usb_serial_configure\n");
if (usb_high_speed) {
tx_packet_size = CDC_TX_SIZE_480;
rx_packet_size = CDC_RX_SIZE_480;
} else {
tx_packet_size = CDC_TX_SIZE_12;
rx_packet_size = CDC_RX_SIZE_12;
}
memset(tx_transfer, 0, sizeof(tx_transfer));
tx_head = 0;
tx_available = 0;
memset(rx_transfer, 0, sizeof(rx_transfer));
memset(rx_count, 0, sizeof(rx_count));
memset(rx_index, 0, sizeof(rx_index));
usb_config_tx(CDC_ACM_ENDPOINT, CDC_ACM_SIZE, 0, NULL);
usb_config_rx(CDC_RX_ENDPOINT, CDC_RX_SIZE, 0, rx_event);
usb_config_tx(CDC_TX_ENDPOINT, CDC_TX_SIZE, 0, NULL);
usb_prepare_transfer(rx_transfer + 0, rx_buffer + 0, CDC_RX_SIZE, 0);
usb_config_tx(CDC_ACM_ENDPOINT, CDC_ACM_SIZE, 0, NULL); // size same 12 & 480
usb_config_rx(CDC_RX_ENDPOINT, rx_packet_size, 0, rx_event);
usb_config_tx(CDC_TX_ENDPOINT, tx_packet_size, 0, NULL);
usb_prepare_transfer(rx_transfer + 0, rx_buffer + 0, rx_packet_size, 0);
usb_receive(CDC_RX_ENDPOINT, rx_transfer + 0);
timer_config(usb_serial_flush_callback, TRANSMIT_FLUSH_TIMEOUT);
}
@@ -111,7 +121,7 @@ int usb_serial_getchar(void)
int c = rx_buffer[rx_index[0]++];
if (rx_index[0] >= rx_count[0]) {
// reschedule transfer
usb_prepare_transfer(rx_transfer + 0, rx_buffer + 0, CDC_RX_SIZE, 0);
usb_prepare_transfer(rx_transfer + 0, rx_buffer + 0, rx_packet_size, 0);
usb_receive(CDC_RX_ENDPOINT, rx_transfer + 0);
}
return c;
@@ -157,7 +167,7 @@ void usb_serial_flush_input(void)
{
if (rx_index[0] < rx_count[0]) {
rx_index[0] = rx_count[0];
usb_prepare_transfer(rx_transfer + 0, rx_buffer + 0, CDC_RX_SIZE, 0);
usb_prepare_transfer(rx_transfer + 0, rx_buffer + 0, rx_packet_size, 0);
usb_receive(CDC_RX_ENDPOINT, rx_transfer + 0);
}
}

Loading…
Peruuta
Tallenna