CAN driver
Posted: Tue Nov 21, 2017 10:08 pm
There are four issues and requirements I'd like to address with the CAN driver, a couple of which I think will need API changes or additions:
Problem 1: Inner priority inversion problem. If the transmit mailboxes are filled with low-priority frames and the bus is saturated, a higher-priority frame cannot transmit.
Problem 2: I need to enforce FIFO ordering of frames with the same ID field. This is a requirement of the higher-level protocol that I am using.
Problem 3: I need accurate receive timestamps for each frame.
Problem 4: I need accurate transmit timestamps for some frames.
Problems 1 and 2 can be addressed to satisfaction by the same mechanism: wait to enqueue frames until they will be the highest priority frame in the hardware queue. This would be pretty simple to address this directly at the LLD level. It could also be done at the HAL level - there would need to be additional LLD APIs to retrieve the ID field from a mailbox.
Problem 3 can be addressed relatively simply. A timestamp field will need to be added to CANRxFrame, it will need to be populated by the LLD using a hardware timestamp, or alternatively (less accurately) it could be a system time collected within the receive ISR. I think both options should be implemented - if a hardware timestamp is available, it should use the hardware timestamp, and otherwise it should use system time in the ISR.
Problem 4 is where the major API change/addition is going to need to happen. Currently, canTransmitTimeout only blocks until the frame is enqueued in hardware, not until it is actually transmitted. It does not return the mailbox or any kind of handle. If canTransmitTimeout returned the mailbox that the frame was enqueued in, then another function could be added to retrieve the transmit timestamp associated with that mailbox. Again, this would optionally be a hardware timestamp, and otherwise it would be a system time collected within the mailbox empty ISR.
I'll get started on it. Let me know if there are any objections.
Problem 1: Inner priority inversion problem. If the transmit mailboxes are filled with low-priority frames and the bus is saturated, a higher-priority frame cannot transmit.
Problem 2: I need to enforce FIFO ordering of frames with the same ID field. This is a requirement of the higher-level protocol that I am using.
Problem 3: I need accurate receive timestamps for each frame.
Problem 4: I need accurate transmit timestamps for some frames.
Problems 1 and 2 can be addressed to satisfaction by the same mechanism: wait to enqueue frames until they will be the highest priority frame in the hardware queue. This would be pretty simple to address this directly at the LLD level. It could also be done at the HAL level - there would need to be additional LLD APIs to retrieve the ID field from a mailbox.
Problem 3 can be addressed relatively simply. A timestamp field will need to be added to CANRxFrame, it will need to be populated by the LLD using a hardware timestamp, or alternatively (less accurately) it could be a system time collected within the receive ISR. I think both options should be implemented - if a hardware timestamp is available, it should use the hardware timestamp, and otherwise it should use system time in the ISR.
Problem 4 is where the major API change/addition is going to need to happen. Currently, canTransmitTimeout only blocks until the frame is enqueued in hardware, not until it is actually transmitted. It does not return the mailbox or any kind of handle. If canTransmitTimeout returned the mailbox that the frame was enqueued in, then another function could be added to retrieve the transmit timestamp associated with that mailbox. Again, this would optionally be a hardware timestamp, and otherwise it would be a system time collected within the mailbox empty ISR.
I'll get started on it. Let me know if there are any objections.