Programming I/O for Embedded System. Page 2 Overview Basis: A DE2 Computer Architecture Parallel I/O 7-Segment Display Basic Manipulating 7-Segment Display.

Slides:



Advertisements
Similar presentations
1 (Review of Prerequisite Material). Processes are an abstraction of the operation of computers. So, to understand operating systems, one must have a.
Advertisements

Chapter 10 Input/Output Organization. Connections between a CPU and an I/O device Types of bus (Figure 10.1) –Address bus –Data bus –Control bus.
I/O Unit.
CS-334: Computer Architecture
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
My First Nios II for Altera DE2-115 Board 數位電路實驗 TA: 吳柏辰 Author: Trumen.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at.
Hardware/software Interfacing. Page 2 Interrupt handling and using internal timer Two way for processor to accept external input: Waiting for input: Processor.
JTAG UART port in NIOS.
Micro-controller or embedded controller
ECE Department: University of Massachusetts, Amherst Lab 1: Introduction to NIOS II Hardware Development.
CSCE 313: Embedded Systems Multiprocessor Systems
Dr. Kimberly E. Newman Hybrid Embedded wk3 Fall 2009.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
ECE 265 – LECTURE 12 The Hardware Interface 8/22/ ECE265.
The 6713 DSP Starter Kit (DSK) is a low-cost platform which lets customers evaluate and develop applications for the Texas Instruments C67X DSP family.
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
Lab 2: Capturing and Displaying Digital Image
NetBurner MOD 5282 Network Development Kit MCF 5282 Integrated ColdFire 32 bit Microcontoller 2 DB-9 connectors for serial I/O supports: RS-232, RS-485,
COMP201 Computer Systems Exceptions and Interrupts.
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
OS Implementation On SOPC Midterm Presentation Performed by: Ariel Morali Nadav Malki Supervised by: Ina Rivkin.
UART and UART Driver B. Ramamurthy.
Project Goals 1.Get to know Quartus SoPC builder environment 2.Stream 2.Stream Video 3.Build 3.Build foundation for part B - Tracking system.
ECE Department: University of Massachusetts, Amherst Using Altera CAD tools for NIOS Development.
Volume. 1-the idea of the program is to increase, decrease the volume. 2-the program does the following: A-PF8:decrease the volume B-Pf9:increase the.
MICROPROCESSOR INPUT/OUTPUT
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Typical Microcontroller Purposes
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Computer Architecture Lecture10: Input/output devices Piotr Bilski.
(More) Interfacing concepts. Introduction Overview of I/O operations Programmed I/O – Standard I/O – Memory Mapped I/O Device synchronization Readings:
Computers Internal Communication. Basic Computer System MAIN MEMORY ALUCNTL..... BUS CONTROLLER Processor I/O moduleInterconnections BUS Memory.
ECS642U Embedded Systems Digital I/O William Marsh.
2009 Sep 10SYSC Dept. Systems and Computer Engineering, Carleton University F09. SYSC2001-Ch7.ppt 1 Chapter 7 Input/Output 7.1 External Devices 7.2.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
NIOS II Ethernet Communication Final Presentation
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
CH10 Input/Output DDDData Transfer EEEExternal Devices IIII/O Modules PPPProgrammed I/O IIIInterrupt-Driven I/O DDDDirect Memory.
L/O/G/O Input Output Chapter 4 CS.216 Computer Architecture and Organization.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
The computer system’s I/O architecture is its interface to the outside world. This architecture provides a systematic means of controlling interaction.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
بسم الله الرحمن الرحيم MEMORY AND I/O.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Chapter Microcontroller
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
Lab 1: Using NIOS II processor for code execution on FPGA
HIBI_PE_DMA Example.
UNIT – Microcontroller.
CS 286 Computer Organization and Architecture
Introduction to Microprocessors and Microcontrollers
Presentation transcript:

Programming I/O for Embedded System

Page 2 Overview Basis: A DE2 Computer Architecture Parallel I/O 7-Segment Display Basic Manipulating 7-Segment Display on DE2 Interrupt and Interruption handling DE2 Internal Timer Basic Manipulating Internal Timer

Page 3 Basis: A DE2 Computer Architecture A SOPC system on DE2 Board Created by Quartus II With a full featured I/O and memory devices integrated

