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

Solution 11 interrupt #159

Open
wants to merge 14 commits into
base: Andrey.Pahomov
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions 10-ConcurrencyAndSynchronization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Concurrency and synchronization

## Homework

**(based on MPU6050 driver)**

_NB_:
Communication with peripheral device on i2c is quite slow asynchronous process
which responsiveness depends on the slave latency and bus utilisation.
Thus generally it's better to be done in background process.

1. Move interaction with MPU6050 into separate thread.

2. Protect static data of the driver (`g_mpu6050_data` in the master)
for the case of concurrent access.

3. Limit interaction with MPU6050 in case of frequent requests:
Define validity interval - if the latest read data is older than this threshold
then new data reading is performed, otherwise previously read data is returned.
(This threshold should be configurable parameter with reasonable default.)

23 changes: 23 additions & 0 deletions 11-InterruptsHandling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Interrupts handling

## Homework

**(based on MPU6050 driver)**

1. Setup handling of MPU6050 interrupts.
- Configure interrupt request on MPU6050 (e.g. motion detection).
- Connect interrupt output of the MPU6050 with Orange-Pi GPIO.
- Configure GPIO as input.
- Register handler for the MPU6050 interrupt.

2. Implement deferred interrupt handler (e.g. in custom workqueue) to handle the request.
- Read new measurements.
- Implement measurements processing (e.g. the following or per your preference).
- filtering (e.g. moving average);
- integrating (for acc to get speed);
- determine trends;
- etc.

3. Provide additional interface (e.g. in procfs) to read the processed data at once.

_Note: Remember to synchronize all concurrent operations_
43 changes: 43 additions & 0 deletions mpu6050/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
MODULE_NAME=mpu6050

ifneq ($(KERNELRELEASE),)

obj-m :=$(MODULE_NAME).o

else

ccflags-y := -Wall
DT_SRCS=$(wildcard *.dts)
DT_OBJS=$(DT_SRCS:.dts=.dtbo)
DTC_FLAGS ?= -i $(DCT_EXTRA_PATH)


.PHONY: all clean

all: $(DT_OBJS)
$(MAKE) -C $(BUILD_KERNEL) M=$(PWD) modules

clean:
$(MAKE) -C $(BUILD_KERNEL) M=$(PWD) clean
-rm ./*.dtbo


$(DT_OBJS): $(DT_SRCS)
$(DTC) -@ -I dts -O dtb -o $@ $<


upload_config:
ssh-copy-id -i ~/.ssh/id_rsa.pub $(SSH_ORANGE)
echo $(KERNEL_VERSION)
-ssh $(SSH_ORANGE) '[ ! -d "/lib/modules/$(KERNEL_VERSION)/kernel/drivers/" ] && mkdir -p "/lib/modules/$(KERNEL_VERSION)/kernel/drivers/"'

upload_dtso: $(DT_OBJS)
-scp $< $(SSH_ORANGE):/boot/dtb/overlay/

upload_module: $(MODULE_NAME).ko
-scp $< $(SSH_ORANGE):/lib/modules/$(KERNEL_VERSION)/kernel/drivers/
-ssh $(SSH_ORANGE) 'depmod'

upload: upload_dtso upload_module

endif
8 changes: 8 additions & 0 deletions mpu6050/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# MPU6050 Practice. Kernel object module development

## Homework

1. Fix the errors in kernel module sources and developed dts.
2. Provide precision 0.001 C for temperature.
3. Measure the performance by getting all values in cycle during 1 second.
4. Improve the performance and measure it.
13 changes: 13 additions & 0 deletions mpu6050/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

export BUILD_KERNEL=$(pwd)/../../build/kernel_opi
export KERNEL_VERSION=5.4.0-rc1-00258-g2d00aee21a5d
export DTC=$BUILD_KERNEL/scripts/dtc/dtc
export CROSS_COMPILE=$(pwd)/../../toolchain/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
export ARCH=arm
export [email protected]
#export INCLUDE_DTS=/home/tymbys/WORK/GL/linux/arch/arm/boot/dts
export DCT_EXTRA_PATH=/home/tymbys/WORK/GL/linux/


make clean && make && make upload
Binary file added mpu6050/doc/MPU-6000-Register-Map1.pdf
Binary file not shown.
Binary file added mpu6050/doc/MPU-6050_DataSheet_V3 4.pdf
Binary file not shown.
Binary file added mpu6050/doc/PS-MPU-6000A.pdf
Binary file not shown.
49 changes: 49 additions & 0 deletions mpu6050/mpu6050-regs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef _MPU6050_REGS_H
#define _MPU6050_REGS_H

/* Registed addresses */
#define REG_CONFIG 0x1A
#define REG_GYRO_CONFIG 0x1B
#define REG_ACCEL_CONFIG 0x1C
#define REG_FIFO_EN 0x23
#define REG_INT_PIN_CFG 0x37
#define REG_INT_ENABLE 0x38
#define REG_ACCEL_XOUT_H 0x3B
#define REG_ACCEL_XOUT_L 0x3C
#define REG_ACCEL_YOUT_H 0x3D
#define REG_ACCEL_YOUT_L 0x3E
#define REG_ACCEL_ZOUT_H 0x3F
#define REG_ACCEL_ZOUT_L 0x40
#define REG_TEMP_OUT_H 0x41
#define REG_TEMP_OUT_L 0x42
#define REG_GYRO_XOUT_H 0x43
#define REG_GYRO_XOUT_L 0x44
#define REG_GYRO_YOUT_H 0x45
#define REG_GYRO_YOUT_L 0x46
#define REG_GYRO_ZOUT_H 0x47
#define REG_GYRO_ZOUT_L 0x48
#define REG_USER_CTRL 0x6A
#define REG_PWR_MGMT_1 0x6B
#define REG_PWR_MGMT_2 0x6C
#define REG_WHO_AM_I 0x75

/* Register values */
#define MPU6050_WHO_AM_I 0x68

char init_table [][2] = {
{0x1A, 0},
{0x1B, 0},
{0x1C, 0},
{0x23, 0},
{0x6A, 0},
{0x6B, 0},
{0x6C, 0},
{0x1D, 0xff},
{0x1E, 0x01},
{0x69, 0x24},
{0x37, 0x1f},
{0x38, 0x80},
{0, 0}
};

#endif /* _MPU6050_REGS_H */
Loading