Zephyr Device Driver and Device Model

Slides:



Advertisements
Similar presentations
I2C bus Inter Integrated Circuits bus by Philips Semiconductors
Advertisements

Embedded Systems I2CI2C. Feature 3 wire GND SCL(clock) SDA(data) All devices share the same bus wire Using wire and, each device gain access to bus (become.
Serial Interfaces, Part Deux -I 2 C and SPI December 4, 2002 Presented by Eugene Ho.
Informática II Prof. Dr. Gustavo Patiño MJ
Input-output and Communication Prof. Sin-Min Lee Department of Computer Science.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
Advanced Operating Systems The I 2 C Bus. Inter-Integrated Circuit Bus Designed for low-cost, medium data rate applications. Characteristics: –Synchronous;
I2CI2C CS-423 Dick Steflik. Inter-Integrated Circuit Developed and patented by Philips for connecting low speed peripherals to a motherboard, embedded.
Input/Output and Communication
Two Wire Interface Another popular serial peripheral interface bus -More flexible than SPI -Master and slave modes supported -7-bit slave address -400khz.
Lecture 27: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I 2 C) Interface.
Memory Technology “Non-so-random” Access Technology:
LSU 10/22/2004Serial I/O1 Programming Unit, Lecture 5.
VERIFICATION OF I2C INTERFACE USING SPECMAN ELITE By H. Mugil Vannan Experts Mr. Rahul Hakhoo, Section Manager, CMG-MCD Mr. Umesh Srivastva, Project Leader.
7/23 Inter-chip Serial Communication: SPI and I 2 C Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee.
Real-time Systems Lab, Computer Science and Engineering, ASU Linux Input Systems (ESP – Fall 2014) Computer Science & Engineering Department Arizona State.
GPIO interface From programmer’s view
Lecture 20: Communications Lecturers: Professor John Devlin Mr Robert Ross.
DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK
1 Synchronous Serial IO Send a separate clock line with data –SPI (serial peripheral interface) protocol –I 2 C (or I2C) protocol Encode a clock with data.
Real-time Systems Lab, Computer Science and Engineering, ASU Quark SPI Interface (ESP – Fall 2014) Computer Science & Engineering Department Arizona State.
ENTC-489 Embedded Real Time Software Development Embedded Real Time Software Development Week 4 Review.
7/23 Coldfire 5211 Signals and IO Multiplexing Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee
©2008 R. Gupta, UCSD COSMOS Summer 2008 Peripheral Interfaces Rajesh K. Gupta Computer Science and Engineering University of California, San Diego.
Data Transmission n Keep errors to an acceptable low probability n Bit-serial transmission n Parallel transmission.
How to write a MSGQ Transport (MQT) Overview Nov 29, 2005 Todd Mullanix.
S4525A Peripherals & Enhanced FLASH 1 © 1999 Microchip Technology Incorporated. All Rights Reserved. S4525A Peripherals & Enhanced FLASH 1 Peripherals.
CE-2810 Dr. Mark L. Hornick 1 Serial Communications Sending and receiving data between devices.
Lab 9 Multiprocessor, Buses, SPI, I2C. Multiprocessors Why multiprocessors? The structure of multiprocessors. Elements of multiprocessors: – Processing.
 The LPC2xxx devices currently have two on- chip UARTS.  Except UART1 has additional modem support.
Input/Output (I/O) Important OS function – control I/O
Linux Device Model A device model after 2.5
CS 704 Advanced Computer Architecture
UNIT 24 I2C Test 로봇 SW 교육원 조용수.
Lecture 3 Cache Bus.
Outline Analog to digital conversion (ADC) of NuMaker TRIO
The I2C Bus.
Two Wire Interface Another popular serial peripheral interface bus
Slides developed in part by Mark Brehob & Prabal Dutta
Input/Output and Communication
Inter-IC Bus (I C) 2.
Chapter 11: Inter-Integrated Circuit (I2C) Interface
UNIT – Microcontroller.
Data Transmission Keep errors to an acceptable low probability
CPU Sequencing 6/30/2018.
I/O Memory Interface Topics:
(Inter-IC bus) By Tejaswini Gadicherla
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Two Wire Interface (TWI)
EE 107 Fall 2017 Lecture 7 Serial Buses – I2C Direct Memory Access
I2C Synchronous Serial Two wire communications (plus ground)
I2C PROTOCOL SPECIFICATION
Communication Lines Fundamentals.
BJ Furman ME 106 Fundamentals of Mechatronics 15NOV2012
EEPROM Comparison – Parallel or Serial
Computer Organization and Design
Introduction to Microprocessors and Microcontrollers
NetSilicon & Digi Confidential
Serial EEPROM (Atmel 24C-512)
I2C and RTC Chapter 18 Sepehr Naimi
Baremetal C Programming for Embedded Systems
Lecture Topics: 11/1 General Operating System Concepts Processes
PZ09A - Activation records
Another Physical Layer – I2C
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
UNIT-III Pin Diagram Of 8086
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pointers, Dynamic Data, and Reference Types
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Zephyr Device Driver and Device Model Computer Science & Engineering Department Arizona State University Tempe, AZ 85287 Dr. Yann-Hang Lee yhlee@asu.edu (480) 727-7507

