Skip to content

Instantly share code, notes, and snippets.

View itrobotics's full-sized avatar

Joseph itrobotics

View GitHub Profile
@itrobotics
itrobotics / chrdev.c
Last active April 6, 2023 06:32
a simple char device example for linux module
/*******************************************************************************
* 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.
*
* 保留所有權利。
* 本程式可任意使用,但是禁止販售行為。
* 修改程式時必須保留所有原有文字說明。
@itrobotics
itrobotics / chrdev_test.c
Created April 27, 2015 07:05
a simple file to test the module : chrdev.c
#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);
@itrobotics
itrobotics / kernel-panic-message
Created April 29, 2015 02:22
kernel panic message
[ 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
@itrobotics
itrobotics / gpio_led.c
Created April 29, 2015 02:57
an example of showing the usage of GPIO in the Linux module based on the raspberry pi B+ version
#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>
@itrobotics
itrobotics / gpio_led_2.c
Created April 30, 2015 01:12
a simple linux driver code for using char dev to control GPIO-LED.
#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
@itrobotics
itrobotics / btn_led.c
Created May 13, 2015 07:24
a simple linux driver code to register GPIO as button input to trigger LED
/*******************************************************************************
* 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
*******************************************************************************/
@itrobotics
itrobotics / chr_dev_completion.c
Created May 13, 2015 07:35
a simple linux driver code to demo completion mechanism
/*******************************************************************************
* 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.
*
* 保留所有權利。
* 本程式可任意使用,但是禁止販售行為。
* 修改程式時必須保留所有原有文字說明。
@itrobotics
itrobotics / chr_led.c
Created May 13, 2015 08:22
a simple linux driver example code which is a char dev to control GPIO-LED on Raspberry Pi
// 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>
@itrobotics
itrobotics / RPi.h
Created May 13, 2015 08:29
a simple linux kernel GPIO API for raspberry pi B+ version
// 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))
@itrobotics
itrobotics / chr_block_read.c
Created May 13, 2015 09:50
simple linux driver code to demo the blocking read and non-blocking read
#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>