Skip to content

Commit 16d1556

Browse files
authored
Merge pull request #27 from quic/kernel-samples-dev
Add QRB5165 Kernel-Demo
2 parents 23de849 + a1f36f9 commit 16d1556

File tree

7 files changed

+148
-0
lines changed

7 files changed

+148
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ Segmentation is to show the effect of object segmentation using Gstreamer comman
8383
```
8484
This app aims to help users to learn how to encode with h264 and decode the video with h264 on the Qualcom platform through this sample app.
8585
```
86+
87+
## 15. Kernel-Demo
88+
```
89+
The kernel demo uses the kernel API to dynamically load and unload the kernel module to control the LED switch.
90+
```
91+
8692
## Getting Started
8793
* [Quick start guide](https://developer.qualcomm.com/qualcomm-robotics-rb5-kit/quick-start-guide)
8894
* [Hardware Reference Guide](https://developer.qualcomm.com/qualcomm-robotics-rb5-kit/hardware-reference-guide)

kernel-demo/LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Copyright (c) 2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted
4+
provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright notice, this list of conditions
7+
and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright notice, this list of
9+
conditions and the following disclaimer in the documentation and/or other materials
10+
provided with the distribution.
11+
* Neither the name of the copyright holder nor the names of its contributors may be used to
12+
endorse or promote products derived from this software without specific prior written
13+
permission.
14+
15+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
16+
LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22+
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Where there is uncertainty as to how, or
26+
where, to apply marks, open an OSR to escalate to OSG for review.
27+
28+
SPDX-License-Identifier: BSD-3-Clause-Clear

kernel-demo/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
#
3+
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
5+
KVERS = $(shell uname -r)
6+
7+
# kernel modules
8+
obj-m := led.o
9+
10+
EXTRA_CFLAGS=-g -O0 -Wno-vla
11+
12+
build: kernel_modules
13+
14+
kernel_modules:
15+
make -C /usr/src/header M=$(CURDIR) modules
16+
17+
clean:
18+
make -C /usr/src/header M=$(CURDIR) clean

kernel-demo/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Kernel Demo
2+
# Overview
3+
The kernel demo uses the kernel API to dynamically load and unload the kernel module to control the LED switch.
4+
5+
## 1. Init
6+
### 1.1 Set kernel environment
7+
```
8+
$ adb shell
9+
$ apt-get install bison flex
10+
```
11+
### 1.2 Build kernel scripts
12+
```
13+
$ cd /usr/src/header
14+
$ make scripts
15+
```
16+
### 1.3 Download source code
17+
```
18+
$ cd /data
19+
$ git clone https://github.com/quic/sample-apps-for-Qualcomm-Robotics-RB5-platform.git
20+
```
21+
## 2. Build
22+
```
23+
$ cd kernel-demo/
24+
$ make
25+
```
26+
## 3. Run
27+
28+
// Open LED
29+
```
30+
$ insmod led.ko
31+
```
32+
![image text](image/ledon.png)
33+
34+
// Close LED
35+
```
36+
$ rmmod led.ko
37+
```
38+
![image text](image/ledoff.png)
39+
40+
## License
41+
This is licensed under the BSD 3-clause-Clear “New” or “Revised” License. Check out the [LICENSE](LICENSE) for more details.

kernel-demo/image/ledoff.png

326 KB
Loading

kernel-demo/image/ledon.png

336 KB
Loading

kernel-demo/led.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* Copyright (c) 2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
*
3+
* SPDX-License-Identifier: GPL-2.0-only
4+
*/
5+
6+
#include <linux/init.h>
7+
#include <linux/module.h>
8+
#include <linux/fs.h>
9+
#include <linux/uaccess.h>
10+
11+
#define LED_FILE "/sys/class/leds/green/breath"
12+
13+
int LED_Ctrol(char *buff)
14+
{
15+
struct file *fd = NULL;
16+
mm_segment_t fs;
17+
loff_t pos;
18+
19+
fd = filp_open(LED_FILE, O_RDWR, 0);
20+
if (IS_ERR(fd)) {
21+
printk(KERN_ERR "open failed!\n");
22+
filp_close(fd, NULL);
23+
return -1;
24+
}
25+
26+
fs = get_fs();
27+
set_fs(KERNEL_DS);
28+
pos = 0;
29+
vfs_write(fd, buff, sizeof(buff), &pos);
30+
pos = 0;
31+
32+
filp_close(fd, NULL);
33+
set_fs(fs);
34+
35+
return 0;
36+
}
37+
38+
static int __init led_init(void)
39+
{
40+
char buff_on[] = {"128"};
41+
LED_Ctrol(buff_on);
42+
printk(KERN_ALERT "LED ON\n");
43+
return 0;
44+
}
45+
46+
static void __exit led_exit(void)
47+
{
48+
char buff_off[] = {"0"};
49+
LED_Ctrol(buff_off);
50+
printk(KERN_ALERT "LED OFF\n");
51+
}
52+
53+
module_init(led_init);
54+
module_exit(led_exit);
55+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)