Skip to content

Commit

Permalink
liboni version 3.1
Browse files Browse the repository at this point in the history
- Update functions that take a dev_idx arguement to reference to the
true device index (XX.XX.hub.idx) rather than index in the device table.
I'm not considering this an API breaking change because the function
signatures remain interoperable with 3.0
- Under the hood, to deal with the non-incremental nature of device
indices, I've implemented a hash table to hold the device map from
within the API for quick device access based on dev_idx. see
_oni_reset_routine() and oni_create_frame() for examples
  • Loading branch information
jonnew committed Jun 30, 2020
1 parent b898f63 commit 0a9a556
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 168 deletions.
3 changes: 3 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,6 @@ FakesAssemblies/

# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw

# Dumpfiles
*.raw
2 changes: 1 addition & 1 deletion api/liboni/drivers/riffa/onidriver_riffa.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ const char* oni_driver_str()
static inline oni_conf_off_t _oni_register_offset(oni_config_t reg)
{
switch (reg) {
case ONI_CONFIG_DEVICE_IDX:
case ONI_CONFIG_DEV_IDX:
return CONFDEVIDXOFFSET;
case ONI_CONFIG_REG_ADDR:
return CONFADDROFFSET;
Expand Down
2 changes: 1 addition & 1 deletion api/liboni/drivers/xillybus/onidriver_xillybus.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ const char* oni_driver_str()
static inline oni_conf_off_t _oni_register_offset(oni_config_t reg)
{
switch (reg) {
case ONI_CONFIG_DEVICE_IDX:
case ONI_CONFIG_DEV_IDX:
return CONFDEVIDXOFFSET;
case ONI_CONFIG_REG_ADDR:
return CONFADDROFFSET;
Expand Down
100 changes: 66 additions & 34 deletions api/liboni/liboni-test/host_riffa.c → api/liboni/liboni-test/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "oelogo.h"

// Dump raw device streams to files?
//#define DUMPFILES
#define DUMPFILES

// Turn on RT optimization
#define RT
Expand Down Expand Up @@ -101,7 +101,10 @@ void *read_loop(void *vargp)
#ifdef DUMPFILES
fwrite(frame->data, 1, frame->data_sz, dump_files[frame->dev_idx]);
#endif
if (display && counter % 1000 == 0) {
if (display
&& counter % 1000 == 0) {
//&& devices[frame->dev_idx].id == ONI_TESTREG0) {
//&& devices[frame->dev_idx].id == ONI_TS4231V2ARR) {

oni_device_t this_dev = devices[frame->dev_idx];

Expand All @@ -111,7 +114,7 @@ void *read_loop(void *vargp)
oni_device_str(this_dev.id));
// this_cnt);

int i;
oni_fifo_dat_t i;
printf("\tData: [");
for (i = 0; i < frame->data_sz; i += 2)
printf("%u ", *(uint16_t *)(frame->data + i));
Expand Down Expand Up @@ -154,7 +157,11 @@ void *write_loop(void *vargp)
// Pre-allocate write frame
// TODO: hardcoded dev_idx not good
oni_frame_t *w_frame = NULL;
oni_create_frame(ctx, &w_frame, 8, 4);
int rc = oni_create_frame(ctx, &w_frame, 7, 24);
if (rc < 0) {
printf("Error: %s\n", oni_error_str(rc));
goto error;
}

// Loop count
uint32_t count = 0;
Expand All @@ -166,15 +173,18 @@ void *write_loop(void *vargp)
out_count++;

int rc = oni_write_frame(ctx, w_frame);
if (rc < 0) { printf("Error: %s\n", oni_error_str(rc)); }
if (rc < 0) {
printf("Error: %s\n", oni_error_str(rc));
goto error;
}

count++;

Sleep(1);
}

oni_destroy_frame(w_frame);

error:
oni_destroy_frame(w_frame);
return NULL;
}

Expand Down Expand Up @@ -233,33 +243,51 @@ void stop_threads()
void print_dev_table(oni_device_t *devices, int num_devs)
{
// Show device table
printf("+-------+-------+-------+-------+-------+-------+------\n");
printf("| \t| \t|Read\t|Reads/\t|Wrt.\t|Wrt./ \t| \n");
printf("|Index\t|ID\t|size\t|frame \t|size\t|frame \t|Desc.\n");
printf("+-------+-------+-------+-------+-------+-------+------\n");
printf(
" "
"+------------------+-------+-------+-------+-------+-------+-----\n");
printf(" | \t\t| \t|Read\t|Reads/\t|Wrt.\t|Wrt./ \t| \n");
printf(" |Dev. idx\t\t|ID\t|size\t|frame \t|size\t|frame \t|Desc.\n");
printf("+----+------------------+-------+-------+-------+-------+-------+-----\n");

size_t dev_idx;
for (dev_idx = 0; dev_idx < num_devs; dev_idx++) {

const char *dev_str = oni_device_str(devices[dev_idx].id);

printf("|%zd\t|%d\t|%u\t|%u\t|%u\t|%u\t|%s\n",
dev_idx,
devices[dev_idx].id,
devices[dev_idx].read_size,
devices[dev_idx].num_reads,
devices[dev_idx].write_size,
devices[dev_idx].num_writes,
dev_str);
printf("|%02zd |%05zd: 0x%02x.0x%02x\t|%d\t|%u\t|%u\t|%u\t|%u\t|%s\n",
dev_idx,
devices[dev_idx].idx,
(uint8_t)(devices[dev_idx].idx >> 8),
(uint8_t)devices[dev_idx].idx,
devices[dev_idx].id,
devices[dev_idx].read_size,
devices[dev_idx].num_reads,
devices[dev_idx].write_size,
devices[dev_idx].num_writes,
dev_str);
}

printf("+-------+-------+-------+-------+-------+-------+------\n");
printf("+----+-------------------+-------+-------+-------+-------+-------+-----\n");
}

int main(int argc, char *argv[])
{
printf(oe_logo_med);

int host_idx = 0;
char *driver;

if (argc != 2 && argc != 3) {
printf("usage:\n");
printf("\thost driver [host_index] ...\n");
exit(1);
}

driver = argv[1];

printf(logo_med);
if (argc == 3)
host_idx = atoi(argv[2]);

#if defined(_WIN32) && defined(RT)
if (!SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)) {
Expand All @@ -277,7 +305,7 @@ int main(int argc, char *argv[])
ctx = oni_create_ctx("riffa");
if (!ctx) { printf("Failed to create context\n"); exit(EXIT_FAILURE); }

// Set acqusition to run immediately following reset
// Set acquisition to run immediately following reset
oni_reg_val_t immediate_run = 0;
rc = oni_set_opt(ctx, ONI_OPT_RUNONRESET, &immediate_run, sizeof(oni_reg_val_t));
if (rc) { printf("Error: %s\n", oni_error_str(rc)); }
Expand All @@ -287,30 +315,30 @@ int main(int argc, char *argv[])
if (rc) { printf("Error: %s\n", oni_error_str(rc)); }
assert(rc == 0);

// Examine device map
// Examine device table
size_t num_devs_sz = sizeof(num_devs);
oni_get_opt(ctx, ONI_OPT_NUMDEVICES, &num_devs, &num_devs_sz);

// Get the device map
// Get the device table
size_t devices_sz = sizeof(oni_device_t) * num_devs;
devices = (oni_device_t *)realloc(devices, devices_sz);
if (devices == NULL) { exit(EXIT_FAILURE); }
oni_get_opt(ctx, ONI_OPT_DEVICEMAP, devices, &devices_sz);
oni_get_opt(ctx, ONI_OPT_DEVICETABLE, devices, &devices_sz);

#ifdef DUMPFILES
// Make room for dump files
dump_files = malloc(num_devs * sizeof(FILE *));

// Open dump files
for (int i = 0; i < num_devss; i++) {
for (size_t i = 0; i < num_devs; i++) {
char * buffer = malloc(100);
snprintf(buffer, 100, "%s_idx-%zd_id-%d.raw", "dev", dev_idx, devices[i].id);
snprintf(buffer, 100, "%s_idx-%zd_id-%d.raw", "dev", i, devices[i].id);
dump_files[i] = fopen(buffer, "wb");
free(buffer);
}
#endif

// Show device map
// Show device table
print_dev_table(devices, num_devs);

oni_size_t frame_size = 0;
Expand Down Expand Up @@ -345,7 +373,7 @@ int main(int argc, char *argv[])
assert(!rc && "Register read failure.");
printf("System clock rate: %u Hz\n", base_hz);

// Start acqusition
// Start acquisition
start_threads();

// Read stdin to start (s) or pause (p)
Expand Down Expand Up @@ -413,7 +441,8 @@ int main(int argc, char *argv[])
oni_size_t addr = (oni_size_t)values[1];
oni_size_t val = (oni_size_t)values[2];

oni_write_reg(ctx, dev_idx, addr, val);
rc = oni_write_reg(ctx, dev_idx, addr, val);
printf("%s\n", oni_error_str(rc));
}
else if (c == 'r') {
printf("Read a device register.\n");
Expand All @@ -436,9 +465,12 @@ int main(int argc, char *argv[])
oni_size_t addr = (oni_size_t)values[1];

oni_reg_val_t val = 0;
oni_read_reg(ctx, dev_idx, addr, &val);

printf("Reg. value: %u\n", val);
rc = oni_read_reg(ctx, dev_idx, addr, &val);
if (!rc) {
printf("Reg. value: %u\n", val);
} else {
printf("%s\n", oni_error_str(rc));
}
}
else if (c == 's') {

Expand All @@ -455,7 +487,7 @@ int main(int argc, char *argv[])

#ifdef DUMPFILES
// Close dump files
for (dev_idx = 0; dev_idx < num_devs; dev_idx++) {
for (int dev_idx = 0; dev_idx < num_devs; dev_idx++) {
fclose(dump_files[dev_idx]);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion api/liboni/liboni-test/liboni-test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="host_riffa.c" />
<ClCompile Include="host.c" />
<ClCompile Include="testfunc.c" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion api/liboni/liboni-test/liboni-test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ClCompile Include="testfunc.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="host_riffa.c">
<ClCompile Include="host.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions api/liboni/liboni.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<ClCompile>
<CompileAs>CompileAsC</CompileAs>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBONI_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>Default</LanguageStandard>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion api/liboni/oelogo.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __OELOGO_H__
#define __OELOGO_H__

const char logo_med[] =
const char oe_logo_med[] =
" \n"
" Jon Newman @ MIT ** \n"
" Jie Zhang @ MIT //// \n"
Expand Down
Loading

0 comments on commit 0a9a556

Please sign in to comment.