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 "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);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
err = ioctl(devc->fd, IOCTL_BL_GET_SAMPLE_RATE, &arg);
|
||||
devc->cur_samplerate = arg;
|
||||
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,
|
||||
(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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static int beaglelogic_get_lasterror(struct dev_context *devc) {
|
||||
static int beaglelogic_get_lasterror(struct dev_context *devc)
|
||||
{
|
||||
int fd;
|
||||
char buf[16];
|
||||
int ret;
|
||||
|
@ -83,23 +94,28 @@ static int beaglelogic_get_lasterror(struct dev_context *devc) {
|
|||
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);
|
||||
}
|
||||
|
||||
static int beaglelogic_stop(struct dev_context *devc) {
|
||||
static int beaglelogic_stop(struct dev_context *devc)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static int beaglelogic_mmap(struct dev_context *devc) {
|
||||
static int beaglelogic_mmap(struct dev_context *devc)
|
||||
{
|
||||
if (!devc->buffersize)
|
||||
beaglelogic_get_buffersize(devc);
|
||||
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);
|
||||
}
|
||||
|
||||
static int beaglelogic_munmap(struct dev_context *devc) {
|
||||
static int beaglelogic_munmap(struct dev_context *devc)
|
||||
{
|
||||
return munmap(devc->sample_buf, devc->buffersize);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
#include "protocol.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 *results, *res;
|
||||
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,
|
||||
const char *format, ...) {
|
||||
const char *format, ...)
|
||||
{
|
||||
int len, out;
|
||||
va_list args, args_copy;
|
||||
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,
|
||||
int maxlen) {
|
||||
int maxlen)
|
||||
{
|
||||
int len;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
fd_set rset;
|
||||
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,
|
||||
char **tcp_resp) {
|
||||
char **tcp_resp)
|
||||
{
|
||||
GString *response = g_string_sized_new(1024);
|
||||
int len;
|
||||
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,
|
||||
const char *cmd, int *response) {
|
||||
const char *cmd, int *response)
|
||||
{
|
||||
int ret;
|
||||
char *resp = NULL;
|
||||
|
||||
|
@ -224,7 +230,8 @@ static int beaglelogic_tcp_get_int(struct dev_context *devc,
|
|||
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;
|
||||
int ret;
|
||||
|
||||
|
@ -238,23 +245,27 @@ SR_PRIV int beaglelogic_tcp_detect(struct dev_context *devc) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int beaglelogic_open(struct dev_context *devc) {
|
||||
static int beaglelogic_open(struct dev_context *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)
|
||||
return SR_ERR;
|
||||
|
||||
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",
|
||||
(int *)&devc->buffersize);
|
||||
}
|
||||
|
||||
static int beaglelogic_set_buffersize(struct dev_context *devc) {
|
||||
static int beaglelogic_set_buffersize(struct dev_context *devc)
|
||||
{
|
||||
int ret;
|
||||
char *resp;
|
||||
|
||||
|
@ -269,14 +280,16 @@ static int beaglelogic_set_buffersize(struct dev_context *devc) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int beaglelogic_get_samplerate(struct dev_context *devc) {
|
||||
static int beaglelogic_get_samplerate(struct dev_context *devc)
|
||||
{
|
||||
int arg, err;
|
||||
err = beaglelogic_tcp_get_int(devc, "samplerate", &arg);
|
||||
devc->cur_samplerate = arg;
|
||||
return err;
|
||||
}
|
||||
|
||||
static int beaglelogic_set_samplerate(struct dev_context *devc) {
|
||||
static int beaglelogic_set_samplerate(struct dev_context *devc)
|
||||
{
|
||||
int ret;
|
||||
char *resp;
|
||||
|
||||
|
@ -292,12 +305,14 @@ static int beaglelogic_set_samplerate(struct dev_context *devc) {
|
|||
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",
|
||||
(int *)&devc->sampleunit);
|
||||
}
|
||||
|
||||
static int beaglelogic_set_sampleunit(struct dev_context *devc) {
|
||||
static int beaglelogic_set_sampleunit(struct dev_context *devc)
|
||||
{
|
||||
int ret;
|
||||
char *resp;
|
||||
|
||||
|
@ -312,12 +327,14 @@ static int beaglelogic_set_sampleunit(struct dev_context *devc) {
|
|||
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",
|
||||
(int *)&devc->triggerflags);
|
||||
}
|
||||
|
||||
static int beaglelogic_set_triggerflags(struct dev_context *devc) {
|
||||
static int beaglelogic_set_triggerflags(struct dev_context *devc)
|
||||
{
|
||||
int ret;
|
||||
char *resp;
|
||||
|
||||
|
@ -332,26 +349,31 @@ static int beaglelogic_set_triggerflags(struct dev_context *devc) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int beaglelogic_get_lasterror(struct dev_context *devc) {
|
||||
static int beaglelogic_get_lasterror(struct dev_context *devc)
|
||||
{
|
||||
devc->last_error = 0;
|
||||
return SR_OK;
|
||||
}
|
||||
|
||||
static int beaglelogic_start(struct dev_context *devc) {
|
||||
static int beaglelogic_start(struct dev_context *devc)
|
||||
{
|
||||
beaglelogic_tcp_drain(devc);
|
||||
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");
|
||||
}
|
||||
|
||||
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",
|
||||
(int *)&devc->bufunitsize);
|
||||
}
|
||||
|
||||
static int beaglelogic_set_bufunitsize(struct dev_context *devc) {
|
||||
static int beaglelogic_set_bufunitsize(struct dev_context *devc)
|
||||
{
|
||||
int ret;
|
||||
char *resp;
|
||||
|
||||
|
@ -366,7 +388,8 @@ static int beaglelogic_set_bufunitsize(struct dev_context *devc) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int dummy(struct dev_context *devc) {
|
||||
static int dummy(struct dev_context *devc)
|
||||
{
|
||||
(void)devc;
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue