Embedded Systems Programming

Similar documents
Embedded Systems Programming

Interrupt Handler: Bottom Half. Changwoo Min

CS 423 Operating System Design: Introduction to Linux Kernel Programming (MP1 Q&A)

Applying User-level Drivers on

Embedded Systems Programming

REVISION HISTORY NUMBER DATE DESCRIPTION NAME

Linux Device Drivers Interrupt Requests

1 #include <linux/module.h> 2 #include <linux/sched.h> 3 #include <linux/interrupt.h> 4 #include <linux/init.h> 5 #include <linux/kernel.

Real Time and Embedded Systems. by Dr. Lesley Shannon Course Website:

Thread and Synchronization

Thread and Synchronization

Embedded Systems Programming

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

Introduction to Operating Systems. Device Drivers. John Franco. Dept. of Electrical Engineering and Computing Systems University of Cincinnati

MP3: VIRTUAL MEMORY PAGE FAULT MEASUREMENT

PCI Bus & Interrupts

Embedded Software Programming

20-EECE-4029 Operating Systems Fall, 2015 John Franco

Embedded Systems Programming

Linux Kernel Development (LKD)

ELEC 377 Operating Systems. Week 4 Lab 2 Tutorial

Character Device Drivers One Module - Multiple Devices

Embedded Systems Programming

Kernel Modules. Kartik Gopalan

Scrivere device driver su Linux. Better Embedded 2012 Andrea Righi

Linux Device Driver. Amir Hossein Payberah. (Kmod & Advanced Modularization)

Finish up OS topics Group plans

Interrupt handling. Interrupt handling. Deferred work. Interrupt handling. Remove an interrupt handler. 1. Link a struct work to a function

Kthreads, Mutexes, and Debugging. Sarah Diesburg CS 3430 Operating Systems

USB. Development of a USB device driver working on Linux and Control Interface. Takeshi Fukutani, Shoji Kodani and Tomokazu Takahashi

Linux Kernel Module Programming. Tushar B. Kute,

CS5460/6460: Operating Systems. Lecture 24: Device drivers. Anton Burtsev April, 2014

The IIC interface based on ATmega8 realizes the applications of PS/2 keyboard/mouse in the system

Overview. This Lecture. Interrupts and exceptions Source: ULK ch 4, ELDD ch1, ch2 & ch4. COSC440 Lecture 3: Interrupts 1

I/O Management Intro. Chapter 5

Threads. studykorner.org

Interrupt Handler: Top Half. Changwoo Min

HiKey970. I2C Development Guide. Issue 01. Date

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

7.4 Simple example of Linux drivers

Embedded Systems Programming

7.3 Simplest module for embedded Linux drivers

CAN Module Documentation

SpiNNaker Application Programming Interface (API)

CS 550 Operating Systems Spring Interrupt

Implementing the Wireless Token Ring Protocol As a Linux Kernel Module

This resource describes how to program the myrio in C to perform timer interrupts.

Scuola Superiore Sant Anna. I/O subsystem. Giuseppe Lipari

Asynchronous Events on Linux

Chapter 3: Processes. Operating System Concepts 8th Edition

Chapter 3: Process Concept

Chapter 3: Process Concept

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

- Knowledge of basic computer architecture and organization, ECE 445

Operating Systems. System calls. Guillaume Salagnac. Fall Insa-Lyon IST Semester

I/O Management Software. Chapter 5

Scheduling Algorithm and Analysis

15: OS Scheduling and Buffering

jelly-near jelly-far

Chapter 3: Process Concept

PS3 Programming. Week 4. Events, Signals, Mailbox Chap 7 and Chap 13

Linux Device Drivers

Chapter 3: Processes. Operating System Concepts 9 th Edition

Any of the descriptors in the set {1, 4} have an exception condition pending

CPSC 8220 FINAL EXAM, SPRING 2016

Advanced Operating Systems #13

Embedded System Programming

Chapter 12 IoT Projects Case Studies. Lesson-01: Introduction

libnetfilter_log Reference Manual

Homework / Exam. Return and Review Exam #1 Reading. Machine Projects. Labs. S&S Extracts , PIC Data Sheet. Start on mp3 (Due Class 19)

Single thread Scheduler All processes called once each sample

Dotstack Porting Guide.

Computer Labs: The PC Keyboard

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

CS 378 (Spring 2003)

T-Engine Forum Specification

Chapter 3: Processes

Embedded Systems Programming

Section 4: Threads CS162. September 15, Warmup Hello World Vocabulary 2

Interrupts Peter Rounce

Maintaining a Real Time Stable Kernel What s different than a vanilla stable kernel?

Lecture 20. Log into Linux. Copy directory /home/hwang/cs375/lecture20 Project 5 due today. Project 6 posted, due Tuesday, April 8. Questions?

FAME Operatinf Systems - Modules

Interrupts and Time. Real-Time Systems, Lecture 5. Martina Maggio 28 January Lund University, Department of Automatic Control

Embedded Systems Programming

NPTEL Course Jan K. Gopinath Indian Institute of Science

Design and Implementation of an Asymmetric Multiprocessor Environment Within an SMP System. Roberto Mijat, ARM Santa Clara, October 2, 2007

The Serial Device Bus

Altering the Control Flow

Interrupts and Time. Interrupts. Content. Real-Time Systems, Lecture 5. External Communication. Interrupts. Interrupts

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Input/Output Systems

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Lecture 3. Introduction to Real-Time kernels. Real-Time Systems

2 Threads vs. Processes

Linux DRM Developer s Guide

SuSE Labs / Novell.

20-EECE-4029 Operating Systems Fall, 2015 John Franco

CSC209H Lecture 11. Dan Zingaro. March 25, 2015

Computer Labs: I/O and Interrupts

Transcription:

Embedded Systems Programming Work Queue and Input Processing in Linux (Module 16) Yann-Hang Lee Arizona State University yhlee@asu.edu (480) 727-7507 Summer 2014

Example of Work Structure and Handler #include <linux/kernel.h> #include <linux/module.h> #include <linux/workqueue.h> MODULE_LICENSE("GPL"); static struct workqueue_struct *my_wq; typedef struct { struct work_struct my_work; int x; } my_work_t; // work queue // work my_work_t *work, *work2; static void my_wq_function( struct work_struct *work) // function to be call { my_work_t *my_work = (my_work_t *)work; printk( "my_work.x %d\n", my_work->x ); kfree( (void *)work ); return; } (http://www.ibm.com/developerworks/linux/library/l-tasklets/index.html) 1

Example of Work and WorkQueue Creation int init_module( void ) { int ret; my_wq = create_workqueue("my_queue"); // create work queue if (my_wq) { work = (my_work_t *)kmalloc(sizeof(my_work_t), GFP_KERNEL); if (work) { // Queue work (item 1) INIT_WORK( (struct work_struct *)work, my_wq_function ); work->x = 1; ret = queue_work( my_wq, (struct work_struct *)work ); } work2 = (my_work_t *)kmalloc(sizeof(my_work_t), GFP_KERNEL); if (work2) { // Queue work (item 2) INIT_WORK( (struct work_struct *)work2, my_wq_function ); work2->x = 2; ret = queue_work( my_wq, (struct work_struct *)work2 ); } } return 0; } (http://www.ibm.com/developerworks/linux/library/l-tasklets/index.html) 2

Linux Kernel Thread A way to implement background tasks inside the kernel static struct task_struct *tsk; static int thread_function(void *data) { int time_count = 0; do { printk(kern_info "thread_function: %d times", ++time_count); msleep(1000); }while(!kthread_should_stop() && time_count<=30); return time_count; } static int hello_init(void) { tsk = kthread_run(thread_function, NULL, "mythread%d", 1); if (IS_ERR(tsk)) {. } } 3

Linux Input Systems An option: each attached input device is handled by a driver with the details of input port and protocol the device used. The other one -- Layers adapter (controller) and port device and driver event interface (Figure is from ELDD, Chapter 7) 4

Software Structure of Input Systems (http://www.linuxjournal.com/article/6396) Device drivers, input core, and event handlers Example: i8042 is the driver for 8042 adapter psmouse is the driver for ps2 mouse mousedev is the event handler for all mice 5

Example: PS2 Mouse Driver The adapter 8042 from PC-AT, now a part of LPC IO PS2 signals: clock, data 5V, and GND. CLOCK and DATA are of "open collector" type bidirectional serial protocol (start, data, parity, stop) PC has always a priority and can stop the transmission any time by setting CLOCK low (http://wiki.osdev.org/images/5/55/ps2-kbc.png) (http://codelake9.files.wordpress.com/2012/09/3.jpg) 6

The driver for the adapter (controller) When installed create a platform_device initialize kbd and aux controllers create serio ports with ids ( serio->id.type = SERIO_8042; ) request_irq and add interrupt handler, and register ports error = request_irq(i8042_kbd_irq, i8042_interrupt, IRQF_SHARED, "i8042", i8042_platform_device); if (likely(port->exists)) serio_interrupt(port->serio, data, dfl); Important fields in struct serio struct serio_device_id id; struct serio_driver *drv; struct device dev; What is done in i8042.c 7

Threaded interrupt handlers Request_threaded_irq isr acknowledges the interrupt to the hardware wake the kernel interrupt handler thread int request_threaded_irq(unsigned int irq, irq_handler_t handler, irq_handler_t thread_fn, unsigned long flags, const char *name, void *dev) handler is called in hard interrupt context and checks if the interrupt was from the device if thread_fn is NULL, use the normal handler, no irq thread handle_irq_event calls handler (check or normal) 8

The driver to handle ps2 mouse protocol When installed, probe serio bus, connect to serio device via the matching serio_id and create a psmouse device psmouse registers itself as an input device to input core report events: EV_KEY and EV_REL eventually, input_pass_event to handlers When psmouse_interrupt is called received mouse data and process the protocol psmouse_process_byte() analyzes the PS/2 data stream and reports relevant events to the input module once full packet has arrived. What else What is done in psmouse-base.c mouse type and protocol command and response with adapter, mouse state, and data decoding. 9

evdev: Event Handlers a generic input event interface to pass the events generated in the kernel straight to the program, with timestamps. a char device to user space when open, an evdev client is created with a buffer for events and is attached to file struct. when read, fetch the events in the buffer and return to the user call. register as a handler of an input device when connected, evdev is created handle is added to the input device input device passes events to handler s clients via input core s input_pass_event handler s evdev_pass_event struct input_event { struct timeval time; u16 type; u16 code; s32 value; }; 10