Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your program will duplicate these steps using a single c program with the makefile as a helper. a) Add a makefile rule, named setup, similar

Your program will duplicate these steps using a single c program with the makefile as a helper.

a) Add a makefile rule, named setup, similar to the clean rule that will implement the config-pin steps 1-4.

image text in transcribed

Running the command make setup will run the config-pin setup functions. Adding echo commands detailing the config-pin steps is probably a good idea, for example the first statement following setup: might be echo beginning the setup procedure.

b) We will write a C program to implement the scripts steps 5 and 6 in Table 1, see Appendices B and C for the gpio_getvalue.sh and gpio_setvalue.sh scripts, note: these scripts are informational only. Read /sys/class/gpio/gpio30/value using fscanf and write to /sys/class/gpio/gpio60/value using fprintf. Place the read and write inside a loop. The format spec for a char is "%c". You will need to account for switch bounce with programming. Debouncing can be accomplished in software by reading the value for the switch, delaying for a short period to account for the bouncing, then re-reading the switch. If the values are the same, the switch can be assumed to be inactive, if different than the switch can assumed to be active. The maximum time that a switch bounces typically is less than 50ms so that calling the function usleep (man -s3 usleep) with an argument of 50000 could be used in this test. Pseudo-code for this debouncing technique is

Read switch and save value in s1

usleep( 50000 )

Read switch and save value in s2

If s1 and s2 have the same value, the switch was not thrown, if different, the switch was thrown.

Notice that this technique is not dependent on the switch being open or closed only that there is a change. The man pages for usleep say that this function is obsolete and that nanosleep should be

used in place of usleep. There is a wealth of both good and bad code on the web for using nanosleep. I tend to look to stackoverflow.com for better code.

Note: Do not under any circumstance write values into the /sys/class/gpio/export or /sys/class/gpio/unexport files!

Note: there should be error checks throughout your c program. Check the man pages for the c functions that you use to see what header files should be included, what return values are expected, what errors are detected and how they are processed. The error checks used in devmem2.c could be used here to print consistent error messages.

To read or write a single character to a gpio device, you must fopen and fclose the value file. The reason for the fopen and fclose encapsulation around each read/write is that you are using buffered I/O and you must fopen and fclose the file to ensure that the buffer is empty at the beginning and left empty at the end.

recommended config-pin usage config-pin P9_12 gpio config-pin P9_11 gpio config-pin P9_12 out config-pin P9_11 in 10 recommended config-pin usage config-pin P9_12 gpio config-pin P9_11 gpio config-pin P9_12 out config-pin P9_11 in 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems On GPUs In Databases

Authors: Johns Paul ,Shengliang Lu ,Bingsheng He

1st Edition

1680838482, 978-1680838480

More Books

Students also viewed these Databases questions