// Generate pulses for speedometer and odometers. void gen_pulse_mod::gen_pulse_proc() { wait(); speed_pulse = false; dist_pulse = false; // Wait until the car is started. // do { wait(); } while (start == true); do { wait(); } while (start == false); while (true) { speed_pulse = true; dist_pulse = true; AWAIT(find_period(speed)); speed_pulse = false; dist_pulse = false; AWAIT(find_period(speed)); } }
// Compute speed. void speed_mod::read_speed_proc() { wait(); double speed = 0.0; while (true) { // More than one pulse is needed to compute a distance and // consequently, speed. This function collects NUM_PULSES_FOR_SPEED // pulses for that purpose. AWAIT(NUM_PULSES_FOR_SPEED); speed = DIST_BETWEEN_TWO_PULSES * PERIODS_PER_HOUR / elapsed_time; // Reset timer. elapsed_time = 0; cout << "Current speed displayed = " << speed << " km/h @ " << sc_time_stamp() << endl; cout << "Current speedometer angle = " << speed * MAX_ANGLE / MAX_SPEED << " degrees @ " << sc_time_stamp() << endl; } }
int main(void) { mailbox_t *m; m = AWAIT(mb1 | mb2 | mb4); if (m == (mailbox_t *)mb3) __CPROVER_assert(0, "E"); return 0; }
// Get the pulses for one distance increment. void dist_mod::get_dist_proc() { wait(); while (true) { // More than one pulse is needed for a distance increment. This // function collects NUM_PULSES_FOR_DIST_INCR pulses for that // purpose. AWAIT(NUM_PULSES_FOR_DIST_INCR); if (start) ok_for_incr = (ok_for_incr ? false : true); else ok_for_incr = false; } }
// Compute speed. void speed_read_mod::read_speed_proc() { wait(); while (true) { // More than one pulse is needed to compute a distance and // consequently, speed. This function collects NUM_PULSES_FOR_SPEED // pulses for that purpose. AWAIT(NUM_PULSES_FOR_SPEED); if (start) raw_speed = DIST_BETWEEN_TWO_PULSES * PERIODS_PER_HOUR / elapsed_time; else raw_speed = 0.0; // Reset timer. elapsed_time = 0; } }