149 Commits

Author SHA1 Message Date
Marc Kleine-Budde
206de0067a can: can_enable: move the mode flags evaluation into the CAN drivers
...having so many arguments doesn't scale.
2024-01-30 11:48:52 +01:00
Marc Kleine-Budde
51e155073b led: use uppercase for defines 2024-01-30 11:48:52 +01:00
Marc Kleine-Budde
3a9e42a242 can: move assignment of rx_frame::channel and ::flags into bxcan 2024-01-30 11:48:52 +01:00
Marc Kleine-Budde
34cbcf021c usbd_gs_can: add support for CAN-FD to USB path 2024-01-30 11:48:52 +01:00
Marc Kleine-Budde
f83fdd8371 usbd_gs_can: import struct gs_host_frame from kernel and adopt code 2024-01-30 11:48:52 +01:00
Marc Kleine-Budde
84ec4d5501 can: rename can_data_t hcan -> channel
No functional change.
2024-01-30 11:48:52 +01:00
Marc Kleine-Budde
78bafcf07b main: move per channel CAN handling code out of main loop into separate functions
No functional change intended.
2024-01-30 11:48:52 +01:00
Marc Kleine-Budde
f418aa362c usbd_gs_can: clean up send to host path
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.
2024-01-30 11:48:52 +01:00
Marc Kleine-Budde
3e4883c74f usbd_gs_can: move send_to_host() to usbd_gs_can.c and rename it to USBD_GS_CAN_SendToHost()
Since USBD_GS_CAN_SendFrame() isn't used anymore outside of
usbd_gs_can.c, mark it as static.
2023-10-16 07:24:56 +02:00
Marc Kleine-Budde
562d765c3c usbd_gs_can: move list_from_host from USBD_GS_CAN_HandleTypeDef to can_data_t 2023-10-16 07:24:56 +02:00
Marc Kleine-Budde
3297e621a7 usbd_gs_can: move led_data_t into can_data_t 2023-10-16 07:24:56 +02:00
Marc Kleine-Budde
66f2f03d58 usbd_gs_can: USBD_GS_CAN_EP0_RxReady(): no need to copy hcan->ep0_buf to a locale variable
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.
2023-10-16 07:24:56 +02:00
Marc Kleine-Budde
1e2e7e226f usbd_gs_can: rename macro holding EP0 buffer size to avoid confusion
The size of the EP0 buffer is not related to the wMaxPacketSize of the
EP0. Rename to avoid confusion.
2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
ea53735f4d usbd_gs_can: shrink CAN_CMD_PACKET_SIZE to minimal size
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.
2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
35fb74228b compiler.h: add some min() and max() macros 2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
3d98b33f15 usbd_gs_can: USBD_GS_CAN_Config_Request(): check size 2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
fa7b91bcc5 usbd_gs_can: USBD_GS_CAN_Transmit(): mark as static 2023-10-13 08:24:14 +02:00
Marc Kleine-Budde
5b9c788ac6 main: can_parse_error_status(): move last_err into can_data_t
This is a preparation patch to support more then 1 channel.
2023-10-13 08:24:14 +02:00
Marc Kleine-Budde
1c386e89ce compiler.h: add fallthrough
Import from FreeBSD.
2023-10-13 08:21:26 +02:00
Marc Kleine-Budde
26134e6a7e compiler.h: add IS_ENABLED
Import from zephyr
2023-07-19 10:39:37 +02:00
Marc Kleine-Budde
0207095915 compiler.h: add DECLARE_FLEX_ARRAY and struct_size
Import from FreeBSD.
2023-05-10 17:29:19 +02:00
Marc Kleine-Budde
6af7be218a treewide: sort includes 2023-05-10 17:29:19 +02:00
Marc Kleine-Budde
881f430c55 config: make NUM_CAN_CHANNEL a per board macro 2023-05-10 17:29:19 +02:00
Marc Kleine-Budde
5109196811 config: make CAN_QUEUE_SIZE depend on number of CAN channels 2023-05-10 17:29:19 +02:00
Marc Kleine-Budde
ab292f22e7 gpio: GPIO_INIT_STATE: use lower case for macro argument 2023-05-10 17:29:18 +02:00
Marc Kleine-Budde
dc1664779f config: convertdevice xCANFD: remove unused CANFDIF_GPIO_Port, CANFDIFRX_Pin, CANFDIFTX_Pin 2023-05-10 17:29:18 +02:00
Marc Kleine-Budde
4cd86590d6 timer: run at 1 MHz for all clock speeds
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.
2023-05-10 17:29:18 +02:00
Marc Kleine-Budde
3bbb594467 gs_usb.h: fix typo in GS_CAN_FEATURE_BERR_REPORTING
Fixes: ad2f13ace724 ("gs_usb.h: document GS_CAN_MODE_BERR_REPORTING")
2023-05-10 16:19:50 +02:00
ConvertDevice
4dc288d174 feat: add convertdevice xCANFD config info 2023-04-22 09:27:07 -04:00
Chris Wilson
4d7abdf9fd
Add support for additional F072 boards
- DSD TECH SH-C30A: https://www.deshide.com/product-details.html?pid=384242&_t=1671089557
- FYSETC UCAN: https://www.fysetc.com/products/fysetc-ucan-board-based-on-stm32f072-usb-to-can-adapter-support-with-canable-candlelight-klipper-firmware
2023-04-19 22:16:22 -07:00
fenugrec
41e0388273 move system clock config to device_XX.c 2022-12-12 11:27:18 -05:00
fenugrec
2d9d1b302c split device-specific can_init() to separate files 2022-12-12 11:27:18 -05:00
ConvertDevice
537c0860c3 feat: change xCAN01 to xCAN 2022-12-11 11:56:15 +08:00
fenugrec
edc684609b led.c : removed unused last_mode 2022-11-28 11:39:45 -05:00
fenugrec
361ab73ddb led : move tx/rx blinking logic to led_update()
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
2022-11-28 11:39:42 -05:00
fenugrec
c2bb46f18f led_update() only every 10ms
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.
2022-11-25 08:36:40 -05:00
Marc Kleine-Budde
0b52b4eaf9 queue: remove no longer used queue implementation 2022-11-24 10:24:36 +01:00
Marc Kleine-Budde
35d6cb8941 queue: convert to Linux compatible list implementation
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.
2022-11-24 10:24:36 +01:00
Marc Kleine-Budde
67b15c19f1 list.h: add new locked variants, remove old ones
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.
2022-11-24 10:24:36 +01:00
Marc Kleine-Budde
61baf8ce90 list.h: add locked variants 2022-11-17 13:41:33 -05:00
Marc Kleine-Budde
9ea65a1d98 list.h: remove BSD specific STANDALONE support and include compiler.h 2022-11-17 13:41:33 -05:00
Marc Kleine-Budde
e2173dc60b list.h: uncrustify 2022-11-17 13:41:33 -05:00
Marc Kleine-Budde
d67381bce3 list.h: import from freebsd 2022-11-17 13:41:33 -05:00
Marc Kleine-Budde
9e98f4b49a usbd_gs_can: move struct gs_host_frame msgbuf into USBD_GS_CAN_HandleTypeDef
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.
2022-11-17 13:41:13 -05:00
Marc Kleine-Budde
6123dbd115 usbd_gs_can: embed can_data_t in USBD_GS_CAN_HandleTypeDef
As USBD_GS_CAN_HandleTypeDef describes the whole device, place the
data structure describing the channels directly into it.
2022-11-17 13:20:19 -05:00
Marc Kleine-Budde
1c9f2e7384 usbd_gs_can: place USBD_GS_CAN_HandleTypeDef in BSS
Get rid of the first calloc().
2022-11-17 13:20:19 -05:00
Marc Kleine-Budde
e739f60960 usbd_gs_can: move USBD_GS_CAN_HandleTypeDef to header
Move USBD_GS_CAN_HandleTypeDef definition to header as a preparation
to place the USBD_GS_CAN_HandleTypeDef into the BSS in main.c
2022-11-17 13:20:19 -05:00
Marc Kleine-Budde
859b7e3717 usbd_gs_can: USBD_GS_CAN_PrepareReceive(): mark as static
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.
2022-11-17 13:20:19 -05:00
Marc Kleine-Budde
e27abfe173 treewide: sort includes 2022-11-17 13:20:19 -05:00
fenugrec
718882b354 move GPIO_INIT_STATE macro to gpio.h 2022-11-17 13:01:58 -05:00