Buffer int msg to ensure alignment and placement correctness.
This commit is contained in:
@@ -86,6 +86,11 @@ tu_static char logMsg[150];
|
|||||||
// imposes a minimum buffer size of 32 bytes.
|
// imposes a minimum buffer size of 32 bytes.
|
||||||
#define USBTMCD_BUFFER_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
#define USBTMCD_BUFFER_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
|
|
||||||
|
// Interrupt endpoint buffer size, default to 2 bytes as USB488 specification.
|
||||||
|
#ifndef CFG_TUD_USBTMC_INT_EP_SIZE
|
||||||
|
#define CFG_TUD_USBTMC_INT_EP_SIZE 2
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The state machine does not allow simultaneous reading and writing. This is
|
* The state machine does not allow simultaneous reading and writing. This is
|
||||||
* consistent with USBTMC.
|
* consistent with USBTMC.
|
||||||
@@ -124,13 +129,15 @@ typedef struct
|
|||||||
uint8_t ep_bulk_in;
|
uint8_t ep_bulk_in;
|
||||||
uint8_t ep_bulk_out;
|
uint8_t ep_bulk_out;
|
||||||
uint8_t ep_int_in;
|
uint8_t ep_int_in;
|
||||||
|
uint32_t ep_bulk_in_wMaxPacketSize;
|
||||||
|
uint32_t ep_bulk_out_wMaxPacketSize;
|
||||||
// IN buffer is only used for first packet, not the remainder
|
// IN buffer is only used for first packet, not the remainder
|
||||||
// in order to deal with prepending header
|
// in order to deal with prepending header
|
||||||
CFG_TUSB_MEM_ALIGN uint8_t ep_bulk_in_buf[USBTMCD_BUFFER_SIZE];
|
CFG_TUSB_MEM_ALIGN uint8_t ep_bulk_in_buf[USBTMCD_BUFFER_SIZE];
|
||||||
uint32_t ep_bulk_in_wMaxPacketSize;
|
|
||||||
// OUT buffer receives one packet at a time
|
// OUT buffer receives one packet at a time
|
||||||
CFG_TUSB_MEM_ALIGN uint8_t ep_bulk_out_buf[USBTMCD_BUFFER_SIZE];
|
CFG_TUSB_MEM_ALIGN uint8_t ep_bulk_out_buf[USBTMCD_BUFFER_SIZE];
|
||||||
uint32_t ep_bulk_out_wMaxPacketSize;
|
// Buffer int msg to ensure alignment and placement correctness
|
||||||
|
CFG_TUSB_MEM_ALIGN uint8_t ep_int_in_buf[CFG_TUD_USBTMC_INT_EP_SIZE];
|
||||||
|
|
||||||
uint32_t transfer_size_remaining; // also used for requested length for bulk IN.
|
uint32_t transfer_size_remaining; // also used for requested length for bulk IN.
|
||||||
uint32_t transfer_size_sent; // To keep track of data bytes that have been queued in FIFO (not header bytes)
|
uint32_t transfer_size_sent; // To keep track of data bytes that have been queued in FIFO (not header bytes)
|
||||||
@@ -243,12 +250,13 @@ bool tud_usbtmc_transmit_dev_msg_data(
|
|||||||
bool tud_usbtmc_transmit_notification_data(const void * data, size_t len)
|
bool tud_usbtmc_transmit_notification_data(const void * data, size_t len)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
TU_ASSERT(len >= 1);
|
TU_ASSERT(len > 0);
|
||||||
TU_ASSERT(usbtmc_state.ep_int_in != 0);
|
TU_ASSERT(usbtmc_state.ep_int_in != 0);
|
||||||
#endif
|
#endif
|
||||||
if (usbd_edpt_busy(usbtmc_state.rhport, usbtmc_state.ep_int_in)) return false;
|
TU_VERIFY(usbd_edpt_busy(usbtmc_state.rhport, usbtmc_state.ep_int_in));
|
||||||
|
|
||||||
TU_VERIFY(usbd_edpt_xfer(usbtmc_state.rhport, usbtmc_state.ep_int_in, (void *)(uintptr_t) data, len));
|
TU_VERIFY(tu_memcpy_s(usbtmc_state.ep_int_in_buf, sizeof(usbtmc_state.ep_int_in_buf), data, len) == 0);
|
||||||
|
TU_VERIFY(usbd_edpt_xfer(usbtmc_state.rhport, usbtmc_state.ep_int_in, usbtmc_state.ep_int_in_buf, len));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -86,21 +86,16 @@ TU_ATTR_WEAK bool tud_usbtmc_msg_trigger_cb(usbtmc_msg_generic_t* msg);
|
|||||||
//TU_ATTR_WEAK bool tud_usbtmc_app_go_to_local_cb();
|
//TU_ATTR_WEAK bool tud_usbtmc_app_go_to_local_cb();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*******************************************
|
// Called from app
|
||||||
* Called from app
|
//
|
||||||
*
|
// We keep a reference to the buffer, so it MUST not change until the app is
|
||||||
* We keep a reference to the buffer, so it MUST not change until the app is
|
// notified that the transfer is complete.
|
||||||
* notified that the transfer is complete.
|
|
||||||
******************************************/
|
|
||||||
|
|
||||||
bool tud_usbtmc_transmit_dev_msg_data(
|
bool tud_usbtmc_transmit_dev_msg_data(
|
||||||
const void * data, size_t len,
|
const void * data, size_t len,
|
||||||
bool endOfMessage, bool usingTermChar);
|
bool endOfMessage, bool usingTermChar);
|
||||||
|
|
||||||
// Buffers a notification to be sent to the host. The buffer must be
|
// Buffers a notification to be sent to the host. The data starts
|
||||||
// valid until the tud_usbtmc_notification_complete_cb callback. The
|
// with the bNotify1 field, see the USBTMC Specification, Table 13.
|
||||||
// data starts with the bNotify1 field, see the USBTMC Specification,
|
|
||||||
// Table 13.
|
|
||||||
//
|
//
|
||||||
// If the previous notification data has not yet been sent, this
|
// If the previous notification data has not yet been sent, this
|
||||||
// returns false.
|
// returns false.
|
||||||
|
Reference in New Issue
Block a user