Device Model To support initializing all the drivers configured into the system The driver fills in the pointer to the structure containing the function pointers to its API functions during driver initialization. These structures are placed into the RAM section in initialization level order. To provide a generic type API for each type of driver (UART, SPI, I2C) can be used by fibers and tasks API calls may be blocked for synchronous IO operations must use proper mechanisms for blocking according to execution context, e.g., a nanokernel semaphore cannot be used when the context is a task. Synchronous calls API type device_sync_call_t inline functions device_sync_call_init() typedef struct { /** Nanokernel semaphore for fiber context */ struct nano_sem f_sem; #ifdef CONFIG_MICROKERNEL /* use microkernel semaphore */ struct _k_sem_struct _t_sem; ksem_t t_sem; enum device_sync_waiter waiter; bool device_ready;#endif } device_sync_call_t;

Driver APIs The runtime device struct per driver instance DEVICE_INIT() create device object and set it up for boot time initialization. DEVICE_AND_API_INIT() Create device object and set it up for boot time initialization. This also takes a pointer to driver API struct for link time pointer assignment. DEVICE_NAME_GET() Expands to the full name of a global device object. DEVICE_GET() Obtain a pointer to a device object by name. DEVICE_DECLARE() Declare a device object. struct device { struct device_config *config; void *driver_api; void *driver_data; }; struct device_config { char *name; int (*init)(struct device *device); void *config_info; };

Device Initialization – DEVICE_INIT() #define DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, cfg_info, level, prio, api) \ \ static struct device_config __config_##dev_name __used \ __attribute__((__section__(".devconfig.init"))) = { \ .name = drv_name, \ .init = (init_fn), \ .config_info = (cfg_info) \ }; \ static struct device (__device_##dev_name) __used \ __attribute__((__section__(".init_" #level STRINGIFY(prio)))) = { \ .config = &(__config_##dev_name), \ .driver_api = api, \ .driver_data = data \ } defines a device object that is automatically configured by the kernel during system initialization two static struct __config##dev_name and __device_##dev_name place them in “.devconfig.init” and “init_ #level STRINGFFY(prio)” sections invoke_sys_device_do_config_level() to call all device->init()

Driver Example: i2c_dw initialization func – i2c_dw_initialize() DEVICE_AND_API_INIT(i2c_0, CONFIG_I2C_DW_0_NAME, &i2c_dw_initialize, &i2c_0_runtime, &i2c_config_dw_0, SECONDARY, CONFIG_I2C_INIT_PRIORITY); initialization func – i2c_dw_initialize() driver API functions config_data and driver_data static struct i2c_driver_api funcs = { .configure = i2c_dw_runtime_configure, .transfer = i2c_dw_transfer, .suspend = i2c_dw_suspend, .resume = i2c_dw_resume, }; struct i2c_dw_dev_config { device_sync_call_t sync; union dev_config app_config; uint8_t *xfr_buf; uint32_t xfr_len; uint32_t rx_pending; uint16_t hcnt; uint16_t lcnt; volatile uint8_t state; /* last dir. of transfer */ uint8_t request_bytes; uint8_t xfr_flags; bool support_hs_mode; }; struct i2c_dw_rom_config { uint32_t base_address; uint32_t irq_num; uint32_t interrupt_mask; #ifdef CONFIG_PCI struct pci_dev_info pci_dev; #endif /* CONFIG_PCI */ i2c_isr_cb_t config_func; #ifdef CONFIG_I2C_DW_SHARED_IRQ char *shared_irq_dev_name; #endif /* CONFIG_I2C_DW_SHARED_IRQ */ };

Bit-Transfer on I2C Bus One clock pulse is generated for each data bit that is transferred Data Validity The data on the SDA line must be stable during the HIGH(1) period of the clock. The data line(SDA) can change data only when the clock signal (SCL) is LOW(0) Wired-and function open-drain or open-collector

Data Transfer With 7-Bit Device Address After START condition (S), a slave address(7-bit) is sent. A read/write (R/W’) direction is then sent(8th bit) Data transfer occurs, and then always terminated by STOP condition. However, repeated START conditions can occur.

Master-Transmitter to Slave-Receiver Data Transfer In this, the transmission direction never changes. The set-up and transfer is straight-forward

Master-Receiver and Slave-Transmitter Data Transfer Master initiates the data transfer by generating the START condition followed by the start byte (with read/write bit set to 1 i.e. read mode) After the first ack from the slave, the direction of data changes and the master becomes receiver and slave transmitter. The STOP condition is still generated by the master (master sends not-ACK before generating the STOP)

Example I2C Device – 24FC256 EEPROM 32K bytes in 512 pages of 64 bytes I2C interface with A2, A1, A0 address pins Page write operation: Random read operation:

Use of I2C Driver in Galileo Board CONFIG_I2C_0=y in /zephyr/boards/galileo/galileo_defconfig I2C interface wrapper in /zephyr/include/i2c.h static int i2c_transfer(struct device *dev, struct i2c_msg *msgs, uint8_t num_msgs, uint16_t addr) Need to find the “struct device” Search the device objects by configuration name With DEVICE_INIT macro, the objects are placed in memory by the linker. struct device *device_get_binding(char *name) { struct device *info; for (info = __device_init_start; info != __device_init_end; info++) { if (!strcmp(name, info->config->name)) { return info; } } return NULL;