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
57 changes: 48 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.22...4.1)

project(libtslitex)

Expand All @@ -19,12 +19,49 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # error if compiler doesn't support c++17
set(CMAKE_CXX_EXTENSIONS ON)

################################
# Project Dependencies
################################
include(FetchContent)

# json-c Library
FetchContent_Declare(
json_c
GIT_REPOSITORY https://github.com/json-c/json-c
GIT_TAG 2372e9518e6ba95b48d37ec162bc7d93b297b52f
FIND_PACKAGE_ARGS NAMES json-c
)

set(BUILD_SHARED_LIBS OFF)
FetchContent_MakeAvailable(json_c)

# zlib Library
FetchContent_Declare(
zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.3.1
FIND_PACKAGE_ARGS NAMES zlib
)

set(ZLIB_BUILD_TESTING OFF)
set(ZLIB_BUILD_SHARED OFF)
set(ZLIB_INSTALL OFF)
FetchContent_MakeAvailable(zlib)



set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/artifacts/libtslitex")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/artifacts/libtslitex")

add_definitions(-DUNICODE -D_UNICODE)
option(ENABLE_FACTORY_PROVISIONING "Include Factory Provisioning Functions" OFF)

if(ENABLE_FACTORY_PROVISIONING)
add_compile_definitions(FACTORY_PROVISIONING_API)
endif()

add_compile_definitions(UNICODE _UNICODE)

add_definitions(-DEN_LOGGING)
add_compile_definitions(EN_LOGGING)

add_compile_definitions("$<$<CONFIG:Debug>:EN_LOGGING_DEBUG>")

Expand All @@ -49,6 +86,7 @@ set(TS_SOURCES
src/samples.c
src/spiflash.c
src/ts_channel.c
src/ts_data.c
src/ts_fw_manager.c
src/thunderscope.c
)
Expand All @@ -69,6 +107,7 @@ set(TS_HEADERS
src/samples.h
src/spiflash.h
src/ts_channel.h
src/ts_data.h
src/ts_fw_manager.h
src/util.h
)
Expand All @@ -92,10 +131,11 @@ set_target_properties(tslitex PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<0:>
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/$<0:>)

target_link_libraries(tslitex litepcie)
target_link_libraries(tslitex PUBLIC litepcie)
target_link_libraries(tslitex PRIVATE json-c-static zlibstatic)

if(APPLE)
target_link_libraries(tslitex "-framework IOKit")
target_link_libraries(tslitex PRIVATE "-framework IOKit")
endif()

target_include_directories(tslitex PUBLIC include)
Expand All @@ -112,12 +152,11 @@ set_target_properties(tslitex_static PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<0:>
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<0:>
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/$<0:>)

#target_compile_definitions(tslitex_static tslitex_static_STATIC)
set_target_properties(tslitex_static PROPERTIES POSITION_INDEPENDENT_CODE 1)

set_target_properties(tslitex_static PROPERTIES POSITION_INDEPENDENT_CODE 1)

target_link_libraries(tslitex_static litepcie)
target_link_libraries(tslitex_static PUBLIC litepcie)
target_link_libraries(tslitex_static PRIVATE json-c-static zlibstatic)
target_include_directories(tslitex_static PUBLIC include)

file(COPY ${TS_LIB_HEADERS} DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/include)
Expand Down
13 changes: 9 additions & 4 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.22...4.1)

find_package(
Python
Expand All @@ -19,6 +19,9 @@ add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib/include/thunderscope.h
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_FILE_DIR:tslitex_static>"
"$<TARGET_FILE_DIR:litepcie>"
"$<TARGET_FILE_DIR:json-c-static>"
"$<TARGET_FILE_DIR:zlibstatic>"
"${CMAKE_CURRENT_BINARY_DIR}/lib"
DEPENDS tslitex_static
)
Expand All @@ -29,9 +32,11 @@ add_custom_target(pydeps
tslitex_static
)

set(PY_BIND_LIBS tslitex_static litepcie)
set(PY_BIND_LIBS tslitex_static)

if(WIN32)
list(APPEND PY_BIND_LIBS setupapi)
list(APPEND PY_BIND_LIBS litepcie json-c-static zlibstatic)
endif()
list(JOIN PY_BIND_LIBS "\", \"" PY_EXT_LIBS)

