CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.

Slides:



Advertisements
Similar presentations
Dr. Rabie A. Ramadan Al-Azhar University Lecture 3
Advertisements

The 8051 Microcontroller Chapter 5 SERIAL PORT OPERATION.
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.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
68HC11 Polling and Interrupts
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
Debouncing Switches Mechanical switches are one of the most common interfaces to a uC. Switch inputs are asynchronous to the uC and are not electrically.
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.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
Unit-5 CO-MPI autonomous
INPUT-OUTPUT ORGANIZATION
Input/Output mechanisms
MICROPROCESSOR INPUT/OUTPUT
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
(More) Interfacing concepts. Introduction Overview of I/O operations Programmed I/O – Standard I/O – Memory Mapped I/O Device synchronization Readings:
Microprocessors 1 MCS-51 Interrupts.
AVR Programming: Interrupts September 17, What are interrupts? An asynchronous signal indicating the need for an event to be handled A synchronous.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
EEE440 Computer Architecture
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
CSCI1600: Embedded and Real Time Software Lecture 4: Introduction to the Arduino Steven Reiss, Fall 2015.
12/16/  List the elements of 8255A Programmable Peripheral Interface (PPI)  Explain its various operating modes  Develop a simple program to.
PPI-8255.
ECE 447 Fall 2009 Lecture 7: MSP430 Polling and Interrupts.
CSCI1600: Embedded and Real Time Software Lecture 9: Input Output Concepts Steven Reiss, Fall 2015.
Chapter 5 - Interrupts.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
CSCI1600: Embedded and Real Time Software Lecture 5: Arduino Programming Steven Reiss, Fall 2015.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This course provides an introduction to the peripheral functions.
بسم الله الرحمن الرحيم MEMORY AND I/O.
CSCI1600: Embedded and Real Time Software Lecture 15: Advanced Programming Concepts Steven Reiss, Fall 2015.
Chapter 3 System Buses.  Hardwired systems are inflexible  General purpose hardware can do different tasks, given correct control signals  Instead.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Microcontroller basics Embedded systems for mortals.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Chapter 2: Computer-System Structures
CS501 Advanced Computer Architecture
68HC11 Interrupts & Resets.
UNIT – Microcontroller.
Chapter 3 Top Level View of Computer Function and Interconnection
E3165 DIGITAL ELECTRONIC SYSTEM
CSCI1600: Embedded and Real Time Software
Module 2: Computer-System Structures
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Robocon 2007 Electronics Quickstart!
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
CSCI1600: Embedded and Real Time Software
Module 2: Computer-System Structures
Module 2: Computer-System Structures
CSCI1600: Embedded and Real Time Software
Chapter 13: I/O Systems.
CSCI1600: Embedded and Real Time Software
Lecture 12 Input/Output (programmer view)
Presentation transcript:

CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015

Problem to Consider  Keypad for entering alarm code  Task to read the keypad  Determine when a button has been pushed  Want to check a sequence of button presses against known code(s)  Task that does the checking  How do these communicate?

Making Communication Simple

Handshake Communication  The previous depended on timing (or sequential tasks)  What should we do when tasks need to synchronize  Task A sends a request to Task B  Task A needs to know when Task B is done  In order to send another request  Ensure no new button is pressed until current one is processed  Can use 2 variables rather than one  Task A owns variable REQ  Task B owns variable ACK

Handshake Communication  Code  A: set Data, set REQ, wait for ACK, clear REQ, wait for ~ACK  B: wait for REQ, read Data, set ACK, wait for ~REQ, clear ACK  Sequence  A: set Data, set REQ  B: wait for REQ, read Data, set ACK  A: wait for ACK, clear REQ, wait for ~ACK  B: wait for ~REQ, clear ACK

Communicating Arduinos  Suppose you want to have two Arduinos talk to each other  Just simple message back and forth (sequence of bits)  How would you do this?

