canpie / CANpie

API for accessing classic CAN and ISO CAN FD controller
https://canpie.github.io
Apache License 2.0
45 stars 14 forks source link

Full implementation of a canpie fd device driver #7

Open mgiaco opened 7 years ago

mgiaco commented 7 years ago

Hello,

I like CANpie. I also like the changes in the new CANpie-fd. But what I am missing most is a full implementation of a real hw device file. I think the whole project is not interesting for others exactly for this reason. Therefore I started with a simple test project https://github.com/liebherrnenzing/stm32f4_canpie-fd showing only the basic usage of the CANpie layer.

I am not sure if you are interested that others use CANpie for different stacks or what else but it is opensource so maybe you do. So it would be great if you help me here to implement this sample device driver.

So I start with some more questions:

1) What is the idea behind the new fifo functions? 2) CpCoreBufferSend... blocking or nonblocking? I am missing a send blocking and send unblocking. 3) Where do you use the CpHdi_s in you stack? 4) What are you doing with CpTime_s? 5) What mechanism are you using to check if the CANpie is the old or new one in the application code?

microcontrol22 commented 7 years ago

1. FIFO functions

The idea is to add a FIFO directly to a message buffer (reception or transmission) in order to decouple the driver from the application. This means you can read (or write messages) with the corresponding functions and don't have to care that a message buffer is empty or not. The FIFO size is determined by the application. We will provide an example inside the driver template to clarify this.

2. CpCoreBufferSend()

It is non-blocking. If you want to get a notice that the message was send you can install a handler using CpCoreInitFunctions(). We take this as a hint to clarify the documentation.

3. Usage of structure CpHdi_s

The function is not used in any of our protocol stacks (CANopen / J1939), but IMHO its a nice way to get details about the hardware during run-time (and not compile-time). For example, does the controller support FD and what is the highest supported bit-rate of the transceiver in the data phase.

4. CpTime_s

This is necessary to support CiA 603 (Requirements for network time management). You can use it as relative or absolute time-stamp. Currently, there are no support functions in C language, but already in C++. (class CpTimeStamp)

5. CANpie version

The CANpie version can be determined either during compile time by checking the symbols CP_VERSION_MAJOR resp. CP_VERSION_MINOR (described here). Or during run-time via the CpCoreHDI() function.

mgiaco commented 6 years ago

Hi, I have updated my driver to the latest HAL lib from st. I also add the file for the f1 also. No I would also have the fifo inside that driver. Are there any plans to add a example for the fifo? many thanks