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

11 interrupts handling module #153

Open
wants to merge 7 commits into
base: Dmitry.Domnin
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
41 changes: 41 additions & 0 deletions 11-InterruptsHandling/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
NAME = mpu6050

ifneq ($(KERNELRELEASE),)

obj-m := $(NAME).o

else

NAMELINUX ?= [email protected]
MODULEDIR ?= /lib/modules/4.19.83-sunxi/kernel/drivers/iio/accel
KERNELDIR ?= /home/dmitry/GL/orange-pi-4.19.83
DTSDIR ?= $(PWD)/dtsi

export ARCH = arm
export CROSS_COMPILE ?= arm-linux-gnueabihf-

.PHONY: all clean

all: $(NAME).c
$(MAKE) -C $(KERNELDIR) M=$(CURDIR) modules

dtbo:
$(KERNELDIR)/scripts/dtc/dtc -I dts -O dtb \
-o $(DTSDIR)/$(NAME).dtbo \
$(DTSDIR)/$(NAME).dtsi

copymod: $(NAME).ko
scp $< $(NAMELINUX):$(MODULEDIR)

copysshid:
ssh-copy-id -i ~/.ssh/id_rsa.pub $(NAMELINUX)

copydtbo:
scp $(PWD)/dtsi/$(NAME).dtbo \
$(NAMELINUX):/boot/overlay-user

clean:
$(MAKE) -C $(KERNELDIR) M=$(CURDIR) clean
-rm $(DTSDIR)/$(NAME).dtbo

endif
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 11-InterruptsHandling/dtsi/mpu6050.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/dts-v1/;
/plugin/;

//IRQ_TYPE_EDGE_RISING = 1
//IRQ_TYPE_EDGE_FALLING = 2
//IRQ_TYPE_LEVEL_HIGH = 4
//IRQ_TYPE_LEVEL_LOW = 8

//GIC_SPI = 0
//GIC_PPI = 1

/ {
compatible = "allwinner,sun8i-h3";

fragment@0 {
target = <&pio>;
__overlay__ {
mpu6050_int: pin_int {
pins = "PA6";
function = "gpio_in";
};
};
};

fragment@1 {
target = <&i2c0>;
__overlay__ {
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

mpu: mpu6050@68 {
compatible = "gl, mpu6050";
pinctrl-names = "default";
reg = <0x68>;
pinctrl-0 = <&mpu6050_int>;
interrupt-parent = <&pio>;
interrupts = <0 6 2>; // PA6
status = "okay";
};
};
};
};
42 changes: 42 additions & 0 deletions 11-InterruptsHandling/mpu6050-regs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#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_FF_THR 0x1D
#define REG_FF_DUR 0x1E
#define REG_MOT_THR 0x1F
#define REG_MOT_DUR 0x20
#define REG_ZRMOT_THR 0x21
#define REG_ZRMOT_DUR 0x22
#define REG_FIFO_EN 0x23
#define REG_SMPRT_DIV 0x25
#define REG_INT_PIN_CFG 0x37
#define REG_INT_ENABLE 0x38
#define REG_INT_STATUS 0x3A
#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
#define REG_MOT_DETECT_STATUS 0x97

/* Register values */
#define MPU6050_WHO_AM_I 0x68

#endif /* _MPU6050_REGS_H */
Loading