-
Notifications
You must be signed in to change notification settings - Fork 20
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
Mpu6050 device improvement and cdev usage #33
base: Sergii.Romantsov
Are you sure you want to change the base?
Mpu6050 device improvement and cdev usage #33
Conversation
I have a question: what was the reason for using sysfs kobject? Also have several warnings about format:
|
<<< I have a question: what was the reason for using sysfs kobject? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix checkpatch errors (and warnings if possible). e.g:
../../linux/scripts/checkpatch.pl -f *.c
../../linux/scripts/checkpatch.pl -f *.h
Code itself is OK. Please fix format issues and I will have no objections.
CS is done |
Thank you! Please merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made shallow review and haven't tested the solution.
Generally I like the work, which you've done. 👍
The driver looks good despite of unneeded complexity in some parts.
I've commented inline some issues.
And here are some more general notes:
- Implementation of
mpu6050_data
module looks like example of overengineering for this case:- If you want to create generic collection, it shouldn't use mpu6050-specific types;
- If its the only purpose to store 10 samples from the mpu6050 - it might be much simpler;
- Please use conventional form of tagging commit subjects (
mpu6050: ...
in this case); - Also commit messages may be more descriptive;
- And don't forget SOB line;
- 7c095fa ("[Lesson 6] mpu6050 review fix") is empty commit;
IMO at least commit messages and some obvious issues should be fixed before merging.
mpu6050/mpu6050_data.h
Outdated
struct mpu6050_data_list *element_iter_current; | ||
struct mpu6050_data_list list; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, never ever do like that.
Functions (except inline) mustn’t be defined in header files!
mpu6050/mpu6050_data.h
Outdated
INDEX_GYRO_Z, | ||
INDEX_TEMPERATURE, | ||
INDEX_COUNT, | ||
/* Another level of data*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid mixing indexes of different arrays within the same enum.
The following are not for the data
- they are for extra_data
and enum should be named accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mpu6050/mpu6050_cdev.c
Outdated
|
||
struct cdevs_holder *get_cdevs(void) | ||
{ | ||
static struct cdevs_holder g_cdevs_holder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the driver's static data defined as local variable?
It may have some sense for future compatibility if you're going to expand the driver to support several instances.
But AFAIK this is not the case.
Right now it makes driver understanding and debugging harder with no benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mpu6050/mpu6050_cdev.c
Outdated
if (result < 0) | ||
goto error1; | ||
cdevs->cdev_full.major = MAJOR(cdevs->cdev_full.dev_no); | ||
cdevs->cdev_line.read_all = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like copy-paste error is here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mpu6050/mpu6050_cdev.h
Outdated
struct cdev_instance { | ||
unsigned int major; | ||
dev_t dev_no; | ||
dev_t read_all; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of read_all
seems to be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mpu6050/mpu6050_main.c
Outdated
} | ||
|
||
g_reading_thread = kthread_run(reading_thread, NULL, "mpu6050_read_th"); | ||
if (!g_reading_thread) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong error handling - kthread_run
will return negative code in case of errors.
IS_ERR
macro should be used for verification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mpu6050/mpu6050_main.c
Outdated
|
||
if (g_reading_thread) { | ||
complete(&g_read_comletion); | ||
kthread_stop(g_reading_thread); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to set should_stop flag by kthread_stop
before waking up the thread by complete
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mpu6050/mpu6050_main.c
Outdated
kthread_stop(g_reading_thread); | ||
} | ||
result = del_timer_sync(&g_read_timer); | ||
pr_info("mpu6050: timer deleted %d\n", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logically timer should be stopped before deleting the thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mpu6050/mpu6050_main.c
Outdated
NULL, | ||
}; | ||
|
||
/* Gets a number of attributes + 1 (null-terminated) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In current implementation there's no need in attributes_count()
function.
So why not to simplify code a bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
mpu6050/mpu6050_main.c
Outdated
/* functionality */ | ||
static size_t get_attribute_index(struct kobj_attribute const *attribute); | ||
|
||
static int mpu6050_read_data(bool debug) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely wrong way of controlling debug printout.
It should be done on preprocessing stage.
Consider defining macro wrapper over dev_info
, which will be expanded to nothing if debug mode not defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is over-control. It used to allow do not print for any type: or debug, or release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming the argument to print_out
doesn't change anything.
The value provided to it is hardcodded, so there's no sense to keep it as parameter - define should be used instead.
Instead of sysfs class used sysfs kobject. Files-data created at once. Reading of data is done by one function. Controlled resources on initialization failure.
Added functionality to hold 10 last reads of data from mpu6050 device.
Data from device mpu6050 will be read not often than 1 time per second.
Fixed misprint in storing timestamp: it was possibility to store diff of timestamps instead of real value.
Added charetcer-device that allows to read mpu6050-device data in one-line format.
Implementation from header-files (mpu6050_cdev.h, mpu6050_data.h) is moved to source-files.
File with initialization-functions wasn't compiled.
Avoided usage of c++-style comments. Added author.
Added support to dump latest 10 reads from mpu6050 by charecter device.
Structure of data and access to them are incapsulated to allow exclusive access and synchronization.
Added synchronization for data reading/writing.
Timer is added to read data each 1000 msecs.
Code correction according to checkpatch.pl
Cleaned code: avoided unused functions. Added support to read to user buffer with requested size. Corrected misprints for variable types. Divided indexes for different data. Improved module unitialization.
f8d5c26
to
9661f28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:+1
Properly rebased pull-request #29 (up to commit d2f5920).
Improved mpu6050 implementation.
Added storage for 10 latest reads from mpu6050.
Added cdevs to print data in one-line and ten-lines format.
Added timer to read data each 1000 msecs.