#include "teal.h" using namespace teal; struct thread_context { thread_context (const std::string& p) : path(p), log (p), condition_ (new teal::condition("semaphore test")) {} std::string path; vout log; teal::condition* condition_; }; void* monitor (void* c) { reg counter_prev(0,4); bool prev_initialized = false; thread_context* context = static_cast (c); vreg counter_out (context->path + ".U_counter.counter_out"); vreg clock (context->path + ".U_counter.clock"); condition* my_condition = context->condition_; while (1) { at(posedge(clock)); context->log << "Current number is: " << counter_out << endm; if ( prev_initialized && (counter_prev + 1) != counter_out) context->log << teal_error << "Values are not consecutive, prev = " << counter_prev << " and current = " << counter_out << endm; counter_prev = counter_out; prev_initialized = true; } return 0; } void verification_top () { file_vlog not_used = file_vlog (teal::dictionary::find ("out_file"), dictionary::find ("interactive", true)); vreg clock("top.clock"); vreg reset("top.reset"); vreg enable("top.enable"); vreg load_en("top.load_en"); vreg load_data("top.load_data"); vreg counter_out("top.counter_out"); vout log("counter_load_test"); //log << teal_error << "Start of verification_top" << endm; // reset sequence reset = 1; int reset_count = 5; for ( int i(0); i < reset_count; i++ ) at (posedge(clock)); reset = 0; // end of reset sequence // enable sequence enable = 0; int enable_count = 3; for ( int i(0); i < enable_count; i++ ) at (posedge(clock)); enable = 1; // enable sequence log << "End of enable sequence" << endm; thread_context context ("top"); pthread_t monitor_thread = start_thread (monitor, &context, "counter_monitor"); int count_number = 17; for (int j(0); j < count_number; j++ ) { at (posedge(clock)); } load_en = 1; load_data = 7; at (posedge(clock)); log << "Load asserted with value " << load_data << endm; load_en = 0; count_number = 5; for (int j(0); j < count_number; j++ ) { at (posedge(clock)); } stop_thread (monitor_thread); if (vlog::get().how_many (vlog::error)) { log << teal_info << "Test Failed: Contained " << dec << vlog::get().how_many (vlog::error) << " errors." << endm; } else { log << teal_info << "Test Passed. " << endm; } vreg finish("top.test_end"); finish = 1; } #include "../teal_hdl_connect.cpp"