Communication: Queues  More complex communication involves multiple requests  Model railroad: multiple switches can be triggered  But only one can be activated at a time  This is generally implemented as a queue  Allows the two tasks to be asynchronous

Queue-based Tasks

Queue Implementation  Queues in embedded programs  Are generally fixed in size  Often sized so they never overflow  Or data is discarded if they would  How to program a queue?

Simple Queue byte queue[10]; int qp = 0; void push(byte x) [ TASK A ] if qp < 10, then queue[qp++] = x else exception byte pop() [ TASK B ] if (qp == 0) exception rslt = queue[0]; for (i = 1; i < qp; ++i) queue[i-1] = queue[i] qp = qp-1 return rslt  What’s wrong with this?

Circular Buffer Queue  Use a single array  Maintain a start and end pointer  Treat the array as a circular buffer  Element beyond the last is the first, etc.  Maintain two pointers  Head (read): pointer to the first element to extract  Tail (write): pointer to the next place to insert

Circular Buffer  Pop:  if read == write then exception  result = buf[read];  read = (read + 1) % size

Circular Buffer  Push(data):  If read == write then exception  buf[write] = data  write = (write + 1)%size

Circular Buffer  Advantages  Little data movement  Pointers are only changed by one task  Queue cells are safely read/written (why?)  Code is simpler  Extensions  Can read/write multiple things at once  Data stream or communications channel

Circular Buffers and Handshakes  What happens with a circular buffer of size one?

Multiple Inputs on a Port  How to multiplex a port with different inputs  Generally unsafe to connect multiple sensors at once  If sensor is at ground, another sensor at high might ground thru the first, not through the input port  Then the input would always be low  To get around this  Switches: only provide power/ground to enabled ones  Other logic circuits/devices: Open collector

Open Collector Circuit  Add a transistor to circuit  Acts as a switch  Effectively unconnected if off  External pull up makes it high  Grounded if on  Result is low  Can connect multiple  Effectively an OR gate  Many ICs have this built in  Hence negated outputs

Serial Communication  Send data from one machine to another  Using only 2 wires  Using clocked serial input  10 bits to send 8  Plus parity?

UART: Hardware for Serial I/O  Accepts bytes in parallel from the CPU  Sends these serially at fixed rate  Reads bytes from the serial line  Tells CPU when a byte is ready to read  Includes lines to ensure synchronization  Ready to transmit, …

UART Internals

Interrupts  Interrupts allow occasional inputs that aren’t polled  Limited set of pins support interrupts  Varies based on arduino model, for example  attachInterrupt(pin,routine,mode)  routine – pointer to function (function name in C)  mode: LOW, CHANGE, RISING, FALLING, HIGH  High not always supported on Arduino  detachInterrupt(pin)

Other Interrupts  Analog interrupts  Configure based on threshold  Timer interrupts  Based on clock counter overflowing  Direct interrupt lines into CPU

Interrupt Synchronization  Interrupts are asynchronous  Need to synchronize for them  noInterrupts() – disables interrupts  interrupts() – enables interrupts  Can have multiple levels of interrupts

Tic Tac Toe  How could you use interrupts for tic-tac-toe?  Lights?  Switches?

Interrupt Coding  Interrupt routines should do a minimum amount of work  Time added to time of executing task  Asynchronous -> race conditions can occur  Typically these routines just set a flag  Possibly read/write value and set flag  Possibly read/write from/to circular buffer

Interrupt Problems static int iTemperatures[2]; void interrupt vReadTemperatures (void) { iTemperatures[0] = read Dev 1 iTemperatures[1] = read Dev 2 } void main(void) { int iTemp0, iTemp1; // Setup code iTemperatures[0] = 0; iTemperatures[1] = 0; while(TRUE) { iTemp0 = iTemperatures[0]; iTemp1 = iTemperatures[1]; if ( iTemp0 != iTemp1 ) { // Set off alarm! }

Homework  Read Chapters 10, 11