Commit 0d894a74 authored by Alessandro Rubini's avatar Alessandro Rubini

userspace/hal (and more): open a logfile for IPC, with '-l'

Meanwhile, this cleans up declaration of functions that were not prototypes
in wrsw_hal.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent c42d6c5a
...@@ -100,7 +100,7 @@ struct rts_pll_state { ...@@ -100,7 +100,7 @@ struct rts_pll_state {
/* API */ /* API */
/* Connects to the RT CPU */ /* Connects to the RT CPU */
int rts_connect(); int rts_connect(char *filename);
/* Queries the RT CPU PLL state */ /* Queries the RT CPU PLL state */
int rts_get_state(struct rts_pll_state *state); int rts_get_state(struct rts_pll_state *state);
......
...@@ -6,6 +6,13 @@ ...@@ -6,6 +6,13 @@
* *
* Released in the public domain * Released in the public domain
*/ */
/*
* This file must *only* be used by wrsw_hal, even if it lives in libwr
* Only wr_phytool uses it, for strange hacking, but it interferes with
* hal. Nobody uses phytool in production, so that's ok. I'll add some
* check, maybe, someday.
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
...@@ -118,11 +125,21 @@ int rts_debug_command(int command, int value) ...@@ -118,11 +125,21 @@ int rts_debug_command(int command, int value)
return rval; return rval;
} }
int rts_connect() int rts_connect(char *logfilename)
{ {
static FILE *f;
minipc_set_poll(25000); /* 25ms, default is 10ms */ minipc_set_poll(25000); /* 25ms, default is 10ms */
client = minipc_client_create(RTS_MAILBOX_ADDR, 0 /* not verbose */ ); client = minipc_client_create(RTS_MAILBOX_ADDR, 0 /* not verbose */ );
if (!client) if (!client)
return -1; return -1;
if (!f && logfilename) {
f = fopen(logfilename, "a");
if (!f) /* ignore error for logs */
return 0;
setvbuf(f, NULL, _IONBF, 0);
minipc_set_logfile(client, f);
}
return 0; return 0;
} }
...@@ -49,8 +49,6 @@ static struct EP_WB _ep_wb; ...@@ -49,8 +49,6 @@ static struct EP_WB _ep_wb;
#define fpga_writel(val, addr) *(volatile uint32_t *)(fpga + (addr)) = val #define fpga_writel(val, addr) *(volatile uint32_t *)(fpga + (addr)) = val
#define fpga_readl(addr) (*(volatile uint32_t *)(fpga + (addr))) #define fpga_readl(addr) (*(volatile uint32_t *)(fpga + (addr)))
extern int rts_connect();
static int hal_nports_local; static int hal_nports_local;
static struct wrs_shm_head *hal_head; static struct wrs_shm_head *hal_head;
static struct hal_port_state *hal_ports; static struct hal_port_state *hal_ports;
...@@ -301,7 +299,7 @@ void calc_trans(int ep, int argc, char *argv[]) ...@@ -301,7 +299,7 @@ void calc_trans(int ep, int argc, char *argv[])
// fpga_writel(EP_DMCR_N_AVG_W(1024) | EP_DMCR_EN, IDX_TO_EP(ep) + EP_REG(DMCR)); // fpga_writel(EP_DMCR_N_AVG_W(1024) | EP_DMCR_EN, IDX_TO_EP(ep) + EP_REG(DMCR));
if( rts_connect() < 0) if( rts_connect(NULL) < 0)
{ {
printf("Can't connect to the RT subsys\n"); printf("Can't connect to the RT subsys\n");
return; return;
...@@ -463,7 +461,7 @@ void rt_command(int ep, int argc, char *argv[]) ...@@ -463,7 +461,7 @@ void rt_command(int ep, int argc, char *argv[])
assert(hal_shm_init() == 0); /* to get hal_nports_local */ assert(hal_shm_init() == 0); /* to get hal_nports_local */
if( rts_connect() < 0) if( rts_connect(NULL) < 0)
{ {
printf("Can't connect to the RT subsys\n"); printf("Can't connect to the RT subsys\n");
return; return;
......
...@@ -176,8 +176,10 @@ static int export_lock_cmd(const struct minipc_pd *pd, ...@@ -176,8 +176,10 @@ static int export_lock_cmd(const struct minipc_pd *pd,
} }
/* Creates a wripc server and exports all public API functions */ /* Creates a wripc server and exports all public API functions */
int hal_init_wripc(struct hal_port_state *hal_ports) int hal_init_wripc(struct hal_port_state *hal_ports, char *logfilename)
{ {
static FILE *f;
ports = hal_ports; /* static pointer used later */ ports = hal_ports; /* static pointer used later */
hal_ch = minipc_server_create(WRSW_HAL_SERVER_ADDR, 0); hal_ch = minipc_server_create(WRSW_HAL_SERVER_ADDR, 0);
...@@ -189,6 +191,14 @@ int hal_init_wripc(struct hal_port_state *hal_ports) ...@@ -189,6 +191,14 @@ int hal_init_wripc(struct hal_port_state *hal_ports)
} }
/* NOTE: check_running is not remotely called, so I don't export it */ /* NOTE: check_running is not remotely called, so I don't export it */
if (!f && logfilename) {
f = fopen(logfilename, "a");
if (f) {/* ignore error for logs */
setvbuf(f, NULL, _IONBF, 0);
minipc_set_logfile(hal_ch, f);
}
}
/* fill the function pointers */ /* fill the function pointers */
__rpcdef_pps_cmd.f = export_pps_cmd; __rpcdef_pps_cmd.f = export_pps_cmd;
__rpcdef_lock_cmd.f = export_lock_cmd; __rpcdef_lock_cmd.f = export_lock_cmd;
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
static int daemon_mode = 0; static int daemon_mode = 0;
static hal_cleanup_callback_t cleanup_cb[MAX_CLEANUP_CALLBACKS]; static hal_cleanup_callback_t cleanup_cb[MAX_CLEANUP_CALLBACKS];
static char *logfilename;
struct hal_shmem_header *hal_shmem; struct hal_shmem_header *hal_shmem;
/* Adds a function to be called during the HAL shutdown. */ /* Adds a function to be called during the HAL shutdown. */
...@@ -95,10 +97,10 @@ static int hal_init() ...@@ -95,10 +97,10 @@ static int hal_init()
/* Low-level hw init, init non-kernel drivers */ /* Low-level hw init, init non-kernel drivers */
assert_init(shw_init()); assert_init(shw_init());
assert_init(hal_init_timing()); assert_init(hal_init_timing(logfilename));
/* Initialize port FSMs and IPC/RPC - see hal_ports.c */ /* Initialize port FSMs and IPC/RPC - see hal_ports.c */
assert_init(hal_port_init_all()); assert_init(hal_port_init_all(logfilename));
//everything is fine up to here, we can blink green LED //everything is fine up to here, we can blink green LED
shw_io_write(shw_io_led_state_o, 0); shw_io_write(shw_io_led_state_o, 0);
...@@ -161,7 +163,7 @@ static void hal_parse_cmdline(int argc, char *argv[]) ...@@ -161,7 +163,7 @@ static void hal_parse_cmdline(int argc, char *argv[])
{ {
int opt; int opt;
while ((opt = getopt(argc, argv, "dhqv")) != -1) { while ((opt = getopt(argc, argv, "dhqvl:")) != -1) {
switch (opt) { switch (opt) {
case 'd': case 'd':
daemon_mode = 1; daemon_mode = 1;
...@@ -172,6 +174,10 @@ static void hal_parse_cmdline(int argc, char *argv[]) ...@@ -172,6 +174,10 @@ static void hal_parse_cmdline(int argc, char *argv[])
exit(0); exit(0);
break; break;
case 'l':
logfilename = optarg;
break;
case 'q': break; /* done in wrs_msg_init() */ case 'q': break; /* done in wrs_msg_init() */
case 'v': break; /* done in wrs_msg_init() */ case 'v': break; /* done in wrs_msg_init() */
......
...@@ -181,7 +181,7 @@ static int hal_port_init(int index) ...@@ -181,7 +181,7 @@ static int hal_port_init(int index)
/* Interates via all the ports defined in the config file and /* Interates via all the ports defined in the config file and
* intializes them one after another. */ * intializes them one after another. */
int hal_port_init_all() int hal_port_init_all(char *logfilename)
{ {
int index; int index;
struct wrs_shm_head *hal_shmem_hdr; struct wrs_shm_head *hal_shmem_hdr;
...@@ -238,7 +238,7 @@ int hal_port_init_all() ...@@ -238,7 +238,7 @@ int hal_port_init_all()
wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_END); wrs_shm_write(hal_shmem_hdr, WRS_SHM_WRITE_END);
/* Create a WRIPC server for HAL public API */ /* Create a WRIPC server for HAL public API */
return hal_init_wripc(ports); return hal_init_wripc(ports, logfilename);
return 0; return 0;
} }
......
...@@ -20,7 +20,7 @@ static int timing_mode; ...@@ -20,7 +20,7 @@ static int timing_mode;
#define LOCK_TIMEOUT_EXT 60000 #define LOCK_TIMEOUT_EXT 60000
#define LOCK_TIMEOUT_INT 10000 #define LOCK_TIMEOUT_INT 10000
int hal_init_timing() int hal_init_timing(char *filename)
{ {
timeout_t lock_tmo; timeout_t lock_tmo;
static struct { static struct {
...@@ -33,7 +33,7 @@ int hal_init_timing() ...@@ -33,7 +33,7 @@ int hal_init_timing()
{NULL, HAL_TIMING_MODE_BC /* default */}, {NULL, HAL_TIMING_MODE_BC /* default */},
}; };
if (rts_connect() < 0) { if (rts_connect(NULL) < 0) {
pr_error( pr_error(
"Failed to establish communication with the RT subsystem.\n"); "Failed to establish communication with the RT subsystem.\n");
return -1; return -1;
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
typedef void (*hal_cleanup_callback_t)(); typedef void (*hal_cleanup_callback_t)();
int hal_check_running(); int hal_check_running(void);
int hal_parse_config(); int hal_parse_config(void);
void hal_config_set_config_file(const char *str); void hal_config_set_config_file(const char *str);
int hal_config_extra_cmdline(const char *str); int hal_config_extra_cmdline(const char *str);
int hal_config_get_int(const char *name, int *value); int hal_config_get_int(const char *name, int *value);
...@@ -16,12 +16,12 @@ int hal_config_get_string(const char *name, char *value, int max_len); ...@@ -16,12 +16,12 @@ int hal_config_get_string(const char *name, char *value, int max_len);
int hal_config_iterate(const char *section, int index, int hal_config_iterate(const char *section, int index,
char *subsection, int max_len); char *subsection, int max_len);
int hal_port_init_all(); int hal_port_init_all(char *logfilename);
void hal_port_update_all(); void hal_port_update_all(void);
struct hexp_port_state; struct hexp_port_state;
struct hal_port_state; struct hal_port_state;
int hal_init_wripc(); int hal_init_wripc(struct hal_port_state *hal_ports, char *logfilename);
int hal_update_wripc(int ms_timeout); int hal_update_wripc(int ms_timeout);
int hal_add_cleanup_callback(hal_cleanup_callback_t cb); int hal_add_cleanup_callback(hal_cleanup_callback_t cb);
...@@ -30,8 +30,8 @@ int hal_port_start_lock(const char *port_name, int priority); ...@@ -30,8 +30,8 @@ int hal_port_start_lock(const char *port_name, int priority);
int hal_port_check_lock(const char *port_name); int hal_port_check_lock(const char *port_name);
int hal_port_enable_tracking(const char *port_name); int hal_port_enable_tracking(const char *port_name);
int hal_init_timing(); int hal_init_timing(char *filename);
int hal_get_timing_mode(); int hal_get_timing_mode(void);
int hal_port_pshifter_busy(); int hal_port_pshifter_busy(void);
#endif #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