Commit 8ab3d5b5 authored by Aurelio Colosimo's avatar Aurelio Colosimo

arch-wrs: implement mini-ipc server functionality

The core of server functionality is in wrs-ipcserver.c, which
basically consists of a porting of PTPWRd/ptpd_exports.[ch], as they are
seen in commit 080d54fb of the repository:
git://ohwr.org/white-rabbit/ppsi/ptp-noposix.git

Two notes:
- this implementation, like the one I'm porting from, does not make use
of minipc_server_get_fdset, which would make the minipc_server_action
be called only when necessary (by means of a select); indeed,
minipc_server_action is called at each cycle in the main loop;
- the server is created by using "ptpd" as its mnemonic name, for
compatibility with ptp-noposix.
Signed-off-by: Aurelio Colosimo's avatarAurelio Colosimo <aurelio@aureliocolosimo.it>
parent 8354c862
......@@ -12,6 +12,7 @@ OBJ-libarch := $A/wrs-startup.o \
$A/main-loop.o \
$A/wrs-io.o \
$A/wrs-calibration.o \
$A/wrs-ipcserver.o \
lib/cmdline.o \
lib/conf.o \
lib/libc-functions.o \
......
......@@ -9,6 +9,7 @@
#include <minipc.h>
extern struct minipc_ch *hal_ch;
extern struct minipc_ch *ppsi_ch;
#define DEFAULT_TO 200000 /* ms */
......@@ -39,3 +40,5 @@ struct unix_arch_data {
extern int unix_net_check_pkt(struct pp_globals *ppg, int delay_ms);
extern void wrs_main_loop(struct pp_globals *ppg);
extern void wrs_init_ipcserver(struct minipc_ch *ppsi_ch);
......@@ -65,6 +65,8 @@ void wrs_main_loop(struct pp_globals *ppg)
while (1) {
int i;
minipc_server_action(ppsi_ch, 10 /* ms */);
if (ppg->ebest_updated) {
/* If Ebest was changed in previous loop, run best master
* clock before checking for new packets, which would affect
......
/*
* Aurelio Colosimo for CERN, 2013 -- public domain
*/
#include <ppsi/ppsi.h>
#include <ppsi-wrs.h>
#include <hal_exports.h>
#include <wr-api.h>
extern int servo_state_valid;
extern ptpdexp_sync_state_t cur_servo_state;
/* minipc Encoding of the supported commands */
#define PTPDEXP_COMMAND_TRACKING 1
#define PTPDEXP_COMMAND_MAN_ADJUST_PHASE 2
static struct minipc_pd __rpcdef_get_sync_state = {
.name = "get_sync_state",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRUCT, ptpdexp_sync_state_t),
.args = {
MINIPC_ARG_END,
},
};
static struct minipc_pd __rpcdef_cmd = {
.name = "cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
/* Fill struct ptpdexp_sync_state_t with current servo state */
static int wrsipc_get_sync_state(ptpdexp_sync_state_t *state)
{
pp_printf(" GSS: valid %d\n", servo_state_valid);
if(servo_state_valid) {
memcpy(state, &cur_servo_state, sizeof(ptpdexp_sync_state_t));
state->valid = 1;
} else
state->valid = 0;
return 0;
}
/* Execute command coming ipc */
static int wrsipc_cmd(int cmd, int value)
{
if(cmd == PTPDEXP_COMMAND_TRACKING)
wr_servo_enable_tracking(value);
if(cmd == PTPDEXP_COMMAND_MAN_ADJUST_PHASE)
wr_servo_man_adjust_phase(value);
return 0;
}
/* Two functions to manage packet/args conversions */
static int export_get_sync_state(const struct minipc_pd *pd,
uint32_t *args, void *ret)
{
ptpdexp_sync_state_t state;
wrsipc_get_sync_state(&state);
*(ptpdexp_sync_state_t *)ret = state;
return 0;
}
static int export_cmd(const struct minipc_pd *pd,
uint32_t *args, void *ret)
{
int i;
i = wrsipc_cmd(args[0], args[1]);
*(int *)ret = i;
return 0;
}
/* To be called at startup, right after the creation of server channel */
void wrs_init_ipcserver(struct minipc_ch *ppsi_ch)
{
__rpcdef_get_sync_state.f = export_get_sync_state;
__rpcdef_cmd.f = export_cmd;
minipc_export(ppsi_ch, &__rpcdef_get_sync_state);
minipc_export(ppsi_ch, &__rpcdef_cmd);
}
......@@ -29,6 +29,7 @@ CONST_VERBOSITY int pp_diag_verbosity = 0;
#define CONF_PATH "/etc/ppsi.conf"
struct minipc_ch *hal_ch;
struct minipc_ch *ppsi_ch;
int main(int argc, char **argv)
{
......@@ -46,6 +47,12 @@ int main(int argc, char **argv)
if (!hal_ch) /* FIXME should we retry with minipc_client_create? */
pp_printf("Fatal: could not connect to HAL");
ppsi_ch = minipc_server_create("ptpd", 0);
if (!ppsi_ch) /* FIXME should we retry with minipc_server_create? */
pp_printf("Fatal: could not create minipc server");
wrs_init_ipcserver(ppsi_ch);
/* We are hosted, so we can allocate */
ppg = calloc(1, sizeof(*ppg));
if (!ppg)
......
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