Open mickeyl opened 9 months ago
@mickeyl Hi, based on your test, I think I have an idea:
The driver using queue construct a front and background system, data is actually send by background.
As you ask a e.g. 350us interval time, which is enough for data timing, then, if you set your queue_size=1
and timeout=0
, then setup a 350us timer to enqueue data every timer event, this can ensure the interval low limit. meanwhile you should also adjust your code to ensure the ISR background for TWAI not interrupted by others, it should ensure the interval high limit.
anyway, it is possible based on exist driver architecture, I'm glade if you agree about this, and hope it can help you
@wanckl Thanks for your answer. I understand queue_size=1
, but where would I configure timeout=0
?
I also understand the need for configuring "ISR background for TWAI not interrupted by others, it should ensure the interval high limit.", but where/how can I do that? I can't seem to setup an IRQ priority for TWAI when IRAM is set – or can I?
@mickeyl Sorry for confusing you, timeout
means 2nd argument of twai_transmission
: ticks_to_wait
.
while, yeah, no IRQ priority you can set, now you can only don't init/enable other features like WIFI or BLE or others, keep twai a minimal app.
Good news is I herd that they are plan to public the IRQ priority to user, but maybe hardware/architecture different, there may just little choices you can use.
:hand_over_mouth:
Did you set freertos frequency to 1000Hz?
Yes
Answers checklist.
General issue report
I'm using TWAI to interface with ECUs in vehicles. Some of the ECUs need a pretty deterministic timing (i.e. send a frame every 350µs), which is why I'm thinking about adjusting the TWAI driver to do that. Before I got into that I took a look at the best-case timing, which looks pretty strange. The following data has been acquired on CAN bus configured to 500KBit/sec with two additional devices:
For testing, I used the following code in a loop that runs every second:
So I enqueue 10 frames into the queue (which is setup for 100 frames) and I would expect that these frames are then transmitted with a relatively stable timing.
Here is a dump made on linux from another CAN device in listen-only mode. The timestamps are delta-timestamps.
This looks pretty unstable to me. Notice that the first two of the 10 frames are transmitted very fast (less than 15 µs between a frame), but then it takes about 200 µs each for the rest of the 8. Once there was even a 500µs interval.
Do you have any idea what we can do to improve that? This is on an ESP32S3 without any other tasks, so there should be enough bandwidth.