Skip to content

Commit

Permalink
Some fixes to ft600 onidriver
Browse files Browse the repository at this point in the history
  • Loading branch information
aacuevas committed Dec 18, 2023
1 parent 0f2de1c commit 31523a8
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 76 deletions.
4 changes: 2 additions & 2 deletions api/liboni/drivers/ft600/circbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//This buffer and its functions should be thread safe as long as only one thread
//writes and only one thread reads
typedef struct {
size_t read;
size_t write;
volatile size_t read;
volatile size_t write;
size_t size;
uint8_t* buffer;
} circ_buffer_t;
Expand Down
113 changes: 71 additions & 42 deletions api/liboni/drivers/ft600/onidriver_ft600.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct oni_ft600_ctx_impl {
uint8_t* auxBuffer;
size_t auxSize;
uint32_t prioValue;
oni_ft600_state state;
volatile oni_ft600_state state;
oni_ft600_sigstate sigState;
unsigned short sigOffset;
unsigned short sigError;
Expand Down Expand Up @@ -180,18 +180,26 @@ void oni_ft600_usb_callback(PVOID context, E_FT_NOTIFICATION_CALLBACK_TYPE type,
if (!info) return;
oni_ft600_ctx ctx = (oni_ft600_ctx)context;
ULONG transferred;
ULONG total = 0;


do {
FT_ReadPipe(ctx->ftHandle,
info->ucEndpointNo,
ctx->auxBuffer + total,
info->ulRecvNotificationLength - total,
&transferred,
&ctx->sigOverlapped);
ftStatus = FT_GetOverlappedResult(
ctx->ftHandle, &ctx->sigOverlapped, &transferred, TRUE);
if (ftStatus != FT_OK) {
ctx->sigError = 1;
return;
}
total += transferred;
} while (total < info->ulRecvNotificationLength);

FT_ReadPipe(ctx->ftHandle, info->ucEndpointNo, ctx->auxBuffer, info->ulRecvNotificationLength, &transferred, &ctx->sigOverlapped);
ftStatus = FT_GetOverlappedResult(ctx->ftHandle, &ctx->sigOverlapped, &transferred, TRUE);
if (ftStatus != FT_OK)
{
ctx->sigError = 1;
return;
}

if (transferred > 0)
if (total > 0)
{
fill_control_buffers(ctx, transferred);
}
Expand Down Expand Up @@ -529,6 +537,8 @@ int oni_driver_read_stream(oni_driver_ctx driver_ctx,
}
else if (stream == ONI_READ_STREAM_DATA)
{
while (ctx->state != STATE_RUNNING)
;
size_t remaining = ((size >> 2) << 2);//round to 32bit boundaries;
FT_STATUS ftStatus;
int read = 0;
Expand All @@ -549,37 +559,55 @@ int oni_driver_read_stream(oni_driver_ctx driver_ctx,
dstPtr += to_read;
read += to_read;
}
while (remaining > 0)
{
unsigned int simIndex = ctx->nextReadIndex % ctx->numInOverlapped;
unsigned int nextIndex = (ctx->nextReadIndex + ctx->numInOverlapped) % (2 * ctx->numInOverlapped);
ULONG transferred;
ftStatus = FT_GetOverlappedResult(ctx->ftHandle, &ctx->inOverlapped[simIndex], &ctx->inTransferred[simIndex], TRUE);
if (ftStatus != FT_OK)
{
printf("Read failure %d\n", ftStatus);
return ONI_EREADFAILURE;
}
transferred = ctx->inTransferred[simIndex];
//read in the next part of the double buffer
FT_ReadPipeEx(ctx->ftHandle, pipe_in, ctx->inBuffer + ((size_t)nextIndex * ctx->inBlockSize), ctx->inBlockSize,
&ctx->inTransferred[simIndex], &ctx->inOverlapped[simIndex]);
srcPtr = ctx->inBuffer + ctx->inBlockSize * (size_t)ctx->nextReadIndex;
to_read = MIN(remaining, transferred);
memcpy(dstPtr, srcPtr, to_read);
// for (int i = 0; i < to_read; i++) printf("%x ", *(dstPtr + i));
remaining -= to_read;
dstPtr += to_read;
read += to_read;
ctx->nextReadIndex = (ctx->nextReadIndex + 1) % (2 * ctx->numInOverlapped);
if (to_read < transferred)
{
ctx->lastReadRead = transferred;
ctx->lastReadOffset = to_read;
}
else
ctx->lastReadOffset = 0;
}
while (remaining > 0) {
unsigned int simIndex = ctx->nextReadIndex % ctx->numInOverlapped;
unsigned int nextIndex = (ctx->nextReadIndex + ctx->numInOverlapped)
% (2 * ctx->numInOverlapped);
ULONG transferred;
ftStatus = FT_GetOverlappedResult(ctx->ftHandle,
&ctx->inOverlapped[simIndex],
&ctx->inTransferred[simIndex],
TRUE);
if (ftStatus != FT_OK) {
printf("Read failure %d\n", ftStatus);
return ONI_EREADFAILURE;
}
transferred = ctx->inTransferred[simIndex];
// read in the next part of the double buffer
FT_ReadPipeEx(ctx->ftHandle,
pipe_in,
ctx->inBuffer
+ ((size_t)nextIndex * ctx->inBlockSize),
ctx->inBlockSize,
&ctx->inTransferred[simIndex],
&ctx->inOverlapped[simIndex]);
// printf("R: %d\n", nextIndex);
srcPtr
= ctx->inBuffer + ctx->inBlockSize * (size_t)ctx->nextReadIndex;
to_read = MIN(remaining, transferred);
/* printf("\n%d - %d - %d - %d\n",
ctx->nextReadIndex,
nextIndex,
simIndex,
to_read);*/
memcpy(dstPtr, srcPtr, to_read);
/* for (int i = 0; i < to_read; i++)
printf("%x ", *(dstPtr + i));
printf("\n");
for (int i = 0; i < to_read; i++) printf("%x ", *(srcPtr +
i));*/
remaining -= to_read;
dstPtr += to_read;
read += to_read;
ctx->nextReadIndex
= (ctx->nextReadIndex + 1) % (2 * ctx->numInOverlapped);
if (to_read < transferred) {
ctx->lastReadRead = transferred;
ctx->lastReadOffset = to_read;
} else {
ctx->lastReadOffset = 0;
}
}
#else
ULONG transferred;
uint8_t* dstPtr = (uint8_t*)data;
Expand Down Expand Up @@ -738,12 +766,13 @@ int oni_driver_read_config(oni_driver_ctx driver_ctx, oni_config_t reg, oni_reg_

inline void oni_ft600_start_acq(oni_ft600_ctx ctx)
{
#if _WIN32
#if _WIN32
FT_STATUS rc;
rc = FT_SetStreamPipe(ctx->ftHandle, FALSE, FALSE, pipe_in, ctx->inBlockSize);
for (size_t i = 0; i < ctx->numInOverlapped; i++)
{
FT_ReadPipeEx(ctx->ftHandle, pipe_in, ctx->inBuffer + (i * ctx->inBlockSize), ctx->inBlockSize, &ctx->inTransferred[i], &ctx->inOverlapped[i]);
//printf("R: %d\n", i);
}
#endif
ctx->state = STATE_RUNNING;
Expand Down
8 changes: 4 additions & 4 deletions api/liboni/drivers/ft600/onidriver_ft600.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions api/liboni/drivers/riffa/onidriver_riffa.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions api/liboni/drivers/test/onidriver_test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions api/liboni/drivers/xillybus/onidriver_xillybus.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
Expand Down
8 changes: 4 additions & 4 deletions api/liboni/liboni-test/liboni-test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions api/liboni/liboni.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down
8 changes: 4 additions & 4 deletions api/liboni/onix-loadtest/onix-loadtest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 31523a8

Please sign in to comment.