Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q3(15 points). Write a short code to perform each of the following tasks Write down your final answers in the following table. (Otherwise it will

image text in transcribedimage text in transcribedimage text in transcribed

Q3(15 points). Write a short code to perform each of the following tasks Write down your final answers in the following table. (Otherwise it will be discarded) Write a simple function to debounce a push button connected to RA4 (the release of the button will indicate that a button was pushed) A push button is connected to RB7 write the code to setup an interrupt every time the button is pushed Write a short code to set timer1 to generate an interrupt every 20 ms assume external crystal oscillator of 8MHz Q4(25 points). Suppose that they need to rebuild the city Bridge. This construction requires closing one lane of the bridge, making it a one-way bridge. Traffic may only cross the bridge in one direction at a time. This construction also will weaken the bridge, limiting its capacity to at most MAX_CARS vehicles. (e.g., try MAX_CARS = 3.) In your system, each vehicle should be represented by a thread, which executes the function OneVehicle(direction) when it arrives at the bridge. OneVehicle (direction) { ArriveBridge (direction); OnBridge (direction); ExitBridge (direction); } direction should be TO_CITY or FROM_CITY. (You may certainly add other arguments, or collapse this all into a general argument structure, as appropriate.) ArriveBridge must not return until it is safe for the car to get on the bridge. OnBridge should, as a side-effect, print the state of the bridge and waiting cars, in some nice format, to make it easier to monitor the behavior of the system. (So.... Watch out for race conditions here, too!) Basic Requirements Safety. Your simulation should always prohibit "bad interleavings" where: . cars going opposite directions crash on the bridge. the bridge collapses, because too many cars were on it. Liveness. Your simulation should also ensure that: Basic Requirements Safety. Your simulation should always prohibit "bad interleavings" where: cars going opposite directions crash on the bridge. the bridge collapses, because too many cars were on it. Liveness. Your simulation should also ensure that: if a car gets on the bridge, it will eventually cross and get off if cars are waiting, and the bridge is empty, a car will get on 1. You should implement this system under Linux using pthreads 2. When a new car gets on the bridge you should print the number of cars on the bridge and the number of cars waiting for each direction 3. You should have a thread that keeps generating more cars with random directions

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago