Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Explanation of Linux interrupt programming principle of Quanzhi A33 lichee Development Board

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Development platform * Xinlingsi SinlinxA33 Development Board Taobao Shop: https://sinlinx.taobao.com/

Embedded linux development board communicates QQ:641395230

The lab goal of this section is to achieve the key trigger interrupt terminal display button to release or press

Experimental platform core Lingsi Sinlinx A33 development board

Step1 looks at the schematic and all three keys are connected to the LRADC0 pin to determine which key is pressed by judging the voltage.

The CPU interrupt number in the linux interrupt registration function of the step2 kernel is not the physical number of the chip, but is determined by the chip vendor in the architecture phase when porting the Linux system

As defined in the header file of Guan, the name is generally irqs.h in the kernel source code.

Open vim / root/work/sinlinx/a33/lichee/linux-3.4/arch/ARM/mach-sunxi/include/mach/irqs.h

Quan Zhi A33 is # include "sun8i/irqs-sun8iw5p1.h" here.

Open vim / root/work/sinlinx/a33/lichee/linux-3.4/arch/arm/mach-sunxi/include/mach/sun8i/irqs-sun8iw5p1.h

Do not know which platform the development board uses, just find it in .config.

From this we can find the interrupt number of the chip in the kernel.

Step 3 briefly introduces the functions to be used in the interrupt driver

Check the irq.h file for the function structure declaration / root/work/sinlinx/a33/lichee/linux-3.4/include/linux/irq.h about interrupts

* struct irq_data-per irq and irq chip data passed down to chip functions* @ irq: interrupt number* @ hwirq: hardware interrupt number Local to the interrupt domain* @ node: node index useful for balancing* @ state_use_accessors: status information for irq chip functions.* Use accessor functions to deal with it* @ chip: low level interrupt hardware access* @ domain: Interrupt translation domain Responsible for mapping* between hwirq number and linux irq number.* @ handler_data: per-IRQ data for the irq_chip methods* @ chip_data: platform-specific per-chip private data for the chip* methods To allow shared chip implementations* @ msi_desc: MSI descriptor* @ affinity: IRQ affinity on SMP** The fields here need to overlay the ones in irq_desc until we* cleaned up the direct references and switched everything over to* irq_data.*/struct irq_data {unsigned int irq Unsigned long hwirq; unsigned int node; unsigned int state_use_accessors; struct irq_chip * chip; struct irq_domain * domain; void * handler_data; void * chip_data; struct msi_desc * msi_desc # ifdef CONFIG_SMP cpumask_var_t affinity;#endif}

The struct irqaction structure is in / root/work/sinlinx/a33/lichee/linux-3.4/include/linux/interrupt.h.

/ * * struct irqaction-per interrupt action descriptor* @ handler: interrupt handler function* @ flags: flags (see IRQF_* above) * @ name: name of the device* @ dev_id: cookie to identify the device* @ percpu_dev_id: cookie to identify the device* @ next: pointer to the next irqaction for shared interrupts* @ irq: interrupt number* @ dir: pointer to the proc Irq/NN/name entry* @ thread_fn: interrupt handler function for threaded interrupts* @ thread: thread pointer for threaded interrupts* @ thread_flags: flags related to @ thread* @ thread_mask: bitmask for keeping track of @ thread activity*/struct irqaction {irq_handler_t handler Interrupt service function handler unsigned long flags; void * dev_id; void _ _ percpu * percpu_dev_id; struct irqaction * next; int irq; irq_handler_t thread_fn; struct task_struct * thread Unsigned long thread_flags; unsigned long thread_mask; const char * name; struct proc_dir_entry * dir;} _ cacheline_internodealigned_in_smp

There are many interrupt-related functions in interrupt.h

Exmple:

Request_irq (unsigned int irq, irq_handler_t handler, unsigned long flags, const char * name, void * dev)

The function registers an interrupt service function with the kernel and executes the handler pointer function when an interrupt with the interrupt number irq occurs.

Void free_irq (unsigned int irq, void * dev_id)

Function to delete an interrupt structure from the kernel interrupt list

Void disable_irq (unsigned int irq)

Function closes the specified interrupt and waits for the interrupt service function to finish running before it returns, calling outside the interrupt function

Cannot be called in an interrupt service program.

Void disable_irq_nosync (unsigned int irq)

The function closes the specified interrupt, does not wait for the interrupt service function to finish, and returns immediately after calling this function. Can interrupt the service function

Called in the.

Void enable_irq (unsigned int irq)

The function enables the specified interrupt

Macro local_save_flags (flags)

The function forbids all interruptions of this CPU, and saves CPU status information.

Macro local _ irq_disable ()

The function forbids all interruptions of this CPU

Linux kernel and GPIO port related kernel API

Exmple:

Static inline int gpio_get_value (unsigned int gpio)

Function to obtain the level status of the specified IO port

Returns the IO level status, non-0: high, 0: low

Static inline void gpio_set_value (unsigned int gpio, int value)

Function sets the level state of gpio port to value

Returns the IO level status, non-0: high, 0: low

Static inline int gpio_to_irq (unsigned int gpio)

The function obtains the external interrupt number on this IO through the gpio port number.

Returns the corresponding external interrupt number on this IO

Step 4 about Linux interrupt sharing

A shared interrupt is a situation in which multiple devices share an interrupt line. When an interrupt arrives, it traverses all the interrupt handlers that share the interrupt.

IRQ_HANDLED is returned when a service function is interrupted.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report