ext/bridge.c in origen_sim-0.5.5 vs ext/bridge.c in origen_sim-0.6.0

- old
+ new

@@ -2,10 +2,11 @@ /// This implements the bridge between Origen and the simulation, it implements a /// simple string-based message protocol for communicating between the two domains /// #include "bridge.h" #include "client.h" +#include "defines.h" #include <stdint.h> #include <stdlib.h> #include <stdio.h> #include <stdbool.h> #include <string.h> @@ -37,11 +38,11 @@ Event events[MAX_WAVE_EVENTS]; Pin *active_pins[MAX_NUMBER_PINS]; int active_pin_count; } Wave; -static int period_in_ns; +static uint64_t period_in_ps; static long repeat = 0; static Pin pins[MAX_NUMBER_PINS]; static int number_of_pins = 0; // Allocate space for a unique wave for each pin, in reality it will be much less static Wave drive_waves[MAX_NUMBER_PINS]; @@ -259,11 +260,11 @@ } static void bridge_set_period(char * p_in_ns) { int p = (int) strtol(p_in_ns, NULL, 10); - period_in_ns = p; + period_in_ps = p * 1000; bridge_clear_waves_and_pins(); } static bool bridge_is_drive_whole_cycle(Pin * pin) { @@ -470,10 +471,11 @@ } /// Registers a callback to apply the given wave during this cycle static void bridge_register_wave_event(int wave_ix, int event_ix, int compare, int delay_in_ns) { + uint64_t delay_in_ps = delay_in_ns * 1000; s_cb_data call; s_vpi_time time; // This will get freed by the callback char * user_data = (char *) malloc((sizeof(int) * 3)); @@ -485,13 +487,14 @@ *d0 = wave_ix; *d1 = event_ix; *d2 = compare; time.type = vpiSimTime; - time.high = (uint32_t)(0); - time.low = (uint32_t)(delay_in_ns); + time.high = (uint32_t)(delay_in_ps >> 32); + time.low = (uint32_t)(delay_in_ps); + call.reason = cbAfterDelay; call.cb_rtn = bridge_apply_wave_event_cb; call.obj = 0; call.time = &time; call.value = 0; @@ -510,11 +513,11 @@ /// Waits and responds to instructions from Origen (to set pin states). /// When Origen requests a cycle, time will be advanced and this func will be called again. PLI_INT32 bridge_wait_for_msg(p_cb_data data) { UNUSED(data); - int max_msg_len = 100; + int max_msg_len = 1024; char msg[max_msg_len]; int err; char *opcode, *arg1, *arg2, *arg3, *arg4; vpiHandle handle; s_vpi_value v; @@ -644,12 +647,14 @@ // 9^origen.debug.errors case '9' : arg1 = strtok(NULL, "^"); handle = vpi_handle_by_name(arg1, NULL); if (handle) { - v.format = vpiDecStrVal; // Seems important to set this before get + //v.format = vpiDecStrVal; // Seems important to set this before get + v.format = vpiBinStrVal; vpi_get_value(handle, &v); + //DEBUG("%s\n", v.value.str); sprintf(msg, "%s\n", v.value.str); client_put(msg); } else { client_put("FAIL\n"); } @@ -724,10 +729,15 @@ // h^14 case 'h' : arg1 = strtok(NULL, "^"); bridge_stop_capture_pin(arg1); break; + // Get version, returns the version of OrigenSim the DUT object was compiled with + // i^ + case 'i' : + client_put(ORIGEN_SIM_VERSION"\n"); + break; default : vpi_printf("ERROR: Illegal message received from Origen: %s\n", orig_msg); runtime_errors += 1; end_simulation(); return 1; @@ -766,11 +776,11 @@ static void bridge_cycle() { s_cb_data call; s_vpi_time time; time.type = vpiSimTime; - time.high = (uint32_t)(0); - time.low = (uint32_t)(period_in_ns); + time.high = (uint32_t)(period_in_ps >> 32); + time.low = (uint32_t)(period_in_ps); call.reason = cbAfterDelay; call.obj = 0; call.time = &time; call.value = 0;