Commit e91b2f97 authored by Adam Wujek's avatar Adam Wujek

Changes to reduce the code size of WRPC

Signed-off-by: 's avatarAdam Wujek <adam.wujek@creotech.pl>
parents 9cff3a5e 9b3f39d8
Pipeline #3234 failed with stage
in 0 seconds
......@@ -38,7 +38,7 @@ obj-$(CONFIG_WR_NODE) += wrc_main.o
obj-$(CONFIG_WR_NODE_SIM) += wrc_main_sim.o
obj-$(CONFIG_TARGET_WR_SWITCH) += ipc/minipc-mem-server.o ipc/rt_ipc.o
obj-$(CONFIG-PPSI) += dump-info.o
obj-$(CONFIG_PPSI) += dump-info.o
# our linker script is preprocessed, so have a rule here
%.ld: %.ld.S $(AUTOCONF) .config
$(CC) -include $(AUTOCONF) -E -P $*.ld.S -o $@
......@@ -60,7 +60,7 @@ cflags-y += \
-I$(PPSI)/arch-wrpc/include \
-I$(PPSI)/include
obj-ppsi = $(PPSI)/ppsi.o
obj-ppsi = $(PPSI)/ppsi.a
obj-$(CONFIG_PPSI) += $(obj-ppsi)
# Below, CONFIG_PPSI is wrong, as we can't build these for the host
......@@ -117,7 +117,7 @@ ASFLAGS = -I.
LDFLAGS = $(ldflags-y) \
-Wl,--gc-sections -Os -lgcc -lc
WRC-O-FLAGS-$(CONFIG_LM32) = --gc-sections -e _start
WRC-O-FLAGS-$(CONFIG_LM32) = -e _start
OBJS = $(obj-y)
......@@ -138,11 +138,11 @@ endif
all: tools $(OUTPUT).elf $(arch-files-y)
.PRECIOUS: %.elf %.bin
.PHONY: all tools clean gitmodules $(PPSI)/ppsi.o extest liblinux
.PHONY: all tools clean gitmodules $(PPSI)/ppsi.a extest liblinux
# we need to remove "ptpdump" support for ppsi if RAM size is small and
# we include etherbone
ifneq ($(CONFIG_RAMSIZE),131072)
ifneq ($(CONFIG_RAMSIZE),196608)
ifdef CONFIG_IP
PPSI_USER_CFLAGS = -DCONFIG_NO_PTPDUMP
endif
......@@ -161,8 +161,8 @@ $(obj-ppsi): gitmodules
else \
echo "Warning: keeping previous ppsi configuration" >& 2; \
fi
$(MAKE) -C $(PPSI) ppsi.o WRPCSW_ROOT=.. \
CROSS_COMPILE=$(CROSS_COMPILE) CONFIG_NO_PRINTF=y
$(MAKE) -C $(PPSI) ppsi.a WRPCSW_ROOT=.. \
CROSS_COMPILE=$(CROSS_COMPILE) CONFIG_NO_PRINTF=y \
USER_CFLAGS="$(PPSI_USER_CFLAGS)"
sdb-lib/libsdbfs.a:
......@@ -170,7 +170,7 @@ sdb-lib/libsdbfs.a:
$(OUTPUT).elf: $(LDS-y) $(AUTOCONF) gitmodules config.o pconfig.o $(OBJS)
$(CC) $(CFLAGS) -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\"" -c revision.c
${CC} -o $@ revision.o config.o pconfig.o $(OBJS) $(LDFLAGS)
${CC} -Wl,-Map,$(OUTPUT).map -o $@ revision.o config.o pconfig.o $(OBJS) $(LDFLAGS)
${OBJDUMP} -d $(OUTPUT).elf > $(OUTPUT)_disasm.S
$(SIZE) $@
./save_size.sh $(SIZE) $@
......
......@@ -90,6 +90,8 @@ int board_update(void);
#undef CONFIG_DISALLOW_LONG_DIVISION
#define BOARD_USE_EVENTS 0
#define BOARD_MAX_CONSOLE_DEVICES 1
#define CONSOLE_UART_BAUDRATE 115200
......
......@@ -6,6 +6,11 @@ obj-$(CONFIG_TARGET_SIS8300KU) += boards/sis8300ku/board.o
obj-$(CONFIG_TARGET_ERTM14) += boards/ertm14/board.o boards/ertm14/ertm15_rf_distr.o boards/ertm14/phy_calibration.o boards/ertm14/rf_frame_transceiver.o boards/ertm14/cmd_ertm14.o
obj-$(CONFIG_TARGET_PXIE_FMC) += boards/pxie-fmc/board.o
REQUIRE_AUTOCONF_PPSI+= \
boards/ertm14/board.o \
boards/ertm14/cmd_ertm14.o \
#boards/sis8300ku/board.o: boards/sis8300ku/sdbfs-image.h
#./tools/gensdbfs -c boards/sis8300ku/sdbfs-image.h boards/sis8300ku/sdbfs boards/sis8300ku/sdbfs-image.bin
......
......@@ -43,6 +43,7 @@
#include <hw/wr_streamers.h>
#include <wrc-event.h>
#include <lib/events-ptp.h>
#include "ertm15_rf_distr.h"
#include "rf_frame_transceiver.h"
......@@ -1188,6 +1189,7 @@ int wrc_board_init()
int wrc_board_create_tasks()
{
wrc_task_create("events-ptp", wrc_events_ptp_init, wrc_events_ptp_poll);
return 0;
}
......@@ -25,6 +25,8 @@
#define BOARD_MAX_CONSOLE_DEVICES 2
#define BOARD_USE_EVENTS 1
/* Board-specific parameters */
#define TICS_PER_SECOND 1000
......
......@@ -345,7 +345,7 @@ static int ertm14_monitor_ui(void)
term_clear();
cprintf(C_BLUE, "eRTM14/15 Board Monitor");
cprintf(C_GREY, "\nEsc = exit\n\n");
cprintf(C_MAGENTA, "\nEsc = exit\n\n");
ret = diag_read_word(8, DIAG_RO_BANK, &val);
......@@ -356,15 +356,15 @@ static int ertm14_monitor_ui(void)
return 0;
cprintf(C_WHITE, "NCO Sync Status:\n");
cprintf(C_GREY, "Streamer RX Message count: ");
cprintf(C_MAGENTA, "Streamer RX Message count: ");
cprintf(C_WHITE, "%d\n", val);
cprintf(C_GREY, "LO DDS Sync Mode: ");
cprintf(C_MAGENTA, "LO DDS Sync Mode: ");
cprintf(C_WHITE, "%s\n", nco_sync_source_to_string(st->lo.sync_source));
cprintf(C_GREY, "REF DDS Sync Mode: ");
cprintf(C_MAGENTA, "REF DDS Sync Mode: ");
cprintf(C_WHITE, "%s\n", nco_sync_source_to_string(st->ref.sync_source));
cprintf(C_GREY, "LO DDS Sync Triggers: ");
cprintf(C_MAGENTA, "LO DDS Sync Triggers: ");
cprintf(C_WHITE, "%d\n", st->lo.sync_count);
cprintf(C_GREY, "REF DDS Sync Triggers: ");
cprintf(C_MAGENTA, "REF DDS Sync Triggers: ");
cprintf(C_WHITE, "%d\n", st->ref.sync_count);
......
......@@ -64,6 +64,8 @@
#undef CONFIG_DISALLOW_LONG_DIVISION
#define BOARD_USE_EVENTS 0
#define BOARD_MAX_CONSOLE_DEVICES (1 + HAS_NETCONSOLE)
#define CONSOLE_UART_BAUDRATE 115200
......
......@@ -54,6 +54,8 @@
#undef CONFIG_DISALLOW_LONG_DIVISION
#define BOARD_USE_EVENTS 0
#define BOARD_MAX_CONSOLE_DEVICES 1
#define CONSOLE_UART_BAUDRATE 115200
......
......@@ -54,6 +54,8 @@
#undef CONFIG_DISALLOW_LONG_DIVISION
#define BOARD_USE_EVENTS 0
#define BOARD_MAX_CONSOLE_DEVICES 1
#define CONSOLE_UART_BAUDRATE 115200
......
......@@ -33,4 +33,6 @@
#define CONSOLE_UART_BAUDRATE 115200
#define BOARD_MAX_CONSOLE_DEVICES 1
#define BOARD_USE_EVENTS 0
#endif
......@@ -38,11 +38,6 @@ int mprintf(const char *fmt, ...)
#ifdef CONFIG_DISALLOW_LONG_DIVISION /* with ppsi we can avoid libgcc code for division */
/* was used twice in picos_to_ts */
long long __moddi3 (long long A, long long B)
{
__you_should_not_divide_ll_in_wrpc_sw();
return 0;
}
/* picos_to_ts again */
long long __udivdi3 (long long A, long long B)
......@@ -51,10 +46,11 @@ long long __udivdi3 (long long A, long long B)
return 0;
}
/* was used in set_phase_shift, phase_to_cf_units */
long long __divdi3 (long long A, long long B)
#endif
long long __moddi3 (long long A, long long B)
{
__you_should_not_divide_ll_in_wrpc_sw();
/* use unsigned modulo instead */
return 0;
}
#endif
......@@ -48,7 +48,7 @@ void bb_i2c_stop(struct i2c_bus *bus)
unsigned char bb_i2c_put_byte(struct i2c_bus *bus, uint8_t data)
{
int i;
uint8_t ack;
int ack;
for (i = 0; i < 8; i++, data <<= 1) {
M_SDA_OUT(data & 0x80);
......@@ -66,7 +66,7 @@ unsigned char bb_i2c_put_byte(struct i2c_bus *bus, uint8_t data)
return ack != 0;
}
void bb_i2c_get_byte(struct i2c_bus *bus, uint8_t *data, uint8_t last)
void bb_i2c_get_byte(struct i2c_bus *bus, uint8_t *data, int last)
{
int i;
......@@ -113,9 +113,9 @@ void bb_i2c_init(struct i2c_bus *bus)
M_SDA_OUT(1);
}
uint8_t bb_i2c_devprobe(struct i2c_bus *bus, uint8_t i2c_addr)
int bb_i2c_devprobe(struct i2c_bus *bus, uint8_t i2c_addr)
{
uint8_t ret;
int ret;
bb_i2c_start(bus);
ret = !bb_i2c_put_byte(bus, i2c_addr << 1);
bb_i2c_stop(bus);
......
......@@ -61,7 +61,7 @@
static uint8_t sfpcount = SFP_DB_EMPTY;
uint8_t has_eeprom = 0;
static int has_eeprom = 0;
static int i2cif, i2c_addr; /* globals, using the names we always used */
......@@ -164,7 +164,7 @@ static uint8_t sfp_chksum(uint8_t *ptr)
int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
{
uint8_t i;
int i;
struct s_sfpinfo dbsfp;
if (pos >= SFPS_MAX) {
......@@ -302,7 +302,7 @@ int storage_init_erase(void)
*/
int storage_init_add(const char *args[])
{
uint8_t i = 1;
int i = 1;
uint8_t separator = ' ';
uint16_t used, readback;
......@@ -371,7 +371,7 @@ int storage_init_readcmd(uint8_t *buf, uint8_t bufsize, uint8_t next)
{
static uint16_t ptr;
static uint16_t used = 0;
uint8_t i = 0;
int i = 0;
if (next == 0) {
if (eeprom_read(i2cif, i2c_addr, EE_BASE_INIT,
......
......@@ -50,19 +50,19 @@ static inline uint32_t minic_readl(uint32_t reg)
return *(volatile uint32_t *)(BASE_MINIC + reg);
}
static inline void minic_txword(uint8_t type, uint16_t word)
static inline void minic_txword(int type, uint16_t word)
{
minic_writel(MINIC_REG_TX_FIFO,
MINIC_TX_FIFO_TYPE_W(type) | MINIC_TX_FIFO_DAT_W(word));
}
static inline void minic_rxword(uint8_t *type, uint16_t *data, uint8_t *empty,
uint8_t *full)
static inline void minic_rxword(int *type, uint16_t *data, int *empty,
int *full)
{
uint32_t rx;
rx = minic_readl(MINIC_REG_RX_FIFO);
*type = (uint8_t) MINIC_RX_FIFO_TYPE_R(rx);
*type = MINIC_RX_FIFO_TYPE_R(rx);
*data = (uint16_t) MINIC_RX_FIFO_DAT_R(rx);
if (empty)
*empty = (rx & MINIC_RX_FIFO_EMPTY) ? 1 : 0;
......@@ -114,7 +114,7 @@ int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
{
uint32_t hdr_size, payload_size;
uint32_t raw_ts;
uint8_t rx_empty, rx_full, rx_type;
int rx_empty, rx_full, rx_type;
uint16_t rx_data;
uint16_t *ptr16_hdr, *ptr16_payload;
uint32_t oob_cnt;
......@@ -224,7 +224,7 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
struct hw_timestamp *hwts)
{
uint32_t d_hdr, mcr, pwords, hwords;
uint8_t ts_valid;
int ts_valid;
int i, hsize;
uint16_t *ptr;
......@@ -307,8 +307,8 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
if(ts_valid)
ts_valid = (uint8_t)(minic_readl(MINIC_REG_TSR0)
& MINIC_TSR0_VALID);
ts_valid = minic_readl(MINIC_REG_TSR0)
& MINIC_TSR0_VALID;
raw_ts = minic_readl(MINIC_REG_TSR1);
fid = MINIC_TSR0_FID_R(minic_readl(MINIC_REG_TSR0));
......
......@@ -496,12 +496,13 @@ static int sfp_valid(struct s_sfpinfo *sfp)
return 1;
}
static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
static int sfp_entry(struct s_sfpinfo *sfp, int oper, int pos)
{
static uint8_t sfpcount = 0;
static int sfpcount = 0;
struct s_sfpinfo tempsfp;
int ret = -1;
uint8_t i, chksum = 0;
int i;
int chksum = 0;
uint8_t *ptr;
int sdb_offset;
......@@ -515,13 +516,13 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
* call */
if (!pos) {
sfpcount = 0;
sdb_offset = sizeof(sfpcount);
sdb_offset = 1; /* sfpcount */
while (sdbfs_fread(&wrc_sdbfs, sdb_offset, &tempsfp,
sizeof(tempsfp)) == sizeof(tempsfp)) {
if (!sfp_valid(&tempsfp))
break;
sfpcount++;
sdb_offset = sizeof(sfpcount) + sfpcount * sizeof(tempsfp);
sdb_offset = 1 /* sfpcount */ + sfpcount * sizeof(tempsfp);
}
}
......@@ -538,7 +539,7 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
}
if (oper == SFP_GET) {
sdb_offset = sizeof(sfpcount) + pos * sizeof(*sfp);
sdb_offset = 1 /* sfpcount */ + pos * sizeof(*sfp);
if (sdbfs_fread(&wrc_sdbfs, sdb_offset, sfp, sizeof(*sfp))
!= sizeof(*sfp))
goto out;
......@@ -547,7 +548,7 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
/* read sizeof() - 1 because we don't include checksum */
for (i = 0; i < sizeof(struct s_sfpinfo) - 1; ++i)
chksum = chksum + *(ptr++);
if (chksum != sfp->chksum) {
if ((chksum & 0xff) != sfp->chksum) {
pp_printf("sfp: corrupted checksum\n");
goto out;
}
......@@ -560,7 +561,7 @@ static int sfp_entry(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
chksum = chksum + *(ptr++);
sfp->chksum = chksum;
/* add SFP at the end of DB */
sdb_offset = sizeof(sfpcount) + sfpcount * sizeof(*sfp);
sdb_offset = 1 /* sfpcount */ + sfpcount * sizeof(*sfp);
if (sdbfs_fwrite(&wrc_sdbfs, sdb_offset, sfp, sizeof(*sfp))
!= sizeof(*sfp)) {
goto out;
......@@ -577,7 +578,7 @@ static int storage_update_sfp(struct s_sfpinfo *sfp)
{
int sfpcount = 1;
int temp;
int8_t i;
int i;
struct s_sfpinfo sfp_db[SFPS_MAX];
struct s_sfpinfo *dbsfp;
......@@ -613,7 +614,7 @@ static int storage_update_sfp(struct s_sfpinfo *sfp)
return i;
}
int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
int storage_get_sfp(struct s_sfpinfo *sfp, int oper, int pos)
{
struct s_sfpinfo tmp_sfp;
......@@ -636,8 +637,8 @@ int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t oper, uint8_t pos)
int storage_match_sfp(struct s_sfpinfo *sfp)
{
uint8_t sfpcount = 1;
int8_t i;
int sfpcount = 1;
int i;
struct s_sfpinfo dbsfp;
for (i = 0; i < sfpcount; ++i) {
......@@ -823,7 +824,7 @@ out_close:
}
// FIXME: migrate to new API
int storage_phtrans(uint32_t *valp, uint8_t write)
int storage_phtrans(uint32_t *valp, int write)
{
if( !write )
return storage_get_calibration_parameter( CAL_PARAM_T24P, valp );
......@@ -834,7 +835,7 @@ int storage_phtrans(uint32_t *valp, uint8_t write)
/* MAC Address Storage */
int storage_get_persistent_mac(uint8_t portnum, uint8_t *mac)
int storage_get_persistent_mac(int portnum, uint8_t *mac)
{
int ret = 0;
//int i;
......@@ -891,7 +892,7 @@ int storage_get_persistent_mac(uint8_t portnum, uint8_t *mac)
return 0;
}
int storage_set_persistent_mac(uint8_t portnum, uint8_t *mac)
int storage_set_persistent_mac(int portnum, uint8_t *mac)
{
int ret;
......@@ -1020,7 +1021,7 @@ out:
return ret;
}
int storage_init_readcmd(uint8_t *buf, uint8_t bufsize, uint8_t next)
int storage_init_readcmd(uint8_t *buf, int bufsize, int next)
{
int i = 0, ret = -1;
uint16_t used;
......
......@@ -215,7 +215,7 @@ int wdiag_get_snapshot(void)
return 0;
}
void wdiags_write_servo_state(int wr_mode, uint8_t servostate, uint64_t mu,
void wdiags_write_servo_state(int wr_mode, int servostate, uint64_t mu,
uint64_t dms, int32_t asym, int32_t cko,
int32_t setp, int32_t ucnt)
{
......@@ -240,7 +240,7 @@ void wdiags_write_port_state(int link, int locked)
syscon->WDIAG_PSTAT = val;
}
void wdiags_write_ptp_state(uint8_t ptpstate)
void wdiags_write_ptp_state(int ptpstate)
{
syscon->WDIAG_PTPSTAT = SYSC_WDIAG_PTPSTAT_PTPSTATE_W(ptpstate);
}
......
......@@ -43,6 +43,7 @@ struct dump_info dump_info[] = {
DUMP_FIELD(UInteger8, priority1),
DUMP_FIELD(UInteger8, priority2),
DUMP_FIELD(UInteger8, domainNumber),
DUMP_FIELD(yes_no_Boolean, slaveOnly),
/** Optional (IEEE1588-2019) */
// FIXME: DUMP_FIELD(Timestamp, currentTime),
......
......@@ -15,13 +15,13 @@ struct i2c_bus
int loop_delay;
};
uint8_t bb_i2c_devprobe(struct i2c_bus *bus, uint8_t i2c_addr);
int bb_i2c_devprobe(struct i2c_bus *bus, uint8_t i2c_addr);
void bb_i2c_create(struct i2c_bus *bus, const struct gpio_pin *pin_scl, const struct gpio_pin *pin_sda );
void bb_i2c_init(struct i2c_bus *bus);
void bb_i2c_start(struct i2c_bus *bus);
void bb_i2c_repeat_start(struct i2c_bus *bus);
void bb_i2c_stop(struct i2c_bus *bus);
void bb_i2c_get_byte(struct i2c_bus *bus, uint8_t *data, uint8_t last);
void bb_i2c_get_byte(struct i2c_bus *bus, uint8_t *data, int last);
uint8_t bb_i2c_put_byte(struct i2c_bus *bus, uint8_t data);
void bb_i2c_delay(uint32_t delay);
void bb_i2c_scan(struct i2c_bus *bus);
......
......@@ -131,11 +131,11 @@ void net_rst(void);
int wdiag_set_valid(int enable);
int wdiag_get_valid(void);
int wdiag_get_snapshot(void);
void wdiags_write_servo_state(int wr_mode, uint8_t servostate, uint64_t mu,
void wdiags_write_servo_state(int wr_mode, int servostate, uint64_t mu,
uint64_t dms, int32_t asym, int32_t cko,
int32_t setp, int32_t ucnt);
void wdiags_write_port_state(int link, int locked);
void wdiags_write_ptp_state(uint8_t ptpstate);
void wdiags_write_ptp_state(int ptpstate);
void wdiags_write_aux_state(uint32_t aux_states);
void wdiags_write_cnts(uint32_t tx, uint32_t rx);
void wdiags_write_time(uint64_t sec, uint32_t nsec);
......
/*
* This work is part of the White Rabbit project
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#ifndef __HAL_EXPORTS_H
#define __HAL_EXPORTS_H
#include <stdint.h>
#define HAL_MAX_PORTS 32
#define WRSW_HAL_SERVER_ADDR "wrsw_hal"
// checks if the calibration unit is idle
#define HEXP_CAL_CMD_CHECK_IDLE 1
// enables/disables transmission of calibration pattern
#define HEXP_CAL_CMD_TX_PATTERN 2
// requests a measurement of TX delta
#define HEXP_CAL_CMD_TX_MEASURE 4
// requests a measurement of RX delta
#define HEXP_CAL_CMD_RX_MEASURE 5
#define HEXP_CAL_RESP_BUSY 1
#define HEXP_CAL_RESP_OK 0
#define HEXP_CAL_RESP_ERROR -1
#define HEXP_LOCK_CMD_START 1
#define HEXP_LOCK_CMD_CHECK 2
#define HEXP_LOCK_CMD_ENABLE_TRACKING 3
#define HEXP_LOCK_STATUS_LOCKED 0
#define HEXP_LOCK_STATUS_BUSY 1
#define HEXP_LOCK_STATUS_NONE 2
#define HEXP_PPSG_CMD_GET 0
#define HEXP_PPSG_CMD_ADJUST_PHASE 1
#define HEXP_PPSG_CMD_ADJUST_SEC 2
#define HEXP_PPSG_CMD_ADJUST_NSEC 3
#define HEXP_PPSG_CMD_POLL 4
#define HEXP_PPSG_CMD_SET_VALID 5
#define HEXP_ON 1
#define HEXP_OFF 0
#define HEXP_FREQ 0
#define HEXP_PHASE 1
/////////////////added by ML//////////
#define HEXP_EXTSRC_CMD_CHECK 0
#define HEXP_EXTSRC_STATUS_LOCKED 0
#define HEXP_LOCK_STATUS_BUSY 1
#define HEXP_EXTSRC_STATUS_NOSRC 2
/////////////////////////////////////
#define HAL_TIMING_MODE_GRAND_MASTER 0
#define HAL_TIMING_MODE_FREE_MASTER 1
#define HAL_TIMING_MODE_BC 2
typedef struct {
char port_name[16];
int pps_valid;
uint32_t current_phase_shift;
int32_t adjust_phase_shift;
int64_t adjust_sec;
int32_t adjust_nsec;
uint64_t current_sec;
uint32_t current_nsec;
} hexp_pps_params_t;
/* Port modes (hexp_port_state_t.mode) */
#define HEXP_PORT_MODE_WR_M_AND_S 4
#define HEXP_PORT_MODE_WR_MASTER 1
#define HEXP_PORT_MODE_WR_SLAVE 2
#define HEXP_PORT_MODE_NON_WR 3
#define FIX_ALPHA_FRACBITS 40
/*
#define HEXP_PORT_TSC_RISING 1
#define HEXP_PORT_TSC_FALLING 2
*/
typedef struct {
int timing_mode; /* Free-running Master/GM/BC */
int locked_port;
} hexp_timing_state_t;
/* Prototypes of functions that call on rpc */
extern int halexp_check_running(void);
extern int halexp_reset_port(const char *port_name);
extern int halexp_calibration_cmd(const char *port_name, int command, int on_off);
extern int halexp_lock_cmd(const char *port_name, int command, int priority);
extern int halexp_pps_cmd(int cmd, hexp_pps_params_t *params);
extern int halexp_get_timing_state(hexp_timing_state_t *state);
/* Export structures, shared by server and client for argument matching */
#ifdef HAL_EXPORT_STRUCTURES
//int halexp_check_running();
struct minipc_pd __rpcdef_check_running = {
.name = "check_running",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_END,
},
};
//int halexp_reset_port(const char *port_name);
struct minipc_pd __rpcdef_reset_port = {
.name = "reset_port",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING, char *),
MINIPC_ARG_END,
},
};
//int halexp_calibration_cmd(const char *port_name, int command, int on_off);
struct minipc_pd __rpcdef_calibration_cmd = {
.name = "calibration_cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING, char *),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
//int halexp_lock_cmd(const char *port_name, int command, int priority);
struct minipc_pd __rpcdef_lock_cmd = {
.name = "lock_cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRING, char *),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_END,
},
};
//int halexp_query_ports(hexp_port_list_t *list);
struct minipc_pd __rpcdef_query_ports = {
.name = "query_ports",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRUCT, hexp_port_list_t),
.args = {
MINIPC_ARG_END,
},
};
//int halexp_pps_cmd(int cmd, hexp_pps_params_t *params);
struct minipc_pd __rpcdef_pps_cmd = {
.name = "pps_cmd",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
.args = {
MINIPC_ARG_ENCODE(MINIPC_ATYPE_INT, int),
MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRUCT, hexp_pps_params_t),
MINIPC_ARG_END,
},
};
struct minipc_pd __rpcdef_get_timing_state = {
.name = "get_timing_state",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRUCT, hexp_timing_state_t),
.args = {
MINIPC_ARG_END,
},
};
#endif /* HAL_EXPORT_STRUCTURES */
#endif
......@@ -6,82 +6,22 @@
#ifndef __LIBWR_HAL_SHMEM_H__
#define __LIBWR_HAL_SHMEM_H__
#include <hal_exports.h>
#include <libwr/sfp_lib.h>
#include <string.h>
/* Port state machine states */
#define HAL_PORT_STATE_DISABLED 0
#define HAL_PORT_STATE_LINK_DOWN 1
#define HAL_PORT_STATE_UP 2
#define HAL_PORT_STATE_CALIBRATION 3
#define HAL_PORT_STATE_LOCKING 4
#define DEFAULT_T2_PHASE_TRANS 0
#define DEFAULT_T4_PHASE_TRANS 0
/* Port delay calibration parameters */
typedef struct hal_port_calibration {
/* PHY delay measurement parameters for PHYs which require
external calibration (i.e. with the feedback network. */
/* minimum possible delay introduced by the PHY. Expressed as time
(in picoseconds) between the beginning of the symbol on the serial input
and the rising edge of the RX clock at which the deserialized word is
available at the parallel output of the PHY. */
uint32_t phy_rx_min;
/* the same set of parameters, but for the TX path of the PHY */
uint32_t phy_tx_min;
/* Current PHY (clock-to-serial-symbol) TX and RX delays, in ps */
uint32_t delta_tx_phy;
uint32_t delta_rx_phy;
/* bit slide expressed in picos */
uint32_t bitslide_ps;
/* Current board routing delays (between the DDMTD inputs to
the PHY clock inputs/outputs), in picoseconds */
uint32_t delta_tx_board;
uint32_t delta_rx_board;
/* When non-zero: RX path is calibrated (delta_*_rx contain valid values) */
int rx_calibrated;
/* When non-zero: TX path is calibrated */
int tx_calibrated;
struct shw_sfp_caldata sfp;
int delta_tx_ps; /* "delta" of this SFP type WRT calibration type */
int delta_rx_ps;
} hal_port_calibration_t;
/* Internal port state structure */
struct hal_port_state {
/* non-zero: allocated */
int in_use;
/* linux i/f name */
char name[16];
struct wrc_port_state {
/* MAC addr */
uint8_t hw_addr[6];
/* ioctl() hw index */
int hw_index;
/* file descriptor for ioctls() */
int fd;
int hw_addr_auto;
/* port timing mode (HEXP_PORT_MODE_xxxx) */
int mode;
/* port FSM state (HAL_PORT_STATE_xxxx) */
int state;
/* fiber type, used to get alpha for SFP frequency */
int fiber_index;
/* 1: PLL is locked to this port */
int locked;
......@@ -91,7 +31,7 @@ struct hal_port_state {
/* current DMTD loopback phase (ps) and whether is it valid or not */
uint32_t phase_val;
int phase_val_valid;
int tx_cal_pending, rx_cal_pending;
/* locking FSM state */
int lock_state;
......@@ -105,43 +45,6 @@ struct hal_port_state {
/* approximate phase value (on master port) at which RX timestamp (T4)
* counter transistion occurs (picoseconds) */
uint32_t t4_phase_transition;
/* Endpoint's base address */
uint32_t ep_base;
};
struct hal_temp_sensors {
int fpga; /* IC19 */
int pll; /* IC18 */
int psl; /* IC20 Power Supply Left (PSL) */
int psr; /* IC17 Power Supply Right (PSR) */
};
/* This is the overall structure stored in shared memory */
#define HAL_SHMEM_VERSION 7 /* Version 7 because of moving of reading
* temperature treshold values to snmpd */
struct hal_shmem_header {
int nports;
struct hal_port_state *ports;
struct hal_temp_sensors temp;
};
static inline int state_up(int state)
{
return (state != HAL_PORT_STATE_LINK_DOWN
&& state != HAL_PORT_STATE_DISABLED);
}
static inline struct hal_port_state *hal_lookup_port(
struct hal_port_state *ports, int nports,
const char *name)
{
int i;
for (i = 0; i < nports; i++)
if (ports[i].in_use && (!strcmp(name, ports[i].name)))
return ports + i;
return NULL;
}
#endif /* __LIBWR_HAL_SHMEM_H__ */
#ifndef __LIBWR_SHW_SFPLIB_H
#define __LIBWR_SHW_SFPLIB_H
/* note each led contains green and orange part */
#define SFP_LED_WRMODE1 (1 << 0)
#define SFP_LED_WRMODE2 (1 << 1)
#define SFP_LED_SYNCED (1 << 2)
#define SFP_TX_DISABLE (1 << 3)
#define shw_sfp_set_led_synced(num, status) \
shw_sfp_set_generic(num, status, SFP_LED_SYNCED)
#define shw_sfp_set_tx_disable(num, status) \
shw_sfp_set_generic(num, status, SFP_TX_DISABLE)
#define SFP_FLAG_CLASS_DATA (1 << 0)
#define SFP_FLAG_DEVICE_DATA (1 << 1)
#define SFP_FLAG_1GbE (1 << 2) /* SFP is 1GbE */
#define SFP_FLAG_IN_DB (1 << 3) /* SFP is present in data base */
#define SFP_SPEED_1Gb 0x0D /* Speed of SFP in 100MB/s. According to
* SFF-8472.PDF: By convention 1.25 Gb/s
* should be rounded up to 0Dh (13 in
* units of 100 MBd) for Ethernet
* 1000BASE-X. */
#define SFP_SPEED_1Gb_10 0x0A /* Unfortunatelly the above is not always true,
* e.g. Cisco copper SFP (MGBT1) says simply 10 and not 13.*/
#define SFP_SPEED_1Gb_12 0x0C /* Some fiber SFPs say 12 and not 13 */
#define SFP_DIAGNOSTIC_IMPLEMENTED (1 << 6) /* Digital diagnostic monitoring
implemented. "1" for compliance
with SFF-8472 */
#define SFP_ADDR_CHANGE_REQ (1 << 2) /* Bit 2 indicates whether or not it is
necessary for the host to perform an
address change sequence before
accessing information at 2-wire serial
address A2h. */
struct shw_sfp_caldata {
uint32_t flags;
/*
* Part number used to identify it. Serial number because we
* may specify per-specimen delays, but it is not used at this
* point in time
*/
char vendor_name[16];
char part_num[16];
char vendor_serial[16];
/* Callibration data */
double alpha;
int delta_tx_ps; /* "delta" of this SFP type WRT calibration type */
int delta_rx_ps;
/* wavelengths, used to get alpha from fiber type */
int tx_wl;
int rx_wl;
/* and link as a list */
struct shw_sfp_caldata *next;
};
struct shw_sfp_header {
uint8_t id;
uint8_t ext_id;
uint8_t connector;
uint8_t transciever[8];
uint8_t encoding;
uint8_t br_nom;
uint8_t reserved1;
uint8_t length1; /* Link length supported for 9/125 mm fiber (km) */
uint8_t length2; /* Link length supported for 9/125 mm fiber (100m) */
uint8_t length3; /* Link length supported for 50/125 mm fiber (10m) */
uint8_t length4; /* Link length supported for 62.5/125 mm fiber (10m) */
uint8_t length5; /* Link length supported for copper (1m) */
uint8_t length6; /* Link length supported on OM3 (1m) */
uint8_t vendor_name[16];
uint8_t reserved3; /* This is now a field named transceiver */
uint8_t vendor_oui[3];
uint8_t vendor_pn[16];
uint8_t vendor_rev[4];
uint8_t tx_wavelength[2];
uint8_t reserved4;
uint8_t cc_base;
/* extended ID fields start here */
uint8_t options[2];
uint8_t br_max;
uint8_t br_min;
uint8_t vendor_serial[16];
uint8_t date_code[8];
uint8_t diagnostic_monitoring_type;
uint8_t enhanced_options;
uint8_t sff_8472_compliance;
uint8_t cc_ext;
} __attribute__ ((packed));
struct shw_sfp_dom {
/* Treshold values, 0 - 55 */
uint8_t temp_high_alarm[2];
uint8_t temp_low_alarm[2];
uint8_t temp_high_warn[2];
uint8_t temp_low_warn[2];
uint8_t volt_high_alarm[2];
uint8_t volt_low_alarm[2];
uint8_t volt_high_warn[2];
uint8_t volt_low_warn[2];
uint8_t bias_high_alarm[2];
uint8_t bias_low_alarm[2];
uint8_t bias_high_warn[2];
uint8_t bias_low_warn[2];
uint8_t tx_pow_high_alarm[2];
uint8_t tx_pow_low_alarm[2];
uint8_t tx_pow_high_warn[2];
uint8_t tx_pow_low_warn[2];
uint8_t rx_pow_high_alarm[2];
uint8_t rx_pow_log_alarm[2];
uint8_t rx_power_high_warn[2];
uint8_t rx_power_low_warn[2];
uint8_t unalloc0[16];
/* Calibration data, 56-91 */
uint8_t cal_rx_pwr4[4];
uint8_t cal_rx_pwr3[4];
uint8_t cal_rx_pwr2[4];
uint8_t cal_rx_pwr1[4];
uint8_t cal_rx_pwr0[4];
uint8_t cal_tx_i_slope[2];
uint8_t cal_tx_i_offset[2];
uint8_t cal_tx_pow_slope[2];
uint8_t cal_tx_pow_offset[2];
uint8_t cal_T_slope[2];
uint8_t cal_T_offset[2];
uint8_t cal_V_slope[2];
uint8_t cal_V_offset[2];
/* Unallocated and checksum, 92-95 */
uint8_t cal_unalloc[3];
uint8_t CC_DMI;
/* Real Time Diagnostics, 96-111 */
uint8_t temp[2];
uint8_t vcc[2];
uint8_t tx_bias[2];
uint8_t tx_pow[2];
uint8_t rx_pow[2];
uint8_t rtd_unalloc0[4];
uint8_t OSCB;
uint8_t rtd_unalloc1;
/* Alarms and Warnings, 112 - 117 */
uint8_t alw[6];
/* Extended Module Control/Status bytes 118 - 119 */
uint8_t emcsb[2];
/* Vendor locations 120 - 127 */
uint8_t vendor_locations[8];
/* User data 128 - 247 */
uint8_t dom_user[120];
/* Vendor specific control function locations 248 - 255 */
uint8_t vendor_functions[8];
} __attribute__ ((packed));
/* Public API */
/*
* Scan all ports for plugged in SFP's. The return value is a bitmask
* of all the ports with detected SFP's (bits 0-17 are valid).
*/
uint32_t shw_sfp_module_scan(void);
/* Set/get the 4 GPIO's connected to PCA9554's for a particular SFP */
void shw_sfp_gpio_set(int num, uint8_t state);
uint8_t shw_sfp_gpio_get(int num);
static inline void shw_sfp_set_generic(int num, int status, int type)
{
uint8_t state;
state = shw_sfp_gpio_get(num);
if (status)
state |= type;
else
state &= ~type;
shw_sfp_gpio_set(num, state);
}
/* Load the db from dot-config to internal structures */
int shw_sfp_read_db(void);
/* Read and verify the header all at once. returns -1 on failure */
int shw_sfp_read_verify_header(int num, struct shw_sfp_header *head);
/* Read the SFP diagnostics page */
int shw_sfp_read_dom(int num, struct shw_sfp_dom *dom);
/* Update the SFP diagnostics page */
int shw_sfp_update_dom(int num, struct shw_sfp_dom *dom);
/* Decode and print the SFP real time diagnostics */
void shw_sfp_print_dom(struct shw_sfp_dom * dom);
/* Dump the SFP diagnostics page in hex */
void shw_sfp_dom_dump(struct shw_sfp_dom * dom);
/* return NULL if no data found */
struct shw_sfp_caldata *shw_sfp_get_cal_data(int num,
struct shw_sfp_header *head);
#endif /* __LIBWR_SHW_SFPLIB_H */
......@@ -111,8 +111,8 @@ void ptpd_netif_linearize_rx_timestamp(struct wr_timestamp *ts,
int clock_period);
void ptpd_netif_set_phase_transition(uint32_t phase);
struct hal_port_state;
int wrpc_get_port_state(struct hal_port_state *port,
struct wrc_port_state;
int wrpc_get_port_state(struct wrc_port_state *port,
const char *port_name /* unused */);
#endif /* __PTPD_NETIF_H */
......@@ -27,7 +27,7 @@ struct wrc_shell_cmd {
/* Put the structures in their own section */
#define DEFINE_WRC_COMMAND(_name) \
const struct wrc_shell_cmd __wrc_cmd_ ## _name
struct wrc_shell_cmd __wrc_cmd_ ## _name
char *env_get(const char *var);
int env_set(const char *var, const char *value);
......
......@@ -123,14 +123,14 @@ void storage_init( struct i2c_bus *bus, int i2c_addr);
int storage_sfpdb_erase(void);
int storage_match_sfp(struct s_sfpinfo *sfp);
int storage_get_sfp(struct s_sfpinfo *sfp, uint8_t add, uint8_t pos);
int storage_get_sfp(struct s_sfpinfo *sfp, int add, int pos);
int storage_phtrans(uint32_t *val, uint8_t write);
int storage_phtrans(uint32_t *val, int write);
int storage_init_erase(void);
int storage_init_add(const char *args[]);
int storage_init_show(void);
int storage_init_readcmd(uint8_t *buf, uint8_t bufsize, uint8_t next);
int storage_init_readcmd(uint8_t *buf, int bufsize, int next);
int storage_sdbfs_erase( struct storage_device *dev, uint32_t addr, int force_base );
int storage_sdbfs_format( struct storage_device *dev, uint32_t addr, int force_base );
void storage_sdbfs_list(void);
......@@ -143,8 +143,8 @@ int storage_save_calibration(void);
int storage_read_hdl_cfg(void);
int storage_mount( struct storage_device *dev );
int storage_get_persistent_mac(uint8_t portnum, uint8_t *mac);
int storage_set_persistent_mac(uint8_t portnum, uint8_t *mac);
int storage_get_persistent_mac(int portnum, uint8_t *mac);
int storage_set_persistent_mac(int portnum, uint8_t *mac);
#endif
......@@ -57,6 +57,12 @@ const char *fromhex(const char *hex, int *v);
const char *fromhex64(const char *hex, int64_t *v);
const char *fromdec(const char *dec, int *v);
char *format_mac(char *s, const unsigned char *mac);
char *format_hex8(char *s, const unsigned char *mac);
void decode_mac(const char *str, unsigned char *mac);
void decode_port(const char *str, int *port);
static inline int within_range(int x, int minval, int maxval, int wrap)
{
int rv;
......
......@@ -27,11 +27,11 @@ struct wrc_task {
unsigned long max_run_ticks; /* in ticks */
};
void wrc_tasks_init(void);
void wrc_tasks_preinit(void);
struct wrc_task* wrc_task_create( const char *name, void (*init)(void), int (*job)(void) );
void wrc_task_set_enable( struct wrc_task* task, int (*enabled)(void) );
struct wrc_task *wrc_task_get(int tid);
void wrc_start_all_tasks(void);
void wrc_tasks_run_inits(void);
void wrc_poll_all_tasks(void);
void wrc_tasks_accounting_init(void);
int wrc_task_not_yet(uint32_t *lastt, unsigned period);
......
......@@ -30,6 +30,9 @@
_a < _b ? _a : _b; })
#endif
/* Don't use abs from the library */
#define abs(x) ((x >= 0) ? x : -x)
#ifndef htons
# define htons(x) (x)
#endif
......@@ -92,9 +95,6 @@ void shell_init(void);
/* Default width (in 8ns/16ns units) of the pulses on the PPS output */
#define PPS_WIDTH (10 * 1000 * 1000 / NS_PER_CLOCK) /* 10ms */
/* This is in the library, somewhere */
extern int abs(int val);
/* refresh period for _gui_ and _stat_ commands */
extern int wrc_ui_refperiod;
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <stdlib.h>
/*
* This is a minimal atoi, that doesn't call strtol. Since we are only
* calling atoi, it saves XXXX bytes of library code
*/
int atoi(const char *s)
{
int sign = 1, res = 0;
/* as (mis)designed in atoi, we make no error check */
if (*s == '-') {
sign = -1;
s++;
}
while (*s >= '0' && *s <= '9')
res = res * 10 + *s++ - '0';
return res * sign;
}
#ifdef TEST_ATOI
/*
* You can try this:
*
make atoi CFLAGS="-DTEST_ATOI -Wall" && \
./atoi foo 0 45 -45 9876543210 -9345.2 97.5 666devils
*
*/
#include <stdio.h>
/* just to be sure I call mine and not a #define somewhere in the headers */
int __local_atoi (const char *s) __attribute__((alias("atoi")));
int main(int argc, char **argv)
{
int i;
for (i = 1; i < argc; i++)
printf("%i\n", __local_atoi(argv[i]));
return 0;
}
#endif /* TEST_ATOI */
......@@ -31,7 +31,7 @@ struct event_handler
static struct event_handler handlers[MAX_EVENT_HANDLERS];
static int event_handler_count = 0;
static inline void queue_put( struct event_queue* buf, uint8_t c )
static inline void queue_put( struct event_queue* buf, int c )
{
if (buf->count >= buf->size)
return;
......@@ -104,6 +104,8 @@ int event_handler_enable( int id, int enable )
int event_post( int event )
{
int i;
if (!BOARD_USE_EVENTS)
return 0;
for(i = 0; i < event_handler_count; i++ )
{
struct event_handler *eh = &handlers[i];
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2020 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#include <wrpc.h>
#include "event.h"
static int prev_ptp_mode;
static int prev_ptp_state;
static int prev_servo_state;
static int prev_timing_ok;
void wrc_events_ptp_init(void)
{
prev_ptp_mode = -1;
prev_ptp_state = -1;
prev_servo_state = -1;
prev_timing_ok = 0;
}
int wrc_events_ptp_poll(void)
{
extern struct pp_instance ppi_static;
struct pp_instance *ppi = &ppi_static;
struct pp_servo *ss = SRV(ppi);//= &((struct wr_data *)ppi->ext_data)->servo_state;
int mode = wrc_ptp_get_mode();
if( mode != prev_ptp_mode )
{
main_dbg("PTP mode changed.\n");
prev_timing_ok = 0;
event_post( WRC_EVENT_PTP_MODE_CHANGED );
}
prev_ptp_mode = mode;
// observe the PTP state machine transitions and the servo state - and depending on the mode of
// operation (master/slave), send the 'Timing up'/'Timing down' events.
if( mode == WRC_MODE_MASTER )
{
if( ppi->state == PPS_MASTER && prev_ptp_state != PPS_MASTER )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP );
}
else if ( ppi->state != PPS_MASTER && prev_ptp_state == PPS_MASTER )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
else if ( mode == WRC_MODE_SLAVE )
{
if( ppi->state == PPS_SLAVE )
{
if( ss->state == WRH_TRACK_PHASE && prev_servo_state != WRH_TRACK_PHASE )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP );
}
else if( ss->state != WRH_TRACK_PHASE && prev_servo_state == WRH_TRACK_PHASE )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
else if( ppi->state != PPS_SLAVE && prev_ptp_state == PPS_SLAVE )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
prev_ptp_state = ppi->state;
prev_servo_state = ss->state;
return 1;
}
void wrc_events_ptp_link_down(void)
{
/* TODO: do boards need events NETIF_LINK_WENT_DOWN and
* WRC_EVENT_TIMING_DOWN? Isn't enough to have link down?
*/
if (!BOARD_USE_EVENTS)
return;
prev_timing_ok = 0;
}
int wrc_is_timing_up(void)
{
return prev_timing_ok;
}
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2020 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#ifndef __EVENTS_PTP_H
#define __EVENTS_PTP_H
void wrc_events_ptp_init(void);
int wrc_events_ptp_poll(void);
int wrc_is_timing_up(void);
void wrc_events_ptp_link_down(void);
#endif /* __EVENTS_PTP_H */
......@@ -281,7 +281,7 @@ static int cmd_ltest(const char *args[])
int v = 0, v1 = 0;
if (args[1]) {
fromdec(args[1], &v1); /* ms */
v1 = atoi(args[1]); /* ms */
}
if (args[0]) {
if (HAS_SYSLOG && !strcmp(args[0], "verbose"))
......@@ -289,9 +289,9 @@ static int cmd_ltest(const char *args[])
else if (HAS_SYSLOG && !strcmp(args[0], "quiet"))
lat_verbose = 0;
else if (!strcmp(args[0], "fake"))
fromdec(args[1], &ltest_fake_delay_ns);
ltest_fake_delay_ns = atoi(args[1]);
else {
fromdec(args[0], &v);
v = atoi(args[0]);
latency_period_ms = v * 1000 + v1;
lastt = 0; /* reset, so it fires immediately */
}
......
obj-y += lib/util.o lib/wrc-tasks.o
obj-y += \
lib/util.o \
lib/wrc-tasks.o \
lib/events-ptp.o \
obj-$(CONFIG_LM32) += \
lib/atoi.o \
lib/assert.o \
lib/usleep.o \
lib/event.o
......@@ -18,3 +20,4 @@ obj-$(CONFIG_NETCONSOLE) += lib/netconsole.o
# below requires $(AUTOCONF_PPSI) to be present before build
REQUIRE_AUTOCONF_PPSI += \
lib/net.o \
lib/events-ptp.o \
......@@ -36,14 +36,14 @@ static struct wr_sockaddr addr;
extern char wrc_hw_name[HW_NAME_LENGTH];
static void lldp_header_tlv(uint8_t tlv_type, uint8_t tlv_len)
static void lldp_header_tlv(int tlv_type, int tlv_len)
{
lldpdu[lldpdu_len] = tlv_type << 1;
lldpdu[lldpdu_len + LLDP_SUBTYPE] = tlv_len;
lldpdu_len += LLDP_HEADER;
}
static void fill_mac(uint8_t *tlv, uint8_t type)
static void fill_mac(uint8_t *tlv, int type)
{
*tlv = type;
/* write MAC after subtype byte */
......@@ -119,10 +119,7 @@ static void lldp_add_tlv(int tlv_type) {
} else {
/* NOTE: no subtype */
ep_get_mac_addr(&wrc_endpoint_dev, mac);
pp_sprintf(buf,
"%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3],
mac[4], mac[5]);
format_mac(buf, mac);
tlv_len = 17;
strncpy((char *)(lldpdu + lldpdu_len + LLDP_HEADER),
(char *)buf, tlv_len);
......
......@@ -49,7 +49,7 @@ struct wrpc_socket *ptpd_netif_create_socket(struct wrpc_socket *sock,
int udp_or_raw, int udpport)
{
int i;
struct hal_port_state pstate;
struct wrc_port_state pstate;
/* Look for the first available socket. */
for (i = 0; i < ARRAY_SIZE(socks); i++)
......@@ -225,7 +225,7 @@ int ptpd_netif_recvfrom(struct wrpc_socket *s, struct wr_sockaddr *from, void *d
uint16_t size;
struct wr_ethhdr hdr;
struct hw_timestamp hwts;
uint8_t spll_busy;
int spll_busy;
/*check if there is something to fetch */
if (!q->n)
......@@ -246,7 +246,7 @@ int ptpd_netif_recvfrom(struct wrpc_socket *s, struct wr_sockaddr *from, void *d
if (rx_timestamp) {
rx_timestamp->raw_nsec = hwts.nsec;
rx_timestamp->raw_ahead = hwts.ahead;
spll_busy = (uint8_t) spll_shifter_busy(0);
spll_busy = spll_shifter_busy(0);
spll_read_ptracker(0, &rx_timestamp->raw_phase, NULL);
rx_timestamp->sec = hwts.sec;
......
......@@ -18,11 +18,11 @@
#include <board.h>
struct wrs_shm_head *ppsi_head;
void *ppsi_head;
/* Following code from ptp-noposix/libposix/freestanding-wrapper.c */
static int read_phase_val(struct hal_port_state *port)
static int read_phase_val(struct wrc_port_state *port)
{
int32_t dmtd_phase;
......@@ -39,34 +39,19 @@ static int read_phase_val(struct hal_port_state *port)
extern uint32_t cal_phase_transition;
int wrpc_get_port_state(struct hal_port_state *port, const char *port_name)
int wrpc_get_port_state(struct wrc_port_state *port, const char *port_name)
{
if (wrc_ptp_get_mode() == WRC_MODE_SLAVE)
port->mode = HEXP_PORT_MODE_WR_SLAVE;
else
port->mode = HEXP_PORT_MODE_WR_MASTER;
/* all deltas are added anyway */
ep_get_deltas(&wrc_endpoint_dev, &port->calib.sfp.delta_tx_ps,
&port->calib.sfp.delta_rx_ps);
ep_get_deltas(&wrc_endpoint_dev, &port->calib.delta_tx_ps,
&port->calib.delta_rx_ps);
/* get the bitslide */
port->calib.bitslide_ps = ep_get_bitslide(&wrc_endpoint_dev);
port->calib.delta_tx_phy = 0;
port->calib.delta_rx_phy = 0;
port->calib.delta_tx_board = 0;
port->calib.delta_rx_board = 0;
read_phase_val(port);
port->state = ep_link_up(&wrc_endpoint_dev, NULL);
port->calib.tx_calibrated = 1;
port->calib.rx_calibrated = 1;
port->locked = spll_check_lock(0);
/* port->lock_priority = 0;*/
/*spll_get_phase_shift(0, NULL, (int32_t *)&port->phase_setpoint);*/
port->clock_period = REF_CLOCK_PERIOD_PS;
port->t2_phase_transition = cal_phase_transition;
port->t4_phase_transition = cal_phase_transition;
ep_get_mac_addr(&wrc_endpoint_dev, port->hw_addr);
port->hw_index = 0;
return 0;
}
......
......@@ -26,7 +26,7 @@ static int verify_lpj(int lpj)
/* wait for the beginning of a tick */
j = timer_get_tics() + 1;
while (timer_get_tics() != j)
while (timer_get_tics() < j)
;
__delay(lpj);
......
......@@ -210,3 +210,88 @@ const char *fromdec(const char *dec, int *v)
*v = o * sign;
return dec;
}
char *format_hex(char *s, const unsigned char *mac, int cnt)
{
int i;
*s = '\0';
for (i = 0; i < cnt; i++) {
pp_sprintf(s, "%s%02x:", s, mac[i]);
}
/* remove last colon */
s[cnt * 3 - 1] = '\0'; /* cnt * strlen("FF:") - 1 */
return s;
}
char *format_mac(char *s, const unsigned char *mac)
{
format_hex(s, mac, 6);
return s;
}
char *format_hex8(char *s, const unsigned char *mac)
{
return format_hex(s, mac, 8);
}
void decode_mac(const char *str, unsigned char *mac)
{
int i, x;
/* Don't try to detect bad input; need small code */
for (i = 0; i < 6; ++i) {
str = fromhex(str, &x);
mac[i] = x;
if (*str == ':')
++str;
}
}
void decode_port(const char *str, int *port)
{
if( !str )
*port = 0;
else
*port = atoi(str);
}
/*
* This is a minimal atoi, that doesn't call strtol. Since we are only
* calling atoi, it saves XXXX bytes of library code
* Use fromdec in atoi. Not the way round, because fromdec can return a pointer
* to non recognized character (atoi cannot).
*/
int atoi(const char *s)
{
int res;
fromdec(s, &res);
return res;
}
/* To save code, in the div of two int64 numbers
* use signed 64bit division, then correct the sign of the result */
long long __divdi3 (long long A, long long B)
{
int sign_a, sign_b;
unsigned long long a_u;
unsigned long long b_u;
sign_a = A < 0 ? -1 : 1;
sign_b = B < 0 ? -1 : 1;
a_u = A * sign_a;
b_u = A * sign_b;
return sign_a * sign_b * (long long) (a_u / b_u);
}
/* To save code, at the 64bit modulo use division and multiplication instead of
* modulo function from the standard library */
unsigned long long __umoddi3 (unsigned long long A, unsigned long long B)
{
volatile uint64_t x = A/B;
return A - (x)*B;
}
......@@ -115,12 +115,12 @@ void wrc_task_set_enable( struct wrc_task* task, int (*enabled)(void) )
task->enabled = enabled;
}
void wrc_tasks_init()
void wrc_tasks_preinit(void)
{
memset(&tasks, 0, sizeof(struct wrc_task) * WRC_MAX_TASKS);
}
void wrc_poll_all_tasks()
void wrc_poll_all_tasks(void)
{
int i;
......@@ -131,7 +131,7 @@ void wrc_poll_all_tasks()
}
}
void wrc_start_all_tasks()
void wrc_tasks_run_inits(void)
{
int i;
......@@ -142,7 +142,7 @@ void wrc_start_all_tasks()
}
}
void wrc_tasks_accounting_init()
void wrc_tasks_accounting_init(void)
{
shw_pps_gen_get_time(NULL, &prev_nanos_for_profile);
/* get tics */
......
......@@ -193,84 +193,16 @@ desired_states[] = {
{}
};
char * timeIntervalToString_ns_dot_ps(TimeInterval time, char *buf)
static inline char * timeToString_ps_as_ns(struct pp_time *time, char *buf)
{
int64_t nanos;
uint32_t picos;
char sign = ' ';
if (time < 0 && time != INT64_MIN) {
sign = '-';
time = -time;
}
nanos = time >> TIME_INTERVAL_FRACBITS;
picos = (((time & TIME_INTERVAL_FRACMASK) * 1000) + TIME_INTERVAL_ROUNDING_VALUE) >> TIME_INTERVAL_FRACBITS;
sprintf(buf, "%c%Ld.%03d", sign, nanos, picos);
return buf;
}
char * timeToString_ps_as_ns(struct pp_time *time, char *buf)
{
char sign = '+';
int64_t scaled_nsecs = time->scaled_nsecs;
int64_t secs = time->secs, nanos, picos;
if (!is_incorrect(time)) {
if (scaled_nsecs < 0 || secs < 0) {
sign = '-';
scaled_nsecs = -scaled_nsecs;
secs = -secs;
}
nanos = scaled_nsecs >> TIME_FRACBITS;
picos = ((scaled_nsecs & TIME_FRACMASK) * 1000 + TIME_ROUNDING_VALUE)
>> TIME_FRACBITS;
if ((scaled_nsecs > 0 && secs < 0)
|| (scaled_nsecs < 0 && secs > 0)) {
sprintf(buf, "!Wsign:s%cns%c", secs > 0 ? '+':'-', scaled_nsecs > 0 ? '+':'-');
return buf;
}
sprintf(buf, "%c%Ld",
sign, secs);
sprintf(buf, "%s.%Ld",
buf, nanos);
sprintf(buf, "%s.%Ld",
buf, picos);
return time_to_string(time);
} else {
sprintf(buf, "--Incorrect--");
}
return buf;
}
char * relativeDifferenceToString(RelativeDifference time, char *buf)
{
char sign;
int32_t nsecs;
uint64_t sub_yocto = 0;
int64_t fraction;
uint64_t bitWeight = 500000000000000000;
uint64_t mask;
if (time < 0) {
time =- time;
sign = '-';
} else {
sign = '+';
}
nsecs = time >> REL_DIFF_FRACBITS;
fraction = time & REL_DIFF_FRACMASK;
for (mask = (uint64_t) 1 << (REL_DIFF_FRACBITS - 1); mask != 0; mask >>= 1) {
if (mask & fraction)
sub_yocto += bitWeight;
bitWeight /= 2;
}
sprintf(buf,"%c%d.%018Ld", sign, nsecs, sub_yocto);
return buf;
}
static inline int extensionStateColor(struct pp_instance *ppi)
{
if (ppi->protocol_extension == PPSI_EXT_NONE) {
......@@ -308,7 +240,7 @@ static char *optimized_pp_time_toString_ps_as_ns(struct pp_time *pptime, char *b
if (pptime->secs)
sprintf(buf,"%s sec ", timeToString_ps_as_ns(pptime, lbuf));
else
sprintf(buf,"%s nsec", timeIntervalToString_ns_dot_ps(pp_time_to_interval(pptime), lbuf));
sprintf(buf,"%s nsec", interval_to_string(pp_time_to_interval(pptime)));
return buf;
}
......@@ -422,7 +354,7 @@ void print_main_description(void)
void print_main_data(void)
{
struct hal_port_state state;
struct wrc_port_state state;
int tx, rx;
int leap_sec, tmp;
uint64_t sec;
......@@ -464,7 +396,7 @@ void print_main_data(void)
for (i = 0 ; i < ndevs; i++) {
struct wrc_netif_device *ndev = netif_get_device(i);
uint8_t port_up = ndev->link_state == NETIF_LINK_UP;
int port_up = ndev->link_state == NETIF_LINK_UP;
if (port_up) {
pcprintf(9, 1, C_GREEN, " %s: ", ndev->name);
......@@ -510,8 +442,8 @@ void print_main_data(void)
for (i = 0 ; i < ndevs; i++) {
struct wrc_netif_device *ndev = netif_get_device(i);
uint8_t port_up = ndev->link_state == NETIF_LINK_UP;
uint8_t color;
int port_up = ndev->link_state == NETIF_LINK_UP;
int color;
if (port_up) {
pcprintf(14, 1, C_GREEN, " %s: ", ndev->name);
......@@ -545,6 +477,7 @@ void print_main_data(void)
unsigned char *p = ppi_pt->activePeer;
char * extension_state_name = EMPTY_EXTENSION_STATE_NAME;
char proto;
char mac_buf[20];
#if 0 /* FIXME: only one instance so far */
if (strcmp(if_name,
......@@ -556,10 +489,10 @@ void print_main_data(void)
#endif
// Evaluate the instance configuration
strcpy(str_config,"unknown");
if (ppg->defaultDS->slaveOnly) {
if (is_slaveOnly(ppg->defaultDS)) {
strncpy(str_config, "slaveOnly", sizeof(str_config) - 1);
} else {
if (ppg->defaultDS->externalPortConfigurationEnabled) {
if (is_externalPortConfigurationEnabled(ppg->defaultDS)) {
int s = 0;
for (s = 0; s < sizeof(desired_states) / sizeof(struct desired_state_t); s++) {
if (desired_states[s].state == ppi_pt->externalPortConfigurationPortDS.desiredState) {
......@@ -569,7 +502,7 @@ void print_main_data(void)
}
} else {
if (ppi_pt->portDS->masterOnly) {
if (is_masterOnly(ppi_pt->portDS)) {
strncpy(str_config, "masterOnly", sizeof(str_config) - 1);
} else {
strncpy(str_config, "auto", sizeof(str_config) - 1);
......@@ -580,10 +513,7 @@ void print_main_data(void)
pcprintf(14, 16, C_WHITE, "%-12s", str_config);
/* peer not implemented */
pprintf(14, 31, "%02x:%02x"
":%02x:%02x:%02x:%02x ",
p[0], p[1], p[2], p[3],
p[4], p[5]);
pprintf(14, 31, format_mac(mac_buf, p));
pcprintf(14, 51, C_GREEN, "%s/", getStateAsString(pp_instance_state_to_name, ppi_pt->state));
/* print extension state */
......@@ -771,7 +701,7 @@ void print_servo_data(struct pp_instance *ppi)
/* +- Timing parameters --------------------------------------------------------- */
pcprintf(21, 20, C_WHITE, "%19s nsec", timeIntervalToString_ns_dot_ps(ppg->currentDS->meanDelay, buf));
pcprintf(21, 20, C_WHITE, "%19s nsec", interval_to_string(ppg->currentDS->meanDelay));
/*delayMS */
pcprintf(22, 20, C_WHITE,"%24s", optimized_pp_time_toString_ps_as_ns(&ppi->servo->delayMS, buf));
......@@ -795,18 +725,18 @@ void print_servo_data(struct pp_instance *ppi)
/* delayAsymmetry */
pcprintf(24, 20, C_WHITE, "%19s nsec", timeIntervalToString_ns_dot_ps(ppi->portDS->delayAsymmetry, buf));
pcprintf(24, 20, C_WHITE, "%19s nsec", interval_to_string(ppi->portDS->delayAsymmetry));
/* delayCoefficient */
pcprintf(25, 23, C_WHITE, "%s", relativeDifferenceToString(ppi->asymmetryCorrectionPortDS.scaledDelayCoefficient, buf));
pcprintf(25, 23, C_WHITE, "%s", relative_interval_to_string(ppi->asymmetryCorrectionPortDS.scaledDelayCoefficient));
/* fpa */
pcprintf(25, 51, C_WHITE, "%Lu", ppi->asymmetryCorrectionPortDS.scaledDelayCoefficient); /* print as unsigned! */
/* ingressLatency */
pcprintf(26, 20, C_WHITE, "%19s nsec", timeIntervalToString_ns_dot_ps(ppi->timestampCorrectionPortDS.ingressLatency, buf));
pcprintf(26, 20, C_WHITE, "%19s nsec", interval_to_string(ppi->timestampCorrectionPortDS.ingressLatency));
/* egressLatency */
pcprintf(27, 20, C_WHITE, "%19s nsec", timeIntervalToString_ns_dot_ps(ppi->timestampCorrectionPortDS.egressLatency, buf));
pcprintf(27, 20, C_WHITE, "%19s nsec", interval_to_string(ppi->timestampCorrectionPortDS.egressLatency));
/* semistaticLatency */
pcprintf(28, 20, C_WHITE, "%19s nsec", timeIntervalToString_ns_dot_ps(ppi->timestampCorrectionPortDS.semistaticLatency, buf));
pcprintf(28, 20, C_WHITE, "%19s nsec", interval_to_string(ppi->timestampCorrectionPortDS.semistaticLatency));
/*if (0) {
cprintf(C_BLUE, "Fiber asymmetry: ");
......@@ -815,7 +745,7 @@ void print_servo_data(struct pp_instance *ppi)
}*/
/* offsetFromMaster */
pcprintf(29, 20, C_WHITE, "%19s nsec", timeIntervalToString_ns_dot_ps (ppg->currentDS->offsetFromMaster, buf));
pcprintf(29, 20, C_WHITE, "%19s nsec", interval_to_string (ppg->currentDS->offsetFromMaster));
row_offset = 30;
if (wr_servo) {
/* Phase setpoint */
......@@ -853,7 +783,7 @@ void print_servo_data(struct pp_instance *ppi)
int wrc_log_stats(void)
{
#if 0
struct hal_port_state state;
struct wrc_port_state state;
int tx, rx;
struct spll_aux_clock_status aux_stat;
uint64_t sec;
......@@ -945,7 +875,7 @@ int wrc_log_stats(void)
int wrc_wr_diags(void)
{
#if 0
struct hal_port_state ps;
struct wrc_port_state ps;
static uint32_t last_jiffies;
int tx, rx;
uint64_t sec;
......
Subproject commit 3d815ee0fba517175db3f3e21c6e6f4151865341
Subproject commit de2bb43c92c40264b983893eb5f94be73539f989
......@@ -19,7 +19,7 @@ OBJDUMP = $(CROSS_COMPILE)objdump
# calculate endianness at compile time
ENDIAN := $(shell ./check-endian $(CC))
CFLAGS = -Wall -ggdb -O2
CFLAGS = -Wall -ggdb -Os -mmultiply-enabled -mbarrel-shift-enabled
CFLAGS += -I../include/linux -I../include # for <sdb.h>
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -Wno-pointer-sign
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <stdlib.h>
#include <string.h>
#include <wrc.h>
#include <shell.h>
static int cmd_help(const char *args[])
{
pp_printf("Available commands:\n");
shell_list_cmds();
return 0;
}
DEFINE_WRC_COMMAND(help) = {
.name = "help",
.exec = cmd_help,
};
......@@ -49,8 +49,8 @@ static int cmd_delays(const char *args[])
return 0;
}
if (args[1]) {
fromdec(args[0], &tx);
fromdec(args[1], &rx);
tx = atoi(args[0]);
rx = atoi(args[1]);
sfp_deltaTx = tx;
sfp_deltaRx = rx;
/* Change the active value too (add bislide here) */
......
......@@ -18,34 +18,6 @@
#include "dev/onewire.h"
#include "dev/endpoint.h"
void decode_mac(const char *str, unsigned char *mac)
{
int i, x;
/* Don't try to detect bad input; need small code */
for (i = 0; i < 6; ++i) {
str = fromhex(str, &x);
mac[i] = x;
if (*str == ':')
++str;
}
}
void decode_port(const char *str, int *port)
{
if( !str )
*port = 0;
else
*port = atoi(str);
}
char *format_mac(char *s, const unsigned char *mac)
{
pp_sprintf(s, "%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return s;
}
static int cmd_mac(const char *args[])
{
......
......@@ -19,7 +19,7 @@ static int cmd_refresh(const char *args[])
int sec;
if (args[0] && !args[1]) {
fromdec(args[0], &sec);
sec = atoi(args[0]);
}
else {
pp_printf("Usage: refresh <seconds>\n");
......
......@@ -14,7 +14,7 @@ static int cmd_sleep(const char *args[])
int sec = 1;
if (args[0])
fromdec(args[0], &sec);
sec = atoi(args[0]);
while (sec--)
usleep(1000 * 1000);
return 0;
......
......@@ -19,7 +19,7 @@ static int cmd_vlan(const char *args[])
if (!args[0] || !strcasecmp(args[0], "get")) {
/* nothing... */
} else if (!strcasecmp(args[0], "set") && args[1]) {
fromdec(args[1], &i);
i = atoi(args[1]);
if (i < 1 || i > 4095) {
pp_printf("%i (\"%s\") out of range\n", i, args[1]);
return -EINVAL;
......
......@@ -296,7 +296,7 @@ static int build_init_readcmd(uint8_t *cmd, int maxlen)
void shell_boot_script(void)
{
uint8_t next = 0;
int next = 0;
while (CONFIG_HAS_BUILD_INIT) {
cmd_len = build_init_readcmd((uint8_t *)cmd_buf,
......@@ -327,7 +327,7 @@ void shell_boot_script(void)
void shell_show_build_init(void)
{
uint8_t i = 0;
int i = 0;
pp_printf("-- built-in script --\n");
while (CONFIG_HAS_BUILD_INIT) {
......@@ -354,16 +354,6 @@ void shell_register_command( struct wrc_shell_cmd* cmd )
n_cmds++;
}
void shell_list_cmds()
{
int i;
for(i = 0; i < n_cmds; i++)
{
pp_printf(" %s\n", cmds[i]->name);
}
}
void shell_activate_ui_command( int (*callback)(void) )
{
shell_ui_callback = callback;
......@@ -373,6 +363,23 @@ void shell_activate_ui_command( int (*callback)(void) )
cmd_len = 0;
}
static int cmd_help(const char *args[])
{
int i;
pp_printf("Available commands:\n");
for(i = 0; i < n_cmds; i++) {
pp_printf(" %s\n", cmds[i]->name);
}
return 0;
}
DEFINE_WRC_COMMAND(help) = {
.name = "help",
.exec = cmd_help,
};
#define REGISTER_WRC_COMMAND(_name) \
{ extern struct wrc_shell_cmd __wrc_cmd_ ## _name; shell_register_command( &__wrc_cmd_ ## _name ); }
......@@ -406,3 +413,4 @@ void shell_register_commands(void)
if (HAS_CMD_NETCONSOLE)
REGISTER_WRC_COMMAND(netconsole);
}
......@@ -2,7 +2,6 @@ obj-$(CONFIG_WR_NODE) += \
shell/shell.o \
shell/cmd_version.o \
shell/cmd_ptp.o \
shell/cmd_help.o \
shell/cmd_mac.o \
shell/cmd_ps.o \
shell/cmd_uptime.o \
......
......@@ -148,3 +148,8 @@ void spll_enable_tagger(int channel, int enable)
pll_verbose("%s: ch %d, OCER 0x%x, RCER 0x%x\n", __FUNCTION__, channel, SPLL->OCER, SPLL->RCER);
}
void spll_debug(int what, int value, int last)
{
SPLL->DFR_SPLL =
(last ? 0x80000000 : 0) | (value & 0xffffff) | (what << 24);
}
......@@ -48,8 +48,4 @@ what: type of the parameter and its' source. For example,
last: when non-zero, indicates the last parameter in a sample.
*/
static inline void spll_debug(int what, int value, int last)
{
SPLL->DFR_SPLL =
(last ? 0x80000000 : 0) | (value & 0xffffff) | (what << 24);
}
void spll_debug(int what, int value, int last);
......@@ -60,12 +60,6 @@ uint32_t cal_phase_transition = 2389;
int wrc_vlan_number = CONFIG_VLAN_NR;
// fixme: this probably deserves to be moved to another file...
static int prev_ptp_mode;
static int prev_ptp_state;
static int prev_servo_state;
static int prev_timing_ok;
struct wr_endpoint_device wrc_endpoint_dev;
int wrc_wr_diags(void); // fixme: move the header
......@@ -116,7 +110,6 @@ static void wrc_initialize(void)
wrc_ptp_set_mode(WRC_MODE_SLAVE);
wrc_tasks_accounting_init();
wrc_board_create_tasks();
}
int link_status;
......@@ -142,7 +135,7 @@ static int wrc_check_link(void)
rv = 1;
} else if (prev_state && !state) {
wrc_verbose("Link down.\n");
prev_timing_ok = 0;
wrc_events_ptp_link_down();
event_post( WRC_EVENT_LINK_DOWN );
gen_gpio_out(&pin_sysc_led_link, 0);
link_status = NETIF_LINK_WENT_DOWN;
......@@ -198,92 +191,22 @@ static int update_uptime(void)
return 0;
}
int wrc_is_timing_up()
{
return prev_timing_ok;
}
static void wrc_dispatch_ptp_events_init(void)
{
prev_ptp_mode = -1;
prev_ptp_state = -1;
prev_servo_state = -1;
prev_timing_ok = 0;
}
static int wrc_dispatch_ptp_events_poll(void)
{
extern struct pp_instance ppi_static;
struct pp_instance *ppi = &ppi_static;
struct pp_servo *ss = SRV(ppi);//= &((struct wr_data *)ppi->ext_data)->servo_state;
int mode = wrc_ptp_get_mode();
if( mode != prev_ptp_mode )
{
main_dbg("PTP mode changed.\n");
prev_timing_ok = 0;
event_post( WRC_EVENT_PTP_MODE_CHANGED );
}
prev_ptp_mode = mode;
// observe the PTP state machine transitions and the servo state - and depending on the mode of
// operation (master/slave), send the 'Timing up'/'Timing down' events.
if( mode == WRC_MODE_MASTER )
{
if( ppi->state == PPS_MASTER && prev_ptp_state != PPS_MASTER )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP );
}
else if ( ppi->state != PPS_MASTER && prev_ptp_state == PPS_MASTER )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
else if ( mode == WRC_MODE_SLAVE )
{
if( ppi->state == PPS_SLAVE )
{
if( ss->state == WRH_TRACK_PHASE && prev_servo_state != WRH_TRACK_PHASE )
{
prev_timing_ok = 1;
event_post( WRC_EVENT_TIMING_UP );
}
else if( ss->state != WRH_TRACK_PHASE && prev_servo_state == WRH_TRACK_PHASE )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
else if( ppi->state != PPS_SLAVE && prev_ptp_state == PPS_SLAVE )
{
prev_timing_ok = 0;
event_post( WRC_EVENT_TIMING_DOWN );
}
}
prev_ptp_state = ppi->state;
prev_servo_state = ss->state;
return 1;
}
static void create_tasks(void)
{
struct wrc_task *t;
wrc_tasks_init();
wrc_task_create( "idle", wrc_initialize, NULL );
/* clear task table in case of a reset */
wrc_tasks_preinit();
/* create all other tasks */
wrc_task_create( "idle", NULL, NULL );
wrc_task_create( "check-link", NULL, wrc_check_link );
wrc_task_create( "uptime", init_uptime, update_uptime );
wrc_task_create( "ptp", NULL, wrc_ptp_update);
wrc_task_create( "ptp_bmc", NULL, wrc_ptp_bmc_update);
wrc_task_create( "shell+gui", shell_boot_script, ui_update );
wrc_task_create( "spll-bh", NULL, spll_update );
wrc_task_create( "ptp-events", wrc_dispatch_ptp_events_init, wrc_dispatch_ptp_events_poll );
//wrc_task_create( "temperature", wrc_temp_init, wrc_temp_refresh );
t = wrc_task_create( "net-bh", NULL, net_bh_poll );
......@@ -333,15 +256,19 @@ int main(void)
{
check_reset();
create_tasks();
wrc_board_create_tasks();
wrc_initialize();
/* initialization of individual tasks */
wrc_start_all_tasks();
wrc_tasks_run_inits();
for (;;) {
// run all pending tasks
wrc_poll_all_tasks();
// call all event handlers
events_dispatch();
if (BOARD_USE_EVENTS)
events_dispatch();
/* better safe than sorry */
check_stack();
}
......
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