-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sesnor:optimize bmi160 sensor adapt to uorb. #10077
Conversation
This is a breaking change for applications that use bmi160 (the same for #10080) as a character device. We should not force users to use uorb framework, at least not without wider community approval. At this point the best option would be to support uorb and char dev interfaces and control them with Kconfig. |
I add configuration items and submit |
@Otpvondoiats and @raiden00pl I think it is a good discussion, if we could support the sensors as char device and then add an option to them be compatible with uorb, it should be ideal. I know that @patacongo created a way to let a driver to incorporate another one, but I could find it. I think nobody used it until now, but it is some "hidden feature" of NuttX. I think he did it after creating the driver that convert char device to block devices. |
Within a driver, you can open and contain another driver using file_open() and access the other driver with file_read(), file_write()(), file_ioctl(), etc. This avoids using file descriptors. Search for file_open under drivers/. There are a few examples. |
I agree that simultaneous support for sensors as char device and with uorb would be ideal. |
@Otpvondoiats @xiaoxiang781216 may I change this PR and the other bmp180 to Draft until we find a way to support sensor driver and char device and include a layer over it to support uorb ? |
sure |
@raiden00pl @acassis @patacongo I've submitted a new version with support for both character devices and Uorb communication. Try not to modify the original character device code, and keep the original code appearance. BMI160 itself supports SPI and I2C, and there are macro distinctions in it. With the addition of character devices and UORB distinctions, the code will be messy. #10080 |
430c91b
to
4e97d0c
Compare
@Otpvondoiats Have you tried implementing the uorb sensor as a wrapper on character device sensor as it was mentioned before ? (based on file_read(), file_write()(), file_ioctl(), etc.). I'm curious if this approach is likely to work. I initially did something like this for lsm9ds1 but I haven't had a chance to test it on HW yet. |
it will bloat the code size since file operation is implemented twice, and waste some RAM.
The old interface couple with the hardware directly, which make the userspace write a general sensor program become an impossible task. For example, lis2dh, lis3dh, lis3dsh and mpu60x0 report the different measurement result. So, it isn't good to write the new senor driver with the old driver model(actually, there is no common upper half at all). |
Nice work @Otpvondoiats ! But I think the IOCTLs and data rate control should be in the main driver instead of only existing only in the _uorb. So the user application even when not using uorb will be able to use IOCTLs to control many features, like it is done in some char driver sensors already. |
@acassis as I mention before, the old sensor driver doesn't follow nuttx driver model, e.g.:
So, we don't plan to do any enhancement to the old drivers which demonstrate the bad practice, but continuing to improve the new driver model to encourage people switch to it. |
You might as well standardize the character driver interface for sensors without forcing the user to use uorb. So that's not an argument.
Why not ? Will uorb be good for all possible use cases?
Since when separate upperhalf and lowerhalf is nuttx driver model ? It seems to me that most drivers don't follow this approach and use bus interface (I2C/SPI) directly.
Totally agree here. A unified interface is something we must strive for. But uorb interface is only one way to achieve this. The old approach seems to use less resources (memory, CPU and hence power consumption) so there are situations where uorb just doesn't make sense. |
The fact is that all sensors expose the different interface util uorb try to unify the interface across all possible sensors. It welcome other people provide a new solution to unify the interface, but it's
I am not sure whether uorb is good for all possible cases, but it's always bad that each driver exposes the different IOCTL to userspace just like lis2dh, lis3dh, lis3dsh and mpu60x0.
It's fine with sample rate around 1KHz. For example, the implementation of an intelligent sensor for industrial applications, where we only need to read sensor data and send it over industrial protocol. I don't think we have enough information at the moment.
Most driver which expose file ioctl to userspace follow upperhalf/lowerhalf model.
could you give more examples except sensor? at least, analog, audio, crypto, efuse, input, ioexpander, lcd, leds, math, mmcsd, motor, mtd, net, battery, rc, rptun, serial, timer, video follow the
Yes, but before another interface similar interface exist,
Nobody forces user to use uorb, both interfaces keep in this patch. But we don't have enough resource to improve the raw driver interface which we don't use, so it's better to decouple both implementations. |
@xiaoxiang781216 I completely agree that uorb helped to force sensors to follow the common standard for IOCTLs, but this could have applied to character drivers as well, if someone had defined the standard to follow. If we create a thin layer that uorb could use over char device sensor drivers then users could use the sensors with or without uorb. Maybe a single sensor_uorb.c could be used to couple to any sensor driver. |
Good to know. Could you reveal the CPU freq? I guess uorb is not a problem for powerful processors, but with limited resources character device seems more reasonable.
You can just
I completely understand that you aren't interested in developing the old approach and that's ok. But from the initial look of this PR and discussion here, I got the impression that you'd want to get rid of the old sensors approach. So I'm hoping that's not the case, at least without much open discussion. Two separate sensor implementations will duplicate a lot of code. If you don't want to separate some common logic between implementations for the sensor, you can at least move the register definitions to a common private header for bmi160.c and bmi160_uorb.c |
Bob Feretich did develop something he called the Sensor Cluster Driver which was a frameworkd for sensor character drivers. It did not see much usage bit it is fully in place and implemented for a few sensor drivers. There is a general description in drivers/sensors/README.txt and include/nuttx/sensors/cluster_driver.h. Perhaps some or all of that could be reused? Ref: https://github.com/apache/nuttx/blob/master/drivers/sensors/README.txt#L217 |
we evaluate this interface before, but it also doesn't define any standard IOCTL and struct(e.g. accel, gryo...), so the different accel vendor provide the different IOCTL to expose the accel data to userspace. |
Then it probably should be removed at some point. It is not supported by many drivers and would not be on the sensor architecture roadmap. |
4e97d0c
to
ebb7058
Compare
34730ae
to
de2bff6
Compare
@raiden00pl could you review the new change? |
755ab56
to
779741d
Compare
…nication mode. create a new bmi160.h file. Signed-off-by: likun17 <[email protected]>
…nication mode. Create bmi160_base.h, bmi160_base.c bmi160_uorb.c files, the bmi160_base file stores public function interfaces, and the bmi160_uorb file stores functions related to the uorb framework. Switch the character interface and UORB interface through the macro CONFIG_SENSORS_BMI160_UORB. Signed-off-by: likun17 <[email protected]>
Summary
Add bmi160 to support uorb frame,retain the original character device capability.
Impact
no effect.
Testing
ubuntu 20.04/SIM
bus: I2C
pass