Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
시
시프실 프로젝트 11조
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
최준영
시프실 프로젝트 11조
Commits
ff57e476
Commit
ff57e476
authored
4 years ago
by
최준영
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
86d18b15
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
buzzer_dev.c
+109
-0
109 additions, 0 deletions
buzzer_dev.c
with
109 additions
and
0 deletions
buzzer_dev.c
0 → 100644
+
109
−
0
View file @
ff57e476
#include
<linux/init.h>
#include
<linux/kernel.h>
#include
<linux/module.h>
#include
<linux/fs.h>
#include
<linux/uaccess.h>
#include
<linux/slab.h>
#include
<linux/delay.h>
#include
<asm/mach/map.h>
#include
<asm/io.h>
#include
<asm/uaccess.h>
#define BUZZER_MAJOR_NUMBER 502
#define BUZZER_DEV_NAME "buzzer_ioctl"
//GPIO18
#define GPIO_BASE_ADDR 0x3F200000
#define GPFSEL1 0x04
#define GPSET0 0x1C
#define GPCLR0 0x28
#define GPFSEL2 0x08
#define GPLEV0 0x34
#define IOCTL_MAGIC_NUMBER 'k'
#define IOCTL_CMD_BUZZER_OFF _IO(IOCTL_MAGIC_NUMBER, 0)
#define IOCTL_CMD_BUZZER_ON _IO(IOCTL_MAGIC_NUMBER, 1)
#define IOCTL_CMD_BUTTON_CLICKED _IO(IOCTL_MAGIC_NUMBER, 2)
static
void
__iomem
*
gpio_base
;
volatile
unsigned
int
*
gpsel1
;
volatile
unsigned
int
*
gpset1
;
volatile
unsigned
int
*
gpclr1
;
volatile
unsigned
int
*
gpsel2
;
volatile
unsigned
int
*
gplev0
;
int
buzzer_open
(
struct
inode
*
inode
,
struct
file
*
flip
)
{
printk
(
KERN_ALERT
"buzzer driver open!!
\n
"
);
gpio_base
=
ioremap
(
GPIO_BASE_ADDR
,
0x60
);
gpsel1
=
(
volatile
unsigned
int
*
)(
gpio_base
+
GPFSEL1
);
gpset1
=
(
volatile
unsigned
int
*
)(
gpio_base
+
GPSET0
);
gpclr1
=
(
volatile
unsigned
int
*
)(
gpio_base
+
GPCLR0
);
gpsel2
=
(
volatile
unsigned
int
*
)(
gpio_base
+
GPFSEL2
);
gplev0
=
(
volatile
unsigned
int
*
)(
gpio_base
+
GPLEV0
);
//set direction out
*
gpsel2
|=
(
1
<<
3
);
*
gpsel1
|=
(
1
<<
24
);
*
gpset1
|=
(
1
<<
18
);
*
gpset1
|=
(
1
<<
21
);
return
0
;
}
int
buzzer_release
(
struct
inode
*
inode
,
struct
file
*
filp
)
{
printk
(
KERN_ALERT
"buzzer driver closed!!
\n
"
);
iounmap
((
void
*
)
gpio_base
);
return
0
;
}
long
buzzer_ioctl
(
struct
file
*
filp
,
unsigned
int
cmd
,
unsigned
long
arg
)
{
switch
(
cmd
)
{
case
IOCTL_CMD_BUZZER_OFF
:
printk
(
KERN_ALERT
"buzzer off!!
\n
"
);
*
gpset1
|=
(
1
<<
18
);
break
;
case
IOCTL_CMD_BUZZER_ON
:
printk
(
KERN_ALERT
"buzzer on!!
\n
"
);
*
gpclr1
|=
(
1
<<
18
);
break
;
case
IOCTL_CMD_BUTTON_CLICKED
:
printk
(
KERN_ALERT
"button on!!
\n
"
);
if
((
*
gplev0
&
(
1
<<
20
))
==
(
1
<<
20
)){
return
0
;
}
else
return
1
;
}
return
0
;
}
static
struct
file_operations
buzzer_fops
=
{
.
owner
=
THIS_MODULE
,
.
open
=
buzzer_open
,
.
release
=
buzzer_release
,
.
unlocked_ioctl
=
buzzer_ioctl
};
int
__init
buzzer_init
(
void
)
{
if
(
register_chrdev
(
BUZZER_MAJOR_NUMBER
,
BUZZER_DEV_NAME
,
&
buzzer_fops
)
<
0
)
printk
(
KERN_ALERT
"buzzer driver initialization fail
\n
"
);
else
printk
(
KERN_ALERT
"buzzer driver initailization success
\n
"
);
return
0
;
}
void
__exit
buzzer_exit
(
void
)
{
unregister_chrdev
(
BUZZER_MAJOR_NUMBER
,
BUZZER_DEV_NAME
);
printk
(
KERN_ALERT
"buzzer driver exit done
\n
"
);
}
module_init
(
buzzer_init
);
module_exit
(
buzzer_exit
);
MODULE_LICENSE
(
"GPL"
);
MODULE_AUTHOR
(
"Jaehoon"
);
MODULE_DESCRIPTION
(
"des"
);
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