19.02.2015 Views

An Introduction to Linux Device Driver Development - Computer ...

An Introduction to Linux Device Driver Development - Computer ...

An Introduction to Linux Device Driver Development - Computer ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6 Labora<strong>to</strong>ry Exercise #6<br />

device file. Accessing the man pages can be done via the terminal. For example, <strong>to</strong> view the<br />

man pages on ‘open’, type ‘man open’ in a terminal window.<br />

(b) Within the ‘modules’ direc<strong>to</strong>ry, create a source file called ‘devtest.c’ and copy the following<br />

starter text in<strong>to</strong> that file:<br />

# i n c l u d e <br />

# i n c l u d e <br />

# i n c l u d e < f c n t l . h><br />

# i n c l u d e <br />

# i n c l u d e <br />

# i n c l u d e < s t d l i b . h><br />

i n t main ( ) {<br />

unsigned i n t r e s u l t ;<br />

i n t fd ; / ∗ f i l e d e s c r i p t o r ∗ /<br />

i n t i , j ; / ∗ loop v a r i a b l e s ∗ /<br />

char i n p u t = 0 ;<br />

/ ∗ open d e v i c e f i l e f o r r e a d i n g and w r i t i n g ∗ /<br />

/ ∗ use ”open” t o open ‘ / dev / m u l t i p l i e r ’ ∗ /<br />

/ ∗ h a n d l e e r r o r opening f i l e ∗ /<br />

i f ( fd == −1){<br />

p r i n t f ( ” F a i l e d t o open d e v i c e f i l e !\ n ” ) ;<br />

return −1;<br />

}<br />

while ( i n p u t != ’ q ’ ){ / ∗ c o n t i n u e u n l e s s u s e r e n t e r e d ’ q ’ ∗ /<br />

f o r ( i =0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!