How to use rtdm_(io/m)map_to_user
Hello all,
This is my first post on this mailing list. I am really new with xenomai, only few month ago.
Currently we have a real-time application using xenomai which interacts with hardware directly by mmaping /dev/mem.
Now, we want to write a real-time device driver that will simulate the hardware. For keeping the same interface than /dev/mem, a conventional linux device driver would register an mmap file operation, but this is not possible with rtdm.
But I have seen in xenomai api the functions : rtdm_mmap_to_user and rtdm_iomap_to_user. Could you explain how to use them, i.e. where do we need to put the function call, do we need to use ioctl file operation to get mmaped address, etc? Maybe you have an example (I have found nothing in xenomai trunk)?
In a near future, instead of use /dev/mem, we plan to use a real-time device driver and rtdm_iomap_to_user (only to have the same code in client application). In this case, is it necessary and possible to call request_mem_region() in the real-time device driver?
Best regards,
Victor Hiairrassary
Quoted 8 lines · Victor Hiairrassary
Hello all,
This is my first post on this mailing list. I am really new with xenomai, only
few month ago.Currently we have a real-time application using xenomai which interacts with hardware directly by mmaping
/dev/mem.
This is wrong. The "abstraction layer" used by an application should be the usual driver interface open/read/write/ioctl and mmap if there are high volumes of data to exchange with the application. Access to the registers should be confined to the driver implementation.
This way, in order to simulate the real hardware you only have to implement another driver with the same interface (but with an implementation not using registers). And when you decide to use another hardware with a completely different registers interface, you do not have to emulate the first device registers using the second one, you simply implement another driver with the same interface.
This is the way, the interface between Linux drivers and applications is done, and the way it can be done with Xenomai RTDM skin.
Signature · 1 line
Gilles.
Quoted 6 lines · Gilles Chanteperdrix
This is wrong. The "abstraction layer" used by an application should be the usual driver interface open/read/write/ioctl and mmap if there are high volumes of data to exchange with the application. Access to the registers should be confined to the driver implementation.
The hardware is a FPGA which expose 1024 registers. Currently to read or write in a register, we use mmap. How use them with read/write file operations of this registers? i.e. in userspace, once mmaped on an ptr, we do : ptr[addr] = value. How achieve this with write operation, because write accepts only a value ?
Quoted 13 lines
This way, in order to simulate the real hardware you only have to implement another driver with the same interface (but with an implementation not using registers). And when you decide to use another hardware with a completely different registers interface, you do not have to emulate the first device registers using the second one, you simply implement another driver with the same interface.
This is the way, the interface between Linux drivers and applications is done, and the way it can be done with Xenomai RTDM skin.
Signature · 1 line
Gilles.
Quoted 12 lines · Victor Hiairrassary
Quoted 7 lines · Gilles Chanteperdrix
This is wrong. The "abstraction layer" used by an application should be the usual driver interface open/read/write/ioctl and mmap if there are high volumes of data to exchange with the application. Access to the registers should be confined to the driver implementation.
Quoted 5 lines
The hardware is a FPGA which expose 1024 registers. Currently to read or write in a register, we use mmap. How use them with read/write file operations of this registers? i.e. in userspace, once mmaped on an ptr, we do : ptr[addr] = value. How achieve this with write operation, because write accepts only a value ?
The register access is almost certainly the wrong abstraction layer. If you need writing to registers 2 to 13 starts a motor, then, there should be an ioctl START_THE_MOTOR, which implementation in RTDM driver writes to registers 2 to 13. In other words, without knowing what you do with this FPGA there is no way to answer.
Anyway, if the 1024 registers are 1024 parameters of the FPGA which you need to configure individually, you can create an ioctl with a structure where you pass the register number and the value.
Signature · 1 line
Gilles.
Quoted 7 lines · Gilles Chanteperdrix
The register access is almost certainly the wrong abstraction layer. If you need writing to registers 2 to 13 starts a motor, then, there should be an ioctl
START_THE_MOTOR, which implementation in RTDM driver writes to registers 2 to 13. In other words, without knowing what you do with this FPGA there is no way to answer.
Quoted 5 lines
Anyway, if the 1024 registers are 1024 parameters of the FPGA which you need to configure individually, you can create an ioctl with a structure where you pass the register number and the value.
Really thanks for your answers ! We have some actions binded to registers :
for example, read registers 5 return current speed, etc.
So we will use an real-time device driver ! Do we need to call devm_request_and_ioremap() in driver initialization, like in linux device driver? i.e. is it allowed and recommended with rtdm?
Regards,
Victor Hiairrassary
Quoted 13 lines · Victor Hiairrassary
Quoted 7 lines · Gilles Chanteperdrix
The register access is almost certainly the wrong abstraction layer. If you need writing to registers 2 to 13 starts a motor, then, there should be an ioctl
START_THE_MOTOR, which implementation in RTDM driver writes to registers 2 to 13. In other words, without knowing what you do with this FPGA there is no way to answer.Quoted 5 lines
Anyway, if the 1024 registers are 1024 parameters of the FPGA which you need to configure individually, you can create an ioctl with a structure where you pass the register number and the value.
Quoted 7 lines
Really thanks for your answers ! We have some actions binded to registers :
for example, read registers 5 return current speed, etc.So we will use an real-time device driver ! Do we need to call
devm_request_and_ioremap()
in driver initialization, like in linux device driver? i.e. is it allowed and recommended with rtdm?
Calling ioremap from an RTDM driver should not raise any problems.
Signature · 1 line
Gilles.