beaglelogic: Coding style fixes
In beaglelogic_native.c and beaglelogic_tcp.c Signed-off-by: Kumar Abhishek <abhishek@theembeddedkitchen.net>
This commit is contained in:
parent
ca0d1a21af
commit
a31010b3e4
|
@ -20,53 +20,64 @@
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "beaglelogic.h"
|
#include "beaglelogic.h"
|
||||||
|
|
||||||
static int beaglelogic_open_nonblock(struct dev_context *devc) {
|
static int beaglelogic_open_nonblock(struct dev_context *devc)
|
||||||
|
{
|
||||||
devc->fd = open(BEAGLELOGIC_DEV_NODE, O_RDONLY | O_NONBLOCK);
|
devc->fd = open(BEAGLELOGIC_DEV_NODE, O_RDONLY | O_NONBLOCK);
|
||||||
return (devc->fd == -1 ? SR_ERR : SR_OK);
|
return (devc->fd == -1 ? SR_ERR : SR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_close(struct dev_context *devc) {
|
static int beaglelogic_close(struct dev_context *devc)
|
||||||
|
{
|
||||||
return close(devc->fd);
|
return close(devc->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_buffersize(struct dev_context *devc) {
|
static int beaglelogic_get_buffersize(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_GET_BUFFER_SIZE, &devc->buffersize);
|
return ioctl(devc->fd, IOCTL_BL_GET_BUFFER_SIZE, &devc->buffersize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_buffersize(struct dev_context *devc) {
|
static int beaglelogic_set_buffersize(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_SET_BUFFER_SIZE, devc->buffersize);
|
return ioctl(devc->fd, IOCTL_BL_SET_BUFFER_SIZE, devc->buffersize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is treated differently as it gets a uint64_t while a uint32_t is read */
|
/* This is treated differently as it gets a uint64_t while a uint32_t is read */
|
||||||
static int beaglelogic_get_samplerate(struct dev_context *devc) {
|
static int beaglelogic_get_samplerate(struct dev_context *devc)
|
||||||
|
{
|
||||||
uint32_t arg, err;
|
uint32_t arg, err;
|
||||||
err = ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_RATE, &arg);
|
err = ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_RATE, &arg);
|
||||||
devc->cur_samplerate = arg;
|
devc->cur_samplerate = arg;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_samplerate(struct dev_context *devc) {
|
static int beaglelogic_set_samplerate(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_RATE,
|
return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_RATE,
|
||||||
(uint32_t)devc->cur_samplerate);
|
(uint32_t)devc->cur_samplerate);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_sampleunit(struct dev_context *devc) {
|
static int beaglelogic_get_sampleunit(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_UNIT, &devc->sampleunit);
|
return ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_UNIT, &devc->sampleunit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_sampleunit(struct dev_context *devc) {
|
static int beaglelogic_set_sampleunit(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_UNIT, devc->sampleunit);
|
return ioctl(devc->fd, IOCTL_BL_SET_SAMPLE_UNIT, devc->sampleunit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_triggerflags(struct dev_context *devc) {
|
static int beaglelogic_get_triggerflags(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_GET_TRIGGER_FLAGS, &devc->triggerflags);
|
return ioctl(devc->fd, IOCTL_BL_GET_TRIGGER_FLAGS, &devc->triggerflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_triggerflags(struct dev_context *devc) {
|
static int beaglelogic_set_triggerflags(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_SET_TRIGGER_FLAGS, devc->triggerflags);
|
return ioctl(devc->fd, IOCTL_BL_SET_TRIGGER_FLAGS, devc->triggerflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_lasterror(struct dev_context *devc) {
|
static int beaglelogic_get_lasterror(struct dev_context *devc)
|
||||||
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char buf[16];
|
char buf[16];
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -83,23 +94,28 @@ static int beaglelogic_get_lasterror(struct dev_context *devc) {
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_start(struct dev_context *devc) {
|
static int beaglelogic_start(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_START);
|
return ioctl(devc->fd, IOCTL_BL_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_stop(struct dev_context *devc) {
|
static int beaglelogic_stop(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_STOP);
|
return ioctl(devc->fd, IOCTL_BL_STOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_bufunitsize(struct dev_context *devc) {
|
static int beaglelogic_get_bufunitsize(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_GET_BUFUNIT_SIZE, &devc->bufunitsize);
|
return ioctl(devc->fd, IOCTL_BL_GET_BUFUNIT_SIZE, &devc->bufunitsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_bufunitsize(struct dev_context *devc) {
|
static int beaglelogic_set_bufunitsize(struct dev_context *devc)
|
||||||
|
{
|
||||||
return ioctl(devc->fd, IOCTL_BL_SET_BUFUNIT_SIZE, devc->bufunitsize);
|
return ioctl(devc->fd, IOCTL_BL_SET_BUFUNIT_SIZE, devc->bufunitsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_mmap(struct dev_context *devc) {
|
static int beaglelogic_mmap(struct dev_context *devc)
|
||||||
|
{
|
||||||
if (!devc->buffersize)
|
if (!devc->buffersize)
|
||||||
beaglelogic_get_buffersize(devc);
|
beaglelogic_get_buffersize(devc);
|
||||||
devc->sample_buf = mmap(NULL, devc->buffersize,
|
devc->sample_buf = mmap(NULL, devc->buffersize,
|
||||||
|
@ -107,7 +123,8 @@ static int beaglelogic_mmap(struct dev_context *devc) {
|
||||||
return (devc->sample_buf == MAP_FAILED ? -1 : SR_OK);
|
return (devc->sample_buf == MAP_FAILED ? -1 : SR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_munmap(struct dev_context *devc) {
|
static int beaglelogic_munmap(struct dev_context *devc)
|
||||||
|
{
|
||||||
return munmap(devc->sample_buf, devc->buffersize);
|
return munmap(devc->sample_buf, devc->buffersize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,8 @@
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "beaglelogic.h"
|
#include "beaglelogic.h"
|
||||||
|
|
||||||
static int beaglelogic_tcp_open(struct dev_context *devc) {
|
static int beaglelogic_tcp_open(struct dev_context *devc)
|
||||||
|
{
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *results, *res;
|
struct addrinfo *results, *res;
|
||||||
int err;
|
int err;
|
||||||
|
@ -84,7 +85,8 @@ static int beaglelogic_tcp_open(struct dev_context *devc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_tcp_send_cmd(struct dev_context *devc,
|
static int beaglelogic_tcp_send_cmd(struct dev_context *devc,
|
||||||
const char *format, ...) {
|
const char *format, ...)
|
||||||
|
{
|
||||||
int len, out;
|
int len, out;
|
||||||
va_list args, args_copy;
|
va_list args, args_copy;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
@ -120,7 +122,8 @@ static int beaglelogic_tcp_send_cmd(struct dev_context *devc,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_tcp_read_data(struct dev_context *devc, char *buf,
|
static int beaglelogic_tcp_read_data(struct dev_context *devc, char *buf,
|
||||||
int maxlen) {
|
int maxlen)
|
||||||
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = recv(devc->socket, buf, maxlen, 0);
|
len = recv(devc->socket, buf, maxlen, 0);
|
||||||
|
@ -133,7 +136,8 @@ static int beaglelogic_tcp_read_data(struct dev_context *devc, char *buf,
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV int beaglelogic_tcp_drain(struct dev_context *devc) {
|
SR_PRIV int beaglelogic_tcp_drain(struct dev_context *devc)
|
||||||
|
{
|
||||||
char *buf = g_malloc(1024);
|
char *buf = g_malloc(1024);
|
||||||
fd_set rset;
|
fd_set rset;
|
||||||
int ret, len = 0;
|
int ret, len = 0;
|
||||||
|
@ -160,7 +164,8 @@ SR_PRIV int beaglelogic_tcp_drain(struct dev_context *devc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_tcp_get_string(struct dev_context *devc, const char *cmd,
|
static int beaglelogic_tcp_get_string(struct dev_context *devc, const char *cmd,
|
||||||
char **tcp_resp) {
|
char **tcp_resp)
|
||||||
|
{
|
||||||
GString *response = g_string_sized_new(1024);
|
GString *response = g_string_sized_new(1024);
|
||||||
int len;
|
int len;
|
||||||
gint64 timeout;
|
gint64 timeout;
|
||||||
|
@ -206,7 +211,8 @@ static int beaglelogic_tcp_get_string(struct dev_context *devc, const char *cmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_tcp_get_int(struct dev_context *devc,
|
static int beaglelogic_tcp_get_int(struct dev_context *devc,
|
||||||
const char *cmd, int *response) {
|
const char *cmd, int *response)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *resp = NULL;
|
char *resp = NULL;
|
||||||
|
|
||||||
|
@ -224,7 +230,8 @@ static int beaglelogic_tcp_get_int(struct dev_context *devc,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV int beaglelogic_tcp_detect(struct dev_context *devc) {
|
SR_PRIV int beaglelogic_tcp_detect(struct dev_context *devc)
|
||||||
|
{
|
||||||
char *resp = NULL;
|
char *resp = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -238,23 +245,27 @@ SR_PRIV int beaglelogic_tcp_detect(struct dev_context *devc) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_open(struct dev_context *devc) {
|
static int beaglelogic_open(struct dev_context *devc)
|
||||||
|
{
|
||||||
return beaglelogic_tcp_open(devc);
|
return beaglelogic_tcp_open(devc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_close(struct dev_context *devc) {
|
static int beaglelogic_close(struct dev_context *devc)
|
||||||
|
{
|
||||||
if (close(devc->socket) < 0)
|
if (close(devc->socket) < 0)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_buffersize(struct dev_context *devc) {
|
static int beaglelogic_get_buffersize(struct dev_context *devc)
|
||||||
|
{
|
||||||
return beaglelogic_tcp_get_int(devc, "memalloc",
|
return beaglelogic_tcp_get_int(devc, "memalloc",
|
||||||
(int *)&devc->buffersize);
|
(int *)&devc->buffersize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_buffersize(struct dev_context *devc) {
|
static int beaglelogic_set_buffersize(struct dev_context *devc)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *resp;
|
char *resp;
|
||||||
|
|
||||||
|
@ -269,14 +280,16 @@ static int beaglelogic_set_buffersize(struct dev_context *devc) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_samplerate(struct dev_context *devc) {
|
static int beaglelogic_get_samplerate(struct dev_context *devc)
|
||||||
|
{
|
||||||
int arg, err;
|
int arg, err;
|
||||||
err = beaglelogic_tcp_get_int(devc, "samplerate", &arg);
|
err = beaglelogic_tcp_get_int(devc, "samplerate", &arg);
|
||||||
devc->cur_samplerate = arg;
|
devc->cur_samplerate = arg;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_samplerate(struct dev_context *devc) {
|
static int beaglelogic_set_samplerate(struct dev_context *devc)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *resp;
|
char *resp;
|
||||||
|
|
||||||
|
@ -292,12 +305,14 @@ static int beaglelogic_set_samplerate(struct dev_context *devc) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_sampleunit(struct dev_context *devc) {
|
static int beaglelogic_get_sampleunit(struct dev_context *devc)
|
||||||
|
{
|
||||||
return beaglelogic_tcp_get_int(devc, "sampleunit",
|
return beaglelogic_tcp_get_int(devc, "sampleunit",
|
||||||
(int *)&devc->sampleunit);
|
(int *)&devc->sampleunit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_sampleunit(struct dev_context *devc) {
|
static int beaglelogic_set_sampleunit(struct dev_context *devc)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *resp;
|
char *resp;
|
||||||
|
|
||||||
|
@ -312,12 +327,14 @@ static int beaglelogic_set_sampleunit(struct dev_context *devc) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_triggerflags(struct dev_context *devc) {
|
static int beaglelogic_get_triggerflags(struct dev_context *devc)
|
||||||
|
{
|
||||||
return beaglelogic_tcp_get_int(devc, "triggerflags",
|
return beaglelogic_tcp_get_int(devc, "triggerflags",
|
||||||
(int *)&devc->triggerflags);
|
(int *)&devc->triggerflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_triggerflags(struct dev_context *devc) {
|
static int beaglelogic_set_triggerflags(struct dev_context *devc)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *resp;
|
char *resp;
|
||||||
|
|
||||||
|
@ -332,26 +349,31 @@ static int beaglelogic_set_triggerflags(struct dev_context *devc) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_lasterror(struct dev_context *devc) {
|
static int beaglelogic_get_lasterror(struct dev_context *devc)
|
||||||
|
{
|
||||||
devc->last_error = 0;
|
devc->last_error = 0;
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_start(struct dev_context *devc) {
|
static int beaglelogic_start(struct dev_context *devc)
|
||||||
|
{
|
||||||
beaglelogic_tcp_drain(devc);
|
beaglelogic_tcp_drain(devc);
|
||||||
return beaglelogic_tcp_send_cmd(devc, "get");
|
return beaglelogic_tcp_send_cmd(devc, "get");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_stop(struct dev_context *devc) {
|
static int beaglelogic_stop(struct dev_context *devc)
|
||||||
|
{
|
||||||
return beaglelogic_tcp_send_cmd(devc, "close");
|
return beaglelogic_tcp_send_cmd(devc, "close");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_get_bufunitsize(struct dev_context *devc) {
|
static int beaglelogic_get_bufunitsize(struct dev_context *devc)
|
||||||
|
{
|
||||||
return beaglelogic_tcp_get_int(devc, "bufunitsize",
|
return beaglelogic_tcp_get_int(devc, "bufunitsize",
|
||||||
(int *)&devc->bufunitsize);
|
(int *)&devc->bufunitsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int beaglelogic_set_bufunitsize(struct dev_context *devc) {
|
static int beaglelogic_set_bufunitsize(struct dev_context *devc)
|
||||||
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *resp;
|
char *resp;
|
||||||
|
|
||||||
|
@ -366,7 +388,8 @@ static int beaglelogic_set_bufunitsize(struct dev_context *devc) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dummy(struct dev_context *devc) {
|
static int dummy(struct dev_context *devc)
|
||||||
|
{
|
||||||
(void)devc;
|
(void)devc;
|
||||||
return SR_ERR_NA;
|
return SR_ERR_NA;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue