kopia lustrzana https://github.com/cariboulabs/cariboulite
library pkg-config for c library installation and usage example
ustimer removed from library bugfixespull/146/head
rodzic
ebbf12e363
commit
b2d43a17ef
|
@ -0,0 +1,15 @@
|
|||
cmake_minimum_required(VERSION 3.2)
|
||||
project(test_app)
|
||||
|
||||
# Find the package using pkg-config
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(CARIBOULITE REQUIRED cariboulite)
|
||||
|
||||
# Add the executable
|
||||
add_executable(test_app main.c)
|
||||
|
||||
# Include directories from the cariboulite package
|
||||
target_include_directories(test_app PRIVATE ${CARIBOULITE_INCLUDE_DIRS})
|
||||
|
||||
# Link against the cariboulite library
|
||||
target_link_libraries(test_app PRIVATE ${CARIBOULITE_LIBRARIES})
|
|
@ -1,5 +0,0 @@
|
|||
CFLAGS=-O3 $(shell pkg-config --cflags libcariboulite)
|
||||
LDFLAGS=$(shell pkg-config --libs libcariboulite)
|
||||
CC=gcc
|
||||
main: main.o
|
||||
main.o: main.c
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
int main ()
|
||||
{
|
||||
cariboulite_init(false, cariboulite_log_level_verbose);
|
||||
cariboulite_init(false, cariboulite_log_level_none);
|
||||
cariboulite_close();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
project(cariboulite
|
||||
VERSION 1.2.0
|
||||
VERSION 1.2.0
|
||||
LANGUAGES C CXX
|
||||
DESCRIPTION "CaribouLite RpiSDR C API")
|
||||
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
@ -9,15 +10,28 @@ 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_setup.c src/cariboulite_events.c src/cariboulite_radio.c src/cariboulite.c)
|
||||
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)
|
||||
|
||||
# Add internal project dependencies
|
||||
add_subdirectory(src/datatypes EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(src/ustimer 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)
|
||||
|
@ -30,34 +44,22 @@ add_subdirectory(src/zf_log EXCLUDE_FROM_ALL)
|
|||
add_subdirectory(src/iir EXCLUDE_FROM_ALL)
|
||||
|
||||
# Create the library cariboulite
|
||||
add_library(cariboulite OBJECT ${SOURCES_LIB})
|
||||
target_link_libraries(cariboulite datatypes
|
||||
production_utils
|
||||
ustimer
|
||||
caribou_fpga
|
||||
at86rf215
|
||||
rffc507x
|
||||
caribou_smi
|
||||
caribou_prog
|
||||
hat
|
||||
io_utils
|
||||
zf_log
|
||||
rt
|
||||
m
|
||||
pthread
|
||||
iir)
|
||||
|
||||
add_library(cariboulite STATIC ${SOURCES_LIB})
|
||||
target_link_libraries(cariboulite PRIVATE ${TARGET_LINK_LIBS})
|
||||
set_target_properties(cariboulite PROPERTIES PUBLIC_HEADER "src/cariboulite.h;src/cariboulite_radio.h")
|
||||
set_property(TARGET cariboulite PROPERTY POSITION_INDEPENDENT_CODE 1)
|
||||
add_library(cariboulite_shared SHARED $<TARGET_OBJECTS:cariboulite>)
|
||||
add_library(cariboulite_static STATIC $<TARGET_OBJECTS:cariboulite>)
|
||||
set_target_properties(cariboulite PROPERTIES OUTPUT_NAME cariboulite)
|
||||
|
||||
add_library(cariboulite_shared SHARED ${SOURCES_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")
|
||||
set_property(TARGET cariboulite_shared PROPERTY POSITION_INDEPENDENT_CODE 1)
|
||||
set_target_properties(cariboulite_shared PROPERTIES OUTPUT_NAME cariboulite)
|
||||
set_target_properties(cariboulite_static PROPERTIES OUTPUT_NAME cariboulite)
|
||||
|
||||
target_include_directories(cariboulite PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_compile_options(-Wall -Wextra -Wno-unused-variable -Wno-missing-braces)
|
||||
|
||||
|
||||
#--------------------------------------
|
||||
# create the Soapy shared object
|
||||
#--------------------------------------
|
||||
find_package(SoapySDR CONFIG)
|
||||
if (NOT SoapySDR_FOUND)
|
||||
message(WARNING "SoapySDR development files not found - skipping support")
|
||||
|
@ -99,7 +101,7 @@ SOAPY_SDR_MODULE_UTIL(
|
|||
src/soapy_api/CaribouliteStream.cpp
|
||||
src/soapy_api/CaribouliteSession.cpp
|
||||
src/soapy_api/CaribouliteSensors.cpp
|
||||
LIBRARIES cariboulite
|
||||
LIBRARIES cariboulite iir
|
||||
DESTINATION ${SOAPY_DEST}
|
||||
PREFIX ""
|
||||
)
|
||||
|
@ -130,18 +132,21 @@ set_target_properties( fpgacomm PROPERTIES RUNTIME_OUTPUT_DIRECTORY test)
|
|||
# INSTALLATION
|
||||
# ------------
|
||||
|
||||
install(TARGETS cariboulite_static
|
||||
LIBRARY DESTINATION ${BIN_DEST}/lib/)
|
||||
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(libcariboulite.pc.in
|
||||
libcariboulite.pc @ONLY)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/libcariboulite.pc
|
||||
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/)
|
||||
|
|
|
@ -16,8 +16,8 @@ add_compile_options(-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wn
|
|||
|
||||
#Generate the static library from the sources
|
||||
add_library(at86rf215 STATIC ${SOURCES_LIB})
|
||||
add_executable(test_at86rf215 ${SOURCES})
|
||||
target_link_libraries(test_at86rf215 rt pthread ${EXTERN_LIBS})
|
||||
#add_executable(test_at86rf215 ${SOURCES})
|
||||
#target_link_libraries(test_at86rf215 rt pthread ${EXTERN_LIBS})
|
||||
|
||||
#Set the location for library installation -- i.e., /usr/lib in this case
|
||||
# not really necessary in this example. Use "sudo make install" to apply
|
||||
|
|
|
@ -20,8 +20,8 @@ add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-missing-braces)
|
|||
|
||||
#Generate the static library from the sources
|
||||
add_library(caribou_fpga STATIC ${SOURCES_LIB})
|
||||
add_executable(test_caribou_fpga ${SOURCES})
|
||||
target_link_libraries(test_caribou_fpga rt pthread ${EXTERN_LIBS})
|
||||
#add_executable(test_caribou_fpga ${SOURCES})
|
||||
#target_link_libraries(test_caribou_fpga rt pthread ${EXTERN_LIBS})
|
||||
|
||||
# Set the location for library installation -- i.e., /usr/lib in this case
|
||||
# not really necessary in this example. Use "sudo make install" to apply
|
||||
|
|
|
@ -49,14 +49,13 @@ int cariboulite_init(bool force_fpga_prog, cariboulite_log_level_en log_lvl)
|
|||
{
|
||||
sys.force_fpga_reprogramming = force_fpga_prog;
|
||||
|
||||
cariboulite_set_log_level(log_lvl);
|
||||
if (cariboulite_init_driver(&sys, NULL)!=0)
|
||||
{
|
||||
fprintf(stderr, "CaribouLite driver init failed, terminating...");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cariboulite_setup_signal_handler (&sys, internal_sighandler, signal_handler_op_last, &sys);
|
||||
|
||||
ctx.initialized = true;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -51,13 +51,14 @@ int cariboulite_radio_dispose(cariboulite_radio_state_st* radio)
|
|||
at86rf215_radio_set_state( &radio->sys->modem,
|
||||
GET_MODEM_CH(radio->type),
|
||||
at86rf215_radio_state_cmd_trx_off);
|
||||
radio->state = at86rf215_radio_state_cmd_trx_off;
|
||||
radio->state = cariboulite_radio_state_cmd_trx_off;
|
||||
|
||||
// Type specific
|
||||
if (radio->type == cariboulite_channel_6g)
|
||||
{
|
||||
caribou_fpga_set_io_ctrl_mode (&radio->sys->fpga, 0, caribou_fpga_io_ctrl_rfm_low_power);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -79,10 +80,12 @@ int cariboulite_radio_ext_ref ( sys_st *sys, cariboulite_ext_ref_freq_en ref)
|
|||
case cariboulite_ext_ref_off:
|
||||
ZF_LOGD("Setting ext_ref = OFF");
|
||||
at86rf215_set_clock_output(&sys->modem, at86rf215_drive_current_8ma, at86rf215_clock_out_freq_off);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
|
@ -178,19 +181,19 @@ int cariboulite_radio_get_rx_gain_limits(cariboulite_radio_state_st* radio,
|
|||
int cariboulite_radio_set_rx_bandwidth(cariboulite_radio_state_st* radio,
|
||||
cariboulite_radio_rx_bw_en rx_bw)
|
||||
{
|
||||
cariboulite_radio_f_cut_en fcut = at86rf215_radio_rx_f_cut_half_fs;
|
||||
cariboulite_radio_f_cut_en fcut = cariboulite_radio_rx_f_cut_half_fs;
|
||||
|
||||
// Automatically calculate the digital f_cut
|
||||
if (rx_bw >= at86rf215_radio_rx_bw_BW160KHZ_IF250KHZ && rx_bw <= at86rf215_radio_rx_bw_BW500KHZ_IF500KHZ)
|
||||
fcut = at86rf215_radio_rx_f_cut_0_25_half_fs;
|
||||
else if (rx_bw >= at86rf215_radio_rx_bw_BW630KHZ_IF1000KHZ && rx_bw <= at86rf215_radio_rx_bw_BW630KHZ_IF1000KHZ)
|
||||
fcut = at86rf215_radio_rx_f_cut_0_375_half_fs;
|
||||
else if (rx_bw >= at86rf215_radio_rx_bw_BW800KHZ_IF1000KHZ && rx_bw <= at86rf215_radio_rx_bw_BW1000KHZ_IF1000KHZ)
|
||||
fcut = at86rf215_radio_rx_f_cut_0_5_half_fs;
|
||||
else if (rx_bw >= at86rf215_radio_rx_bw_BW1250KHZ_IF2000KHZ && rx_bw <= at86rf215_radio_rx_bw_BW1250KHZ_IF2000KHZ)
|
||||
fcut = at86rf215_radio_rx_f_cut_0_75_half_fs;
|
||||
if (rx_bw >= cariboulite_radio_rx_bw_BW160KHZ_IF250KHZ && rx_bw <= cariboulite_radio_rx_bw_BW500KHZ_IF500KHZ)
|
||||
fcut = cariboulite_radio_rx_f_cut_0_25_half_fs;
|
||||
else if (rx_bw >= cariboulite_radio_rx_bw_BW630KHZ_IF1000KHZ && rx_bw <= cariboulite_radio_rx_bw_BW630KHZ_IF1000KHZ)
|
||||
fcut = cariboulite_radio_rx_f_cut_0_375_half_fs;
|
||||
else if (rx_bw >= cariboulite_radio_rx_bw_BW800KHZ_IF1000KHZ && rx_bw <= cariboulite_radio_rx_bw_BW1000KHZ_IF1000KHZ)
|
||||
fcut = cariboulite_radio_rx_f_cut_0_5_half_fs;
|
||||
else if (rx_bw >= cariboulite_radio_rx_bw_BW1250KHZ_IF2000KHZ && rx_bw <= cariboulite_radio_rx_bw_BW1250KHZ_IF2000KHZ)
|
||||
fcut = cariboulite_radio_rx_f_cut_0_75_half_fs;
|
||||
else
|
||||
fcut = at86rf215_radio_rx_f_cut_half_fs;
|
||||
fcut = cariboulite_radio_rx_f_cut_half_fs;
|
||||
|
||||
radio->rx_fcut = fcut;
|
||||
|
||||
|
@ -201,9 +204,9 @@ int cariboulite_radio_set_rx_bandwidth(cariboulite_radio_state_st* radio,
|
|||
// by factor of 1.25. This is useful to place the image frequency according
|
||||
// to channel scheme. This increases the IF frequency to max 2.5MHz
|
||||
// thus places the internal LO fasr away from the signal => lower noise
|
||||
.bw = rx_bw,
|
||||
.fcut = radio->rx_fcut, // keep the same
|
||||
.fs = radio->rx_fs, // keep the same
|
||||
.bw = (at86rf215_radio_rx_bw_en)rx_bw,
|
||||
.fcut = (at86rf215_radio_f_cut_en)radio->rx_fcut, // keep the same
|
||||
.fs = (at86rf215_radio_sample_rate_en)radio->rx_fs, // keep the same
|
||||
};
|
||||
at86rf215_radio_set_rx_bandwidth_sampling(&radio->sys->modem, GET_MODEM_CH(radio->type), &cfg);
|
||||
radio->rx_bw = rx_bw;
|
||||
|
@ -217,8 +220,8 @@ int cariboulite_radio_get_rx_bandwidth(cariboulite_radio_state_st* radio,
|
|||
at86rf215_radio_set_rx_bw_samp_st cfg = {0};
|
||||
at86rf215_radio_get_rx_bandwidth_sampling(&radio->sys->modem, GET_MODEM_CH(radio->type), &cfg);
|
||||
radio->rx_bw = (cariboulite_radio_rx_bw_en)cfg.bw;
|
||||
radio->rx_fcut = cfg.fcut;
|
||||
radio->rx_fs = cfg.fs;
|
||||
radio->rx_fcut = (cariboulite_radio_f_cut_en)cfg.fcut;
|
||||
radio->rx_fs = (cariboulite_radio_sample_rate_en)cfg.fs;
|
||||
if (rx_bw) *rx_bw = radio->rx_bw;
|
||||
return 0;
|
||||
}
|
||||
|
@ -235,9 +238,9 @@ int cariboulite_radio_set_rx_samp_cutoff(cariboulite_radio_state_st* radio,
|
|||
.shift_if_freq = 1, // A value of one configures the receiver to shift the IF frequency
|
||||
// by factor of 1.25. This is useful to place the image frequency according
|
||||
// to channel scheme.
|
||||
.bw = radio->rx_bw, // keep the same
|
||||
.fcut = rx_cutoff,
|
||||
.fs = rx_sample_rate,
|
||||
.bw = (at86rf215_radio_rx_bw_en)radio->rx_bw, // keep the same
|
||||
.fcut = (at86rf215_radio_f_cut_en)rx_cutoff,
|
||||
.fs = (at86rf215_radio_sample_rate_en)rx_sample_rate,
|
||||
};
|
||||
at86rf215_radio_set_rx_bandwidth_sampling(&radio->sys->modem, GET_MODEM_CH(radio->type), &cfg);
|
||||
radio->rx_fs = rx_sample_rate;
|
||||
|
@ -247,14 +250,15 @@ int cariboulite_radio_set_rx_samp_cutoff(cariboulite_radio_state_st* radio,
|
|||
uint32_t sample_rate = 4000000;
|
||||
switch(rx_sample_rate)
|
||||
{
|
||||
at86rf215_radio_rx_sample_rate_4000khz: sample_rate = 4000000; break;
|
||||
at86rf215_radio_rx_sample_rate_2000khz: sample_rate = 2000000; break;
|
||||
at86rf215_radio_rx_sample_rate_1333khz: sample_rate = 1333000; break;
|
||||
at86rf215_radio_rx_sample_rate_1000khz: sample_rate = 1000000; break;
|
||||
at86rf215_radio_rx_sample_rate_800khz: sample_rate = 800000; break;
|
||||
at86rf215_radio_rx_sample_rate_666khz: sample_rate = 666000; break;
|
||||
at86rf215_radio_rx_sample_rate_500khz: sample_rate = 500000; break;
|
||||
at86rf215_radio_rx_sample_rate_400khz: sample_rate = 400000; break;
|
||||
case cariboulite_radio_rx_sample_rate_4000khz: sample_rate = 4000000; break;
|
||||
case cariboulite_radio_rx_sample_rate_2000khz: sample_rate = 2000000; break;
|
||||
case cariboulite_radio_rx_sample_rate_1333khz: sample_rate = 1333000; break;
|
||||
case cariboulite_radio_rx_sample_rate_1000khz: sample_rate = 1000000; break;
|
||||
case cariboulite_radio_rx_sample_rate_800khz: sample_rate = 800000; break;
|
||||
case cariboulite_radio_rx_sample_rate_666khz: sample_rate = 666000; break;
|
||||
case cariboulite_radio_rx_sample_rate_500khz: sample_rate = 500000; break;
|
||||
case cariboulite_radio_rx_sample_rate_400khz: sample_rate = 400000; break;
|
||||
default: sample_rate = 4000000; break;
|
||||
}
|
||||
|
||||
caribou_smi_set_sample_rate(&radio->sys->smi, sample_rate);
|
||||
|
@ -267,8 +271,8 @@ int cariboulite_radio_get_rx_samp_cutoff(cariboulite_radio_state_st* radio,
|
|||
cariboulite_radio_f_cut_en *rx_cutoff)
|
||||
{
|
||||
cariboulite_radio_get_rx_bandwidth(radio, NULL);
|
||||
if (rx_sample_rate) *rx_sample_rate = radio->rx_fs;
|
||||
if (rx_cutoff) *rx_cutoff = radio->rx_fcut;
|
||||
if (rx_sample_rate) *rx_sample_rate = (cariboulite_radio_sample_rate_en)radio->rx_fs;
|
||||
if (rx_cutoff) *rx_cutoff = (cariboulite_radio_f_cut_en)radio->rx_fcut;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -308,9 +312,9 @@ int cariboulite_radio_set_tx_power(cariboulite_radio_state_st* radio, int tx_pow
|
|||
.current_reduction = at86rf215_radio_pa_current_reduction_0ma, // we can use this to gain some more
|
||||
// granularity with the tx gain control
|
||||
.tx_power = tx_power_ctrl,
|
||||
.analog_bw = radio->tx_bw, // same as before
|
||||
.digital_bw = radio->tx_fcut, // same as before
|
||||
.fs = radio->tx_fs, // same as before
|
||||
.analog_bw = (at86rf215_radio_tx_cut_off_en)radio->tx_bw, // same as before
|
||||
.digital_bw = (at86rf215_radio_f_cut_en)radio->tx_fcut, // same as before
|
||||
.fs = (at86rf215_radio_sample_rate_en)radio->tx_fs, // same as before
|
||||
.direct_modulation = 0,
|
||||
};
|
||||
|
||||
|
@ -327,7 +331,7 @@ int cariboulite_radio_get_tx_power(cariboulite_radio_state_st* radio, int *tx_po
|
|||
at86rf215_radio_get_tx_ctrl(&radio->sys->modem, GET_MODEM_CH(radio->type), &cfg);
|
||||
|
||||
float x = cfg.tx_power;
|
||||
float actual_model;
|
||||
float actual_model = 0;
|
||||
|
||||
if (radio->type == cariboulite_channel_s1g)
|
||||
{
|
||||
|
@ -339,9 +343,9 @@ int cariboulite_radio_get_tx_power(cariboulite_radio_state_st* radio, int *tx_po
|
|||
}
|
||||
|
||||
radio->tx_power = (int)(actual_model);
|
||||
radio->tx_bw = cfg.analog_bw;
|
||||
radio->tx_fcut = cfg.digital_bw;
|
||||
radio->tx_fs = cfg.fs;
|
||||
radio->tx_bw = (cariboulite_radio_tx_cut_off_en)cfg.analog_bw;
|
||||
radio->tx_fcut = (cariboulite_radio_f_cut_en)cfg.digital_bw;
|
||||
radio->tx_fs = (cariboulite_radio_sample_rate_en)cfg.fs;
|
||||
|
||||
if (tx_power_dbm) *tx_power_dbm = radio->tx_power;
|
||||
return 0;
|
||||
|
@ -357,9 +361,9 @@ int cariboulite_radio_set_tx_bandwidth(cariboulite_radio_state_st* radio,
|
|||
.current_reduction = at86rf215_radio_pa_current_reduction_0ma, // we can use this to gain some more
|
||||
// granularity with the tx gain control
|
||||
.tx_power = 18 + radio->tx_power, // same as before
|
||||
.analog_bw = tx_bw,
|
||||
.digital_bw = radio->tx_fcut, // same as before
|
||||
.fs = radio->tx_fs, // same as before
|
||||
.analog_bw = (at86rf215_radio_tx_cut_off_en)tx_bw,
|
||||
.digital_bw = (at86rf215_radio_f_cut_en)radio->tx_fcut, // same as before
|
||||
.fs = (at86rf215_radio_sample_rate_en)radio->tx_fs, // same as before
|
||||
.direct_modulation = 0,
|
||||
};
|
||||
|
||||
|
@ -390,9 +394,9 @@ int cariboulite_radio_set_tx_samp_cutoff(cariboulite_radio_state_st* radio,
|
|||
.current_reduction = at86rf215_radio_pa_current_reduction_0ma, // we can use this to gain some more
|
||||
// granularity with the tx gain control
|
||||
.tx_power = 18 + radio->tx_power, // same as before
|
||||
.analog_bw = radio->tx_bw, // same as before
|
||||
.digital_bw = tx_cutoff,
|
||||
.fs = tx_sample_rate,
|
||||
.analog_bw = (at86rf215_radio_tx_cut_off_en)radio->tx_bw, // same as before
|
||||
.digital_bw = (at86rf215_radio_f_cut_en)tx_cutoff,
|
||||
.fs = (at86rf215_radio_sample_rate_en)tx_sample_rate,
|
||||
.direct_modulation = 0,
|
||||
};
|
||||
|
||||
|
@ -404,14 +408,14 @@ int cariboulite_radio_set_tx_samp_cutoff(cariboulite_radio_state_st* radio,
|
|||
// setup the new sample rate in the FPGA
|
||||
switch (tx_sample_rate)
|
||||
{
|
||||
case at86rf215_radio_rx_sample_rate_4000khz: sample_gap = 0; break;
|
||||
case at86rf215_radio_rx_sample_rate_2000khz: sample_gap = 1; break;
|
||||
case at86rf215_radio_rx_sample_rate_1333khz: sample_gap = 2; break;
|
||||
case at86rf215_radio_rx_sample_rate_1000khz: sample_gap = 3; break;
|
||||
case at86rf215_radio_rx_sample_rate_800khz: sample_gap = 4; break;
|
||||
case at86rf215_radio_rx_sample_rate_666khz: sample_gap = 5; break;
|
||||
case at86rf215_radio_rx_sample_rate_500khz: sample_gap = 7; break;
|
||||
case at86rf215_radio_rx_sample_rate_400khz: sample_gap = 9; break;
|
||||
case cariboulite_radio_rx_sample_rate_4000khz: sample_gap = 0; break;
|
||||
case cariboulite_radio_rx_sample_rate_2000khz: sample_gap = 1; break;
|
||||
case cariboulite_radio_rx_sample_rate_1333khz: sample_gap = 2; break;
|
||||
case cariboulite_radio_rx_sample_rate_1000khz: sample_gap = 3; break;
|
||||
case cariboulite_radio_rx_sample_rate_800khz: sample_gap = 4; break;
|
||||
case cariboulite_radio_rx_sample_rate_666khz: sample_gap = 5; break;
|
||||
case cariboulite_radio_rx_sample_rate_500khz: sample_gap = 7; break;
|
||||
case cariboulite_radio_rx_sample_rate_400khz: sample_gap = 9; break;
|
||||
default: sample_gap = 0; break;
|
||||
}
|
||||
|
||||
|
@ -565,23 +569,23 @@ bool cariboulite_radio_wait_mixer_lock(cariboulite_radio_state_st* radio, int re
|
|||
}
|
||||
|
||||
//=========================================================================
|
||||
int cariboulite_radio_set_modem_state(cariboulite_radio_state_st* radio, at86rf215_radio_state_cmd_en state)
|
||||
int cariboulite_radio_set_modem_state(cariboulite_radio_state_st* radio, cariboulite_radio_state_cmd_en state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case at86rf215_radio_cmd_nop: ZF_LOGD("Setup Modem state to %d (nop)", state); break;
|
||||
case at86rf215_radio_cmd_sleep: ZF_LOGD("Setup Modem state to %d (sleep)", state); break;
|
||||
case at86rf215_radio_state_cmd_trx_off: ZF_LOGD("Setup Modem state to %d (trx off)", state); break;
|
||||
case at86rf215_radio_state_cmd_tx_prep: ZF_LOGD("Setup Modem state to %d (tx prep)", state); break;
|
||||
case at86rf215_radio_state_cmd_tx: ZF_LOGD("Setup Modem state to %d (tx)", state); break;
|
||||
case at86rf215_radio_state_cmd_rx: ZF_LOGD("Setup Modem state to %d (rx)", state); break;
|
||||
case at86rf215_radio_state_transition: ZF_LOGD("Setup Modem state to %d (transition)", state); break;
|
||||
case at86rf215_radio_state_cmd_reset: ZF_LOGD("Setup Modem state to %d (reset)", state); break;
|
||||
deafult: ZF_LOGD("Setup Modem state to %d (unknown)", state); break;
|
||||
case cariboulite_radio_cmd_nop: ZF_LOGD("Setup Modem state to %d (nop)", state); break;
|
||||
case cariboulite_radio_cmd_sleep: ZF_LOGD("Setup Modem state to %d (sleep)", state); break;
|
||||
case cariboulite_radio_state_cmd_trx_off: ZF_LOGD("Setup Modem state to %d (trx off)", state); break;
|
||||
case cariboulite_radio_state_cmd_tx_prep: ZF_LOGD("Setup Modem state to %d (tx prep)", state); break;
|
||||
case cariboulite_radio_state_cmd_tx: ZF_LOGD("Setup Modem state to %d (tx)", state); break;
|
||||
case cariboulite_radio_state_cmd_rx: ZF_LOGD("Setup Modem state to %d (rx)", state); break;
|
||||
case cariboulite_radio_state_transition: ZF_LOGD("Setup Modem state to %d (transition)", state); break;
|
||||
case cariboulite_radio_state_cmd_reset: ZF_LOGD("Setup Modem state to %d (reset)", state); break;
|
||||
default: ZF_LOGD("Setup Modem state to %d (unknown)", state); break;
|
||||
}
|
||||
at86rf215_radio_set_state( &radio->sys->modem,
|
||||
GET_MODEM_CH(radio->type),
|
||||
state);
|
||||
(at86rf215_radio_state_cmd_en)state);
|
||||
radio->state = state;
|
||||
return 0;
|
||||
}
|
||||
|
@ -655,7 +659,7 @@ int cariboulite_radio_set_frequency(cariboulite_radio_state_st* radio,
|
|||
{
|
||||
if (FREQ_IN_ISM_S1G_RANGE(f_rf))
|
||||
{
|
||||
if (break_before_make) cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_trx_off);
|
||||
if (break_before_make) cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_trx_off);
|
||||
|
||||
modem_act_freq = at86rf215_setup_channel (&radio->sys->modem,
|
||||
at86rf215_rf_channel_900mhz,
|
||||
|
@ -686,7 +690,7 @@ int cariboulite_radio_set_frequency(cariboulite_radio_state_st* radio,
|
|||
{
|
||||
if (FREQ_IN_ISM_24G_RANGE(f_rf))
|
||||
{
|
||||
if (break_before_make) cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_trx_off);
|
||||
if (break_before_make) cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_trx_off);
|
||||
|
||||
modem_act_freq = at86rf215_setup_channel (&radio->sys->modem,
|
||||
at86rf215_rf_channel_2400mhz,
|
||||
|
@ -720,7 +724,7 @@ int cariboulite_radio_set_frequency(cariboulite_radio_state_st* radio,
|
|||
{
|
||||
// make sure that during the transition the modem is not transmitting and then
|
||||
// verify that the FE is in low power mode
|
||||
cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_trx_off);
|
||||
cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_trx_off);
|
||||
caribou_fpga_set_io_ctrl_mode (&radio->sys->fpga, 0, caribou_fpga_io_ctrl_rfm_low_power);
|
||||
}
|
||||
|
||||
|
@ -827,7 +831,7 @@ int cariboulite_radio_set_frequency(cariboulite_radio_state_st* radio,
|
|||
}
|
||||
|
||||
// Make sure the LO and the IF PLLs are locked
|
||||
cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_tx_prep);
|
||||
cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_tx_prep);
|
||||
if (!cariboulite_radio_wait_for_lock(radio, &radio->modem_pll_locked,
|
||||
lo_act_freq > CARIBOULITE_MIN_LO ? &radio->lo_pll_locked : NULL,
|
||||
100))
|
||||
|
@ -861,6 +865,7 @@ int cariboulite_radio_get_frequency(cariboulite_radio_state_st* radio,
|
|||
if (freq) *freq = radio->actual_rf_frequency;
|
||||
if (lo) *lo = radio->lo_frequency;
|
||||
if (i_f) *i_f = radio->if_frequency;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
|
@ -876,7 +881,7 @@ int cariboulite_radio_activate_channel(cariboulite_radio_state_st* radio,
|
|||
ZF_LOGD("Activating channel %d, dir = %s, activate = %d", radio->type, radio->channel_direction==cariboulite_channel_dir_rx?"RX":"TX", activate);
|
||||
|
||||
// then deactivate the modem's stream
|
||||
cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_trx_off);
|
||||
cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_trx_off);
|
||||
|
||||
// DEACTIVATION
|
||||
if (!activate)
|
||||
|
@ -887,10 +892,10 @@ int cariboulite_radio_activate_channel(cariboulite_radio_state_st* radio,
|
|||
}
|
||||
|
||||
// ACTIVATION STEPS
|
||||
if (radio->state != at86rf215_radio_state_cmd_tx_prep)
|
||||
if (radio->state != cariboulite_radio_state_cmd_tx_prep)
|
||||
{
|
||||
// deactivate the channel and prep it for pll lock
|
||||
cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_tx_prep);
|
||||
cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_tx_prep);
|
||||
|
||||
at86rf215_radio_get_tx_iq_calibration(&radio->sys->modem, GET_MODEM_CH(radio->type), &cal_i, &cal_q);
|
||||
|
||||
|
@ -901,7 +906,7 @@ int cariboulite_radio_activate_channel(cariboulite_radio_state_st* radio,
|
|||
ZF_LOGE("PLL didn't lock");
|
||||
|
||||
// deactivate the channel if this happens
|
||||
cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_trx_off);
|
||||
cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_trx_off);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -936,7 +941,7 @@ int cariboulite_radio_activate_channel(cariboulite_radio_state_st* radio,
|
|||
//caribou_fpga_set_io_ctrl_dig (&radio->sys->fpga, radio->type == cariboulite_channel_s1g? 0 : 1, 0);
|
||||
|
||||
// turn on the modem RX
|
||||
cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_rx);
|
||||
cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_rx);
|
||||
|
||||
// turn on the SMI stream
|
||||
if (caribou_smi_set_driver_streaming_state(&radio->sys->smi, smi_state) != 0)
|
||||
|
@ -976,7 +981,7 @@ int cariboulite_radio_activate_channel(cariboulite_radio_state_st* radio,
|
|||
else if (radio->cw_output)
|
||||
{
|
||||
ZF_LOGD("Transmitting with cw_output");
|
||||
cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_tx_prep);
|
||||
cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_tx_prep);
|
||||
|
||||
if (radio->sys->board_info.numeric_product_id == system_type_cariboulite_full)
|
||||
{
|
||||
|
@ -984,7 +989,7 @@ int cariboulite_radio_activate_channel(cariboulite_radio_state_st* radio,
|
|||
rffc507x_output_lo(&radio->sys->mixer, 0);
|
||||
}
|
||||
|
||||
cariboulite_radio_set_tx_bandwidth(radio, at86rf215_radio_tx_cut_off_80khz);
|
||||
cariboulite_radio_set_tx_bandwidth(radio, cariboulite_radio_tx_cut_off_80khz);
|
||||
|
||||
// CW output - constant I/Q values override
|
||||
at86rf215_radio_set_tx_dac_input_iq(&radio->sys->modem,
|
||||
|
@ -993,12 +998,12 @@ int cariboulite_radio_activate_channel(cariboulite_radio_state_st* radio,
|
|||
1, 0x3F);
|
||||
|
||||
// transition to state TX
|
||||
cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_tx);
|
||||
cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_tx);
|
||||
}
|
||||
else
|
||||
{
|
||||
ZF_LOGD("Transmitting with iq");
|
||||
cariboulite_radio_set_modem_state(radio, at86rf215_radio_state_cmd_tx_prep);
|
||||
cariboulite_radio_set_modem_state(radio, cariboulite_radio_state_cmd_tx_prep);
|
||||
|
||||
cariboulite_radio_set_tx_bandwidth(radio, radio->tx_bw);
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
|
||||
// Global system object for signals
|
||||
sys_st* sigsys = NULL;
|
||||
static sys_st* sigsys = NULL;
|
||||
|
||||
//=================================================================
|
||||
void print_siginfo(siginfo_t *si)
|
||||
static void print_siginfo(siginfo_t *si)
|
||||
{
|
||||
printf("Signal [%d] caught, with the following information: \n", si->si_signo);
|
||||
printf(" signal errno = %d\n", si->si_errno);
|
||||
|
@ -391,15 +391,15 @@ int cariboulite_init_submodules (sys_st* sys)
|
|||
cariboulite_radio_init(&sys->radio_low, sys, cariboulite_channel_s1g);
|
||||
cariboulite_radio_init(&sys->radio_high, sys, cariboulite_channel_6g);
|
||||
|
||||
cariboulite_radio_set_rx_samp_cutoff(&sys->radio_low, at86rf215_radio_rx_sample_rate_4000khz, at86rf215_radio_rx_f_cut_half_fs);
|
||||
cariboulite_radio_set_tx_samp_cutoff(&sys->radio_low, at86rf215_radio_rx_sample_rate_4000khz, at86rf215_radio_rx_f_cut_half_fs);
|
||||
cariboulite_radio_set_rx_bandwidth(&sys->radio_low, at86rf215_radio_rx_bw_BW2000KHZ_IF2000KHZ);
|
||||
cariboulite_radio_set_tx_bandwidth(&sys->radio_low, at86rf215_radio_tx_cut_off_1000khz);
|
||||
cariboulite_radio_set_rx_samp_cutoff(&sys->radio_low, cariboulite_radio_rx_sample_rate_4000khz, cariboulite_radio_rx_f_cut_half_fs);
|
||||
cariboulite_radio_set_tx_samp_cutoff(&sys->radio_low, cariboulite_radio_rx_sample_rate_4000khz, cariboulite_radio_rx_f_cut_half_fs);
|
||||
cariboulite_radio_set_rx_bandwidth(&sys->radio_low, cariboulite_radio_rx_bw_BW2000KHZ_IF2000KHZ);
|
||||
cariboulite_radio_set_tx_bandwidth(&sys->radio_low, cariboulite_radio_tx_cut_off_1000khz);
|
||||
|
||||
cariboulite_radio_set_rx_samp_cutoff(&sys->radio_high, at86rf215_radio_rx_sample_rate_4000khz, at86rf215_radio_rx_f_cut_half_fs);
|
||||
cariboulite_radio_set_tx_samp_cutoff(&sys->radio_high, at86rf215_radio_rx_sample_rate_4000khz, at86rf215_radio_rx_f_cut_half_fs);
|
||||
cariboulite_radio_set_rx_bandwidth(&sys->radio_high, at86rf215_radio_rx_bw_BW2000KHZ_IF2000KHZ);
|
||||
cariboulite_radio_set_tx_bandwidth(&sys->radio_high, at86rf215_radio_tx_cut_off_1000khz);
|
||||
cariboulite_radio_set_rx_samp_cutoff(&sys->radio_high, cariboulite_radio_rx_sample_rate_4000khz, cariboulite_radio_rx_f_cut_half_fs);
|
||||
cariboulite_radio_set_tx_samp_cutoff(&sys->radio_high, cariboulite_radio_rx_sample_rate_4000khz, cariboulite_radio_rx_f_cut_half_fs);
|
||||
cariboulite_radio_set_rx_bandwidth(&sys->radio_high, cariboulite_radio_rx_bw_BW2000KHZ_IF2000KHZ);
|
||||
cariboulite_radio_set_tx_bandwidth(&sys->radio_high, cariboulite_radio_tx_cut_off_1000khz);
|
||||
|
||||
cariboulite_radio_activate_channel(&sys->radio_low, cariboulite_channel_dir_rx, false);
|
||||
cariboulite_radio_activate_channel(&sys->radio_high, cariboulite_channel_dir_rx, false);
|
||||
|
|
|
@ -25,7 +25,6 @@ extern "C" {
|
|||
#include "io_utils/io_utils.h"
|
||||
#include "io_utils/io_utils_spi.h"
|
||||
#include "io_utils/io_utils_sys_info.h"
|
||||
#include "ustimer/ustimer.h"
|
||||
#include "cariboulite_config_default.h"
|
||||
|
||||
#define CARIBOULITE_MAJOR_VERSION 1
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
//=======================================================================
|
||||
// INTERNAL VARIABLES AND DEFINITIONS
|
||||
|
||||
struct sigaction act;
|
||||
int signal_shown = 0;
|
||||
CARIBOULITE_CONFIG_DEFAULT(cariboulite_sys);
|
||||
static struct sigaction act;
|
||||
static int signal_shown = 0;
|
||||
CARIBOULITE_CONFIG_STATIC_DEFAULT(cariboulite_sys);
|
||||
|
||||
// Program state structure
|
||||
typedef struct
|
||||
|
|
|
@ -16,11 +16,11 @@ add_compile_options(-Wall -Wextra -pedantic -Wno-missing-braces)
|
|||
add_library(datatypes STATIC ${SOURCES_LIB})
|
||||
target_include_directories(datatypes PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
add_executable(test_tsqueue test_tsqueue.c)
|
||||
target_link_libraries(test_tsqueue datatypes pthread)
|
||||
#add_executable(test_tsqueue test_tsqueue.c)
|
||||
#target_link_libraries(test_tsqueue datatypes pthread)
|
||||
|
||||
add_executable(test_circular_buffer test_circular_buffer.cpp)
|
||||
target_link_libraries(test_circular_buffer datatypes pthread)
|
||||
#add_executable(test_circular_buffer test_circular_buffer.cpp)
|
||||
#target_link_libraries(test_circular_buffer datatypes pthread)
|
||||
|
||||
add_executable(test_tiny_list test_tiny_list.c)
|
||||
target_link_libraries(test_tiny_list datatypes pthread)
|
||||
|
|
|
@ -17,8 +17,8 @@ add_compile_options(-Wall -Wextra -Wmissing-braces)
|
|||
add_library(hat STATIC ${SOURCES_LIB})
|
||||
target_link_libraries(hat rt m pthread)
|
||||
|
||||
add_executable(test_hat ${SOURCES})
|
||||
target_link_libraries(test_hat rt pthread ${EXTERN_LIBS})
|
||||
#add_executable(test_hat ${SOURCES})
|
||||
#target_link_libraries(test_hat rt pthread ${EXTERN_LIBS})
|
||||
|
||||
# Set the location for library installation -- i.e., /usr/lib in this case
|
||||
# not really necessary in this example. Use "sudo make install" to apply
|
||||
|
|
|
@ -27,8 +27,8 @@ add_library(io_utils STATIC ${SOURCES_LIB} ${SOURCES_RPI_LIB} ${SOURCES_SPIDEV_L
|
|||
target_include_directories(io_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(io_utils PRIVATE pthread)
|
||||
|
||||
add_executable(test_io_utils main.c)
|
||||
target_link_libraries(test_io_utils io_utils pthread ${EXTERN_LIBS})
|
||||
#add_executable(test_io_utils main.c)
|
||||
#target_link_libraries(test_io_utils io_utils pthread ${EXTERN_LIBS})
|
||||
|
||||
#Set the location for library installation -- i.e., /usr/lib in this case
|
||||
# not really necessary in this example. Use "sudo make install" to apply
|
||||
|
|
|
@ -45,7 +45,7 @@ inline void io_utils_set_pullupdn(int gpio, io_utils_pull_en pud)
|
|||
inline void io_utils_setup_gpio(int gpio, io_utils_dir_en direction, io_utils_pull_en pud)
|
||||
{
|
||||
io_utils_set_pullupdn(gpio, pud);
|
||||
io_utils_set_gpio_mode(gpio, direction);
|
||||
io_utils_set_gpio_mode(gpio, (io_utils_alt_en)direction);
|
||||
}
|
||||
|
||||
//=============================================================================================
|
||||
|
|
|
@ -18,8 +18,8 @@ add_compile_options(-Wall -Wextra -Wno-missing-braces)
|
|||
add_library(rffc507x STATIC ${SOURCES_LIB})
|
||||
target_link_libraries(rffc507x rt m pthread)
|
||||
|
||||
add_executable(test_rffc507x ${SOURCES})
|
||||
target_link_libraries(test_rffc507x rt m pthread ${EXTERN_LIBS})
|
||||
#add_executable(test_rffc507x ${SOURCES})
|
||||
#target_link_libraries(test_rffc507x rt m pthread ${EXTERN_LIBS})
|
||||
|
||||
#Set the location for library installation -- i.e., /usr/lib in this case
|
||||
# not really necessary in this example. Use "sudo make install" to apply
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
# build directories
|
||||
build
|
|
@ -1,24 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
project(cariboulite)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
#Bring the headers, such as Student.h into the project
|
||||
set(SUPER_DIR ${PROJECT_SOURCE_DIR}/..)
|
||||
include_directories(/.)
|
||||
include_directories(${SUPER_DIR})
|
||||
|
||||
#However, the file(GLOB...) allows for wildcard additions:
|
||||
set(SOURCES_LIB ustimer.c)
|
||||
#add_compile_options(-Wall -Wextra -pedantic -Werror)
|
||||
add_compile_options(-Wall -Wextra -Wno-missing-braces)
|
||||
|
||||
#Generate the static library from the sources
|
||||
add_library(ustimer STATIC ${SOURCES_LIB})
|
||||
target_include_directories(ustimer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
add_executable(test_ustimer main.c)
|
||||
target_link_libraries(test_ustimer ustimer rt)
|
||||
|
||||
#Set the location for library installation -- i.e., /usr/lib in this case
|
||||
# not really necessary in this example. Use "sudo make install" to apply
|
||||
install(TARGETS ustimer DESTINATION /usr/lib)
|
|
@ -1,33 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include "ustimer.h"
|
||||
|
||||
|
||||
static void test_ustimer_handler(unsigned int id, struct timeval iv)
|
||||
{
|
||||
printf("Got Timer event: %d, %ld, %ld\n", id, iv.tv_sec, iv.tv_usec);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int id = -1;
|
||||
printf("ustimer testing...\n");
|
||||
|
||||
ustimer_init( );
|
||||
int err = ustimer_register_function ( test_ustimer_handler, 1000, &id);
|
||||
if (err == 0)
|
||||
printf("Regirtered id = %d\n", id);
|
||||
else
|
||||
printf("Registration error\n");
|
||||
|
||||
ustimer_start (1);
|
||||
|
||||
printf("push enter to quit...\n");
|
||||
while (!getchar())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ustimer_close ( );
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,230 +0,0 @@
|
|||
#include "ustimer.h"
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
static ustimer_t timer_info;
|
||||
|
||||
//================================================
|
||||
static void ustimer_handle_quant ( int sig )
|
||||
{
|
||||
int i;
|
||||
struct timeval new_time = {0};
|
||||
|
||||
if (sig != SIGUSR1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
gettimeofday(&new_time, NULL);
|
||||
timer_info.timer_count ++;
|
||||
|
||||
if (!timer_info.global_running)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i<USTIMER_NUM_SLOTS; i++)
|
||||
{
|
||||
if (timer_info.time_enabled[i] &&
|
||||
timer_info.handlers[i] &&
|
||||
!timer_info.timer_func_busy[i] &&
|
||||
timer_info.timer_count%timer_info.timer_quant[i]==0)
|
||||
{
|
||||
timer_info.timer_func_busy[i] = 1;
|
||||
timer_info.handlers[i](i, timer_info.timetags[i]);
|
||||
timer_info.timer_func_busy[i] = 0;
|
||||
}
|
||||
|
||||
// record the last time this event occured
|
||||
timer_info.timetags[i].tv_sec = new_time.tv_sec;
|
||||
timer_info.timetags[i].tv_usec = new_time.tv_usec;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//================================================
|
||||
static int ustimer_make_timer( timer_t *timerID, int expireMS, int intervalMS )
|
||||
{
|
||||
struct sigevent te;
|
||||
struct itimerspec its;
|
||||
struct sigaction sa;
|
||||
int sigNo = SIGUSR1;
|
||||
|
||||
// Set up signal handler
|
||||
sa.sa_flags = SA_RESTART;
|
||||
sa.sa_handler = ustimer_handle_quant;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
if (sigaction(sigNo, &sa, NULL) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set and enable alarm
|
||||
te.sigev_notify = SIGEV_SIGNAL;
|
||||
te.sigev_signo = sigNo;
|
||||
te.sigev_value.sival_ptr = timerID;
|
||||
timer_create(CLOCK_REALTIME, &te, timerID); // monotonic clock to prevent clock change glitches
|
||||
|
||||
its.it_interval.tv_sec = 0;
|
||||
its.it_interval.tv_nsec = intervalMS * 1000000;
|
||||
its.it_value.tv_sec = 0;
|
||||
its.it_value.tv_nsec = expireMS * 1000000;
|
||||
|
||||
if (timer_settime(*timerID, 0, &its, NULL) < 0)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//================================================
|
||||
int ustimer_init ( void )
|
||||
{
|
||||
int err = 0;
|
||||
struct timespec res;
|
||||
int i;
|
||||
|
||||
memset (&timer_info, 0, sizeof(ustimer_t));
|
||||
|
||||
// all clocks are disabled
|
||||
for (i = 0; i<USTIMER_NUM_SLOTS; i++)
|
||||
{
|
||||
timer_info.time_enabled[i] = 0;
|
||||
timer_info.handlers[i] = NULL;
|
||||
timer_info.timer_func_busy[i] = 0;
|
||||
timer_info.timer_quant[i] = 100000000;
|
||||
}
|
||||
|
||||
// init the periodic counter
|
||||
timer_info.timer_count = 0;
|
||||
timer_info.global_running = 0;
|
||||
|
||||
// check RT ability capability
|
||||
clock_getres(CLOCK_REALTIME, &res);
|
||||
|
||||
if (res.tv_sec==0 && res.tv_nsec < 100)
|
||||
{
|
||||
timer_info.initialized = 1;
|
||||
}
|
||||
|
||||
// create the global timer with QUANTIZED interval
|
||||
err = ustimer_make_timer(&timer_info.timer_id, USTIMER_MIN_QUANT, USTIMER_MIN_QUANT);
|
||||
if (err == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//================================================
|
||||
int ustimer_close ( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
// check if module inited
|
||||
if (timer_info.initialized == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// disable all active clocks
|
||||
for (i = 0; i < USTIMER_NUM_SLOTS; i++)
|
||||
{
|
||||
if (timer_info.time_enabled[i])
|
||||
{
|
||||
ustimer_unregister( i );
|
||||
}
|
||||
}
|
||||
|
||||
timer_delete(timer_info.timer_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//================================================
|
||||
int ustimer_register_function ( ustimer_handler func,
|
||||
unsigned int interval,
|
||||
int *id )
|
||||
{
|
||||
int cur_id = -1;
|
||||
int found_slot = 0;
|
||||
|
||||
// check if initialized
|
||||
if (timer_info.initialized == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check that id is not NULL
|
||||
if (id == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// find an empty slot
|
||||
for (cur_id = 0; cur_id < USTIMER_NUM_SLOTS; cur_id ++)
|
||||
{
|
||||
// if the current slot is free
|
||||
if (timer_info.time_enabled[cur_id] == 0)
|
||||
{
|
||||
found_slot = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found_slot == 0)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
|
||||
timer_info.timer_quant[cur_id] = interval / USTIMER_MIN_QUANT;
|
||||
if (timer_info.timer_quant[cur_id] == 0) timer_info.timer_quant[cur_id] = 1; // for smaller then QUANT millisec
|
||||
timer_info.handlers[cur_id] = func;
|
||||
gettimeofday ( &(timer_info.timetags[cur_id]), NULL);
|
||||
timer_info.time_enabled[cur_id] = 1;
|
||||
|
||||
|
||||
*id = cur_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//================================================
|
||||
int ustimer_unregister ( int id )
|
||||
{
|
||||
// check if the module is initialized
|
||||
if (timer_info.initialized == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check that the id is a valid value
|
||||
if ( id < 0 || id >= USTIMER_NUM_SLOTS )
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
// check if the specific timer id is enabled
|
||||
if (timer_info.time_enabled[id] == 0)
|
||||
{
|
||||
return -3;
|
||||
}
|
||||
timer_info.time_enabled[id] = 0;
|
||||
timer_info.handlers[id] = NULL;
|
||||
timer_info.timer_quant[id] = 100000000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//================================================
|
||||
int ustimer_start ( unsigned int run )
|
||||
{
|
||||
timer_info.global_running = run;
|
||||
return 0;
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
#ifndef ___USTIMER_H__
|
||||
#define ___USTIMER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
#define USTIMER_NUM_SLOTS 30 // maximum 10 timers available
|
||||
#define USTIMER_DELTA(a,b) (((b).tv_sec-(a).tv_sec)*1e6+((b).tv_usec-(a).tv_usec))
|
||||
#define USTIMER_MIN_QUANT 5 // Millisec
|
||||
|
||||
// handler function gets the timer id and the timeval from its last occurence
|
||||
typedef void (*ustimer_handler)(unsigned int,struct timeval);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int timer_quant[USTIMER_NUM_SLOTS];
|
||||
int time_enabled[USTIMER_NUM_SLOTS];
|
||||
int timer_func_busy[USTIMER_NUM_SLOTS];
|
||||
ustimer_handler handlers[USTIMER_NUM_SLOTS];
|
||||
struct timeval timetags[USTIMER_NUM_SLOTS];
|
||||
|
||||
timer_t timer_id;
|
||||
unsigned int initialized;
|
||||
unsigned int timer_count;
|
||||
unsigned int global_running;
|
||||
int init_err;
|
||||
} ustimer_t;
|
||||
|
||||
|
||||
// timer function prototypes
|
||||
int ustimer_init ( void );
|
||||
int ustimer_close ( void );
|
||||
int ustimer_register_function ( ustimer_handler func,// IN: the handler function
|
||||
unsigned int interval,// IN: interval in millisec between events
|
||||
int *id ); // OUT: the specific timer id [0..WH_TIMER_NUM_SLOTS-1]
|
||||
int ustimer_unregister ( int id );
|
||||
int ustimer_start ( unsigned int run );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //___USTIMER_H__
|
Ładowanie…
Reference in New Issue