This file contains hidden or 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
/******************************************************************************* | |
* Copyright (c) 2015 Song Yang @ ittraining | |
* | |
* All rights reserved. | |
* This program is free to use, but the ban on selling behavior. | |
* Modify the program must keep all the original text description. | |
* | |
* 保留所有權利。 | |
* 本程式可任意使用,但是禁止販售行為。 | |
* 修改程式時必須保留所有原有文字說明。 |
This file contains hidden or 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
#include<stdio.h> | |
#include<stdlib.h> | |
#include<sys/types.h> | |
#include<sys/stat.h> | |
#include<unistd.h> | |
#include<fcntl.h> | |
#include<time.h> | |
int main(int argc,char *argv[]){ | |
int dev_0 = open("/dev/mydev_0",O_RDWR); |
This file contains hidden or 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
[ 788.476664] | |
[ 788.476664] *****Some body is opening me at major 200 minor 0***** | |
[ 788.476729] | |
[ 788.476729] *****Some body is opening me at major 200 minor 1***** | |
[ 798.479961] *****Some body is closing me at major 0***** | |
[ 798.480004] *****Some body is closing me at major 1***** | |
[ 814.005473] Goodbye | |
[ 829.987718] Unable to handle kernel NULL pointer dereference at virtual address 00000000 | |
[ 829.998678] pgd = d9ef0000 | |
[ 830.002707] [00000000] *pgd=1b2be831, *pte=00000000, *ppte=00000000 |
This file contains hidden or 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
#include <linux/module.h> | |
#include <linux/string.h> | |
#include <linux/fs.h> | |
#include <asm/uaccess.h> | |
#include <linux/init.h> | |
#include <linux/cdev.h> | |
#include <linux/device.h> | |
#include <linux/kernel.h> | |
#include <linux/errno.h> |
This file contains hidden or 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
#include <linux/module.h> | |
#include <linux/init.h> | |
#include <linux/fs.h> | |
#include <linux/slab.h> | |
#include <linux/cdev.h> | |
#include <linux/gpio.h> | |
#include <asm/uaccess.h> | |
#define LED0_GPIO 22 | |
#define LED1_GPIO 27 |
This file contains hidden or 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
/******************************************************************************* | |
* Copyright (c) 2015 Song Yang @ ittraining | |
* | |
* All rights reserved. | |
* This program is free to use, but the ban on selling behavior. | |
* Modify the program must keep all the original text description. | |
* | |
* Email: [email protected] | |
* Blog : http://blog.ittraining.com.tw | |
*******************************************************************************/ |
This file contains hidden or 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
/******************************************************************************* | |
* Copyright (c) 2015 Song Yang @ ittraining | |
* | |
* All rights reserved. | |
* This program is free to use, but the ban on selling behavior. | |
* Modify the program must keep all the original text description. | |
* | |
* 保留所有權利。 | |
* 本程式可任意使用,但是禁止販售行為。 | |
* 修改程式時必須保留所有原有文字說明。 |
This file contains hidden or 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
// Simple Character Device Driver Module for Raspberry Pi. | |
/* | |
* DESCRIPTION: | |
* a simple example of char device | |
* this char device can control the GPIO by file operation : write | |
* to write specific message as command | |
* */ | |
#include <linux/module.h> | |
#include <linux/string.h> |
This file contains hidden or 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
// Reference to http://elinux.org/RPi_Low-level_peripherals | |
#define BCM2708_PERI_BASE 0x20000000 | |
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) // GPIO controller | |
//#define BLOCK_SIZE (4*1024) | |
// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) | |
#define INP_GPIO(g) *(gpio.addr + ((g)/10)) &= ~(7<<(((g)%10)*3)) | |
#define OUT_GPIO(g) *(gpio.addr + ((g)/10)) |= (1<<(((g)%10)*3)) |
This file contains hidden or 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
#include <linux/kernel.h> | |
#include <linux/module.h> | |
#include <asm/uaccess.h> | |
#include <linux/fs.h> | |
#include <linux/init.h> | |
#include <linux/cdev.h> | |
#include <linux/sched.h> | |
#include <linux/interrupt.h> | |
#include <linux/irq.h> | |
#include <linux/gpio.h> |