Reentrant driver
Download
1 / 23

Reentrant Driver - PowerPoint PPT Presentation


  • 97 Views
  • Uploaded on

Reentrant Driver. read() { if (INIT) sleep_on(&wq); else { start = getTime(); INIT = 1; sleep_on(wq); } compute_distance(); copy_to_user(); return; } isr() { stop = getTime(); INIT = 0; compute_distance() wake_on(wq); }. open() { if (count++) return(0);

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Reentrant Driver' - pooky


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Reentrant driver
Reentrant Driver

read() {

if (INIT) sleep_on(&wq);

else {

start = getTime();

INIT = 1;

sleep_on(wq);

}

compute_distance();

copy_to_user();

return;

}

isr() {

stop = getTime();

INIT = 0;

compute_distance() wake_on(wq);

}

open() {

if (count++) return(0);

else return(grab_resources());

}

release() {

if (--count) return(0);

else return(release_resources());

}

read() {

if (read_count++) sleep_on_interruptible(&wq);

else {

start = getTime();

INIT = 1;

sleep_on_interruptible(wq);

INIT = 0;

}

compute_distance();

copy_to_user();

if (--read_count) INIT == ;

return(length);

}

isr() {

stop = getTime();

wake_on_interruptible(wq);

}

problem:

processes added to wq

after wake_on may

never get awakened!

They have to wait until

a read is attempted after

the queue is emptied and INIT

is turned off.

read after wake problem

still: a new read

that occurs before the queue is emptied will overwrite “start”

wakeINIT=0readblocked reader computes wrong distance

CSE 466 – Fall 2000 - Introduction - 1


Use a bottom half
Use a Bottom Half!

read() {

if (INIT) sleep_on(wq);

else {

start = getTime();

INIT = 1;

sleep_on(wq);

}

copy_to_user();

if (empty(wq)) INIT = 0;

return;

}

isr() { // reads will still pile up on the wait queue until the bh executes.

stop = getTime();

add_to_bh_queue(isr_bh);

}

isr_bh() { // make a new queue for all future reads, compute distance with correct start-stop data.

sonar_result = Compute_distance(); // do this once per interrupt

INIT = 0;

tmp = wq; // re-initialize queue to catch for read calls

wq = (wait_queue*) kmalloc(sizeof(wait_queue));

wake_on(tmp); // wake old queue

}

will each reader get the “correct” reading?

CSE 466 – Fall 2000 - Introduction - 2


Fifo s which are named pipes
FIFO’s, which are named pipes

  • Process 1

    void main() {

    mknod(“/tmp/myfifo”, S_IFIFO ); // create a FIFO file node

    f = open(“/tmp/myfifo”, O_WRONLY);

    while (1) {generate_data(buf); write(q, buf, n);}

    }

  • Process 2

    void main() {

    f = open(“/tmp/myfifo”, O_RDONLY);

    while (1) {read(q, buf, n); process_data(buf);}

    }

  • Works for “unrelated” processes

  • Multiple writers, Multiple readers

    • Kernel ensures mutual exclusion

    • Kernel does not control interleaving of writers, readers

CSE 466 – Fall 2000 - Introduction - 3


Multi processor systems a control dominated example
Multi-Processor Systems A Control Dominated Example

  • controller

  • sense:

    • Temperature

    • H2

    • Output Current

    • Output Voltage

    • Fan Speed

  • control

    • H2 valves

    • Output MOSFET

    • Fan Speed

    • Stack MOSFETS

Air

H2

Heat

H20

not showing power supply circuitry for the controller…runs off fuel cell w/ backup battery.

CSE 466 – Fall 2000 - Introduction - 4


System level modes logical structure
System level Modes (Logical Structure)

warmup

online

startup

Self Check

Pass

Error

Warm

On

Error

Overload+

Off

shtdwn

Self Check

Fail

offline

Error

off

Error

CSE 466 – Fall 2000 - Introduction - 5


State table error conditions are mode dependent

Mode

Outputs

Tasks

Signals

New Mode

Off

Load Disabled

Power Supply Off

Gas Valves Closed

Power Button Enabled

none

Power Button Push

Startup

Startup

Load Disabled

Power Supply On

Gas Valves Closed

Initialize

Temp Control

H2 Detection

Load Monitor

UI Running

Initialize Complete

Warm Up

Error Condition Detected* or shutdown request

Shutdown

Warmup

Load Disabled

Power Supply On

Gas Valves Open

Temp Control

H2 Detection

Load Monitor

UI Running

Operating Temp Reached

Off Line

Error Condition Detected* or shutdown request

Shutdown

Off Line

Load Disabled

Power Supply On

Gas Valves Open

Temp Control

H2 Detection

Load Monitor

UI Running

On-Line Command Received (UI)

On Line

Error Condition or Shutdown request

Shutdown

On Line

Load Enabled

Power Supply On

Gas Valves Open

Temp Control

H2 Detection

Load Monitor

UI Running

Off Line Command

Off Line

Overload

Off Line

Error Condition* or Shutdown Request

Shutdown

Shutdown

Load Disabled

Power Supply On

Gas Valves Closed

Fan On

Temp Control

Schedule transition to Off state

Timeout

Off

State Table (*error conditions are mode dependent)

CSE 466 – Fall 2000 - Introduction - 6


Examples of mode dependencies
Examples of Mode Dependencies

  • Fan Speed Control:

    • In startup or shutdown mode always run minimum speed

    • otherwise attempt to maintain temperature set point

    • If fan doesn’t turn, issue badfan signal

  • Hydrogen Detection: always close hydrogen valves and issue h2dectected signal if hydrogen detected, except in startup mode.

  • Load Monitoring

    • If not online and output current > 0 or output voltage < min, then issue mosfet failure signal

    • If online and load current is > max allowed, or if output voltage is < min then turn on another stack. If all stacks are on, then issue overload signal.

  • UI Process

    • If “line” button pushed and online issue offline event, If offline issue online signal.

    • If “power” button pushed and not in off mode, then issue shutdown signal.

CSE 466 – Fall 2000 - Introduction - 7


Logical decomposition
Logical Decomposition

Output Logic

signals

UI

Next

State

Logic

Temp

Load

H2 Task

inputs

signals

CSE 466 – Fall 2000 - Introduction - 8


Logical implementation
Logical Implementation

synchronized volatile state;

task tempControl _task_ 1 {

while(1) {

t = readTemp();

if (t > MAXT) send_signal(TOOHOT); //blocking

if (t < MINT) send_signal(TOOCOLD);

if (t < setpoint)

increase_fan_speed();

if (t > setpoint)

decrease_fan_speed();

wait(ThermalTime);

}}

task loadMonitor _task_ 2 {

while(1){

if (state != ONLINE)

if (getLoad() > 0) send_signal(BADFET);

else if (getLoad() > MAXLOAD) send_signal(OVRLOAD);

wait(LoadTime);

}}

task H2Monitor _task_ 3 {

while (1) {

if (state() != startUp)

if ((getH2() < MINH) || (getH2() > MAXH)) send_signal(H2FAILURE);

}} // let this process fill in all unused cycles!

task stateMgr _task_ 0 {

while (1) {

recv_signal(&s); // blocking

switch(state)

startUp: switch(s)

TOOHOT: state = SHTDWN;

break;

}

Issues: what are send_signal() and recv_signal()?

How can synchronized state be implemented?

CSE 466 – Fall 2000 - Introduction - 9


Physical decomposition layers
Physical Decomposition -- Layers

network layer

Socket could be implemented in shared memory, internet, or anything in between.

High level architecture can be independent of implementation choices.

Synthesis Problem:

Map processes and sockets to processors and networks. Optimize performance,

latency, shared mem.

Warning: usually not done this way for embedded systems…usually designer performs the physical decomposition and

app is written to the

hardware…not a good idea!

application

layer

signals

load

State

Mgr +

UI

state

physical layer

temp

H2

CSE 466 – Fall 2000 - Introduction - 10


Example of physical layer spi bus
Example of Physical Layer: SPI Bus

Master

Slave

SCK

SCK

SDO

SDI

SDI

SDO

void isr() interrupt TIMER {

SDR = S;

while(!SPF);

R = SDR;

}

void isr() interrupt SPF{

R = SDR;

SDR = S

signal(RECV);

}

1 0 0 1 1 1 1 0

0 0 0 1 1 0 0 0

shift reg

shift reg

CSE 466 – Fall 2000 - Introduction - 11


Multiple slave configuration
Multiple Slave Configuration

Master

Slave

SCK

SCK

SDO

SDI

SDI

SDO

Slave

SCK

SDI

SDO

CSE 466 – Fall 2000 - Introduction - 12


Iso layers continued
ISO Layers Continued

  • Transport Layer: responsible for end-to-end protocol of user data buffer transmissions. Source and destination addresses are private – host to host.

    • Maps application space channel (socket) name to network address.

    • makes network packets w/ transport header and communicates w/ network layer.

  • Each layer has a peer-to-peer and an intra-stack protocol

Application

Application

write(s, buf,n);

read(s, buf,n );

Transport -- TCP

Transport -- TCP

Network -- IP

Network -- IP

Network -- IP

Network -- IP

Datalink -- Ether

Datalink -- Ether

Datalink -- Ether

Datalink -- Ether

Physical -- Ether

ethernet fiber

fiber ethernet

Physical -- Ether

CSE 466 – Fall 2000 - Introduction - 13


Embedded networking simplest case
Embedded Networking: Simplest Case

  • Simple case: socket name is the same as physical address. No mapping, we just need to break our message into frames…maybe

  • Physical Layer – typically low bandwidth, serial, byte oriented

  • Data link layer – read/write interface to the application

  • frames: destination address, data, checksum.

    • No mapping from sockets to network address

    • No mapping from network address to physical address (no routing)

Application

Application

write(s, buf,n);

read(s, buf,n );

Transport

Transport

Network -- IP

Network -- IP

Network -- IP

Network -- IP

Datalink

Datalink -- Ether

Datalink -- Ether

Datalink

Physical

ethernet fiber

fiber ethernet

Physical

CSE 466 – Fall 2000 - Introduction - 14


Master slave data link protocol
Master Slave Data Link Protocol

  • As an example frame is [destination address, command, data]

  • An acknowledgement frame is [address, data, checksum]

Master

Slave

SCK

SCK

SDO

SDI

SDI

SDO

mux

Slave

SCK

dst

cmd

data

dst

type

data

SDI

addr

data

sum

type

data

sum

SDO

mux x x x 1 1 1 2 2 2

CSE 466 – Fall 2000 - Introduction - 15


Multi master systems i2c
Multi-master Systems: I2C

  • Multi-mastered

  • Send and receive

  • Two wire (plus ground)

  • Packet oriented (block send)

CSE 466 – Fall 2000 - Introduction - 16


Major features of i2c
Major Features of I2C

CSE 466 – Fall 2000 - Introduction - 17


Physical layer
Physical Layer

CSE 466 – Fall 2000 - Introduction - 18


Bit transfer
Bit Transfer

Transmitter

Master

CSE 466 – Fall 2000 - Introduction - 19


Who gets to be master
Who gets to be master

The one who initiates a frame:

A frame is:

<Start><addr><data>…<data><Stop> OR

<Start><addr><data>…<data><R_Start><addr><data>…<Stop>

CSE 466 – Fall 2000 - Introduction - 20


An i2c byte transfer
An I2C Byte Transfer

MSB First

Rx

MSB……………….LSB

slave

slave

Tx Device

Rx Device

master

CSE 466 – Fall 2000 - Introduction - 21


A complete frame
A Complete Frame

MSB……..LSB

CSE 466 – Fall 2000 - Introduction - 22


Beauty of layers
Beauty of Layers

  • App doesn’t care if lower layer is SPI or I2C

  • How much can we isolate the physical differences?

CSE 466 – Fall 2000 - Introduction - 23


ad