Commit a799afca authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Alessandro Rubini

wrsw_hal: imported external clock source function from the old repo and removed…

wrsw_hal: imported external clock source function from the old repo and removed all compilation warnings
parent aee7d856
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <lualib.h>
#include <hw/trace.h> #include <hw/trace.h>
#define HAL_CONFIG_FILE "/wr/etc/wrsw_hal.conf" #define HAL_CONFIG_FILE "/wr/etc/wrsw_hal.conf"
...@@ -26,11 +27,14 @@ void hal_config_set_config_file(const char *str) ...@@ -26,11 +27,14 @@ 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)
{ {
extra_cmdline = strdup(str); extra_cmdline = strdup(str);
return 0;
} }
/* Parses the HAL configuration file */ /* Parses the HAL configuration file */
int hal_parse_config() int hal_parse_config()
{ {
int ret;
TRACE(TRACE_INFO, "Parsing wrsw_hal configuration file: %s", HAL_CONFIG_FILE); TRACE(TRACE_INFO, "Parsing wrsw_hal configuration file: %s", HAL_CONFIG_FILE);
cfg_file = lua_open(); cfg_file = lua_open();
...@@ -39,12 +43,11 @@ int hal_parse_config() ...@@ -39,12 +43,11 @@ int hal_parse_config()
/* Just execute the config file as a regular Lua script. The contents of the file will be ordinary /* Just execute the config file as a regular Lua script. The contents of the file will be ordinary
Lua variables accessible via lua_State. */ Lua variables accessible via lua_State. */
if (luaL_dofile(cfg_file, hal_config_file)) ret = luaL_dofile(cfg_file, hal_config_file);
TRACE(TRACE_ERROR, "Error parsing the configuration file: %s", lua_tostring(cfg_file,-1));
/* Declare a Lua "helper" function for regexp searching global variables - it's much easier to implement /* Declare a Lua "helper" function for regexp searching global variables - it's much easier to implement
in Lua than in plain C. */ in Lua than in plain C. */
luaL_dostring(cfg_file, "\ ret |= luaL_dostring(cfg_file, "\
function get_var(name) \ function get_var(name) \
local t = _G \ local t = _G \
for w in name:gmatch(\"([%w_]+)\\.?\") do \ for w in name:gmatch(\"([%w_]+)\\.?\") do \
...@@ -55,7 +58,13 @@ int hal_parse_config() ...@@ -55,7 +58,13 @@ int hal_parse_config()
/* Execute extra code from the command line */ /* Execute extra code from the command line */
if(extra_cmdline) if(extra_cmdline)
luaL_dostring(cfg_file, extra_cmdline); ret |= luaL_dostring(cfg_file, extra_cmdline);
if(ret)
{
TRACE(TRACE_ERROR, "Error parsing the configuration file: %s", lua_tostring(cfg_file,-1));
return -1;
}
return 0; return 0;
} }
...@@ -138,7 +147,7 @@ int hal_config_iterate(const char *section, int index, char *subsection, int max ...@@ -138,7 +147,7 @@ int hal_config_iterate(const char *section, int index, char *subsection, int max
while (lua_next(cfg_file, -2) != 0) { while (lua_next(cfg_file, -2) != 0) {
/* uses 'key' (at index -2) and 'value' (at index -1) */ /* uses 'key' (at index -2) and 'value' (at index -1) */
char *key_type = lua_typename(cfg_file, lua_type(cfg_file, -1)); char *key_type = (char *) lua_typename(cfg_file, lua_type(cfg_file, -1));
if(!strcmp(key_type, "table") && i == index) if(!strcmp(key_type, "table") && i == index)
{ {
strncpy(subsection, lua_tostring(cfg_file, -2), max_len); strncpy(subsection, lua_tostring(cfg_file, -2), max_len);
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <hw/trace.h> #include <hw/trace.h>
#include <hw/dmpll.h> /* for direct access to DMPLL */ #include <hw/pps_gen.h> /* for direct access to DMPLL and PPS generator */
#include <hw/dmpll.h>
#include "wrsw_hal.h" #include "wrsw_hal.h"
#include "hal_exports.h" /* for exported structs/function protos */ #include "hal_exports.h" /* for exported structs/function protos */
...@@ -134,12 +135,14 @@ int halexp_pps_cmd(int cmd, hexp_pps_params_t *params) ...@@ -134,12 +135,14 @@ int halexp_pps_cmd(int cmd, hexp_pps_params_t *params)
case HEXP_PPSG_CMD_POLL: case HEXP_PPSG_CMD_POLL:
return shw_dmpll_shifter_busy(params->port_name) || shw_pps_gen_busy(); return shw_dmpll_shifter_busy(params->port_name) || shw_pps_gen_busy();
} }
return -1; /* fixme: real error code */
} }
/* PLL debug call, foreseen for live adjustment of some internal PLL parameters (gains, timeouts, etc.) /* PLL debug call, foreseen for live adjustment of some internal PLL parameters (gains, timeouts, etc.)
To be implemented. */ To be implemented. */
int halexp_pll_cmd(int cmd, hexp_pll_cmd_t *params) int halexp_pll_cmd(int cmd, hexp_pll_cmd_t *params)
{ {
return 0;
} }
static void hal_cleanup_wripc() static void hal_cleanup_wripc()
......
...@@ -190,6 +190,7 @@ int halexp_query_ports(hexp_port_list_t *list); ...@@ -190,6 +190,7 @@ int halexp_query_ports(hexp_port_list_t *list);
int halexp_get_port_state(hexp_port_state_t *state, const char *port_name); int halexp_get_port_state(hexp_port_state_t *state, const char *port_name);
int halexp_pps_cmd(int cmd, hexp_pps_params_t *params); int halexp_pps_cmd(int cmd, hexp_pps_params_t *params);
int halexp_pll_set_gain(int pll, int branch, int kp, int ki); int halexp_pll_set_gain(int pll, int branch, int kp, int ki);
int halexp_extsrc_cmd(int command); //added by ML
#endif #endif
......
...@@ -181,6 +181,11 @@ int hal_init() ...@@ -181,6 +181,11 @@ int hal_init()
/* Perform a low-level hardware init, load bitstreams, initialize non-kernel drivers */ /* Perform a low-level hardware init, load bitstreams, initialize non-kernel drivers */
assert_init(shw_init()); assert_init(shw_init());
/* If running in grandmaster mode, synchronize the internal PPS counter with the external source after
initializing the PPS generator. */
if(!hal_config_get_int("timing.use_external_clock", &enable))
shw_pps_gen_sync_external_pps();
/* Load kernel drivers */ /* Load kernel drivers */
assert_init(hal_load_kernel_modules()); assert_init(hal_load_kernel_modules());
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include <math.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
...@@ -361,7 +362,9 @@ int hal_init_port(const char *name, int index) ...@@ -361,7 +362,9 @@ int hal_init_port(const char *name, int index)
if(!hal_config_get_string(key_name, val, sizeof(val))) if(!hal_config_get_string(key_name, val, sizeof(val)))
{ {
if(!strcasecmp(val, "wr_master")) if(!strcasecmp(val, "wr_m_and_s"))
p->mode = HEXP_PORT_MODE_WR_M_AND_S;
else if(!strcasecmp(val, "wr_master"))
p->mode = HEXP_PORT_MODE_WR_MASTER; p->mode = HEXP_PORT_MODE_WR_MASTER;
else if(!strcasecmp(val, "wr_slave")) else if(!strcasecmp(val, "wr_slave"))
p->mode = HEXP_PORT_MODE_WR_SLAVE; p->mode = HEXP_PORT_MODE_WR_SLAVE;
...@@ -556,6 +559,7 @@ static void calibration_fsm(hal_port_state_t *p) ...@@ -556,6 +559,7 @@ static void calibration_fsm(hal_port_state_t *p)
} }
} }
#if 0
/* Port LED update function. To be removed in V3. */ /* Port LED update function. To be removed in V3. */
static int update_port_leds(hal_port_state_t *p) static int update_port_leds(hal_port_state_t *p)
{ {
...@@ -580,6 +584,8 @@ static int update_port_leds(hal_port_state_t *p) ...@@ -580,6 +584,8 @@ static int update_port_leds(hal_port_state_t *p)
return 0; return 0;
} }
#endif
/* Main port state machine */ /* Main port state machine */
static void port_fsm(hal_port_state_t *p) static void port_fsm(hal_port_state_t *p)
{ {
...@@ -588,6 +594,9 @@ static void port_fsm(hal_port_state_t *p) ...@@ -588,6 +594,9 @@ static void port_fsm(hal_port_state_t *p)
/* If, at any moment, the link goes down, reset the FSM and the port state structure. */ /* If, at any moment, the link goes down, reset the FSM and the port state structure. */
if(!link_up && p->state != HAL_PORT_STATE_LINK_DOWN) if(!link_up && p->state != HAL_PORT_STATE_LINK_DOWN)
{ {
if(p->locked)
shw_hpll_switch_reference("local"); /* FIXME: ugly workaround. The proper way is to do the TX calibration AFTER LOCKING ! */
TRACE(TRACE_INFO, "%s: link down", p->name); TRACE(TRACE_INFO, "%s: link down", p->name);
p->state = HAL_PORT_STATE_LINK_DOWN; p->state = HAL_PORT_STATE_LINK_DOWN;
reset_port_state(p); reset_port_state(p);
...@@ -751,11 +760,11 @@ int halexp_calibration_cmd(const char *port_name, int command, int on_off) ...@@ -751,11 +760,11 @@ int halexp_calibration_cmd(const char *port_name, int command, int on_off)
switch(command) switch(command)
{ {
/* Checks if the calibrator is idle (i.e. if there are no ports being currently calibrated). /* Checks if the calibrator is idle (i.e. if there are no ports being currently calibrated). */
case HEXP_CAL_CMD_CHECK_IDLE: case HEXP_CAL_CMD_CHECK_IDLE:
return !any_port_calibrating() && p->state == HAL_PORT_STATE_UP ? HEXP_CAL_RESP_OK : HEXP_CAL_RESP_BUSY; return !any_port_calibrating() && p->state == HAL_PORT_STATE_UP ? HEXP_CAL_RESP_OK : HEXP_CAL_RESP_BUSY;
/* Returns taw deltaTx/Rx (debug only) */ /* Returns raw deltaTx/Rx (debug only) */
case HEXP_CAL_CMD_GET_RAW_DELTA_RX: case HEXP_CAL_CMD_GET_RAW_DELTA_RX:
return p->calib.raw_delta_rx_phy; return p->calib.raw_delta_rx_phy;
break; break;
...@@ -850,3 +859,51 @@ int halexp_query_ports(hexp_port_list_t *list) ...@@ -850,3 +859,51 @@ int halexp_query_ports(hexp_port_list_t *list)
return 0; return 0;
} }
/* Maciek's ptpx export for checking the presence of the external 10 MHz ref clock */
int hal_extsrc_check_lock()
{
char val[128];
FILE *fp;
if(!hal_config_get_string("extsrc.status", val, sizeof(val)))
{
printf("mlDGB_HAL: read value: %s\n",val);
if(!strcasecmp(val, "faked"))
{
return 1;
}
else if(!strcasecmp(val, "disabled"))
{
return -1;
}
else if(!strcasecmp(val, "enabled"))
{
//TODO: implement in HW, for the time being temprary solution
//#ifdef TMP
fp=fopen("/wr/etc/tmp_extsrc", "r");
if(!fp)
return 0;
if(fscanf(fp,"%s",val)>0)
{
if(!strcasecmp(val, "locked"))
return 1;
else if(!strcasecmp(val, "none"))
return -1;
else
return 0;
}
fclose(fp);
} else
//#endif
return 0;
}
return -1;
/*
return -1; //<0 - there is no external source lock
return 1; //>0 - we are locked to an external source
return 0; //=0 - HW problem, wait
*/
}
\ No newline at end of file
...@@ -72,9 +72,11 @@ typedef struct { ...@@ -72,9 +72,11 @@ typedef struct {
} hal_port_calibration_t; } hal_port_calibration_t;
int hal_parse_config();
int hal_check_running(); int hal_check_running();
int hal_parse_config();
void hal_config_set_config_file(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);
int hal_config_get_double(const char *name, double *value); int hal_config_get_double(const char *name, double *value);
int hal_config_get_string(const char *name, char *value, int max_len); int hal_config_get_string(const char *name, char *value, int max_len);
...@@ -90,6 +92,7 @@ int hal_add_cleanup_callback(hal_cleanup_callback_t cb); ...@@ -90,6 +92,7 @@ int hal_add_cleanup_callback(hal_cleanup_callback_t cb);
int hal_port_start_lock(const char *port_name, int priority); 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_extsrc_check_lock(void); // added by ML
#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