Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
lerwys committed Jul 3, 2020
2 parents d7ff779 + dcd9c7d commit dcef719
Show file tree
Hide file tree
Showing 33 changed files with 1,155 additions and 309 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/sm_io_table)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ldconf)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/dev_mngr)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/apps)

Expand Down
4 changes: 2 additions & 2 deletions examples/include/halcs_examples_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

/* version macros for compile-time API detection */

#define HALCS_EXAMPLES_VERSION_MAJOR 1
#define HALCS_EXAMPLES_VERSION_MINOR 11
#define HALCS_EXAMPLES_VERSION_MAJOR 2
#define HALCS_EXAMPLES_VERSION_MINOR 0
#define HALCS_EXAMPLES_VERSION_PATCH 0

#define HALCS_EXAMPLES_MAKE_VERSION(major, minor, patch) \
Expand Down
71 changes: 52 additions & 19 deletions examples/src/monit_amp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <inttypes.h>
#include <halcs_client.h>
#include <time.h>

#define DFLT_BIND_FOLDER "/tmp/halcs"

Expand All @@ -20,6 +21,7 @@ void print_help (char *program_name)
"\t-b <broker_endpoint> Broker endpoint\n"
"\t-board <AMC board = [0|1|2|3|4|5]>\n"
"\t-halcs <HALCS number = [0|1]>\n"
"\t-poll_time <ms>\n"
, program_name);
}

Expand All @@ -29,6 +31,7 @@ int main (int argc, char *argv [])
char *broker_endp = NULL;
char *board_number_str = NULL;
char *halcs_number_str = NULL;
char *poll_time_str = NULL;
char **str_p = NULL;

if (argc < 2) {
Expand Down Expand Up @@ -60,6 +63,10 @@ int main (int argc, char *argv [])
{
str_p = &halcs_number_str;
}
else if (streq(argv[i], "-poll_time"))
{
str_p = &poll_time_str;
}
/* Fallout for options with parameters */
else {
*str_p = strdup (argv[i]);
Expand All @@ -85,21 +92,29 @@ int main (int argc, char *argv [])
/* Set default halcs number */
uint32_t halcs_number;
if (halcs_number_str == NULL) {
fprintf (stderr, "[client:leds]: Setting default value to HALCS number: %u\n",
fprintf (stderr, "[client:monit_amp]: Setting default value to HALCS number: %u\n",
DFLT_HALCS_NUMBER);
halcs_number = DFLT_HALCS_NUMBER;
}
else {
halcs_number = strtoul (halcs_number_str, NULL, 10);

if (halcs_number > MAX_HALCS_NUMBER) {
fprintf (stderr, "[client:leds]: HALCS number too big! Defaulting to: %u\n",
fprintf (stderr, "[client:monit_amp]: HALCS number too big! Defaulting to: %u\n",
MAX_HALCS_NUMBER);
halcs_number = MAX_HALCS_NUMBER;
}
}

/* Set default halcs number */
uint32_t poll_time;
if (poll_time_str != NULL) {
poll_time = strtoul (poll_time_str, NULL, 10);
}

char producer[50];
char service[50];
snprintf (producer, sizeof (producer), "HALCS%u:DEVIO:DSP%u:%s", board_number, halcs_number, "DATA_PRODUCER");
snprintf (service, sizeof (service), "HALCS%u:DEVIO:DSP%u", board_number, halcs_number);

halcs_client_t *halcs_client = halcs_client_new (broker_endp, verbose, NULL);
Expand All @@ -108,26 +123,44 @@ int main (int argc, char *argv [])
goto err_halcs_client_new;
}

smio_dsp_data_t dsp_data;
halcs_client_err_e err = halcs_get_monit_amp_pos (halcs_client, service, &dsp_data);
if (err != HALCS_CLIENT_SUCCESS){
fprintf (stderr, "[client:monit_amp]: halcs_get_monit_amp_pos failed\n");
goto err_get_monit_amp;
halcs_client_err_e err = HALCS_CLIENT_SUCCESS;
if (poll_time_str != NULL) {
err = halcs_set_monit_poll_time (halcs_client, service, poll_time);
if (err != HALCS_CLIENT_SUCCESS) {
fprintf (stderr, "[client:monit_amp]: halcs_set_monit_poll_time failed\n");
goto err_set_poll_time;
}
}

fprintf (stdout, "[client:monit_amp]: \n"
"monitoring amplitude ch0 = %d\n"
"monitoring amplitude ch1 = %d\n"
"monitoring amplitude ch2 = %d\n"
"monitoring amplitude ch3 = %d\n",
(int32_t) dsp_data.amp_ch0,
(int32_t) dsp_data.amp_ch1,
(int32_t) dsp_data.amp_ch2,
(int32_t) dsp_data.amp_ch3);

err_get_monit_amp:
err_halcs_client_new:
err = halcs_set_monit_subscription (halcs_client, producer, "MONIT_AMP");
if (err != HALCS_CLIENT_SUCCESS) {
fprintf (stderr, "[client:monit_amp]: halcs_set_monit_subscription failed\n");
goto err_set_monit_subscription;
}

smio_dsp_monit_data_t monit_data;
while (!zsys_interrupted) {

err = halcs_get_monit_stream (halcs_client, "MONIT_AMP", &monit_data);
if(err == HALCS_CLIENT_SUCCESS) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);

fprintf (stdout, "[client:monit_amp]: %lld.%.9ld "
"ch0/ch1/ch2/ch3 = %d %d %d %d\n",
(long long)ts.tv_sec, ts.tv_nsec,
(int32_t) monit_data.amp_ch0,
(int32_t) monit_data.amp_ch1,
(int32_t) monit_data.amp_ch2,
(int32_t) monit_data.amp_ch3);
}
}

halcs_remove_monit_subscription (halcs_client, "MONIT_AMP");
err_set_monit_subscription:
err_set_poll_time:
halcs_client_destroy (&halcs_client);
err_halcs_client_new:
str_p = &board_number_str;
free (*str_p);
board_number_str = NULL;
Expand Down
3 changes: 3 additions & 0 deletions include/dev_io_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ extern "C" {
/* SMIO hash key length in chars */
#define SMIO_HKEY_LEN 8
#define NODES_MAX_LEN 100
/* We use 2 PIPE MSG sockets per SMIO */
#define NUM_PIPE_MSG_PER_SMIO 2
#define NODES_MAX_PIPE_MSG_LEN (NUM_PIPE_MSG_PER_SMIO * NODES_MAX_LEN)

/* Node of sig_ops list */
typedef struct {
Expand Down
4 changes: 2 additions & 2 deletions include/halcs_server_prelude.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#endif

/* CZMQ */
#if CZMQ_VERSION < 30001
#error "HALCS requires at least czmq/3.0.1"
#if CZMQ_VERSION < 40002
#error "HALCS requires at least czmq/4.0.2"
#endif

/* MLM */
Expand Down
4 changes: 2 additions & 2 deletions include/revision.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

/* HALCS version macros for compile-time API detection */

#define HALCS_VERSION_MAJOR 1
#define HALCS_VERSION_MINOR 11
#define HALCS_VERSION_MAJOR 2
#define HALCS_VERSION_MINOR 0
#define HALCS_VERSION_PATCH 0

#define HALCS_MAKE_VERSION(major, minor, patch) \
Expand Down
50 changes: 29 additions & 21 deletions include/rw_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ typedef int (*rw_param_check_fp) (uint32_t param);
* format the read parameter to a specific output */
typedef int (*rw_param_format_fp) (uint32_t *param);

/* User function to write 32-bit data */
typedef ssize_t (*smio_thsafe_client_write_32_gen_fp) (smio_t *self, void *sock, uint64_t offs, const uint32_t *data);

/* User function to read 32-bit data */
typedef ssize_t (*smio_thsafe_client_read_32_gen_fp) (smio_t *self, void *sock, uint64_t offs, uint32_t *data);

#define SINGLE_BIT_PARAM 1
#define MULT_BIT_PARAM 0

Expand Down Expand Up @@ -74,7 +80,7 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
void *ret)

#define GET_PARAM_GEN(self, module, base_addr, prefix, reg, field, single_bit, var, \
fmt_funcp, read_32_fp) \
fmt_funcp, read_32_fp, sock) \
({ \
RW_REPLY_TYPE err = RW_OK; \
uint32_t __value; \
Expand All @@ -83,8 +89,8 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
DBE_DEBUG (DBG_SM_IO | DBG_LVL_TRACE, "[sm_io:rw_param:"#module"] " \
"GET_PARAM_" #reg "_" #field ": reading from address 0x%"PRIx64 "\n", \
smio_base_addr | addr); \
ssize_t __ret = ((thsafe_client_read_32_fp) read_32_fp)(self, addr, \
&__value); \
ssize_t __ret = ((smio_thsafe_client_read_32_gen_fp) read_32_fp)(self, \
sock, addr, &__value); \
\
if (__ret != sizeof(uint32_t)) { \
DBE_DEBUG (DBG_SM_IO | DBG_LVL_ERR, "[sm_io:rw_param:"#module"] " \
Expand Down Expand Up @@ -113,11 +119,11 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
#define GET_PARAM(self, module, base_addr, prefix, reg, field, single_bit, var, \
fmt_funcp) \
GET_PARAM_GEN(self, module, base_addr, prefix, reg, field, single_bit, var, \
fmt_funcp, smio_thsafe_client_read_32)
fmt_funcp, smio_thsafe_client_read_32_gen, smio_get_pipe_msg (self))

/* SET or CLEAR parameter based on the last macro parameter "clr_field" */
#define SET_PARAM_GEN(self, module, base_addr, prefix, reg, field, single_bit, value, \
min, max, chk_funcp, clr_field, read_32_fp, write_32_fp) \
min, max, chk_funcp, clr_field, read_32_fp, write_32_fp, sock) \
({ \
RW_REPLY_TYPE err = RW_OK; \
uint64_t addr = base_addr + CONCAT_NAME3(prefix, REG, reg); \
Expand All @@ -128,8 +134,8 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
if (EXPAND_CHECK_LIM_NE(min, max) \
((chk_funcp == NULL) || ((rw_param_check_fp) chk_funcp) (value) == PARAM_OK)) { \
uint32_t __write_value; \
ssize_t __ret = ((thsafe_client_read_32_fp) read_32_fp)(self, \
addr, &__write_value); \
ssize_t __ret = ((smio_thsafe_client_read_32_gen_fp) read_32_fp)(self, \
sock, addr, &__write_value); \
\
if (__ret != sizeof(uint32_t)) { \
DBE_DEBUG (DBG_SM_IO | DBG_LVL_ERR, "[sm_io:rw_param:"#module"] " \
Expand All @@ -154,8 +160,8 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
) \
) \
; \
__ret = ((thsafe_client_write_32_fp) write_32_fp)(self, addr, \
&__write_value); \
__ret = ((smio_thsafe_client_write_32_gen_fp) write_32_fp)(self, sock, \
addr, &__write_value); \
\
if (__ret != sizeof(uint32_t)) { \
DBE_DEBUG (DBG_SM_IO | DBG_LVL_ERR, "[sm_io:rw_param:"#module"] " \
Expand All @@ -181,16 +187,16 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
#define SET_PARAM(self, module, base_addr, prefix, reg, field, single_bit, value, \
min, max, chk_funcp, clr_field) \
SET_PARAM_GEN(self, module, base_addr, prefix, reg, field, single_bit, value, \
min, max, chk_funcp, clr_field, smio_thsafe_client_read_32, \
smio_thsafe_client_write_32)
min, max, chk_funcp, clr_field, smio_thsafe_client_read_32_gen, \
smio_thsafe_client_write_32_gen, smio_get_pipe_msg (self))

/* zmq message in SET_GET_PARAM macro is:
* frame 0: operation code
* frame 1: rw R /W 1 = read mode, 0 = write mode
* frame 2: value to be written (rw = 0) or dummy value (rw = 1)
* */
#define SET_GET_PARAM_GEN(module, base_addr, prefix, reg, field, single_bit, min, \
max, chk_funcp, fmt_funcp, clr_field, read_32_fp, write_32_fp) \
max, chk_funcp, fmt_funcp, clr_field, read_32_fp, write_32_fp, sock) \
do { \
assert (owner); \
assert (args); \
Expand All @@ -204,7 +210,8 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
RW_REPLY_TYPE set_param_return; \
if (rw) { \
set_param_return = GET_PARAM_GEN(self, module, base_addr, \
prefix, reg, field, single_bit, value, fmt_funcp, read_32_fp); \
prefix, reg, field, single_bit, value, fmt_funcp, read_32_fp, \
sock); \
if (set_param_return != RW_OK) { \
return -set_param_return; \
} \
Expand All @@ -216,16 +223,16 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
else { \
set_param_return = SET_PARAM_GEN(self, module, base_addr, \
prefix, reg, field, single_bit, value, min, max, chk_funcp, \
clr_field, read_32_fp, write_32_fp); \
clr_field, read_32_fp, write_32_fp, sock); \
return -set_param_return; \
} \
} while (0)

#define SET_GET_PARAM(module, base_addr, prefix, reg, field, single_bit, min, \
max, chk_funcp, fmt_funcp, clr_field) \
SET_GET_PARAM_GEN(module, base_addr, prefix, reg, field, single_bit, min, \
max, chk_funcp, fmt_funcp, clr_field, smio_thsafe_client_read_32, \
smio_thsafe_client_write_32)
max, chk_funcp, fmt_funcp, clr_field, smio_thsafe_client_read_32_gen, \
smio_thsafe_client_write_32_gen, smio_get_pipe_msg (self))

