kopia lustrzana https://github.com/cariboulabs/cariboulite
added hat detection api
rodzic
70ba2bdf69
commit
6016e3c1e2
|
@ -3,18 +3,51 @@
|
|||
|
||||
static cariboulite_lib_version_st version = {0};
|
||||
static uint32_t serial_number = 0;
|
||||
cariboulite_version_en hw_ver;
|
||||
char hw_name[128];
|
||||
char hw_uuid[128];
|
||||
|
||||
int main ()
|
||||
{
|
||||
cariboulite_init(false, cariboulite_log_level_none);
|
||||
cariboulite_get_lib_version(&version);
|
||||
// board detection
|
||||
bool detected = cariboulite_detect_connected_board(&hw_ver, hw_name, hw_uuid);
|
||||
if (detected) printf("Detection: %d, HWVer: %d, HWName: %s, UUID: %s\n", detected, hw_ver, hw_name, hw_uuid);
|
||||
else
|
||||
{
|
||||
printf("No board detection, Exiting\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// library version
|
||||
cariboulite_get_lib_version(&version);
|
||||
printf("Version: %02d.%02d.%02d\n", version.major_version, version.minor_version, version.revision);
|
||||
|
||||
serial_number = cariboulite_get_sn();
|
||||
// init
|
||||
cariboulite_init(false, cariboulite_log_level_none);
|
||||
|
||||
// board serial number
|
||||
serial_number = cariboulite_get_sn();
|
||||
printf("Serial Number: %08X\n", serial_number);
|
||||
|
||||
// channels names and freqs
|
||||
char ch_name[64];
|
||||
int ch_num_ranges;
|
||||
float low_freq_vec[3]; // the actual size determined by ch_num_ranges but here we just statically allocated
|
||||
float high_freq_vec[3];
|
||||
int channels[2] = {cariboulite_channel_s1g, cariboulite_channel_hif};
|
||||
|
||||
for (int ch_ind = 0; ch_ind < 2; ch_ind ++)
|
||||
{
|
||||
cariboulite_get_channel_name(channels[ch_ind], ch_name, sizeof(ch_name));
|
||||
ch_num_ranges = cariboulite_get_num_frequency_ranges(channels[ch_ind]);
|
||||
printf("Channel: %d, Name: %s, Num. Freq. Ranges: %d\n", channels[ch_ind], ch_name, ch_num_ranges);
|
||||
cariboulite_get_frequency_limits(channels[ch_ind], low_freq_vec, high_freq_vec, NULL);
|
||||
for (int i = 0; i < ch_num_ranges; i++)
|
||||
{
|
||||
printf(" Range %d: [%.2f, %.2f]\n", i, low_freq_vec[i], high_freq_vec[i]);
|
||||
}
|
||||
}
|
||||
|
||||
cariboulite_close();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,38 @@ static void internal_sighandler( struct sys_st_t *sys,
|
|||
if (ctx.sighandler) ctx.sighandler(ctx.sig_context, signal_number, si);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
bool cariboulite_detect_connected_board(cariboulite_version_en *hw_ver, char* name, char *uuid)
|
||||
{
|
||||
hat_board_info_st hat;
|
||||
if (hat_detect_board(&hat) == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (hat.numeric_product_id)
|
||||
{
|
||||
case system_type_cariboulite_full:
|
||||
if (hw_ver) *hw_ver = cariboulite_full;
|
||||
if (name) sprintf(name, "CaribouLite 6G");
|
||||
break;
|
||||
|
||||
case system_type_cariboulite_ism:
|
||||
if (hw_ver) *hw_ver = cariboulite_ism;
|
||||
if (name) sprintf(name, "CaribouLite ISM");
|
||||
break;
|
||||
|
||||
case system_type_unknown:
|
||||
if (hw_ver) *hw_ver = cariboulite_unknown;
|
||||
if (name) sprintf(name, "CaribouLite Unknown");
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (uuid) sprintf(uuid, "%s", hat.product_uuid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
int cariboulite_init(bool force_fpga_prog, cariboulite_log_level_en log_lvl)
|
||||
{
|
||||
|
|
|
@ -54,6 +54,25 @@ typedef void (*cariboulite_signal_handler)( void* context, // custom contex
|
|||
int signal_number, // the signal number
|
||||
siginfo_t *si);
|
||||
|
||||
/**
|
||||
* @brief check if board connected (without initing it)
|
||||
*
|
||||
* This function attempts to read the HAT information and checks if a
|
||||
* CaribouLite is registerred in the OS. If so gets its details.
|
||||
* this fucntion is good to check whether the board is mounted without the need
|
||||
* to initialize it. Preferably this is a simple check before we start working
|
||||
* - kind of a sanity check.
|
||||
*
|
||||
* @param hw_ver the type of HW (full / ism) as ENUM (nullable is not needed)
|
||||
* @param name the type of HW in textual manner - preallocate the string (at least 32 bytes)
|
||||
* (nullable is not needed)
|
||||
* @uuid uuid if this is needed, the user needs to provide a preallocated string 64 byte typical
|
||||
* (nullable if not needed)
|
||||
* @return true - when board was detected
|
||||
* false - board was not detected and then other parameters will not be valid
|
||||
*/
|
||||
bool cariboulite_detect_connected_board(cariboulite_version_en *hw_ver, char* name, char *guid);
|
||||
|
||||
/**
|
||||
* @brief initialize the system
|
||||
*
|
||||
|
@ -61,12 +80,12 @@ typedef void (*cariboulite_signal_handler)( void* context, // custom contex
|
|||
* a short self-test sequence to communication and check all the components
|
||||
* respond.
|
||||
*
|
||||
* @param sys a pre-allocated device handle structure
|
||||
* @param info the initialization performs internally the board detection sequence.
|
||||
* which is stored into the "sys" struct. If the user wants to receive the
|
||||
* information explicitely, he can pass here a pre-allocated info structure and
|
||||
* it will be filled with the board information. If this is not needed
|
||||
* user can pass "NULL"
|
||||
* @param force_fpga_prog force the FPGA to program (even if it is already programmed
|
||||
* this will have a penalty of around 3 seconds on init. If false
|
||||
* and the FPGA is already programmed (typically when this is not
|
||||
* the first time a program has run since last boot session), the program
|
||||
* will not rerun the FPGA programming process.
|
||||
* @param log_lvl the logging level according to 'cariboulite_log_level_en'
|
||||
* @return success / fail codes according to "cariboulite_errors_en"
|
||||
*/
|
||||
int cariboulite_init(bool force_fpga_prog, cariboulite_log_level_en log_lvl);
|
||||
|
@ -90,7 +109,6 @@ void cariboulite_close(void);
|
|||
*/
|
||||
bool cariboulite_is_initialized(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Register an explicit linux signal handler in the application level
|
||||
*
|
||||
|
@ -108,8 +126,6 @@ bool cariboulite_is_initialized(void);
|
|||
*/
|
||||
void cariboulite_register_signal_handler ( cariboulite_signal_handler handler,
|
||||
void *context);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get lib version
|
||||
|
@ -143,7 +159,7 @@ cariboulite_radio_state_st* cariboulite_get_radio(cariboulite_channel_en ch);
|
|||
*
|
||||
* Returns the version of the hardware - ISM / 6G / Unknown
|
||||
* ISM has two channels - 900MHz and 2.4 GHz
|
||||
* 6G has two channels - 900MHz and 30-6000MHz
|
||||
* 6G has two channels - 900MHz and 6000MHz
|
||||
*
|
||||
* @return according to cariboulite_version_en
|
||||
*/
|
||||
|
@ -164,7 +180,7 @@ bool cariboulite_frequency_available(cariboulite_channel_en ch, float freq_hz);
|
|||
*
|
||||
* Each channel has its frequency capabilities. in the ISM channel there are 2
|
||||
* ranges, while in the HiF there is a single range. This function returns the number
|
||||
* of available ranges. To get the actual limits use 'cariboulite_get_frequency_limits'
|
||||
* of available ranges per channel. To get the actual limits use 'cariboulite_get_frequency_limits'
|
||||
*
|
||||
* @return number of ranges or -1 if the channel doesn't exist
|
||||
*/
|
||||
|
@ -175,7 +191,7 @@ int cariboulite_get_num_frequency_ranges(cariboulite_channel_en ch);
|
|||
*
|
||||
* freq_low and freq_hi need to be pre-allocated according to 'cariboulite_get_num_frequency_ranges'
|
||||
* then all the minimum values will be in the freq_low list and the corresponding max values will be in
|
||||
* freq_hi.
|
||||
* freq_hi. All frequencies in Hz
|
||||
* num_ranges returns the number of written ranges
|
||||
*
|
||||
* @return 0 for success or -1 if channel is wrong
|
||||
|
@ -192,7 +208,7 @@ int cariboulite_get_frequency_limits(cariboulite_channel_en ch, float *freq_low,
|
|||
* @param max_len the size of the pre-allocated char array
|
||||
* @return 0 (success) or -1 (failed - when channel is incorrect)
|
||||
*/
|
||||
int cariboulite_radio_get_channel_name(cariboulite_channel_en ch, char* name, size_t max_len);
|
||||
int cariboulite_get_channel_name(cariboulite_channel_en ch, char* name, size_t max_len);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -602,7 +602,7 @@ int cariboulite_init_driver_minimal(sys_st *sys, hat_board_info_st *info, bool p
|
|||
if (hat_detect_from_eeprom(&sys->board_info) != 1)
|
||||
{
|
||||
ZF_LOGE("Failed to detect the board in /proc/device-tree/hat - EEPROM needs to be configured.");
|
||||
ZF_LOGE("Please run the hermon_prod application with sudo permissions...");
|
||||
ZF_LOGE("Please run the cariboulite_prod application with sudo permissions...");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue