LAB 13: IO Driver Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Windows Basics An Introduction to the Windows Operating System.
LAB 9: Environment Setup for Tower System Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems.
Ch-11 Project Execution and Termination. System Testing This involves two different phases with two different outputs First phase is system test planning.
 2005 Pearson Education, Inc. All rights reserved Introduction.
TK 2633 Microprocessor & Interfacing
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
 2006 Pearson Education, Inc. All rights reserved Midterm review Introduction to Classes and Objects.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
C Programming for Embedded Systems. fig_06_00 Computer Layers Low-level hardware to high-level software (4GL: “domain-specific”, report-driven, e.g.)
CS4101 嵌入式系統概論 RTOS and MQX Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan ( Materials from Freescale; Prof.
TM Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of.
LAB 7: WDT+ and Low-Power Optimization
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
Introduction to The Linaro Toolchain Embedded Processors Training Multicore Software Applications Literature Number: SPRPXXX 1.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Outline Introduction to MQX Initializing and starting MQX
Operating System Program 5 I/O System DMA Device Driver.
Intermediate PHP (2) File Input/Output & User Defined Functions.
Writing Classes (Chapter 4)
LAB 11: Task Synchronization Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
File I/O 11_file_processing.ppt
File I/O Static void Main( ) {... } data. Topics I/O Streams Reading and Writing Text Files Formatting Text Files Handling Stream Errors File Pointers.
This example is a step by step walkthrough for installing the SRH Front Desk printer in Windows 7 (64 Bit).
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Fall 2012 Lecture 8: File I/O; Introduction to classes.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
LAB 12: Timer and Interrupt Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Lesson No: 6 Introduction to Windows XP CHBT-01 Basic Micro process & Computer Operation.
Lecture 8a: File I/O BJ Furman 21MAR2011. Learning Objectives Explain what is meant by a data stream Explain the concept of a ‘file’ Open and close files.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Bootable Programs Building an O/S. Basic Requirements of any O/S Respond to interrupts (all kinds) Preserve user environment Protect users and self from.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
File Input/Output. File information Name z:\Visual Studio 2005\Projects\fileio\fileio\myinput.txt \\file-svr-1\class\ECE-160\pviall\myoutput.txt Read/Write.
Starting Out with C++, 3 rd Edition 1 Chapter 13 – Introduction to Classes Procedural and Object-Oriented Programming Procedural programming is a method.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Configuring MQ Connections and Handlers for MQ adapter 6.5 July 2008.
Using CVUSD Print Center Desktop Printer Chino Valley Unified School District.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
Senerver_Sun | Dept. | SOP for use CSD DL tool V1.2_ CN_SDD2.
How to Apply PDF in Flipbook on Website. Description If you are finding solution for applying PDF in flipbook mode on website, and adding multimedia items.
MQX GPIO.
CS4101 Introduction to Embedded Systems Lab 8: Tower System
3 Introduction to Classes and Objects.
Chapter 7 Text Input/Output Objectives
ECE Application Programming
Chapter 7 Text Input/Output Objectives
CS4101 Introduction to Embedded Systems Lab 13: Task Synchronization
Chapter 7 Text Input/Output Objectives
Functions, locals, parameters, and separate compilation
Computer Programming Lecturer: Ir Dr Frank H.F. LEUNG
Writing and Testing Your First RTOS Project with MQX
TCL command in C, a simple example Nguyen Truong – GCS VN Aug 5, 2004
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Operation System Program 4
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
CS4101 嵌入式系統概論 I/O Drivers Prof. Chung-Ta King
Microcontrollers and Microprocessors
ECE 3567 Microcontroller Lab
File Management.
How to stop C programming problems at the source
University of Warith AL-Anbiya’a
EECE.2160 ECE Application Programming
CS4101 嵌入式系統概論 Device Drivers
EECE.2160 ECE Application Programming
An Introduction to the Windows Operating System
ECE 3567 Microcontrollers Lab
ECE 3567 Microcontrollers Lab
Introduction to Classes and Objects
Presentation transcript:

LAB 13: IO Driver Chung-Ta King National Tsing Hua University CS 4101 Introduction to Embedded Systems

Introduction In this lab, we will learn – Basics of I/O device drivers of MQX – To create and install a null IO driver – To develop a driver for the 3-axis accelerometer

Basics of I/O Device Drivers

I/O Device Drivers Dynamically installed software packages that provide a direct interface to hardware Driver installation: – Each device driver has a driver-specific installation function, io_device_install(), which is called in init_bsp.c under “mqx\source\bsp\” directory. – The installation function then calls _io_dev_install() to register the device with MQX. – To install a new device driver, the init_bsp.c needs to be modified and the BSP rebuilt

I/O Device Drivers Device names – Device name must end with “:”, e.g. _io_mfs_install("mfs1:"...) – Characters following “:” are information passed to device driver by fopen() call, e.g., fopen("mfs1:bob.txt") opens file bob.txt on device mfs1: I/O device drivers must provide following services: – _io_device_open: required – _io_device_close: required – _io_device_read: optional – _io_device_write: optional – _io_device_ioctl: optional

Null Driver The null device driver is an I/O device that functions as a device driver but does not perform any work. – Code at “mqx\source\io\io_null\”

Null Driver _mqx_uint _io_my_null_install(char_ptr identifier) /* “idetifier” identifies the device for fopen */ { _mqx_uint result; result = _io_dev_install(identifier, _io_my_null_open, _io_my_null_close, _io_my_null_read, _io_my_null_write, _io_my_null_ioctl, NULL); return result; }

Null Driver /* This function is called when the user calls fopen. It prepares the driver for subsequent read, write, and ioctl operations.*/ _mqx_int _io_my_null_open(MQX_FILE_PTR fd_ptr, char_ptr open_name_ptr, char_ptr flags) { /* Nothing to do */ return(MQX_OK); }

Null Driver _mqx_int _io_my_null_read(MQX_FILE_PTR fd_ptr, char_ptr data_ptr, _mqx_int num) { /* Body */ return(0); } /* Endbody */ _mqx_int _io_my_null_ioctl(MQX_FILE_PTR fd_ptr, _mqx_uint cmd, pointer param_ptr) { /* Body */ return IO_ERROR_INVALID_IOCTL_CMD; } /* Endbody */...

Using Null Driver #include #define MY_TASK 5 extern void my_task(uint_32); TASK_TEMPLATE_STRUCT MQX_template_list[] = { {MY_TASK, my_task, 1500, 9, "null_test", MQX_AUTO_START_TASK, 0, 0}, {0} }; void my_task(uint_32 initial_data) { FILE_PTR null_file; uint_8 data[10]; if (IO_OK != _io_my_null_install("null:")) { printf("Error opening Null\n"); }

Using Null Driver if (NULL == (null_file = fopen("null:", NULL ))) { printf("Opening NULL device driver failed.\n"); _mqx_exit(-1); } if (write(null_file, data, 4 ) != 4) { printf("Writing to NULL driver failed.\n"); _mqx_exit(-1); } fclose(null_file); printf ("NULL driver working\n"); _mqx_exit(0); }