/* zmq message in SET_GET_PARAM_CHANNEL macro is:
* frame 0: operation code
Expand All @@ -235,7 +242,7 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
* */
#define SET_GET_PARAM_CHANNEL_GEN(module, base_addr, prefix, reg, field, \
chan_offset, chan_num, single_bit, min, max, chk_funcp, fmt_funcp, clr_field, \
read_32_fp, write_32_fp) \
read_32_fp, write_32_fp, sock) \
do { \
assert (owner); \
assert (args); \
Expand All @@ -255,7 +262,8 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
if (rw) { \
set_param_return = GET_PARAM_GEN(self, module, \
(base_addr + (chan*chan_offset)), \
prefix, reg, field, single_bit, value, fmt_funcp, read_32_fp); \
prefix, reg, field, single_bit, value, fmt_funcp, read_32_fp, \
sock); \
if (set_param_return != RW_OK) { \
return -set_param_return; \
} \
Expand All @@ -268,7 +276,7 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
set_param_return = SET_PARAM_GEN(self, module, \
(base_addr + (chan*chan_offset)), \
prefix, reg, field, single_bit, value, min, max, chk_funcp, \
clr_field, read_32_fp, write_32_fp); \
clr_field, read_32_fp, write_32_fp, sock); \
return -set_param_return; \
} \
} while (0)
Expand All @@ -277,8 +285,8 @@ typedef int (*rw_param_format_fp) (uint32_t *param);
chan_num, single_bit, min, max, chk_funcp, fmt_funcp, clr_field) \
SET_GET_PARAM_CHANNEL_GEN(module, base_addr, prefix, reg, field, \
chan_offset, chan_num, single_bit, min, max, chk_funcp, \
fmt_funcp, clr_field, smio_thsafe_client_read_32, \
smio_thsafe_client_write_32)
fmt_funcp, clr_field, smio_thsafe_client_read_32_gen, \
smio_thsafe_client_write_32_gen, smio_get_pipe_msg (self))

#define GET_PARAM_CHANNEL(self, module, base_addr, prefix, reg, field, chan_offset, \
chan_num, single_bit, var, fmt_funcp) \
Expand Down
Loading

0 comments on commit dcef719

Please sign in to comment.