- CDC line buffer size fixed

This commit is contained in:
Wiesner András 2024-04-11 13:32:48 +02:00
parent 0adc9c8664
commit ecc9b70710
6 changed files with 27 additions and 26 deletions

View File

@ -19,6 +19,6 @@ target_sources(
usb_driver.h usb_driver.h
usb.h usb.h
utils/gen_queue.c # utils/gen_queue.c
utils/gen_queue.h # utils/gen_queue.h
) )

View File

@ -72,7 +72,7 @@ int usb_cdc_process_and_return(USB_CallbackEvent *cbevt) {
//MSG("%c\n", cbevt->data[0]); //MSG("%c\n", cbevt->data[0]);
ret = 0; ret = 0;
usbcore_write(cdcs.ep_assignments.data_ep, cbevt->data, cbevt->size); // echo //usbcore_write(cdcs.ep_assignments.data_ep, cbevt->data, cbevt->size); // echo
} }
break; break;
} }

View File

@ -62,7 +62,7 @@ typedef struct {
// ---------------- // ----------------
#define USB_CDC_PCKT_BUFSIZE (128) #define USB_CDC_PCKT_BUFSIZE (64)
// ---------------- // ----------------

2
usb.c
View File

@ -5,7 +5,7 @@
#include "usb_common.h" #include "usb_common.h"
#include "usb_core_types.h" #include "usb_core_types.h"
#include "utils/gen_queue.h" // #include "utils/gen_queue.h"
#include "desc/usb_desc.h" #include "desc/usb_desc.h"

View File

@ -28,7 +28,7 @@ static uint8_t rx_buf[USB_MAX_FS_PCKT_SIZE_NON_ISOCHRONOUS] DWORD_ALIGN; // rece
#define USB_EVENT_QUEUE_LENGTH (16) #define USB_EVENT_QUEUE_LENGTH (16)
static uint8_t event_queue_mem[Q_REQ_MEM_SIZE_T(USB_EVENT_QUEUE_LENGTH, USBDRV_EventCompound)] DWORD_ALIGN; // backing memory for the event queue // static uint8_t event_queue_mem[Q_REQ_MEM_SIZE_T(USB_EVENT_QUEUE_LENGTH, USBDRV_EventCompound)] DWORD_ALIGN; // backing memory for the event queue
static const char *FIFO_STATUS_STR[6] = { static const char *FIFO_STATUS_STR[6] = {
"GLOBAL OUT NAK", "GLOBAL OUT NAK",
@ -102,7 +102,7 @@ void usbdrv_init_global_state() {
gs.rx_buf_level = 0; gs.rx_buf_level = 0;
// initialize event queue // initialize event queue
gs.event_queue = Q_CREATE_T(USB_EVENT_QUEUE_LENGTH, USBDRV_EventCompound, event_queue_mem); // gs.event_queue = Q_CREATE_T(USB_EVENT_QUEUE_LENGTH, USBDRV_EventCompound, event_queue_mem);
} }
// --------------- // ---------------
@ -265,6 +265,7 @@ void usbdrv_build_fifo() {
if (cfg->is_configured) { if (cfg->is_configured) {
cfg->fifo_size = CEIL4(MAX(USB_MIN_GROSS_TX_FIFO_SIZE, cfg->max_packet_size)); // correct FIFO size if necessary cfg->fifo_size = CEIL4(MAX(USB_MIN_GROSS_TX_FIFO_SIZE, cfg->max_packet_size)); // correct FIFO size if necessary
cfg->fifo_address = next_fifo_addr; // store FIFO address cfg->fifo_address = next_fifo_addr; // store FIFO address
cfg->zlp_next = false; // clear ZLP next
next_fifo_addr += cfg->fifo_size; // advance next address next_fifo_addr += cfg->fifo_size; // advance next address
} }
} }
@ -538,24 +539,24 @@ void usbdrv_set_address(uint8_t addr) {
// ---------------- // ----------------
// push event onto the event queue // push event onto the event queue
void usbdrv_push_event(uint32_t evt_code, USBDRV_EventData *evt_data) { // void usbdrv_push_event(uint32_t evt_code, USBDRV_EventData *evt_data) {
USBDRV_EventCompound evt_cpd; // USBDRV_EventCompound evt_cpd;
if (evt_data != NULL) { // if (evt_data != NULL) {
evt_cpd.data = *evt_data; // evt_cpd.data = *evt_data;
} // }
evt_cpd.code = evt_code; // evt_cpd.code = evt_code;
q_push(gs.event_queue, &evt_cpd); // q_push(gs.event_queue, &evt_cpd);
} // }
// call this to process incoming events // // call this to process incoming events
void usbdrv_periodic_processing() { // void usbdrv_periodic_processing() {
if ((gs.event_queue != NULL) && (q_avail(gs.event_queue))) { // if ((gs.event_queue != NULL) && (q_avail(gs.event_queue))) {
USBDRV_EventCompound evt_cpd; // USBDRV_EventCompound evt_cpd;
q_top(gs.event_queue, &evt_cpd); // q_top(gs.event_queue, &evt_cpd);
q_pop(gs.event_queue); // q_pop(gs.event_queue);
usbdrv_process_event(evt_cpd.code, NULL); // usbdrv_process_event(evt_cpd.code, NULL);
} // }
} // }
// ---------------- // ----------------

View File

@ -1,7 +1,7 @@
#ifndef CORE_USB_USB_DRIVER #ifndef CORE_USB_USB_DRIVER
#define CORE_USB_USB_DRIVER #define CORE_USB_USB_DRIVER
#include "utils/gen_queue.h" //#include "utils/gen_queue.h"
#include "usb_common_types.h" #include "usb_common_types.h"
@ -58,7 +58,7 @@ typedef struct {
uint16_t state; // FSM state uint16_t state; // FSM state
uint8_t *rx_buf; // pointer to the receive buffer (this way declaration can be separated) uint8_t *rx_buf; // pointer to the receive buffer (this way declaration can be separated)
uint16_t rx_buf_level; // fill level of the rx buffer uint16_t rx_buf_level; // fill level of the rx buffer
Queue *event_queue; // event queue // Queue *event_queue; // event queue
uint8_t address; // device address uint8_t address; // device address
} USBDRV_GlobalState; } USBDRV_GlobalState;