Do not send further USB packets when connections is stale
This commit is contained in:
parent
6500f67b5e
commit
39a91034d9
@ -1,5 +1,5 @@
|
|||||||
2F62501ED4689FB349E356AB974DBE57=6F84FD31C089E822CF61FFCABCD0B7D1
|
2F62501ED4689FB349E356AB974DBE57=EF826FD321FB312AEADE4DB74B81458C
|
||||||
66BE74F758C12D739921AEA421D593D3=2
|
66BE74F758C12D739921AEA421D593D3=2
|
||||||
8DF89ED150041C4CBC7CB9A9CAA90856=6F84FD31C089E822CF61FFCABCD0B7D1
|
8DF89ED150041C4CBC7CB9A9CAA90856=EF826FD321FB312AEADE4DB74B81458C
|
||||||
DC22A860405A8BF2F2C095E5B6529F12=6E2D4146EA2709ED1E4A1764BC291F57
|
DC22A860405A8BF2F2C095E5B6529F12=6E2D4146EA2709ED1E4A1764BC291F57
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
|
@ -24,6 +24,9 @@ static uint16_t usb_transmit_read_index = 0;
|
|||||||
static uint16_t usb_transmit_fifo_level = 0;
|
static uint16_t usb_transmit_fifo_level = 0;
|
||||||
static bool data_transmission_active = false;
|
static bool data_transmission_active = false;
|
||||||
static bool log_transmission_active = true;
|
static bool log_transmission_active = true;
|
||||||
|
static uint32_t last_transmission = 0;
|
||||||
|
|
||||||
|
#define USB_TRANMISSION_TIMEOUT 100
|
||||||
|
|
||||||
USBD_ClassTypeDef USBD_ClassDriver =
|
USBD_ClassTypeDef USBD_ClassDriver =
|
||||||
{
|
{
|
||||||
@ -162,6 +165,14 @@ static bool trigger_next_fifo_transmission() {
|
|||||||
return USBD_LL_Transmit(&hUsbDeviceFS, EP_DATA_IN_ADDRESS, &usb_transmit_fifo[usb_transmit_read_index], continous_length) == USBD_OK;
|
return USBD_LL_Transmit(&hUsbDeviceFS, EP_DATA_IN_ADDRESS, &usb_transmit_fifo[usb_transmit_read_index], continous_length) == USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool connection_okay() {
|
||||||
|
if(data_transmission_active && HAL_GetTick() - last_transmission > USB_TRANMISSION_TIMEOUT) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static uint8_t USBD_Class_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) {
|
static uint8_t USBD_Class_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) {
|
||||||
// A bulk transfer is complete when the endpoint does on of the following:
|
// A bulk transfer is complete when the endpoint does on of the following:
|
||||||
// - Has transferred exactly the amount of data expected
|
// - Has transferred exactly the amount of data expected
|
||||||
@ -189,6 +200,7 @@ static uint8_t USBD_Class_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) {
|
|||||||
log_transmission_active = false;
|
log_transmission_active = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
last_transmission = HAL_GetTick();
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
static uint8_t USBD_Class_DataOut(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_Class_DataOut(USBD_HandleTypeDef *pdev,
|
||||||
@ -222,6 +234,9 @@ void usb_init(usbd_recv_callback_t receive_callback) {
|
|||||||
HAL_NVIC_EnableIRQ(USB_LP_IRQn);
|
HAL_NVIC_EnableIRQ(USB_LP_IRQn);
|
||||||
}
|
}
|
||||||
bool usb_transmit(const uint8_t *data, uint16_t length) {
|
bool usb_transmit(const uint8_t *data, uint16_t length) {
|
||||||
|
if(!connection_okay()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// attempt to add data to fifo
|
// attempt to add data to fifo
|
||||||
if(length > usb_available_buffer()) {
|
if(length > usb_available_buffer()) {
|
||||||
// data won't fit, abort
|
// data won't fit, abort
|
||||||
|
Loading…
Reference in New Issue
Block a user