Expand All @@ -47,7 +52,7 @@ add_custom_target(PyBindings
COMMAND Python::Interpreter -m pipx run build --wheel .
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Building python whl"
DEPENDS pydeps tslitex_static
DEPENDS pydeps
)

if (NOT DEFINED PY_PLATFORM)
Expand All @@ -61,7 +66,7 @@ add_custom_target(PyWheels
COMMAND Python::Interpreter -m cibuildwheel --platform ${PY_PLATFORM} --archs ${PY_ARCH} --config-file pyproject.toml
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Building all Python wheels"
DEPENDS pydeps tslitex_static
DEPENDS pydeps
)
else()
message(STATUS "Python bindings not available: Python not found")
Expand Down
6 changes: 6 additions & 0 deletions bindings/python/tslitex.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ cdef extern from "thunderscope.h":
uint32_t hw_id
uint32_t gw_id
uint32_t litex
uint32_t board_rev
char device_path[256]
char identity[256]
char serial_number[256]
char build_config[256]
char build_date[256]
char mfg_signature[256]

ctypedef tsDeviceInfo_s tsDeviceInfo_t

Expand Down Expand Up @@ -93,6 +97,8 @@ cdef extern from "thunderscope.h":

int32_t thunderscopeSampleModeSet(tsHandle_t ts, uint32_t rate, uint32_t resolution)

int32_t thunderscopeSampleInterruptRate(tsHandle_t ts, uint32_t interrupt_rate)

int32_t thunderscopeDataEnable(tsHandle_t ts, uint8_t enable)

int32_t thunderscopeRead(tsHandle_t ts, uint8_t* buffer, uint32_t len) nogil
Expand Down
13 changes: 12 additions & 1 deletion bindings/python/tslitex.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,22 @@ cdef class Thunderscope:

@SampleResolution.setter
def SampleResolution(self, resolution: int):
assert resolution is 256, f"Support for 8-bit mode only"
assert resolution in [256, 4096], f"Unsupported Resolution"
self._sample_resolution = resolution
retval = <int32_t> tslitex.thunderscopeSampleModeSet(<tslitex.tsHandle_t>self._tsHandle,
<uint32_t>self._sample_rate, <uint32_t>self._sample_resolution)

@property
def UpdateRate(self):
return self._interrupt_rate

@UpdateRate.setter
def UpdateRate(self, rate : int):
assert rate > 0, f"Invalid Update Rate"
self._interrupt_rate = rate
retval = <int32_t> tslitex.thunderscopeSampleInterruptRate(<tslitex.tsHandle_t>self._tsHandle,
<uint32_t> rate)

def Enable(self, enable: bool):
cdef int32_t retVal = tslitex.thunderscopeDataEnable(self._tsHandle, <uint8_t>enable)
if retVal != tslitex.TS_STATUS_OK:
Expand Down
37 changes: 37 additions & 0 deletions doc/calibration_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Calibration Data

### API

- Factory Provision Prepare
- Factory Provision Append Data
- Factory Provision Verify
- Factory Read Item


### Factory TLV's

Each section is dentoted by a 32-bit TAG, 32-bit LENGTH, ASCII Data, and CRC32 Checksum.

#### HWID

- Tag: `HWID`
- Format: JSON
- Contents:
- ID Version
- "Serial Number"
- "Board Revision"
- "Build Config"
- "Build Date"
- "Mfg Signature"


#### FCAL

- Tag: `FCAL`
- Format: JSON
- Contents:
- Calibration Version
- Calibration Station
- Calibration Date
- Calibration Data

34 changes: 34 additions & 0 deletions doc/data/hwid.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Hardware Identity Description",
"type": "object",
"properties": {
"version": {
"type": "integer",
"minimum": 1
},
"Serial Number": {
"type": "string",
"maxLength": 256
},
"Board Revision": {
"type": "number"
},
"Build Config": {
"type": "string",
"maxLength": 256
},
"Build Date": {
"type": "string",
"maxLength": 256
},
"Mfg Signature": {
"type": "string",
"maxLength": 256
}
},
"required": [
"version",
"Serial Number"
]
}
Loading