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
2a2a4906
Commit
2a2a4906
authored
4 years ago
by
최준영
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
a9556e4d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
firesensor.c
+109
-0
109 additions, 0 deletions
firesensor.c
with
109 additions
and
0 deletions
firesensor.c
0 → 100644
+
109
−
0
View file @
2a2a4906
#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
<linux/gpio.h>
#include
<asm/mach/map.h>
#include
<asm/io.h>
#include
<asm/uaccess.h>
#define FIRE_GPIO 22 //GPIO 22
#define FIRE_MAJOR_NUMBER 503
#define FIRE_DEV_NAME "fire_ioctl"
//GPIO 18
#define GPIO_BASE_ADDR 0x3F200000
#define GPFSEL2 0x08
#define GPSET0 0x1C
#define GPCLR0 0x28
#define IOCTL_MAGIC_NUMBER 'f'
#define IOCTL_CMD_FIRE_ON _IO(IOCTL_MAGIC_NUMBER, 0)
#define IOCTL_CMD_FIRE_OFF _IO(IOCTL_MAGIC_NUMBER, 1)
#define HIGH 1
#define LOW 0
static
void
__iomem
*
gpio_base
;
volatile
unsigned
int
*
gpsel2
;
volatile
unsigned
int
*
gpset1
;
volatile
unsigned
int
*
gpclr1
;
int
fire_open
(
struct
inode
*
inode
,
struct
file
*
flip
)
{
printk
(
KERN_ALERT
"fire driver open!!
\n
"
);
gpio_base
=
ioremap
(
GPIO_BASE_ADDR
,
0x60
);
gpsel2
=
(
volatile
unsigned
int
*
)(
gpio_base
+
GPFSEL2
);
gpset1
=
(
volatile
unsigned
int
*
)(
gpio_base
+
GPSET0
);
gpclr1
=
(
volatile
unsigned
int
*
)(
gpio_base
+
GPCLR0
);
gpio_request
(
FIRE_GPIO
,
"FIRE_GPIO"
);
//set direction in
*
gpsel2
|=
(
0
<<
6
);
return
0
;
}
int
fire_release
(
struct
inode
*
inode
,
struct
file
*
filp
)
{
printk
(
KERN_ALERT
"fire driver closed!!
\n
"
);
iounmap
((
void
*
)
gpio_base
);
return
0
;
}
long
fire_ioctl
(
struct
file
*
filp
,
unsigned
int
cmd
,
unsigned
long
arg
)
{
switch
(
cmd
)
{
case
IOCTL_CMD_FIRE_ON
:
printk
(
KERN_ALERT
"fire detecting start!!
\n
"
);
while
(
1
)
{
int
i
=
gpio_get_value
(
FIRE_GPIO
);
if
(
i
==
HIGH
)
{
return
HIGH
;
}
else
return
LOW
;
}
ssleep
(
3
);
case
IOCTL_CMD_FIRE_OFF
:
printk
(
KERN_ALERT
"FIRE off!!
\n
"
);
*
gpsel2
|=
(
1
<<
6
);
break
;
}
return
0
;
}
static
struct
file_operations
fire_fops
=
{
.
owner
=
THIS_MODULE
,
.
open
=
fire_open
,
.
release
=
fire_release
,
.
unlocked_ioctl
=
fire_ioctl
};
int
__init
fire_init
(
void
)
{
if
(
register_chrdev
(
FIRE_MAJOR_NUMBER
,
FIRE_DEV_NAME
,
&
fire_fops
)
<
0
)
printk
(
KERN_ALERT
"fire driver initialization fail
\n
"
);
else
printk
(
KERN_ALERT
"fire driver initailization success
\n
"
);
return
0
;
}
void
__exit
fire_exit
(
void
)
{
unregister_chrdev
(
FIRE_MAJOR_NUMBER
,
FIRE_DEV_NAME
);
printk
(
KERN_ALERT
"FIRE driver exit done
\n
"
);
}
module_init
(
fire_init
);
module_exit
(
fire_exit
);
MODULE_LICENSE
(
"GPL"
);
MODULE_AUTHOR
(
"sang"
);
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