Commit 4721a1a1 authored by Lucas Russo's avatar Lucas Russo

hal/sm_io/modules/rffe/*: add new RFFE exported module

parent 8182021e
sm_io_rffe_DIR = hal/sm_io/modules/rffe
sm_io_rffe_OBJS = $(sm_io_rffe_DIR)/sm_io_rffe_core.o \
$(sm_io_rffe_DIR)/sm_io_rffe_exp.o \
$(sm_io_rffe_DIR)/sm_io_rffe_exports.o \
$(sm_io_rffe_DIR)/sm_io_rffe_defaults.o
sm_io_rffe_INCLUDE_DIRS = $(sm_io_rffe_DIR)
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _SM_IO_RFFE_CODES_H_
#define _SM_IO_RFFE_CODES_H_
#include <inttypes.h>
/* This must match the RFFE BSMP server */
#define RFFE_BLOCK_SIZE 127
struct _smio_rffe_data_block_t {
uint8_t data[RFFE_BLOCK_SIZE]; /* data buffer */
};
typedef struct _smio_rffe_data_block_t smio_rffe_data_block_t;
#define RFFE_VERSION_SIZE 8
struct _smio_rffe_version_t {
char data[RFFE_VERSION_SIZE]; /* data buffer */
};
typedef struct _smio_rffe_version_t smio_rffe_version_t;
/* Messaging OPCODES */
#define RFFE_OPCODE_SIZE (sizeof(uint32_t))
#define RFFE_OPCODE_TYPE uint32_t
#define RFFE_OPCODE_SET_GET_SW 0
#define RFFE_NAME_SET_GET_SW "rffe_sw"
#define RFFE_OPCODE_SET_GET_ATT1 1
#define RFFE_NAME_SET_GET_ATT1 "rffe_att1"
#define RFFE_OPCODE_SET_GET_ATT2 2
#define RFFE_NAME_SET_GET_ATT2 "rffe_att2"
#define RFFE_OPCODE_SET_GET_TEMP1 3
#define RFFE_NAME_SET_GET_TEMP1 "rffe_temp1"
#define RFFE_OPCODE_SET_GET_TEMP2 4
#define RFFE_NAME_SET_GET_TEMP2 "rffe_temp2"
#define RFFE_OPCODE_SET_GET_TEMP3 5
#define RFFE_NAME_SET_GET_TEMP3 "rffe_temp3"
#define RFFE_OPCODE_SET_GET_TEMP4 6
#define RFFE_NAME_SET_GET_TEMP4 "rffe_temp4"
#define RFFE_OPCODE_SET_GET_SET_POINT1 7
#define RFFE_NAME_SET_GET_SET_POINT1 "rffe_set_point1"
#define RFFE_OPCODE_SET_GET_SET_POINT2 8
#define RFFE_NAME_SET_GET_SET_POINT2 "rffe_set_point2"
#define RFFE_OPCODE_SET_GET_TEMP_CONTROL 9
#define RFFE_NAME_SET_GET_TEMP_CONTROL "rffe_temp_control"
#define RFFE_OPCODE_SET_GET_OUTPUT1 10
#define RFFE_NAME_SET_GET_OUTPUT1 "rffe_output1"
#define RFFE_OPCODE_SET_GET_OUTPUT2 11
#define RFFE_NAME_SET_GET_OUTPUT2 "rffe_output2"
#define RFFE_OPCODE_SET_GET_RESET 12
#define RFFE_NAME_SET_GET_RESET "rffe_reset"
#define RFFE_OPCODE_SET_GET_REPROG 13
#define RFFE_NAME_SET_GET_REPROG "rffe_reprog"
#define RFFE_OPCODE_SET_GET_DATA 14
#define RFFE_NAME_SET_GET_DATA "rffe_data"
#define RFFE_OPCODE_SET_GET_VERSION 15
#define RFFE_NAME_SET_GET_VERSION "rffe_version"
#define RFFE_OPCODE_SET_GET_SW_LVL 16
#define RFFE_NAME_SET_GET_SW_LVL "rffe_sw_lvl"
#define RFFE_OPCODE_END 17
#define RFFE_OK 0 /* Operation was successful */
#define RFFE_ERR 1 /* Could not set/get value */
#define RFFE_UNINPL 2 /* Unimplemented function or operation */
#define RFFE_REPLY_END 3 /* End marker */
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <stdlib.h>
#include <assert.h>
#include <czmq.h>
#include "sm_io_rffe_core.h"
#include "sm_io_err.h"
#include "hal_assert.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label, /* err_core */ ...) \
ASSERT_HAL_TEST(test_boolean, SM_IO, "[sm_io_rffe_core]", \
err_str, err_goto_label, /* err_core */ __VA_ARGS__)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label, /* err_core */ ...) \
ASSERT_HAL_ALLOC(ptr, SM_IO, "[sm_io_rffe_core]", \
smio_err_str(SMIO_ERR_ALLOC), \
err_goto_label, /* err_core */ __VA_ARGS__)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, SM_IO, "[sm_io_rffe_core]", \
smio_err_str (err_type))
/* Creates a new instance of Device Information */
smio_rffe_t * smio_rffe_new (smio_t *parent)
{
(void) parent;
smio_rffe_t *self = (smio_rffe_t *) zmalloc (sizeof *self);
ASSERT_ALLOC(self, err_self_alloc);
self->ctl = smch_rffe_new (parent, 0);
ASSERT_ALLOC(self->ctl, err_rffe_alloc);
return self;
err_rffe_alloc:
free (self);
err_self_alloc:
return NULL;
}
/* Destroy an instance of the Device Information */
smio_err_e smio_rffe_destroy (smio_rffe_t **self_p)
{
assert (self_p);
if (*self_p) {
smio_rffe_t *self = *self_p;
smch_rffe_destroy (&self->ctl);
free (self);
*self_p = NULL;
}
return SMIO_SUCCESS;
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _SM_IO_RFFE_CORE_H_
#define _SM_IO_RFFE_CORE_H_
#include <inttypes.h>
#include "sm_io_err.h"
#include "sm_io.h"
#include "sm_ch_rffe.h"
#define SMIO_RFFE_HANDLER(self) ((smio_rffe_t *) self->smio_handler)
#define SMIO_CTL_HANDLER(self) (SMIO_RFFE_HANDLER(self)->ctl)
struct _smio_rffe_t {
smch_rffe_t *ctl;
};
/* Opaque class structure */
typedef struct _smio_rffe_t smio_rffe_t;
/***************** Our methods *****************/
/* Creates a new instance of the smio realization */
smio_rffe_t * smio_rffe_new (smio_t *parent);
/* Destroys the smio realization */
smio_err_e smio_rffe_destroy (smio_rffe_t **self_p);
#endif
#include "hal_assert.h"
#include "sm_io_err.h"
#include "sm_io_rffe_defaults.h"
/* We actually use the libclient to do the "heavy" work for us */
#include "bpm_client.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
#undef ASSERT_TEST
#endif
#define ASSERT_TEST(test_boolean, err_str, err_goto_label, /* err_core */ ...) \
ASSERT_HAL_TEST(test_boolean, SM_IO, "[sm_io:rffe_defaults]", \
err_str, err_goto_label, /* err_core */ __VA_ARGS__)
#ifdef ASSERT_ALLOC
#undef ASSERT_ALLOC
#endif
#define ASSERT_ALLOC(ptr, err_goto_label, /* err_core */ ...) \
ASSERT_HAL_ALLOC(ptr, SM_IO, "[sm_io:rffe_defaults]", \
smio_err_str(SMIO_ERR_ALLOC), \
err_goto_label, /* err_core */ __VA_ARGS__)
#ifdef CHECK_ERR
#undef CHECK_ERR
#endif
#define CHECK_ERR(err, err_type) \
CHECK_HAL_ERR(err, SM_IO, "[sm_io:rffe_defaults]", \
smio_err_str (err_type))
#define SMIO_RFFE_LIBCLIENT_LOG_MODE "a"
/* We use the actual libclient to send and configure our default values,
* maintaining internal consistency. So, in fact, we are sending ourselves
* a message containing the default values. Because of this approach, we
* only get to default our values when the functions are already exported
* to the broker, which happens on a late stage. This could cause a fast
* client to get an inconsistent state from our server */
/* TODO: Avoid exporting the functions before we have initialized
* our server with the default values */
smio_err_e rffe_config_defaults (char *broker_endp, char *service,
const char *log_file_name)
{
DBE_DEBUG (DBG_SM_IO | DBG_LVL_INFO, "[sm_io:rffe_defaults] Configuring SMIO "
"RFFE with default values ...\n");
bpm_client_err_e client_err = BPM_CLIENT_SUCCESS;
smio_err_e err = SMIO_SUCCESS;
bpm_client_t *config_client = bpm_client_new_log_mode (broker_endp, 0,
log_file_name, SMIO_RFFE_LIBCLIENT_LOG_MODE);
client_err = bpm_set_rffe_sw (config_client, service, RFFE_DFLT_SW);
ASSERT_TEST(client_err == BPM_CLIENT_SUCCESS, "Could not set RFFE switching value",
err_param_set, SMIO_ERR_CONFIG_DFLT);
client_err = bpm_set_rffe_att1 (config_client, service, RFFE_DFLT_ATT1);
ASSERT_TEST(client_err == BPM_CLIENT_SUCCESS, "Could not set RFFE attenuator 1 value",
err_param_set, SMIO_ERR_CONFIG_DFLT);
client_err = bpm_set_rffe_att2 (config_client, service, RFFE_DFLT_ATT2);
ASSERT_TEST(client_err == BPM_CLIENT_SUCCESS, "Could not set RFFE attenuator 2 value",
err_param_set, SMIO_ERR_CONFIG_DFLT);
err_param_set:
bpm_client_destroy (&config_client);
return err;
}
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _RFFE_DEFAULTS_H_
#define _RFFE_DEFAULTS_H_
#define RFFE_DFLT_SW 0x1 /* No switching, direct position */
#define RFFE_DFLT_ATT1 31.5 /* 31.1 dB attenuation */
#define RFFE_DFLT_ATT2 31.5 /* 31.1 dB attenuation */
smio_err_e rffe_config_defaults (char *broker_endp, char *service,
const char *log_file_name);
#endif
This diff is collapsed.
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _RFFE_H_
#define _RFFE_H_
#include "sm_io_bootstrap.h"
#include "smio_thsafe_zmq_client.h"
#include "exp_ops_codes.h"
#include "sm_io_rffe_core.h"
/* Known modules IDs */
#define RFFE_DEVID 0x7af21909
#define RFFE_NAME "RFFE"
extern const smio_bootstrap_ops_t rffe_bootstrap_ops;
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "sm_io_rffe_exports.h"
#include "sm_io_rffe_codes.h"
/* Description SMIO RFFE functions */
disp_op_t rffe_set_get_sw_exp = {
.name = RFFE_NAME_SET_GET_SW,
.opcode = RFFE_OPCODE_SET_GET_SW,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_att1_exp = {
.name = RFFE_NAME_SET_GET_ATT1,
.opcode = RFFE_OPCODE_SET_GET_ATT1,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_att2_exp = {
.name = RFFE_NAME_SET_GET_ATT2,
.opcode = RFFE_OPCODE_SET_GET_ATT2,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_temp1_exp = {
.name = RFFE_NAME_SET_GET_TEMP1,
.opcode = RFFE_OPCODE_SET_GET_TEMP1,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_temp2_exp = {
.name = RFFE_NAME_SET_GET_TEMP2,
.opcode = RFFE_OPCODE_SET_GET_TEMP2,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_temp3_exp = {
.name = RFFE_NAME_SET_GET_TEMP3,
.opcode = RFFE_OPCODE_SET_GET_TEMP3,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_temp4_exp = {
.name = RFFE_NAME_SET_GET_TEMP4,
.opcode = RFFE_OPCODE_SET_GET_TEMP4,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_set_point1_exp = {
.name = RFFE_NAME_SET_GET_SET_POINT1,
.opcode = RFFE_OPCODE_SET_GET_SET_POINT1,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_set_point2_exp = {
.name = RFFE_NAME_SET_GET_SET_POINT2,
.opcode = RFFE_OPCODE_SET_GET_SET_POINT2,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_temp_control_exp = {
.name = RFFE_NAME_SET_GET_TEMP_CONTROL,
.opcode = RFFE_OPCODE_SET_GET_TEMP_CONTROL,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_output1_exp = {
.name = RFFE_NAME_SET_GET_OUTPUT1,
.opcode = RFFE_OPCODE_SET_GET_OUTPUT1,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_output2_exp = {
.name = RFFE_NAME_SET_GET_OUTPUT2,
.opcode = RFFE_OPCODE_SET_GET_OUTPUT2,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_DOUBLE, double),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_reset_exp = {
.name = RFFE_NAME_SET_GET_RESET,
.opcode = RFFE_OPCODE_SET_GET_RESET,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_reprog_exp = {
.name = RFFE_NAME_SET_GET_REPROG,
.opcode = RFFE_OPCODE_SET_GET_REPROG,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_data_exp = {
.name = RFFE_NAME_SET_GET_DATA,
.opcode = RFFE_OPCODE_SET_GET_DATA,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_STRUCT, smio_rffe_data_block_t),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_STRUCT, smio_rffe_data_block_t),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_version_exp = {
.name = RFFE_NAME_SET_GET_VERSION,
.opcode = RFFE_OPCODE_SET_GET_VERSION,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_STRUCT, smio_rffe_version_t),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_STRUCT, smio_rffe_version_t),
DISP_ARG_END
}
};
disp_op_t rffe_set_get_sw_lvl_exp = {
.name = RFFE_NAME_SET_GET_SW_LVL,
.opcode = RFFE_OPCODE_SET_GET_SW_LVL,
.retval = DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
.retval_owner = DISP_OWNER_OTHER,
.args = {
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_ENCODE(DISP_ATYPE_UINT32, uint32_t),
DISP_ARG_END
}
};
/* Exported function description */
const disp_op_t *rffe_exp_ops [] = {
&rffe_set_get_sw_exp,
&rffe_set_get_att1_exp,
&rffe_set_get_att2_exp,
&rffe_set_get_temp1_exp,
&rffe_set_get_temp2_exp,
&rffe_set_get_temp3_exp,
&rffe_set_get_temp4_exp,
&rffe_set_get_set_point1_exp,
&rffe_set_get_set_point2_exp,
&rffe_set_get_temp_control_exp,
&rffe_set_get_output1_exp,
&rffe_set_get_output2_exp,
&rffe_set_get_reset_exp,
&rffe_set_get_reprog_exp,
&rffe_set_get_data_exp,
&rffe_set_get_version_exp,
&rffe_set_get_sw_lvl_exp,
NULL
};
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _SM_IO_RFFE_EXPORTS_H_
#define _SM_IO_RFFE_EXPORTS_H_
#include "dispatch_table.h"
extern disp_op_t rffe_set_get_kx_exp;
extern disp_op_t rffe_set_get_sw_exp;
extern disp_op_t rffe_set_get_att1_exp;
extern disp_op_t rffe_set_get_att2_exp;
extern disp_op_t rffe_get_temp1_exp;
extern disp_op_t rffe_get_temp2_exp;
extern disp_op_t rffe_get_temp3_exp;
extern disp_op_t rffe_get_temp4_exp;
extern disp_op_t rffe_set_get_set_point1_exp;
extern disp_op_t rffe_set_get_set_point2_exp;
extern disp_op_t rffe_set_get_temp_control_exp;
extern disp_op_t rffe_set_get_output1_exp;
extern disp_op_t rffe_set_get_output2_exp;
extern disp_op_t rffe_set_get_reset_exp;
extern disp_op_t rffe_set_get_reprog_exp;
extern disp_op_t rffe_set_get_data_exp;
extern disp_op_t rffe_get_version_exp;
extern disp_op_t rffe_set_get_sw_lvl_exp;
extern const disp_op_t *rffe_exp_ops [];
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment