wrs-ipcserver.c 1.24 KB
Newer Older
1
/*
2 3 4 5
 * Copyright (C) 2013 CERN (www.cern.ch)
 * Author: Aurelio Colosimo
 *
 * Released to the public domain
6 7 8 9 10 11 12 13
 */

#include <ppsi/ppsi.h>
#include <ppsi-wrs.h>
#include <hal_exports.h>

/* minipc Encoding  of the supported commands */

14 15
#define PTPDEXP_COMMAND_WR_TRACKING 1
#define PTPDEXP_COMMAND_L1SYNC_TRACKING 2
16 17 18 19 20 21 22 23 24 25 26 27 28 29

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,
	},
};

/* Execute command coming ipc */
static int wrsipc_cmd(int cmd, int value)
{
30
	if(cmd == PTPDEXP_COMMAND_WR_TRACKING) {
baujc's avatar
baujc committed
31
		if ( CONFIG_HAS_EXT_WR ) {
32
			wrh_servo_enable_tracking(value);
baujc's avatar
baujc committed
33 34
			return 0;
		}
35 36
	}
	if(cmd == PTPDEXP_COMMAND_L1SYNC_TRACKING) {
baujc's avatar
baujc committed
37
		if ( CONFIG_HAS_EXT_L1SYNC ) {
38
			wrh_servo_enable_tracking(value);
baujc's avatar
baujc committed
39 40
			return 0;
		}
41 42
	}
	return -1;
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

}

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_cmd.f = export_cmd;

	minipc_export(ppsi_ch, &__rpcdef_cmd);
}