Commit 7e4799f3 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/libwr: move timeout functions from HAL

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent b9d40358
......@@ -3,7 +3,8 @@ OBJS = init.o fpga_io.o util.o pps_gen.o i2c.o shw_io.o i2c_bitbang.o \
ptpd_netif.o hal_client.o \
shmem.o rt_client.o \
dot-config.o wrs-msg.o \
mac.o
mac.o \
timeout.o
LIB = libwr.a
......
#ifndef __TIMEOUT_H
#define __TIMEOUT_H
#include <stdint.h>
#include <libwr/util.h>
typedef struct {
int repeat;
uint64_t start_tics;
uint64_t timeout;
} timeout_t;
int libwr_tmo_init(timeout_t *tmo, uint32_t milliseconds, int repeat);
int libwr_tmo_restart(timeout_t *tmo);
int libwr_tmo_expired(timeout_t *tmo);
#endif
#ifndef __TIMEOUT_H
#define __TIMEOUT_H
#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>
#include "libwr/util.h"
typedef struct {
int repeat;
uint64_t start_tics;
uint64_t timeout;
} timeout_t;
#include <libwr/timeout.h>
static inline int tmo_init(timeout_t * tmo, uint32_t milliseconds, int repeat)
int libwr_tmo_init(timeout_t *tmo, uint32_t milliseconds, int repeat)
{
tmo->repeat = repeat;
tmo->start_tics = get_monotonic_us();
tmo->timeout = (uint64_t) milliseconds *1000ULL;
tmo->timeout = (uint64_t) milliseconds * 1000ULL;
return 0;
}
static inline int tmo_restart(timeout_t * tmo)
int libwr_tmo_restart(timeout_t *tmo)
{
tmo->start_tics = get_monotonic_us();
return 0;
}
static inline int tmo_expired(timeout_t * tmo)
int libwr_tmo_expired(timeout_t *tmo)
{
int expired = (get_monotonic_us() - tmo->start_tics > tmo->timeout);
......@@ -35,5 +25,3 @@ static inline int tmo_expired(timeout_t * tmo)
return expired;
}
#endif
......@@ -22,10 +22,10 @@
#include <libwr/sfp_lib.h>
#include <libwr/shmem.h>
#include <libwr/config.h>
#include <libwr/timeout.h>
#include <ppsi/ppsi.h>
#include "wrsw_hal.h"
#include "timeout.h"
#include <rt_ipc.h>
#include <hal_exports.h>
#include <libwr/hal_shmem.h>
......@@ -230,8 +230,8 @@ int hal_port_init_shmem(char *logfilename)
pr_info("Initializing switch ports...\n");
/* default timeouts */
tmo_init(&hal_port_tmo_sfp, SFP_POLL_INTERVAL, 1);
tmo_init(&hal_port_tmo_rts, RTS_POLL_INTERVAL, 1);
libwr_tmo_init(&hal_port_tmo_sfp, SFP_POLL_INTERVAL, 1);
libwr_tmo_init(&hal_port_tmo_rts, RTS_POLL_INTERVAL, 1);
/* Open a single raw socket for accessing the MAC addresses, etc. */
hal_port_fd = socket(AF_PACKET, SOCK_DGRAM, 0);
......@@ -341,7 +341,7 @@ static void poll_rts_state(void)
{
struct rts_pll_state *hs = &hal_port_rts_state;
if (tmo_expired(&hal_port_tmo_rts)) {
if (libwr_tmo_expired(&hal_port_tmo_rts)) {
hal_port_rts_state_valid = rts_get_state(hs) < 0 ? 0 : 1;
if (!hal_port_rts_state_valid)
printf("rts_get_state failure, weird...\n");
......@@ -618,7 +618,7 @@ static void hal_port_remove_sfp(struct hal_port_state * p)
/* detects insertion/removal of SFP transceivers */
static void hal_port_poll_sfp(void)
{
if (tmo_expired(&hal_port_tmo_sfp)) {
if (libwr_tmo_expired(&hal_port_tmo_sfp)) {
uint32_t mask = shw_sfp_module_scan();
static int old_mask = 0;
......
......@@ -9,9 +9,9 @@
#include <libwr/switch_hw.h>
#include <libwr/config.h>
#include <libwr/wrs-msg.h>
#include <libwr/timeout.h>
#include "wrsw_hal.h"
#include "timeout.h"
#include <rt_ipc.h>
#include <hal_exports.h>
......@@ -57,7 +57,7 @@ int hal_init_timing(char *filename)
switch (timing_mode) {
case HAL_TIMING_MODE_GRAND_MASTER:
rts_set_mode(RTS_MODE_GM_EXTERNAL);
tmo_init(&lock_tmo, LOCK_TIMEOUT_EXT, 0);
libwr_tmo_init(&lock_tmo, LOCK_TIMEOUT_EXT, 0);
break;
default: /* never hit, but having it here prevents a warning */
......@@ -66,14 +66,14 @@ int hal_init_timing(char *filename)
case HAL_TIMING_MODE_FREE_MASTER:
case HAL_TIMING_MODE_BC:
rts_set_mode(RTS_MODE_GM_FREERUNNING);
tmo_init(&lock_tmo, LOCK_TIMEOUT_INT, 0);
libwr_tmo_init(&lock_tmo, LOCK_TIMEOUT_INT, 0);
break;
}
while (1) {
struct rts_pll_state pstate;
if (tmo_expired(&lock_tmo)) {
if (libwr_tmo_expired(&lock_tmo)) {
pr_error("Can't lock the PLL. "
"If running in the GrandMaster mode, "
"are you sure the 1-PPS and 10 MHz "
......@@ -82,7 +82,7 @@ int hal_init_timing(char *filename)
if (timing_mode == HAL_TIMING_MODE_GRAND_MASTER) {
/*ups... something went wrong, try again */
rts_set_mode(RTS_MODE_GM_EXTERNAL);
tmo_init(&lock_tmo, LOCK_TIMEOUT_EXT, 0);
libwr_tmo_init(&lock_tmo, LOCK_TIMEOUT_EXT, 0);
} else {
pr_error("Got timeout\n");
return -1;
......
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