21
SE-3910 Real-time Systems • Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C environment • Watchdog follow-up – Watchdog demo – (Tentative) HOW to set time-out for watchdog – Bash Scripting – Real-Time OS’s SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling, Some from Dr. Hornick, etc. 1

SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Embed Size (px)

Citation preview

Page 1: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

SE-3910Real-time Systems

• Week 5, Class 2– Lab turn-in page is up!– Lost-and-not-found power supply– Quick-Quiz (Ungraded) – Use interrupts in a Linux/C environment

• Watchdog follow-up– Watchdog demo– (Tentative) HOW to set time-out for watchdog

– Bash Scripting– Real-Time OS’s

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling, Some from Dr. Hornick, etc.1

Page 2: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Quick Quiz! (1)

How do you get a reference (pointer) to the first element in an array?int x[5] = {1,2,3,4,5}boolean foo(int *ip);a)foo(&x);b)foo(&x[0]);c)foo(x);d)foo(x[0]);

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling2

Page 3: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Quick Quiz! (2)How do you get a reference (pointer) to the second element in an array?int x[5] = {1,2,3,4,5}boolean foo(int *ip);a)foo(&x+1);b)foo(&x[0]);c)foo(x+1);d)foo(x[0]);e)foo(&(x+1));

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling3

Page 4: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Real-Time Operating Systems• What does an operating system REALLY need?

– Essential• Scheduler• Memory allocation (e.g. malloc)• File system• Interrupts

– Important• Protection (security) (if on network)

– Less important • Networking• Protection (security) (if off network)

– Nice to have• GUI• Virtual memory• Multithreading

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling4

Page 5: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

UNIX Operating System• Common driver strategies

– Write to a file– Read from a file– ioctl (system call)– Short programs that wrap ioctl calls– [Addendum] “system calls” from C programs (which

don’t really call the kernel, but rather execute the short command-line programs mentioned above or execute a program that reads/writes from a file…

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling5

Page 6: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Scripting• Why learn scripting?

– Faster to write than compiled code

• Why learn command-line (bash) scripting?– Command line works very naturally with files– UNIX/Linux runs on files

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling6

Page 7: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Starting a Script• (More details)• Put the following into a file (e.g. script)

#!/bin/bashecho "Hello World"# other fun

• Now, run this command to make it executablechmod u+x script

• Now run the script like this:./script

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling7

Page 8: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Variables

Set a variableexport myVar="This is a variable"

Read a variable, printing to standard out:echo $myVar

Increment a Variableexport myVar=$((myVar+1))

Other integer mathexport myVar=$((myVar+1))

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling8

Page 9: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Arguments• Suppose we run our script like this:

./script arg1 arg2 arg3

• And inside the script, we run this command:echo "argument 3 is: $3"

• This will print:argument 3 is: arg3

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling9

Page 10: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Quoting - Escapes• Suppose we run

./script "this is a test" "of" "arguments"

• The quotes group the words …echo "arg1: $1"echo "arg2: $2"echo "arg3: $3"

• will printarg1: this is a testarg2: ofarg3: arguments

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling10

Page 11: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Quoting - EscapesIn the example from the previous section,

echo "arg1: $1"

prints arg1: this is a test

but echo 'arg1: $1'

printsarg1: $1

Escapes (e.g. "\\, \n, \r") are also useful.SE-3910 - Dr. Josiah Yoder

Slide style: Dr. HornickMuch Material: Dr. Schilling

11

Page 12: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Quoting Challenge:• How do I run an ssh command like this

– ssh host “command to run”

• But give “to run” as a single argument?• Hint: Use escapes!• Hint2: Command to run will be interpretted

twice.

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling12

Page 13: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Conditionals(More details) (UPDATED link at end of lab)Comparison

if test "$var1" = "$var2”; thenecho "true"

elseecho "false"

fiIf file “$var1” exists…

if test –e "$var1"; thenecho "true"

fi

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling13

Page 14: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

“Counting” LoopsCounting loop (my preferred approach)

for i in `seq 1 10`; doecho $i;

done;

Processing files in current directoryfor i in *.pdf; do

echo cp $i ${i/.pdf}.bak.pdf;done;# (Untested – test before use!)

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling14

Page 15: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

“Sentinal” loopsLoop while command succeeds (returns 0)

while commandecho "looping"

done;

Keep looping as long as the command fails.while !command

echo "looping"done;

Keep looping as long as test is “true”while test …

echo "looping"done;

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling15

Page 16: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Useful commands• Useful commands

– sleep 0.5 will sleep for half a second– time command args1 arg2 arg3– will measure how long it takes– command arg1 arg2 arg3 to run

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling16

Page 17: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

References for scripting

One of the main resources linked from above:http://linuxcommand.org/writing_shell_scripts.php

For if test …, I like this one betterhttp://www.tldp.org/LDP/Bash-Beginners-

Guide/html/sect_07_01.htmlIntro to variables (possibly useful)http://www.tldp.org/LDP/abs/html/parameter-substitution.html

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling17

Page 18: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Watchdog On the Beaglebone• http://beaglebone.cameon.net/home/watchdog-

timer• Open the file /dev/watchdog• Do not close the file• Write something (e.g. "\n") to the file at least

every 59 seconds to keep the system runningDEMO• Yes, it is possible to change the time.DEMO? DETAILS?

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling18

Page 19: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Command-Line Cheat-sheet• I’m working on one• I’ve got links to online ones I like• Just ask me

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling19

Page 20: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Demo – Connecting to Beaglebone• [TODO]

– I plan to put instructions for setting up a DHCP server on your laptop using “connection sharing”

– You know my number.

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling20

Page 21: SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C

Demo – Watchdog• [See computer]

SE-3910 - Dr. Josiah YoderSlide style: Dr. Hornick

Much Material: Dr. Schilling21