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.
The TIM2 timer is expected to run at 1 MHz, but it's clocked by the
CPU clock. The current code expects the CPU runs with 48 MHz.
Introduce TIM2_CLOCK_SPEED and calculate a proper divider.
This allows a much lighter implementation of led_indicate_trx(), which
is called for every frame !
Test with 'cangen -L0 -g0 -p10 can0'
After : 13174 frames/sec
Not necessary to spam it every mainloop. Currently throughputs of 17-18k
frames per second is realistic, which means function calls from mainloop
are very frequent and must be "short" compared to the processing time
for each frame.
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.
It turned out, that the locked functions added in
61baf8ce9039 ("list.h: add locked variants") are not needed. Remove
these and replace them by locked variants of functions needed in the
upcoming patches.
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.