Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TOOL_DIRS = simer benchmark
################
## DSE Projects.
DSE_CLIB_REPO ?= https://github.com/boschglobal/dse.clib
DSE_CLIB_VERSION ?= 1.1.2
DSE_CLIB_VERSION ?= 1.1.5
export DSE_CLIB_URL ?= $(DSE_CLIB_REPO)/archive/refs/tags/v$(DSE_CLIB_VERSION).zip

DSE_SCHEMA_REPO ?= https://github.com/boschglobal/dse.schemas
Expand Down
7 changes: 5 additions & 2 deletions dse/mocks/simmock.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,11 @@ void simmock_setup(SimMock* mock, const char* sig_name, const char* net_name)
if (model->sv_signal) {
ModelFunction* mf = controller_get_model_function(
model->mi, model->sv_signal->function_name);
model->mfc_signal =
hashmap_get(&mf->channels, model->sv_signal->name);
ModelFunctionChannelIndexItem* item = vector_find(&mf->channels,
&(ModelFunctionChannelIndexItem){
.name = model->sv_signal->name, .mfc = NULL },
0, NULL);
model->mfc_signal = item ? item->mfc : NULL;
model->sm_signal =
calloc(model->sv_signal->count, sizeof(SignalMap));
for (uint32_t i = 0; i < model->sv_signal->count; i++) {
Expand Down
81 changes: 42 additions & 39 deletions dse/modelc/adapter/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,25 @@ SignalMap* adapter_get_signal_map(AdapterModel* am, const char* channel_name,
}


static void _update_channels_keys(AdapterModel* am)
AdapterModel* adapter_get_model(Adapter* adapter, uint32_t model_uid)
{
if (am->channels_keys) {
for (uint32_t _ = 0; _ < am->channels_length; _++)
free(am->channels_keys[_]);
free(am->channels_keys);
am->channels_keys = NULL;
}
am->channels_keys = hashmap_keys(&am->channels);
am->channels_length = hashmap_number_keys(am->channels);
AdapterModelIndexItem* idx = vector_find(&adapter->models,
&(AdapterModelIndexItem){ .uid = model_uid, .am = NULL }, 0, NULL);
return idx ? idx->am : NULL;
}

static Channel* _create_channel(AdapterModel* am, const char* channel_name)
{
assert(am);

Channel* ch = hashmap_get(&am->channels, channel_name);
if (ch) {
assert(ch->name == channel_name);
return ch;
ChannelIndexItem* item = vector_find(&am->channels,
&(ChannelIndexItem){ .name = channel_name, .ch = NULL }, 0, NULL);
if (item) {
assert(item->ch->name == channel_name);
return item->ch;
}
/* Create a new Channel object. */
ch = calloc(1, sizeof(Channel));
Channel* ch = calloc(1, sizeof(Channel));
ch->name = channel_name;
int rc = hashmap_init(&ch->signal_values);
if (rc) {
Expand All @@ -75,18 +71,18 @@ static Channel* _create_channel(AdapterModel* am, const char* channel_name)
am->adapter->endpoint, ch->name);
}
}
/* Allocate index objects.*/
hashmap_init(&ch->index.uid2sv_lookup);

/* Add the new Channel to the hashmap. */
if (hashmap_set(&am->channels, ch->name, ch)) {
_update_channels_keys(am);
return ch;
}
log_error("Adapter _create_channel failed to create new Channel object!");
goto error_clean_up;
/* Allocate index objects. Initialize uid vector for lookups. */
ch->index.uid2sv_lookup =
vector_make(sizeof(SignalValueIndexItem), 0, adapter_uid2sv_compar);

/* Add the new Channel to the lookup vector. */
ChannelIndexItem new_item = { .name = ch->name, .ch = ch };
vector_push(&am->channels, &new_item);
vector_sort(&am->channels);
return ch;

error_clean_up:
vector_reset(&ch->index.uid2sv_lookup);
free(ch);
return NULL;
}
Expand All @@ -100,6 +96,8 @@ Channel* adapter_init_channel(AdapterModel* am, const char* channel_name,
Channel* ch = _create_channel(am, channel_name);
assert(ch);
ch->mfc = mfc;
ch->is_binary =
mfc && ((ModelFunctionChannel*)mfc)->signal_value_binary != NULL;

/* Initialise the Signal properties. */
for (uint32_t i = 0; i < signal_count; i++) {
Expand Down Expand Up @@ -259,13 +257,12 @@ static void _destroy_signal_value(void* map_item, void* data)

void adapter_destroy_adapter_model(AdapterModel* am)
{
if (am && am->channels_length) {
for (uint32_t i = 0; i < am->channels_length; i++) {
if (am && vector_len(&am->channels)) {
for (uint32_t i = 0; i < vector_len(&am->channels); i++) {
Channel* ch = _get_channel_byindex(am, i);
hashmap_destroy_ext(
&ch->signal_values, _destroy_signal_value, NULL);
_destroy_index(ch);
hashmap_destroy(&ch->index.uid2sv_lookup);
if (ch->model_register_set) {
set_destroy(ch->model_register_set);
free(ch->model_register_set);
Expand All @@ -276,13 +273,7 @@ void adapter_destroy_adapter_model(AdapterModel* am)
}
free(ch);
}
hashmap_destroy(&am->channels);
if (am->channels_keys) {
for (uint32_t _ = 0; _ < am->channels_length; _++)
free(am->channels_keys[_]);
}
free(am->channels_keys);
am->channels_length = 0;
vector_reset(&am->channels);
}
free(am);
}
Expand All @@ -291,7 +282,7 @@ void adapter_destroy(Adapter* adapter)
{
if (adapter == NULL) return;

hashmap_destroy(&adapter->models);
vector_reset(&adapter->models);
if (adapter->endpoint) {
Endpoint* endpoint = adapter->endpoint;
endpoint->disconnect(endpoint);
Expand Down Expand Up @@ -336,11 +327,11 @@ void adapter_model_dump_debug(AdapterModel* am, const char* name)
log_simbus("model_uid : %u", am->model_uid);
log_simbus("model_time : %f", am->model_time);
log_simbus("stop_time : %f", am->stop_time);
log_simbus("channel_count : %u", am->channels_length);
log_simbus("channel_count : %u", vector_len(&am->channels));
log_simbus("----------------");
log_simbus("Channel Objects:");
log_simbus("----------------");
for (uint32_t channel_index = 0; channel_index < am->channels_length;
for (uint32_t channel_index = 0; channel_index < vector_len(&am->channels);
channel_index++) {
Channel* ch = _get_channel_byindex(am, channel_index);
_refresh_index(ch);
Expand All @@ -350,9 +341,21 @@ void adapter_model_dump_debug(AdapterModel* am, const char* name)
log_simbus(" signal_count : %u", ch->index.count);
log_simbus(" signal_value :");
for (uint32_t i = 0; i < ch->index.count; i++) {
SignalValue* sv = ch->index.map[i].signal;
SignalValue* sv = ch->index.map[i].signal;
double value = sv->val;
double final_value = sv->final_val;
ModelFunctionChannel* mfc = ch->mfc;
if (mfc != NULL && mfc->scalar_sync.enabled &&
mfc->signal_names != NULL && mfc->signal_value_double != NULL) {
for (uint32_t local = 0; local < mfc->signal_count; local++) {
if (strcmp(mfc->signal_names[local], sv->name) == 0) {
value = final_value = mfc->signal_value_double[local];
break;
}
}
}
log_simbus(" [%u] uid=%u, val=%f, final_val=%f, name=%s", i,
sv->uid, sv->val, sv->final_val, sv->name);
sv->uid, value, final_value, sv->name);
}
}
}
Expand Down
55 changes: 48 additions & 7 deletions dse/modelc/adapter/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#ifdef _WIN32
#include <winsock2.h>
Expand All @@ -20,6 +21,7 @@
#endif
#include <dse/clib/collections/set.h>
#include <dse/clib/collections/hashmap.h>
#include <dse/clib/collections/vector.h>
#include <dse/modelc/adapter/transport/endpoint.h>
#include <dse/modelc/model.h>
#include <dse/platform.h>
Expand Down Expand Up @@ -53,6 +55,11 @@ typedef struct AdapterVTable {
AdapterStart start;
AdapterExit exit;
AdapterDestroy destroy;

/* Mode indicator. */
struct {
bool flat_scalar;
} mode;
} AdapterVTable;

typedef AdapterVTable* (*AdapterVTableCreate)(void);
Expand Down Expand Up @@ -81,11 +88,31 @@ typedef struct SignalMap {
SignalValue* signal;
} SignalMap;

typedef struct SignalValueIndexItem {
uint32_t uid;
SignalValue* sv;
} SignalValueIndexItem;

typedef struct AdapterModelIndexItem {
uint32_t uid;
AdapterModel* am;
} AdapterModelIndexItem;

static __inline__ int adapter_uid2am_compar(const void* a, const void* b)
{
const AdapterModelIndexItem* x = a;
const AdapterModelIndexItem* y = b;
if (x->uid < y->uid) return -1;
if (x->uid > y->uid) return 1;
return 0;
}


typedef struct Channel {
const char* name;
void* endpoint_channel; // Reference to an Endpoint object.
void* mfc; // Reference to ModelFunctionChannel object.
bool is_binary;

/* Signal properties. */
HashMap signal_values; // map{name:SignalValue}
Expand All @@ -96,8 +123,8 @@ typedef struct Channel {
uint32_t hash_code;
/* Map used by _this_ channel (contains all signals). */
SignalMap* map;
/* Hashmap Lookup. */
HashMap uid2sv_lookup;
/* Vector Lookup. */
Vector uid2sv_lookup; // vector{SignalValueIndexItem}
} index;

/* Bus properties. */
Expand All @@ -106,6 +133,18 @@ typedef struct Channel {
uint32_t expected_model_count;
} Channel;

typedef struct ChannelIndexItem {
const char* name;
Channel* ch;
} ChannelIndexItem;

static __inline__ int adapter_name2ch_compar(const void* a, const void* b)
{
const ChannelIndexItem* x = a;
const ChannelIndexItem* y = b;
return strcmp(x->name, y->name);
}


typedef struct AdapterModel {
/* Model properties. */
Expand All @@ -114,9 +153,7 @@ typedef struct AdapterModel {
double stop_time;

/* Channel properties. */
HashMap channels; // map{name: Channel}.
char** channels_keys;
uint32_t channels_length;
Vector channels; // vector{ChannelIndexItem}

/* Reference objects. */
Adapter* adapter;
Expand All @@ -128,8 +165,9 @@ typedef struct AdapterModel {


typedef struct Adapter {
bool stop_request;
HashMap models; // map{uid:AdapterModel}
bool stop_request;
bool sequential_cosim;
Vector models; // vector{AdapterModelIndexItem}

/* Adapter vtable, type may be extended. */
AdapterVTable* vtable;
Expand Down Expand Up @@ -191,6 +229,9 @@ DLL_PRIVATE SignalMap* adapter_get_signal_map(AdapterModel* am,
const char* channel_name, const char** signal_name, uint32_t signal_count);
DLL_PRIVATE void adapter_dump_debug(Adapter* adapter, SimulationSpec* sim);
DLL_PRIVATE void adapter_model_dump_debug(AdapterModel* am, const char* name);
DLL_PRIVATE int adapter_uid2sv_compar(const void* a, const void* b);
DLL_PRIVATE AdapterModel* adapter_get_model(
Adapter* adapter, uint32_t model_uid);

/* adapter_msg.c */
DLL_PUBLIC AdapterVTable* adapter_create_msg_vtable(void);
Expand Down
Loading
Loading