Skip to content
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_part2 #155

Open
wants to merge 48 commits into
base: Vitalii.Pudov
Choose a base branch
from

Conversation

VitaliiPudov
Copy link

  • fix mpu6050 module
  • add performance test
  • optimize source code

an1kh and others added 30 commits October 3, 2019 14:48
Task is described in the README.md file.

Signed-off-by: Andriy Khulap <[email protected]>
    The tasks are in README.md file of each subfolder.

Signed-off-by: Yevgen Kovalyov <[email protected]>
Signed-off-by: Yevgen Kovalyov <[email protected]>
Signed-off-by: Yevgen Kovalyov <[email protected]>
This starts development of driver
for gyroscope & accelerometer mpu6050.
Some documentation for the device is attached.

Signed-off-by: Aleksandr Bulyshchenko <[email protected]>
Driver skeleton consist of two functions:
1. Module entry point (mpu6050_init)
   This function is called when driver is loaded.
   Should return 0 on success (driver will be loaded) or negative  error value
   on failure (driver will not be loaded).
2. Module exit point (mpu6050_exit)
   This function is called on driver removal. No return value.

Both functions should be exported using module_init and module_exit macroses.

Debug information may be printed using printk() function and can be read using
dmesg program. But checkpatch.pl script treat printk(KERN_INFO as warnings
so pr_info() was used instead.

Signed-off-by: Andriy.Khulap <[email protected]>
I2C driver consist of:

1. probe and remove functions. Called on driver load and removal respectively.

2. i2c_device_id structure. Should contain strings exact equal to devive tree.
   MODULE_DEVICE_TABLE() macro is mandatory for match with dtb. Without it
   driver will not be probed.
   static const struct i2c_device_id mpu6050_idtable [] = {
       { "mpu6050", 0 },
       { }
   };
   MODULE_DEVICE_TABLE(i2c, mpu6050_idtable);

3. i2c_driver structure itself.
   Important fields: probe, remove and id_table should point to items described
   above.
   static struct i2c_driver mpu6050_i2c_driver = {
       .driver = {
           .name = "gl_mpu6050",
       },

       .probe = mpu6050_probe ,
       .remove = mpu6050_remove,
       .id_table = mpu6050_idtable,
   };

I2C driver is created using i2c_add_driver(&mpu6050_i2c_driver) function.
It will return 0 on success and most likely is called from module_init().
Please note that without device tree match probe function will not be called,
but i2c_add_driver() will return OK. With device tree match, probe function
will be called right after i2c_add_driver().

I2C driver is removed with i2c_del_driver(&mpu6050_i2c_driver) function.
If driver was created, remove function will be called.

Signed-off-by: Andriy.Khulap <[email protected]>
Most of i2c chips have a special read-only register with unique id.
So the easiest way to communicate with the device is to read that register.
It should be accessibe even during power off modes and so failing to read it
means no communication with the device. Reading non-expected value will indicate
wrong adress or data size used, or incorrect device connected (other revision).

Reading small amounts of data is easiest done using i2c_smbus_read_byte()
or similar functions. Why smbus? Because they are wrappers to i2c_transfer()
function and have internal device address as a parameter. This eliminates need
to fill i2c_transfer structure for each small read or write.
Using i2c_transfer() should be considered for large blocks of data and gives
a performance boost over i2c_smbus wrappers.

Signed-off-by: Andriy.Khulap <[email protected]>
This mpu6050 driver functionality consist of reading relevant values and
exporting them to the user space. Needed parameters are: accelerometer x,
y, z, gyroscope x, y, z and temperature (as an easiest check that device
is configured and operating properly).

First, the chip must be configured. This consist of programming all setup
registers with correct values. For example: clear power down, set prescalers,
configures fifos and so on.
Configuration is usually done in driver probe routine.

Second, reading values or performing needed actions can be done in a separate
theread inside driver, or in the workqueue. But this driver is supposed to
give values on demand so there is no need for that. All values are read at
once in a single function.

To export data to the user space was decided to use sysfs.
A class was created and 7 attributes for each parameter. Since all
parameters are read-only, all attributes have only show function and
their access rights are set to 0444.
So all _show() fuctions are almost the same: read all parameters first,
then return the needed one.

The summary how this driver works:
1. Create i2c device in module_init() and configure the chip from i2c_probe().
2. Create sysfs class and attributes for each parameter from module_init().
3. Read and return mpu6050 parameters in each sysfs_attribute_x_show().

Signed-off-by: Andriy.Khulap <[email protected]>
Initialization of the project. Empty files were added.

Signed-off-by: Vitalii Pudov <[email protected]>
User interface functionality was added.

Signed-off-by: Vitalii Pudov <[email protected]>
makefile was implemented

Signed-off-by: Vitalii Pudov <[email protected]>
Win selection functionality was implemented.

Signed-off-by: Vitalii Pudov <[email protected]>
The script with no any functionality was added

Signed-off-by: Vitalii Pudov <[email protected]>
Bash script was implemented: Print the quantity of files with extention .c, .cpp and *.py. for target directory

Signed-off-by: Vitalii Pudov <[email protected]>
Find the quantity of commits with word 'revert' in commit name for target directory

Signed-off-by: Vitalii Pudov <[email protected]>
Empty file for owner fix was added

Signed-off-by: Vitalii Pudov <[email protected]>
Solution was implemented: For every user in system with id >= 1000 check home folder.

Signed-off-by: Vitalii Pudov <[email protected]>
In case of inequality of user's id and file/dir/link owner's id
ask for fixing it.

Signed-off-by: Vitalii Pudov <[email protected]>
Empty script file was added

Signed-off-by: Vitalii Pudov <[email protected]>
Print file names and file size for files with same md5 checksum.

Signed-off-by: Vitalii Pudov <[email protected]>
How many lines for each author are in *.py files was implemented

Signed-off-by: Vitalii Pudov <[email protected]>
Fix logical error in project `make_simplest`

Signed-off-by: Vitalii Pudov <[email protected]>
Add buy functionality from food market

Signed-off-by: Vitalii Pudov <[email protected]>
Receipt for sup was added

Signed-off-by: Vitalii Pudov <[email protected]>
Resource generation was added. Some bash files were removed

Signed-off-by: Vitalii Pudov <[email protected]>
Vitalii Pudov and others added 18 commits December 23, 2019 17:53
Simple module (source and makefile) was created

Signed-off-by: Vitalii Pudov <[email protected]>
Module parameter for return codes was added. OK/Error logs were added

Signed-off-by: Vitalii Pudov <[email protected]>
Uppercase convertor module was implemented for Linux Kernel version 4.13.x with profs

Signed-off-by: Vitalii Pudov <[email protected]>
Attribute for total calls was added.

Signed-off-by: Vitalii Pudov <[email protected]>
Attribute for total processed characters was added.

Signed-off-by: Vitalii Pudov <[email protected]>
Attribute for total converted characters was added.

Signed-off-by: Vitalii Pudov <[email protected]>
Empty files were added for lowercase converter module using sysfs

Signed-off-by: Vitalii Pudov <[email protected]>
Implementation of lowercase converter using sysfs

Signed-off-by: Vitalii Pudov <[email protected]>
Implementation of number of function calls show

Signed-off-by: Vitalii Pudov <[email protected]>
Implementation of processed and converted characters number showing

Signed-off-by: Vitalii Pudov <[email protected]>
Implementation of absolute time returning in User space

Signed-off-by: Vitalii Pudov <[email protected]>
Implement kernel module with API in sysfs.
Module returns relation time in maximum possible resolution
passed since previous read of it.

Signed-off-by: Vitalii Pudov <[email protected]>
Implement kernel module with API in sysfs
which returns absolute time of previous reading with maximum resolution

Signed-off-by: Vitalii Pudov <[email protected]>
Average processor load updated once in a second was implemented

Signed-off-by: Vitalii Pudov <[email protected]>
Create user-space program which allocates buffers x = 0..64 with sizes
2x and 2x + 1
using functions: malloc, calloc, alloca.
Measure time of each allocation/freeing

Signed-off-by: Vitalii Pudov <[email protected]>
Create kernel module and test allocation/freeing time for functions:
kmalloc, kzmalloc, vmalloc, get_free_pages

Signed-off-by: Vitalii Pudov <[email protected]>
Fixes in mpu6050.c. DTS file for module was added.
0.001 precision for temperature was provided

Signed-off-by: Vitalii Pudov <[email protected]>
User space application for perfomance testing was added.
mpu6050 module was optimized.

Signed-off-by: Vitalii Pudov <[email protected]>
@VitaliiPudov VitaliiPudov added the ready The PR is ready for review (set by author). label Dec 26, 2019
@yekovalyov
Copy link
Contributor

Some commits are not related to this PR. Please rebase your branch.

@yekovalyov yekovalyov added changes requested The PR review revealed issues which should be fixed (set by reviewer) and removed ready The PR is ready for review (set by author). labels Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes requested The PR review revealed issues which should be fixed (set by reviewer)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants