-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c5758e
commit ada52a1
Showing
55 changed files
with
2,861 additions
and
564 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
cmd_/home/zhangxiao/embededSystem/example/driver/globalvar.ko := ld -r -m elf_i386 -T /usr/src/linux-2.6.32.60/scripts/module-common.lds --build-id -o /home/zhangxiao/embededSystem/example/driver/globalvar.ko /home/zhangxiao/embededSystem/example/driver/globalvar.o /home/zhangxiao/embededSystem/example/driver/globalvar.mod.o | ||
cmd_/home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.ko := ld -r -m elf_x86_64 -T /usr/src/linux-headers-3.11.0-26-generic/scripts/module-common.lds --build-id -o /home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.ko /home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.o /home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.mod.o |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/home/zhangxiao/embededSystem/example/driver/globalvar.ko | ||
/home/zhangxiao/embededSystem/example/driver/globalvar.o | ||
/home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.ko | ||
/home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.o |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
kernel//home/zhangxiao/embededSystem/example/driver/globalvar.ko | ||
kernel//home/xianb/WorkSpace/embedded_system/doc/2012lab/driver/globalvar.ko |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cmd_/home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.ko := ld -r -m elf_x86_64 -T /usr/src/linux-headers-3.11.0-26-generic/scripts/module-common.lds --build-id -o /home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.ko /home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.o /home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.mod.o |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.ko | ||
/home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <linux/module.h> | ||
#include <linux/vermagic.h> | ||
#include <linux/compiler.h> | ||
|
||
MODULE_INFO(vermagic, VERMAGIC_STRING); | ||
|
||
struct module __this_module | ||
__attribute__((section(".gnu.linkonce.this_module"))) = { | ||
.name = KBUILD_MODNAME, | ||
.init = init_module, | ||
#ifdef CONFIG_MODULE_UNLOAD | ||
.exit = cleanup_module, | ||
#endif | ||
.arch = MODULE_ARCH_INIT, | ||
}; | ||
|
||
static const struct modversion_info ____versions[] | ||
__used | ||
__attribute__((section("__versions"))) = { | ||
{ 0x4c46c04, __VMLINUX_SYMBOL_STR(module_layout) }, | ||
{ 0x15692c87, __VMLINUX_SYMBOL_STR(param_ops_int) }, | ||
{ 0x35b6b772, __VMLINUX_SYMBOL_STR(param_ops_charp) }, | ||
{ 0x6bc3fbc0, __VMLINUX_SYMBOL_STR(__unregister_chrdev) }, | ||
{ 0x9f3ac793, __VMLINUX_SYMBOL_STR(__register_chrdev) }, | ||
{ 0xf432dd3d, __VMLINUX_SYMBOL_STR(__init_waitqueue_head) }, | ||
{ 0x7149fc2a, __VMLINUX_SYMBOL_STR(kmem_cache_alloc_trace) }, | ||
{ 0xbb323702, __VMLINUX_SYMBOL_STR(kmalloc_caches) }, | ||
{ 0x37a0cba, __VMLINUX_SYMBOL_STR(kfree) }, | ||
{ 0x4f8b5ddb, __VMLINUX_SYMBOL_STR(_copy_to_user) }, | ||
{ 0x27e1a049, __VMLINUX_SYMBOL_STR(printk) }, | ||
{ 0x4f6b400b, __VMLINUX_SYMBOL_STR(_copy_from_user) }, | ||
{ 0xd2b09ce5, __VMLINUX_SYMBOL_STR(__kmalloc) }, | ||
{ 0xbdfb6dbb, __VMLINUX_SYMBOL_STR(__fentry__) }, | ||
}; | ||
|
||
static const char __module_depends[] | ||
__used | ||
__attribute__((section(".modinfo"))) = | ||
"depends="; | ||
|
||
|
||
MODULE_INFO(srcversion, "5222B96E967A182D7A4AF6B"); |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kernel//home/xianb/WorkSpace/embedded_system/doc/2012lab/poll/char_dev.ko |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
|
||
#define FIFO_FILE "/tmp/myfifo" | ||
int main(void) | ||
{ | ||
char buf[100]; | ||
int n = 0; | ||
int fd; | ||
|
||
if ((mkfifo(FIFO_FILE, S_IRWXU < 0) && (errno != EEXIST))) { | ||
perror("mkfifo error"); | ||
exit(-1); | ||
} | ||
|
||
if ((fd = open(FIFO_FILE, O_RDONLY| O_NONBLOCK)) < 0) { | ||
perror("open error"); | ||
exit(-1); | ||
} | ||
|
||
while (1) { | ||
if ((n = read(fd, buf, 100)) < 0) { | ||
/*已经被只写打开:返回 EAGAIN 错误*/ | ||
if (errno == EAGAIN) { | ||
printf("No data yet\n"); | ||
} | ||
} else if (n == 0) | ||
printf("No opened by write_only\n"); | ||
else if (n > 0) | ||
write(STDOUT_FILENO, buf, n); | ||
sleep(1); | ||
} | ||
|
||
unlink(FIFO_FILE); | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
|
||
#define FIFO_FILE "/tmp/myfifo" | ||
int main(void) | ||
{ | ||
int fd = 0; | ||
int n; | ||
char buf[100]; | ||
|
||
if ((fd = open(FIFO_FILE, O_WRONLY | O_NONBLOCK)) < 0) { | ||
perror("open error"); | ||
exit(-1); | ||
} | ||
while (1) { | ||
fgets(buf, 100, stdin); | ||
n = strlen(buf); | ||
if ((n = write(fd, buf, n)) < 0) { | ||
if (errno == EAGAIN) { | ||
printf("The FIFO has not been read yet, Please try later\n"); | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int pipe_fd[2]; | ||
pid_t pid; | ||
char r_buf[4]; | ||
char* w_buf; | ||
int writenum; | ||
int cmd; | ||
|
||
memset(r_buf,0,sizeof(r_buf)); | ||
if(pipe(pipe_fd)<0) | ||
{ | ||
printf("pipe create error\n"); | ||
return -1; | ||
} | ||
|
||
if((pid=fork())==0) | ||
{ | ||
/*子进程关闭写端口,这样的话pipe就不可用了*/ | ||
// close(pipe_fd[0]); | ||
close(pipe_fd[1]); | ||
sleep(2); | ||
exit(0); | ||
} | ||
else if(pid>0) | ||
{ | ||
sleep(1); //等待子进程完成关闭读端的操作 | ||
/*父进程关闭读端口*/ | ||
close(pipe_fd[0]); | ||
w_buf="111"; | ||
printf("FILE: %s, LINE: %d\r\n", __FILE__, __LINE__); | ||
/*父进程向子进程写入数据*/ | ||
writenum=write(pipe_fd[1],w_buf,4)==-1; | ||
|
||
if((writenum=write(pipe_fd[1],w_buf,4))==-1) | ||
printf("write to pipe error\n"); | ||
else | ||
printf("the bytes write to pipe is %d \n", writenum); | ||
|
||
printf("FILE: %s, LINE: %d\r\n", __FILE__, __LINE__); | ||
close(pipe_fd[1]); | ||
} | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <string.h> | ||
#include <errno.h> | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
int pipe_fd[2]; | ||
pid_t pid; | ||
char r_buf[100]; | ||
char w_buf[4]; | ||
int r_num; | ||
int cmd; | ||
|
||
memset(r_buf, 0, sizeof(r_buf)); | ||
memset(w_buf, 0, sizeof(w_buf)); | ||
|
||
if (pipe(pipe_fd) < 0) { | ||
printf("FILE: %s, LINE: %d.pipe create error\n", __FILE__, __LINE__); | ||
return -1; | ||
} | ||
|
||
/*子进程关闭写端口,父进程关闭读端口,建立一个从父进程到到子进程的通道*/ | ||
if ((pid = fork()) == 0) { | ||
printf("##################\n"); | ||
close(pipe_fd[1]); /*子进程关闭写端口*/ | ||
/*等待父进程向端口写入数据,然后子进程才能读数据*/ | ||
sleep(3); | ||
/*父进程写入数据后进行读写数据*/ | ||
r_num = read(pipe_fd[0], r_buf, 100); | ||
printf("child read num is %d, the data read from the pipe is %d\n", r_num, atoi(r_buf)); | ||
close(pipe_fd[0]); | ||
} else if (pid > 0) { | ||
close(pipe_fd[0]); /*父进程关闭读端口*/ | ||
strcpy(w_buf, "111"); | ||
/*向pipe里写入数据*/ | ||
if (write(pipe_fd[1], w_buf, 4) != -1) { | ||
printf("parent write over\n"); | ||
} | ||
/*父进程关闭写端口,也就是关闭了pipe了*/ | ||
close(pipe_fd[1]); | ||
printf("parent close fd[1]-write over\n"); | ||
sleep(3); | ||
} | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <sys/mman.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <assert.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#define FILENAME "/tmp/test" | ||
#define BUFLEN 256 | ||
|
||
typedef struct { | ||
char name[BUFLEN]; | ||
int id; | ||
}people; | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
int i; | ||
unsigned int *pmap = 0; | ||
int fd; | ||
fd = open(FILENAME, O_CREAT | O_RDWR, 00777); | ||
assert(fd != -1); | ||
pmap = (unsigned int *)mmap(0, sizeof(people), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | ||
unsigned int *addr; | ||
addr = pmap; | ||
addr = pmap + sizeof(char)*BUFLEN; | ||
printf("id = %id name = %s\n\r", *((int *)addr), (char *)pmap); | ||
munmap((void *)pmap, sizeof(char) * BUFLEN); | ||
close(fd); | ||
printf("umap os\n\r"); | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <sys/mman.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <assert.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#define FILENAME "/tmp/test" | ||
#define BUFLEN 256 | ||
|
||
typedef struct { | ||
char name[BUFLEN]; | ||
int id; | ||
}people; | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
int i; | ||
unsigned int *pmap = 0; | ||
int fd; | ||
fd = open(FILENAME, O_CREAT | O_RDWR | O_TRUNC, 00777); | ||
assert(fd != -1); | ||
pmap = (unsigned int *)mmap(0, sizeof(people), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); | ||
write(fd, "", sizeof(people)); | ||
unsigned int *addr; | ||
addr = pmap; | ||
char tempname[30] = "xianb"; | ||
int tempid = 253; | ||
addr = pmap + sizeof(char) * BUFLEN; | ||
memcpy((void *)pmap, tempname, strlen(tempname)); | ||
memcpy((void *)addr, &tempid, sizeof(int)); | ||
|
||
munmap((void *) pmap, sizeof(char) * BUFLEN); | ||
close(fd); | ||
printf("umap ok\r\n"); | ||
return 0; | ||
} |
Binary file not shown.
Oops, something went wrong.