2
0
forked from Ivasoft/DSView

Development progress 1

This commit is contained in:
dreamsourcelabTAI
2022-07-15 11:57:50 +08:00
parent b424accfd5
commit c06bfe35e7
6 changed files with 164 additions and 62 deletions

View File

@@ -47,15 +47,24 @@
/* api
sr_init();
sr_lib_init();
sr_exit();
sr_lib_exit();
sr_set_firmware_resource_dir();
sr_set_datafeed_callback(data_cb);
sr_set_event_callback(event_cb);
sr_update_device_list();
sr_get_device_list();
sr_get_device_channels();
*/
//当断开设备时,如果属当前设备且存在数据,不能自动切换到其它设备,须提示用户保存数据,再自动切换当前设备
//当接入新设备时,如果当前设备有数据,须提示用户保存数据,再扫描设备列表
//加载文件时,由外部判断当前硬件是否存在数据,以便提示用户保存,再执行加载文件,并通知用户更新列表
//扫描设备列表会自动切换到最新设备,并通知用户更新列表
*/

61
libsigrok4DSL/lib_main.c Normal file
View File

@@ -0,0 +1,61 @@
/*
* This file is part of the DSView project.
* DSView is based on PulseView.
*
* Copyright (C) 2022 DreamSourceLab <support@dreamsourcelab.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libsigrok-internal.h"
struct sr_context *lib_sr_context = NULL;
char DS_RES_PATH[500] = {0};
libsigrok_event_callback_t *lib_event_callback = NULL;
SR_API int sr_lib_init()
{
return sr_init(&lib_sr_context);
}
SR_API int sr_lib_exit()
{
if (lib_sr_context != NULL){
return sr_exit(lib_sr_context);
lib_sr_context = NULL;
}
return SR_OK;
}
void sr_set_firmware_resource_dir(const char *dir)
{
if (dir){
strcpy(DS_RES_PATH, dir);
int len = strlen(DS_RES_PATH);
if (DS_RES_PATH[len-1] != '/'){
DS_RES_PATH[len] = '/';
DS_RES_PATH[len + 1] = 0;
}
}
}
/**
* event type see enum libsigrok_event_type
*/
SR_API void sr_set_event_callback(libsigrok_event_callback_t *cb)
{
lib_event_callback = cb;
}

View File

