Emandhal / MCP251XFD

MCP2517FD, MCP2518FD and MCP251863 driver
MIT License
28 stars 6 forks source link

Enable/Disable MCP251XFD_INT_TX_EVENT at runtime #15

Open xmurx opened 4 months ago

xmurx commented 4 months ago

First of all, great work. I am trying to use the library in CAN 2.0 mode. I can't find a way to enable/disable MCP251XFD_INT_TX_EVENT when the controller is already in CAN 2.0. I found this function MCP251XFD_ConfigureInterrupt(), but calling the function with parameter MCP251XFD_INT_ENABLE_ALL_EVENTS does not enable the MCP251XFD_INT_TX_EVENT event. Is there another way to activate or deactivate interrupt events even if the controller is already in CAN2.0 mode? Many thanks in advance...

Emandhal commented 4 months ago

Hi, I see no reason for you to not be able to enable/disable Tx interrupts at runtime. Datasheets does not say any restriction for this.

The enable of MCP251XFD_INT_TX_EVENT in MCP251XFD_ConfigureInterrupt() is the first step. Next, you need to configure one or more of the following flags on each TXQ/TxFIFO that you need a Tx interrupt:

Set the interrupt config in your list of MCP251XFD_FIFO configuration (in .InterruptFlags member) for the MCP251XFD_ConfigureFIFOList() function.

Hope this help

xmurx commented 4 months ago

Hi, thanks for quick reply. I dived a little deeper on your suggestion. For me it looks like you designed the library to be configured at startup - only once in configuration mode (or switch back to configuration mode). If I have seen it correctly:

Enable or disable TX events during runtime is not supported. So, I have to work around this ;-) Otherwise the library works great.

Thanks!

Emandhal commented 4 months ago

Hi,

Now I understand perfectly what you want to do. Yes, the configuration at startup is its primary purpose, but modifying this parameter at runtime is important too. After checking how I can implement a new solution, I see one problem for this: the MCP251XFD_FIFO_AUTO_RTR_RESPONSE flag (ie. CiFIFOCONm.RTREN bit). I have 2 solution for this:

And for MCP251XFD_ConfigureInterrupt() you are right, it is not necessary a good idea to clear the clearable flags when changing the interrupt configuration.

As a "runtime changing interrupt configuration" user ( :blush: ), what do you think of this?

xmurx commented 4 months ago

Hi,

I would go for solution one (read - modify - rewrite configuration) - even though there is a bit of overhead changing this at runtime. May be you can think about a configuration-API which primary purpose is static configuration at startup and a "runtime"-API to change the configuration later.

Emandhal commented 3 months ago

Hi, I made a new commit for this "feature". Can you try it so I we can close this issue ?

Thanks