Page 4 System components NIOS II Processor with on-chip memory SDRAM Flash Memory Internal Timer Parallel output ports to 8 green leds and 16 red leds Parallel output ports to 8 on-board 7-segment leds On-board LCD output Parallel input ports to 16 switches Parallel input ports to 4 push-buttons JTAG-UART connection to host machine

Page 5 Basis: A DE2 Computer Architecture CPU: 32 bits word width, 50 MHz On-Chip SRAM: 32 bits, 4KB On-board SDRAM: 16bits, 8MB On-board Flash Memory: 16 bits, 4MB Internal Timer: period: 1ms 3 Parallel I/O ports to LEDs and Switches: 8 bits 8 Parallel I/O ports to 7-segment LED: 8 bits On-board LCD: Optrex JTG UART Serial Communication: 64 bits FIFO buffer

Page 6 Interrupt request (IRQ) Input device generated interrupts: push buttons : IRQ 2 JTAG_UART : IRQ 0 Internal Timer : IRQ 1 Interrupts provide an asynchronous way for data transmission between I/O devices and CPU

Page 7 Address Map Check sopc configuration for detailed Address map

Page 8 Using HAL for embedded software development HAL: Hardware Abstraction Layer A programming interface for embedded system development, provide user a hardware-irrevelant programming platform Parallel I/O Communication Device Driver Interrupt and DMA control Video/Audio signal processing Ethernet/Internet access

Page 9 Using HAL HAL require a bunch of header files be included in user C source file, different HAL module require different header files “system.h” includes the basic configuration of SOPC, Processor parameters, address and data bus width, I/O Address Map, should be included if HAL is used.

Page 10 Parallel I/O Parallel I/O is directly connected to processor pins, NIOS parallel I/O is addressed in 8-bit, and made up by 5 basic port registers: Data Register Direction Register Interruptmask Register Edge Capture Register Outset Register Outclear Register

Page 11 Parallel I/O Port

Page 12 Access to Parallel I/O port in NIOS HAL integrated a group of macros and functions for I/O port access Header file requested: #include “system.h” #include "altera_avalon_pio_regs.h“

Page 13 Access to Parallel I/O port in NIOS IORD_ALTERA_AVALON_PIO_DATA(base) IOWR_ALTERA_AVALON_PIO_DATA(base,data) // Read and write to I/O Port IORD_ALTERA_AVALON_PIO_DIRECTION(base) IOWR_ALTERA_AVALON_PIO_DIRECTION(base,data) // Set/Get port direction IORD_ALTERA_AVALON_PIO_IRQ_MASK(base) IOWR_ALTERA_AVALON_PIO_IRQ_MASK(base, data) // Set/Get interrupt mask

Page 14 Difference between direct assignment and using HAL Macro We have already seen such code before #define PIO_ADDR 0x …. *((char *)PIO_ADDR)=(char) 0xff; Equivalent code using HAL Macro will be #define PIO_ADDR 0x IOWR_ALTERA_AVALON_PIO_DATA(PIO_ADDR,0xff) Difference? HAL provides a safety way for data transmission, user doesn’t need to be involved into complicated type cast and data alignment.

Page 15 Constants definition in system.h The constants in SOPC system s.t. I/O port and register file address, are defined in system.h. For example, user have a 8-bit PIO port named switch_0_7 build in SOPC The corresponding definition will be added to system.h #define SWITCH_0_7_BASE 0x

Page 16 7-segment Display Can display hex numbers (0-9,A-F) Widely used in digital clock, temperature controller,etc

Page 17 7-segment Display

Page 18 How board segment display works Segment display on DE2 board is implemented as common-cathode bit X x

Page 19 Connecting segment display to processor the 7 pins of segment display can be connected to parallel I/O port and use parallel I/O operation to control the display on LED.

Page 20 C Code Example of Segment Display #include “system.h” #include "altera_avalon_pio_regs.h” // #define SEG_LED_0_ADDR 0x // Or use the definition in system.h, which is SEG_LED_0_BASE main() { IOWR_ALTERA_AVALON_PIO_DATA(SEG_LED_0_BASE,0x 30); ; //turn segment e and f off }

Page 21 Push button Push button is similar to switch, the difference is it need to be hold pressed down to keep the value on the parallel I/O port. The way to read push button input is the same to switch

Page 22 Interrupt handling and using internal timer Two way for processor to accept external input: Waiting for input: Processor will be halting and listening to the input port until data is transmitted while(data is not updated){ read data from address of some I/O port }

