The USBD_GS_CAN_SendToHost() function is used to send to struct
gs_host_frame_object to the host.
Until this patch, after the sending process has been started, the
outgoing frame object is already added to the list of free objects and
the variable USBD_GS_CAN_HandleTypeDef::TxState is used to track if
the transfer to the host is in progress.
Instead, hold the outgoing object in
USBD_GS_CAN_HandleTypeDef::to_host_buf and move it to the free list
after the transfer is finished in USBD_GS_CAN_DataIn(). Use this to
track if a transfer is ongoing.
In GS_USB_BREQ_IDENTIFY and GS_USB_BREQ_SET_TERMINATION the received
data is copied to a locale variable. Remove this and cast
hcan->ep0_buf to the struct gs_identify_mode respectively struct
gs_identify_mode.
Mark USBD_GS_CAN_HandleTypeDef::ep0_buf as aligned, so that it can be
casted to others structs that then can be dereferenced without
problems.
Since commit "usbd_gs_can: USBD_GS_CAN_Config_Request(): pass data
buffer to USBD_CtlSendData() directly" control frames from Device ->
Host are not copied to hcan->ep0_buf anymore. Shrink
CAN_CMD_PACKET_SIZE to minimal size.
Convert from the queue implementation to a Linux compatible list
implementation. Get rid of This way we can avoid dynamic memory
allocation altogether.
As the struct gs_host_frame is not placed into the data segment,
requirements for the static memory grows. On the low end processors
the heap reserved in the linker file is too big, resulting in a linker
error. On STM32F042 and STM32F072 set a HEAP size of 0 bytes.
Place the struct gs_host_frame msgbuf directly into
USBD_GS_CAN_HandleTypeDef. Get rid of another calloc().
This also requires a tweak to heap size in order to fit on the smaller
targets.
USBD_GS_CAN_PrepareReceive() is only used in usbd_gs_can.c, remove
function prototype from usbd_gs_can.h, mark as static, and move in
front to avoid forward declaration.
Move CAN_INTERFACE and CAN_CLOCK_SPEED to the config file as the CAN
clock can vary based on HW implementation.
Better to add it here than to keep adding defines into the
usbd_gs_can.h file.
CAN_INTERFACE can vary based on the number of channels you are using
so also makes sense to add here even though most chips use the same
interface ID.
with help from include-what-you-use (iwyu-tool). It's not quite clever
enough to understand our intent of including "hal_include.h" but still
offers good suggestions.
commit 46b01339f5eeab1157d "Add new mode to pad output usb packets
to max packet size for better ..." introduced an unused function
USBD_GS_CAN_GetPadPacketsToMaxPacketSize, get rid of it.
Needed for hcan->TxState to reset. In some cases when the host reboots, the TxState get locked forever and there's no way to recover other than resetting the controller.
Some files have Windows line endings which is annoying, since pathes
won't apply, diffs looks ugly etc. So do convert the few files which
have Windows line endings to use Unix line endings as well.