Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
embedded-linux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Maul
embedded-linux
Commits
15b1b4d0
Commit
15b1b4d0
authored
5 months ago
by
Leon Bohnwagner
Browse files
Options
Downloads
Patches
Plain Diff
feat: add hrtimer to kernel module
parent
6c8c0a3e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
kernel/kmod.c
+19
-0
19 additions, 0 deletions
kernel/kmod.c
with
19 additions
and
0 deletions
kernel/kmod.c
+
19
−
0
View file @
15b1b4d0
...
@@ -4,17 +4,23 @@
...
@@ -4,17 +4,23 @@
#include
<linux/cdev.h>
#include
<linux/cdev.h>
#include
<linux/vmalloc.h>
#include
<linux/vmalloc.h>
#include
<linux/uaccess.h>
#include
<linux/uaccess.h>
#include
<linux/hrtimer.h>
#include
"../common/include/message.h"
#include
"../common/include/message.h"
#define DEVICE_NAME "amogus"
#define DEVICE_NAME "amogus"
#define CLASS_NAME "amogus_class"
#define CLASS_NAME "amogus_class"
#define SLOT_INTERVAL_NS 250000
static
int
major_number
;
static
int
major_number
;
static
struct
class
*
class
=
NULL
;
static
struct
class
*
class
=
NULL
;
static
struct
cdev
mycdev
;
static
struct
cdev
mycdev
;
static
message_t
*
message
;
static
message_t
*
message
;
static
struct
hrtimer
timer
;
static
ktime_t
interval
;
static
int
device_open
(
struct
inode
*
inode
,
struct
file
*
file
)
static
int
device_open
(
struct
inode
*
inode
,
struct
file
*
file
)
{
{
return
0
;
return
0
;
...
@@ -48,6 +54,11 @@ static const struct file_operations fops = {
...
@@ -48,6 +54,11 @@ static const struct file_operations fops = {
.
release
=
device_release
.
release
=
device_release
};
};
static
enum
hrtimer_restart
timer_callback
(
struct
hrtimer
*
timer
)
{
hrtimer_forward_now
(
timer
,
interval
);
return
HRTIMER_RESTART
;
}
static
int
__init
lkm_init
(
void
)
static
int
__init
lkm_init
(
void
)
{
{
dev_t
dev
;
dev_t
dev
;
...
@@ -93,6 +104,12 @@ static int __init lkm_init(void)
...
@@ -93,6 +104,12 @@ static int __init lkm_init(void)
}
}
printk
(
KERN_INFO
"lkm: device created successfully
\n
"
);
printk
(
KERN_INFO
"lkm: device created successfully
\n
"
);
interval
=
ktime_set
(
0
,
SLOT_INTERVAL_NS
);
hrtimer_init
(
&
timer
,
CLOCK_MONOTONIC
,
HRTIMER_MODE_REL
);
timer
.
function
=
timer_callback
;
hrtimer_start
(
&
timer
,
interval
,
HRTIMER_MODE_REL
);
return
0
;
return
0
;
}
}
...
@@ -104,6 +121,8 @@ static void __exit lkm_exit(void)
...
@@ -104,6 +121,8 @@ static void __exit lkm_exit(void)
class_destroy
(
class
);
class_destroy
(
class
);
unregister_chrdev_region
(
MKDEV
(
major_number
,
0
),
1
);
unregister_chrdev_region
(
MKDEV
(
major_number
,
0
),
1
);
printk
(
KERN_INFO
"lkm: device removed successfully
\n
"
);
printk
(
KERN_INFO
"lkm: device removed successfully
\n
"
);
hrtimer_cancel
(
&
timer
);
}
}
module_init
(
lkm_init
);
module_init
(
lkm_init
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment