Skip to content

Commit

Permalink
IO control from API c and CPP
Browse files Browse the repository at this point in the history
Flush control on I/Q streams
  • Loading branch information
David Michaeli committed Jan 29, 2024
1 parent 4d993d2 commit 0ed53aa
Show file tree
Hide file tree
Showing 818 changed files with 116,181 additions and 1,380 deletions.
9 changes: 9 additions & 0 deletions software/libcariboulite/src/CaribouLite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ class CaribouLite
static bool DetectBoard(SysVersion *sysVer, std::string& name, std::string& guid);
static void DefaultSignalHandler(void* context, int signal_number, siginfo_t *si);

// IO Control
void SetLed0States (bool state);
bool GetLed0States (void);
void SetLed1States (bool state);
bool GetLed1States (void);
bool GetButtonState (void);
void SetPmodState (uint8_t val);
uint8_t GetPmodState (void);

private:
std::vector<CaribouLiteRadio*> _channels;
SysVersion _systemVersion;
Expand Down
54 changes: 54 additions & 0 deletions software/libcariboulite/src/CaribouLiteCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,57 @@ CaribouLiteRadio* CaribouLite::GetRadioChannel(CaribouLiteRadio::RadioType ch)
return _channels[(int)ch];
}

//==================================================================
void CaribouLite::SetLed0States (bool state)
{
int led1 = 0;
cariboulite_get_leds_state (NULL, &led1);
cariboulite_set_leds_state (state, led1);
}

//==================================================================
bool CaribouLite::GetLed0States ()
{
int led0 = 0;
cariboulite_get_leds_state (&led0, NULL);
return led0 != 0;
}

//==================================================================
void CaribouLite::SetLed1States (bool state)
{
int led0 = 0;
cariboulite_get_leds_state (&led0, NULL);
cariboulite_set_leds_state (led0, state);

}

//==================================================================
bool CaribouLite::GetLed1States ()
{
int led1 = 0;
cariboulite_get_leds_state (NULL, &led1);
return led1 != 0;
}

//==================================================================
bool CaribouLite::GetButtonState ()
{
int btn = 0;
cariboulite_get_button_state (&btn);
return btn != 0;
}

//==================================================================
void CaribouLite::SetPmodState (uint8_t val)
{
cariboulite_set_pmod_val (val);
}

