linuxsocketsembedded-linuxcan-bussocketcan

Can you attach a custom CAN interrupt handler to SocketCAN?


I have an application running baremetal which controls a peripheral via CAN. In its original form, my application hands messages to the CAN "driver", which is actually a buffering layer. Incoming messages are pulled out of the hardware buffer and either:

  1. pushed onto the queue by an interrupt handler, using a further CAN HAL.
  2. sent to an emergency secondary handler, which runs in the context of the ISR.

Now, I am required to replace the buffering layer and HAL with a SocketCAN-based driver for the peripheral.

+---------------------+                                 |   +---------------------+  
|                     |                                 |   |                     |  
|  Peripheral driver  |              Emergency          |   |  Peripheral driver  |  
|                     |                  ^              |   |                     |  
+----------------^----+                  |              |   +----------------^----+  
      |Queue     |                       |              |         |Queue     |       
      |          |Dequeue                |              |         |          |Dequeue
+-----v---------------+       +---------------------+   |   +-----v---------------+  
|                     |       |                     |   |   |                     |  
| CAN driver (queues) <--------         ISR         |   |   |      SocketCAN      |  
|                     |       |                     |   |   |                     |  
+---------------------+       +----------^----------+   |   +---------------------+  
      | Tx                               |              |                            
      |                                  |              |                            
+-----v---------------+                  |              |                            
|                     |                  |              |                            
|       CAN HAL       |       Rx         |              |                            
|                     |-------------------              |                            
+---------------------+                                 |                            

In the original setup, handling CAN reception in the ISR means that the emergency messages are dealt with as soon as possible. My understanding of SocketCAN is that it (or the World of Sockets, which I am not familiar with) handles the queuing of incoming frames, which means that emergency messages will have to wait until the peripheral driver has pulled out of the queue everything that arrived before the emergency.

Surely there is a way to handle certain messages first. How would I do that?


Solution

  • The answer I think I was looking for is that you must set up a signal and signal handler, or a handler for SIGIO, for the socket.

    The topology would then again look like the original (left-hand side of the diagram).