Installing a Null Device Driver The Freescale MQX software solution includes several I/O device drivers that can be used as a reference to develop your own. These drivers are located in your default installation folder (referred to in this document as “ ”) inside the following path: \mqx\source\io

Under /mqx/source/io, create a folder called “my_null_io” to contain your device driver.

Under the “my_null_io” folder, put the following 3 files into it : ionulprv.h my_null_io.c my_null_io.h

Drag-and-drop Drag-and-drop the whole my_null_io folder to your Codewarrior project inside the IO Drivers folder. bsp_twrk60d100m/Peripheral IO Drivers

When you finish Drag-and-drop action, you will see the following.

The projects will execute a.bat file, which, among other things, copies header files to the output directory. This file is located at: \mqx\build\bat\bsp_twrk60d100m

Add the following line to the file : copy /Y..\..\..\mqx\source\io\my_null_io\my_null_io.h. ATTENTION !!!!! Don’t miss the dot behind “copy /Y..\..\..\mqx\source\io\my_null_io\my_null_io.h.”

Testing the Null Driver This device driver can be used by adding the following header to your application: #include New a mqx project and add #include to see if it can be built successfully or not.

Basic Lab Create a driver for the 3-axis accelerometer by filling the 5 driver services. Create a new project to print the 3-axis value by calling the 3-axis accelerometer service. (Set the value of CTRL_REG1 to 0x03)

Write_I2C(I2C_ACCELEROMETER_ADDRESS,0x2A,0x03); On 0x03 mode, the MSB value of 3-axis is meaningful. So you need to catch the MSB data of 3-axis when reading the accelerometer.

Bonus Use a button to toggle a flag that selects the return value from _io_null_read(). – If the flag is equal to 0, then return the value of the 3 axis- accelerometer as in Basic Lab. – If the flag is 1, then return additionally the inclination, e.g., right, left, front, back. – To do this, you have to add a control function using _io_null_ioctl(). X-axis Y-axis Z-axis Regular gravity value will be between ±65

3-axis Original Value The measured acceleration data are stored in the OUT_X_MSB, OUT_Y_MSB, OUT_Z_MSB registers as 2’s complement 8-bit numbers Sign bit Data bit Reference :