Object-oriented driver programming - interrupt (linux system, s3c6410 development board)

Publisher:悠然自在Latest update time:2024-09-23 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*-------------------------

*First of all, I am a novice and just started to write driver programs. I will explain the development environment (host system redhat6.3, development board ARM-s3c6410)

Take watchdog (commonly known as dog interrupt) as an example to write a simple interrupt (driver)

-------------------------*/

#include

#include

#include

#include

#include

#include

#include


MODULE_LICENSE("GPL");

MODULE_AUTHOR("cheng");


typedef struct mydev{

unsigned long gpio_virt;

unsigned long wdt_virt;

unsigned long *gpmcon, *gpmdat;

unsigned long *wtcon, *wtdat, *wtcnt, *wtclrint;

void (*init_nydev)(struct mydev *this);

void (*exit_mydev)(struct mydev *this);

irqreturn_t (*do_irq)(int irq, struct mydev *this);

void (*led_on)(struct mydev *this);

void (*led_off)(struct mydev *this);

void (*wdt_on)(struct mydev *this);

void (*wdt_off)(struct mydev *this);

}MYDEV;


void my_init_mydev(struct mydev *this);

void my_exit_mydev(struct mydev *this);

irqreturn_t my_do_irq(int irq, struct mydev *this);

void my_led_on(struct mydev *this);

void my_led_off(struct mydev *this);

void my_wdt_on(struct mydev *this);

void my_wdt_off(struct mydev *this);


MYDEV my ;

static int test_init(void)

{

printk("hello,in my test_initn");

my.init_mydev = my_init_mydev;

my.exit_mydev = my_exit_mydev;

my.init_mydev(&my);


return 0;

}


void test_exit()

{

my.exit_mydev(&my);

printk("this is test exitn");

}


module_init(test_init);

module_exit(test_exit);


void my_init_mydev(struct mydev *this)

{

this->do_irq   = my_do_irq;

this->led_on   = my_led_on;

this->led_off   = my_led_off;

this->wdt_on  = my_wdt_on;

this->wdt_off  = my_wdt_off;

int ret = request_irq(IRQ_WDT, this->do_irq, IRQF_SHARED,"hello", this);

if(ret < 0){

printk("request_irq errorn");

return ;

}

this->gpio_virt   =    ioremap(0x7f008000, SZ_4K);

this->wdt_virt     =    ioremap(0x7e004000, SZ_4K);

this->gpmcon    =    this->gpio_virt + 0x820;

this->gpmdat     =    this->gpio_virt + 0x824;

this->wtcon        =    this->wdt_virt + 0x00;

this->wtdat         =    this->wdt_virt + 0x04;

this->wtcnt         =    this->wdt_virt + 0x08;

this->wtclrint      =    this->wdt_virt + 0x0c;

this->wdt_on(this);

}


void my_exit_mydev(struct mydev *this)

{

this->my_wtd_off(this);

iounmap(this->wdt_virt);

iounmap(this->gpio_virt);

free_irq(IRQ_WDT,this);

}


irqreturn_t my_do_irq(int irq, struct mydev *this)

{

if(irq == IRQ_WDT){

*this->wtclrint = 0;

printk("wang wang wangn");

static int flag = 1;

if(flag)

this->led_on(this);

else

this->led_off(this);

flag ^= 1;

}

return IRQ_HANDLED;

}


void my_led_on(struct mydev *this)

{

*this->gpmcon = 1;

*this->gpmdat = 0;

}


void my_led_off(struct mydev *this)

{

*this->gpmcon = 1;

*this->gpmdat = 1;

}


void my_wdt_on(struct mydev *this)

{

*this->wtcon = (1 << 2) | (1 << 3) | (1 << 5) | (31 << 8);

*this->wtdat = 0x4000;

*this->wtcnt = 0x8000;

}


void my_wdt_off(struct mydev *this)

{

*this->wtcon = 0;

}


/*

Here is the Makefile content:

*/


all:

make -C linux-2.6.28_smdk6410 M=`pwd` modules

clean:

make -C /linux-2.6.28_smdk6410 M=`pwd` clean

rm -rf modules.order

obj-m += test.o


Reference address:Object-oriented driver programming - interrupt (linux system, s3c6410 development board)

Previous article:S3C6410 development board development environment construction
Next article:【Embedded Development】Burn the Linux system into the development board - Model S3C6410

Recommended ReadingLatest update time:2024-11-22 23:23

LPC2124+L297+L298+ drive motor proteus simulation
  /**************************************************************************** * File:Main.C * Function: ****************************************************************************/ #include  "config.h" /******************************************************************************* * Name: IRQ_Eint0() *Function:
[Microcontroller]
LPC2124+L297+L298+ drive motor proteus simulation
Allegro MicroSystems Expands Isolated Gate Driver Product Family with Power Thru Combo Chip
New products provide design engineers with greater flexibility in high-power output applications such as electric vehicle chargers Manchester, NH, USA – Allegro MicroSystems (Allegro), a global leader in sensing technology and power semiconductor solutions for motion control and energy-efficient s
[Power Management]
Allegro MicroSystems Expands Isolated Gate Driver Product Family with Power Thru Combo Chip
Embedded driver writing simple driver Hello_word
Development Environment BootLoader: u-boot-1.1.6 kernel:linux-2.6.30.4 cpu:S3C2440 step 1. Write driver code This should be the simplest driver, which only prints information in the kernel. The code is as follows: #include linux/module.h #include linux/kernel.h MODULE_LICENSE("GPL");                 static in
[Microcontroller]
Embedded driver writing simple driver Hello_word
The LED driven by the PB port flashes cyclically at a frequency of once per second
#include hidef.h       /* common defines and macros */ #include "derivative.h"      /* derivative-specific definitions */ #define BUS_CLOCK 40000000 #define OSC_CLOCK 20000000 /***************************/ void INIT_PLL(void) {   CLKSEL&=0X7F;         PLLCTL&=0X8F;   CRGINT&=0XDF;   SYNR=0X44;   REFDV=0X81;   PLLCTL=
[Microcontroller]
Research on Improving the Reliability of High-Power LED Drivers
As LED luminous efficiency improves and costs continue to fall, the LED market is expanding from mobile phone backlights and automotive instrument lighting, as well as special lighting and landscape lighting with low brightness requirements, to ordinary white light lighting. LED is a solid-state cold light sour
[Power Management]
Research on Improving the Reliability of High-Power LED Drivers
51 Assembly programming: 8255 drives matrix keyboard and digital tube
Assembly programming: The matrix keyboard controls the digital tube to switch and display 0~F. The following is the circuit diagram. It is required that 16 keys can display 0~F when pressed. Seeing such circuits and programs, I can’t help but think of the time when I first learned about microcontrollers. More than t
[Microcontroller]
51 Assembly programming: 8255 drives matrix keyboard and digital tube
S3C6410 input subsystem key driver
The driver I wrote before requires a separate test program. Such a driver has great limitations and can only be used by myself. For the sake of versatility, other people's applications can also use my driver. I have to introduce an input subsystem. . There are 5 buttons L, S, ENTER, LEFTSHIFT, and ESC set in this driv
[Microcontroller]
S3C6410 input subsystem key driver
MAX867 Step-Down Converter Driven by a Boost Controller
A converter is a device that converts one signal into another. A signal is a form or carrier of information. In automated instrumentation and automatic control systems, one signal is often converted into another signal that is compared with a standard or reference quantity in order to connect the two types of instru
[Analog Electronics]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号