Page 23 Interrupt handling and using internal timer Interrupt: Data arrival will start an interrupt request to processor, when a interrupt is generated, processor will stop it’s current work and turn to interrupt service function (data receive), and resume work after interrupt is handled. interrupt_func() { transmit data from I/O port to processor } Main() { setup interrupt handling function }

Page 24 Interrupt Request “interrupt request" (or IRQ) is used to refer to either the act of interrupting the bus lines used to signal an interrupt, or the interrupt input lines on a Programmable Interrupt Controller Generated when an I/O event occurs, handled by interrupt controller Interrupts from different sources are differentiated by IRQ line number

Page 25 IRQ setting in DE2 Computer DeviceIRQ JTAG_UART0 Internal Timer1 Push Button2

Page 26 Interrupt handler function NIOS Processer keeps a special address in memory ad the entry point for interrupt handler function Exception Vector: stores the address of interrupt handler function, when an IRQ is received by processor, it will save the instruction context and jump to interrupt handler function.

Page 27 How to use interrupt handler Enable corresponding IRQ line to processor in SOPC builder Set I/O devices to enable external interrupt generation Enable the interruptmask register of Parallel I/O The ITO bit in internal timer control register Write interrupt handler function Register interrupt handler function

Page 28 Code sample for interrupt handler setup Include files: #include "system.h" #include "alt_types.h" #include "sys/alt_irq.h" #include "sys/alt_sys_init.h"

Page 29 Pseudo-Code sample for interrupt handler setup void interrupt_handler() { … } main() { enable system irq register handler of irqX as interrupt_handler }

Page 30 Internal Timer NIOS Internal Timer Works as a stop watch, period register and control signals are set by user by programming, once started, counter will count down from the value in period register to 0 and generate an interrupt when time is over.

Page 31 Top-level timer diagram

Page 32 Timer configuration

Page 33 Timer configuration Configured in SOPC Builder

Page 34 Register File for Internal Timer

Page 35 Register File for Internal Timer

Page 36 Register File for Internal Timer

Page 37 How to use internal timer in programming Internal timer will loopingly count down from value in period register to 0, when counter reaches 0, an interrupt on IRQ 1 will generated, user need to write IRS function for IRQ 1 to capture timer events In DE2 Computer, the period of timer is 1 ms, means the interrupt will occur 1000 per second

Page 38 How to use internal timer in programming #include "system.h" #include "alt_types.h" #include "altera_avalon_timer_regs.h" #include "altera_avalon_timer.h" #include "sys/alt_irq.h" #include "sys/alt_sys_init.h"

Page 39 Macros for timer register file access IORD_ALTERA_AVALON_TIMER_STATUS(base) IOWR_ALTERA_AVALON_TIMER_STATUS(base, data) // Read/write to 16 bits status register IORD_ALTERA_AVALON_TIMER_CONTROL(base) IOWR_ALTERA_AVALON_TIMER_CONTROL(base, data) // Read/write to 16 bits control register IORD_ALTERA_AVALON_TIMER_PERIODL(base) IOWR_ALTERA_AVALON_TIMER_PERIODL(base, data) // Read/write to lower 16 bits of period register IORD_ALTERA_AVALON_TIMER_PERIODH(base) IOWR_ALTERA_AVALON_TIMER_PERIODH(base, data) // Read/write to higher 16 bits of period register

Page 40 How to use internal timer in programming Write user IRS function static void Timer_Interrupts(void *context,alt_u32 id) { if(Timer_counter >= 1000) /* 1S */ { Timer_counter = 0; //global variable to store reached counter event } else { Timer_counter++; } IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_BASE, 0x00);//clear status register }

Page 41 How to use internal timer in programming Register IRS alt_irq_register(TIMER_IRQ,NULL,Timer_Interrupts); //Register IRS IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_BA SE, 0x07); //Start timer

Page 42 How to capture Timer event in user program Keep a global variable for storing information from timer events, in main function, check the global variable to update timer events static int timer_event; interrupt_handler() { …. //set timer_event } main() { register IRS function while(timer_event updated) { … user actions } }

Page 43 Summary DE2 Computer A basic hardware configuration in Quartus for embedded system software design Parallel I/O Basic, register file structure and programming 7-Segment LED Driven by parallel I/O, programming and display Interrupt handling Basic concepts, and how to use in programming Internal Timer Basic, register file structure and programming