//==================================================================
uint8_t CaribouLite::GetPmodState ()
{
uint8_t val = 0;
cariboulite_get_pmod_val (&val);
return val;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ extern "C" {

/*
* Time tagging of the module through the 'struct tm' structure
* Date: 2024-01-15
* Time: 20:30:23
* Date: 2024-01-25
* Time: 15:48:17
*/
struct tm smi_stream_dev_date_time = {
.tm_sec = 23,
.tm_min = 30,
.tm_hour = 20,
.tm_mday = 15,
.tm_sec = 17,
.tm_min = 48,
.tm_hour = 15,
.tm_mday = 25,
.tm_mon = 0, /* +1 */
.tm_year = 124, /* +1900 */
};
Expand Down
31 changes: 31 additions & 0 deletions software/libcariboulite/src/cariboulite.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,35 @@ int cariboulite_flush_pipeline()
{
// request the smi driver to flush its drivers fifo
return caribou_smi_flush_fifo(&sys.smi);
}

//=============================================================================
int cariboulite_set_leds_state (int led0, int led1)
{
return caribou_fpga_set_io_ctrl_dig (&sys.fpga, led0, led1);
}

//=============================================================================
int cariboulite_get_leds_state (int *led0, int *led1)
{
return caribou_fpga_get_io_ctrl_dig (&sys.fpga, led0, led1, NULL, NULL);
}


//=============================================================================
int cariboulite_get_button_state (int *btn)
{
return caribou_fpga_get_io_ctrl_dig (&sys.fpga, NULL, NULL, btn, NULL);
}

//=============================================================================
int cariboulite_set_pmod_val (uint8_t val)
{
return caribou_fpga_set_io_ctrl_pmod_val (&sys.fpga, val);
}

//=============================================================================
int cariboulite_get_pmod_val (uint8_t *val)
{
return caribou_fpga_get_io_ctrl_pmod_val (&sys.fpga, val);
}
12 changes: 12 additions & 0 deletions software/libcariboulite/src/cariboulite.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ int cariboulite_get_frequency_limits(cariboulite_channel_en ch, float *freq_low,
*/
int cariboulite_flush_pipeline(void);

/**
* @brief IO Control
*
* FPGA level IO control API
*
* @return 0 (success) or -1 (failed)
*/
int cariboulite_set_leds_state (int led0, int led1);
int cariboulite_get_leds_state (int *led0, int *led1);
int cariboulite_get_button_state (int *btn);
int cariboulite_set_pmod_val (uint8_t val);
int cariboulite_get_pmod_val (uint8_t *val);

#ifdef __cplusplus
}
Expand Down
2,748 changes: 1,374 additions & 1,374 deletions software/libcariboulite/src/cariboulite_fpga_firmware.h

Large diffs are not rendered by default.

2,058 changes: 2,058 additions & 0 deletions software/libcariboulite/src/cariboulite_fpga_firmware1.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions software/utils/libcariboulite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
155 changes: 155 additions & 0 deletions software/utils/libcariboulite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
cmake_minimum_required(VERSION 3.15)
project(cariboulite
VERSION 1.2.0
LANGUAGES C CXX
DESCRIPTION "CaribouLite RpiSDR C API")

set(CMAKE_BUILD_TYPE Release)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Bring the headers
include_directories(./src)
include_directories(${PROJECT_SOURCE_DIR}/src)
add_compile_options(-Wall -Wextra -Wno-unused-variable -Wno-missing-braces)

# ------------------------------------
# MAIN - Source files for main library
# ------------------------------------
set(SOURCES_LIB src/cariboulite.c src/cariboulite_setup.c src/cariboulite_events.c src/cariboulite_radio.c)
set(TARGET_LINK_LIBS datatypes
production_utils
caribou_fpga
at86rf215
rffc507x
caribou_smi
caribou_prog
hat
io_utils
zf_log
rt
m
pthread)

set(SOURCES_CPP_LIB src/CaribouLiteCpp.cpp src/CaribouLiteRadioCpp.cpp)

# Add internal project dependencies
add_subdirectory(src/datatypes EXCLUDE_FROM_ALL)
add_subdirectory(src/caribou_programming EXCLUDE_FROM_ALL)
add_subdirectory(src/caribou_fpga EXCLUDE_FROM_ALL)
add_subdirectory(src/at86rf215 EXCLUDE_FROM_ALL)
add_subdirectory(src/caribou_smi EXCLUDE_FROM_ALL)
add_subdirectory(src/io_utils EXCLUDE_FROM_ALL)
add_subdirectory(src/rffc507x EXCLUDE_FROM_ALL)
add_subdirectory(src/hat EXCLUDE_FROM_ALL)
add_subdirectory(src/production_utils EXCLUDE_FROM_ALL)
add_subdirectory(src/zf_log EXCLUDE_FROM_ALL)
add_subdirectory(src/iir EXCLUDE_FROM_ALL)

# Create the library cariboulite
add_library(cariboulite STATIC ${SOURCES_LIB} ${SOURCES_CPP_LIB})
target_link_libraries(cariboulite PRIVATE ${TARGET_LINK_LIBS})
set_target_properties(cariboulite PROPERTIES PUBLIC_HEADER "src/cariboulite.h;src/cariboulite_radio.h;src/CaribouLite.hpp")
set_target_properties(cariboulite PROPERTIES OUTPUT_NAME cariboulite)

add_library(cariboulite_shared SHARED ${SOURCES_LIB} ${SOURCES_CPP_LIB})
target_link_libraries(cariboulite_shared PRIVATE ${TARGET_LINK_LIBS})
set_target_properties(cariboulite_shared PROPERTIES PUBLIC_HEADER "src/cariboulite.h;src/cariboulite_radio.h;src/CaribouLite.hpp")
set_property(TARGET cariboulite_shared PROPERTY POSITION_INDEPENDENT_CODE 1)
set_target_properties(cariboulite_shared PROPERTIES OUTPUT_NAME cariboulite)



#--------------------------------------
# create the Soapy shared object
#--------------------------------------
find_package(SoapySDR CONFIG)
if (NOT SoapySDR_FOUND)
message(WARNING "SoapySDR development files not found - skipping support")
return()
endif ()

if(CMAKE_COMPILER_IS_GNUCXX)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_STD_CXX11)
if(HAS_STD_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
else(HAS_STD_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -O3")
endif()
#Thread support enabled (not the same as -lpthread)
list(APPEND SOAPY_CARIBOULITE_LIBRARIES)
add_definitions(-Wno-unused-parameter -Wno-missing-field-initializers -Wno-parentheses -Wno-psabi)
endif(CMAKE_COMPILER_IS_GNUCXX)

execute_process (
COMMAND bash -c "SoapySDRUtil --info | grep 'Search path' | cut -d':' -f2 | xargs | cut -d' ' -f1 | xargs"
OUTPUT_VARIABLE SOAPY_DEST
)
string(STRIP ${SOAPY_DEST} SOAPY_DEST)

execute_process (
COMMAND bash -c "SoapySDRUtil --info | grep 'Search path' | cut -d':' -f2 | xargs | cut -d' ' -f1 | awk -F '/lib/' '{print $1}' | xargs"
OUTPUT_VARIABLE BIN_DEST
)
string(STRIP ${BIN_DEST} BIN_DEST)

SOAPY_SDR_MODULE_UTIL(
TARGET SoapyCariboulite
SOURCES
src/soapy_api/SoapyCariboulite.cpp
src/soapy_api/Cariboulite.cpp
src/soapy_api/Cariboulite.hpp
src/soapy_api/CaribouliteStreamFunctions.cpp
src/soapy_api/CaribouliteStream.cpp
src/soapy_api/CaribouliteSession.cpp
src/soapy_api/CaribouliteSensors.cpp
LIBRARIES cariboulite iir
DESTINATION ${SOAPY_DEST}
PREFIX ""
)

# ----------------------------------
# TESTS - source files for the tests
# ----------------------------------
set(SOURCES_CARIBOU_PROGRAMMER test/caribou_programmer.c)
set(SOURCES_FPGA_COMM test/fpga_comm_test.c)
set(SOURCES_TEST_MAIN src/cariboulite_test_app.c src/app_menu.c)
set(SOURCES_MAIN src/cariboulite_util.c)
set(SOURCES_PROD src/cariboulite_production.c)

add_executable(caribou_programmer ${SOURCES_CARIBOU_PROGRAMMER})
add_executable(fpgacomm ${SOURCES_FPGA_COMM})
add_executable(cariboulite_test_app ${SOURCES_TEST_MAIN})
add_executable(cariboulite_util ${SOURCES_MAIN})

target_link_libraries(caribou_programmer cariboulite)
target_link_libraries(fpgacomm cariboulite)
target_link_libraries(cariboulite_test_app cariboulite)
target_link_libraries(cariboulite_util cariboulite)

set_target_properties( caribou_programmer PROPERTIES RUNTIME_OUTPUT_DIRECTORY test)
set_target_properties( fpgacomm PROPERTIES RUNTIME_OUTPUT_DIRECTORY test)

# ------------
# INSTALLATION
# ------------

install(TARGETS cariboulite
LIBRARY DESTINATION ${BIN_DEST}/lib/
ARCHIVE DESTINATION ${BIN_DEST}/lib/
PUBLIC_HEADER DESTINATION ${BIN_DEST}/include/)

install(TARGETS cariboulite_shared
LIBRARY DESTINATION ${BIN_DEST}/lib/
ARCHIVE DESTINATION ${BIN_DEST}/lib/
PUBLIC_HEADER DESTINATION ${BIN_DEST}/include/)

# generate pc file for pkg-config
set(PC_FILE cariboulite)
configure_file(cariboulite.pc.in
cariboulite.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/cariboulite.pc
DESTINATION ${BIN_DEST}/lib/pkgconfig/)

#install(TARGETS cariboulite_test_app DESTINATION ${BIN_DEST}/bin/)
install(TARGETS cariboulite_util DESTINATION ${BIN_DEST}/bin/)
46 changes: 46 additions & 0 deletions software/utils/libcariboulite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# CaribouLite RPI API
This folder contains the low-level and SoapySDR APIs for CaribouLite

# Building
To start from scratch we need to check for the dependencies and install them as needed.

Dependencies installation:
```
# Update the package definitions
sudo apt update
# We used gcc version 8.3+
sudo apt install gcc
# We used libsoapysdr-dev version 0.6.1-4+
sudo apt install libsoapysdr-dev libpthread-stubs0-dev
# cmake version 3.15+
sudo apt install cmake
```

Now to compile we use `cmake` as follows:

```
# create the building directory to contain
# compilation / linking artifacts. if already exists skip
# the creation
mkdir build
# goto the build directory
cd build
# tell cmake to create the Makefiles
# according to the code in the parent directory
cmake ../
# build the code (this will take about 30 seconds @ RPi4)
make
# install the package in your Linux
# environment (including SoapyAPIs)
sudo make install
```

# License
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
11 changes: 11 additions & 0 deletions software/utils/libcariboulite/cariboulite.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix="@BIN_DEST@"
exec_prefix="${prefix}"/bin
libdir="${prefix}/lib"
includedir="${prefix}/include"

Name: @PROJECT_NAME@
Description: @CMAKE_PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -l@PROJECT_NAME@

Loading

0 comments on commit 0ed53aa

Please sign in to comment.