@@ -26,6 +26,7 @@
#include <libusb-1.0/libusb.h>
#include "libsigrok.h"
/**
* @file
*
@@ -47,10 +48,6 @@
#undef max
#define max(a,b) ((a)>(b)?(a):(b))
// firmware binary file directory, endswith letter '/'
extern char DS_RES_PATH[500];
struct sr_context {
libusb_context *libusb_ctx;
libusb_hotplug_callback_handle hotplug_handle;
@@ -87,7 +84,6 @@ struct drv_context {
#define MAX_TIMEBASE SR_SEC(10)
#define MIN_TIMEBASE SR_NS(10)
struct ds_trigger {
uint16_t trigger_en;
uint16_t trigger_mode;
@@ -103,6 +99,11 @@ struct ds_trigger {
};
/*-------------------global variable----------------*/
// firmware binary file directory, endswith letter '/'
extern char DS_RES_PATH[500];
extern struct sr_context *lib_sr_context;
/*--- device.c --------------------------------------------------------------*/
SR_PRIV struct sr_channel *sr_channel_new(uint16_t index, int type,
@@ -128,6 +129,8 @@ SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial);
/*--- hwdriver.c ------------------------------------------------------------*/
typedef int (*sr_receive_data_callback_t)(int fd, int revents, const struct sr_dev_inst *sdi);
SR_PRIV void sr_hw_cleanup_all(void);
SR_PRIV int sr_source_remove(int fd);
SR_PRIV int sr_source_add(int fd, int events, int timeout,
@@ -175,6 +178,13 @@ SR_PRIV uint64_t sr_trigger_get_value1(uint16_t stage);
SR_PRIV uint64_t sr_trigger_get_edge0(uint16_t stage);
SR_PRIV uint64_t sr_trigger_get_edge1(uint16_t stage);
SR_PRIV uint16_t ds_trigger_get_mask0(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_value0(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_edge0(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_mask1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_value1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_edge1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
/*--- hardware/common/serial.c ----------------------------------------------*/
enum {
@@ -217,5 +227,8 @@ SR_PRIV int ezusb_upload_firmware(libusb_device *dev, int configuration,
SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
/*--- backend.c -------------------------------------------------------------*/
SR_PRIV int sr_init(struct sr_context **ctx);
SR_PRIV int sr_exit(struct sr_context *ctx);
#endif

View File

@@ -25,8 +25,8 @@
#include <sys/time.h>
#include <stdint.h>
#include <inttypes.h>
#include <glib.h>
//#include "version.h"
#include <glib.h>
#include <log/xlog.h>
#ifdef __cplusplus
extern "C" {
@@ -81,6 +81,8 @@ enum {
*/
};
typedef int bool_t;
#define SR_MAX_PROBENAME_LEN 32
#define DS_MAX_ANALOG_PROBES_NUM 4
#define DS_MAX_DSO_PROBES_NUM 2
@@ -1262,12 +1264,7 @@ struct ds_trigger_pos {
uint32_t remain_cnt_h;
uint32_t status;
};
typedef int (*sr_receive_data_callback_t)(int fd, int revents, const struct sr_dev_inst *sdi);
#include <log/xlog.h>
/**
* @file
*
@@ -1278,25 +1275,10 @@ typedef int (*sr_receive_data_callback_t)(int fd, int revents, const struct sr_d
//@event, 1:attach, 2:left
typedef void (*hotplug_event_callback)(void *context,void *device, int event, void *userdata);
SR_API int sr_init(struct sr_context **ctx);
SR_API int sr_exit(struct sr_context *ctx);
SR_API int sr_listen_hotplug(struct sr_context *ctx, hotplug_event_callback callback, void *userdata);
SR_API int sr_close_hotplug(struct sr_context *ctx);
SR_API void sr_hotplug_wait_timout(struct sr_context *ctx);
/*--- log.c -----------------------------------------------------------------*/
/**
* Use a shared context, and drop the private log context
*/
SR_API void sr_log_set_context(xlog_context *ctx);
/**
* Set the private log context level
*/
SR_API void sr_log_level(int level);
/*--- device.c --------------------------------------------------------------*/
SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi,
@@ -1341,12 +1323,7 @@ SR_API void sr_config_free(struct sr_config *src);
/*--------------------session.c----------------*/
typedef void (*sr_datafeed_callback_t)(const struct sr_dev_inst *sdi,
const struct sr_datafeed_packet *packet, void *cb_data);
/**
* firmware binary file directory
*/
SR_API void sr_set_firmware_resource_dir(const char *dir);
/* Session setup */
SR_API int sr_session_load(const char *filename);
@@ -1424,14 +1401,64 @@ SR_API uint16_t ds_trigger_get_pos();
SR_API int ds_trigger_set_en(uint16_t enable);
SR_API uint16_t ds_trigger_get_en();
SR_API int ds_trigger_set_mode(uint16_t mode);
SR_PRIV uint16_t ds_trigger_get_mask0(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_value0(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_edge0(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_mask1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_value1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
SR_PRIV uint16_t ds_trigger_get_edge1(uint16_t stage, uint16_t msc, uint16_t lsc, gboolean qutr_mode, gboolean half_mode);
/*--- log.c -----------------------------------------------------------------*/
/**
* Use a shared context, and drop the private log context
*/
SR_API void sr_log_set_context(xlog_context *ctx);
/**
* Set the private log context level
*/
SR_API void sr_log_level(int level);
/*---event define ---------------------------------------------*/
enum libsigrok_event_type
{
EV_DEVICE_ATTACH = 0,
};
struct sr_device_handle;
typedef struct sr_device_handle sr_device_handle;
struct sr_device_info
{
sr_device_handle *_handle;
char _name[50];
char _full_name[300];
bool_t _is_active; //is the current device
bool_t _is_hardware;
};
/*---lib_main.c -----------------------------------------------*/
typedef void (*libsigrok_event_callback_t)(int event);
SR_API int sr_lib_init();
SR_API int sr_lib_exit();
/**
* event type see enum libsigrok_event_type
*/
SR_API void sr_set_event_callback(libsigrok_event_callback_t *cb);
/**
* Store current session data to file
*/
SR_API int sr_store_session_data(const char *file_path);
/**
* firmware binary file directory
*/
SR_API void sr_set_firmware_resource_dir(const char *dir);
#ifdef __cplusplus
}
#endif

View File

@@ -29,10 +29,7 @@
#undef LOG_PREFIX
#define LOG_PREFIX "session: "
char DS_RES_PATH[500] = {0};
/**
* @file
*
@@ -823,18 +820,5 @@ SR_PRIV int sr_session_source_remove_channel(GIOChannel *channel)
{
return _sr_session_source_remove((gintptr)channel);
}
void sr_set_firmware_resource_dir(const char *dir)
{
if (dir){
strcpy(DS_RES_PATH, dir);
int len = strlen(DS_RES_PATH);
if (DS_RES_PATH[len-1] != '/'){
DS_RES_PATH[len] = '/';
DS_RES_PATH[len + 1] = 0;
}
}
}
/** @} */

View File

@@ -0,0 +1,8 @@
#include <libsigrok.h>
int main()
{
return 0;
}