Commit ece127f9 authored by li hongming's avatar li hongming

add a new mode "cascaded" for dualport function.

    separate PPS_out with time_valid.
    Disable transmitting packets when link is not up.
parent 46d036c8
# #
# Automatically generated make config: don't edit # Automatically generated file; DO NOT EDIT.
# WR PTP Core software configuration
# #
# CONFIG_WR_SWITCH is not set # CONFIG_WR_SWITCH is not set
CONFIG_WR_NODE=y CONFIG_WR_NODE=y
CONFIG_PPSI_FORCE_CONFIG=y
CONFIG_PRINT_BUFSIZE=128 CONFIG_PRINT_BUFSIZE=128
CONFIG_PRINTF_XINT=y
CONFIG_RAMSIZE=131072 CONFIG_RAMSIZE=131072
CONFIG_TEMP_POLL_INTERVAL=15
CONFIG_TEMP_HIGH_THRESHOLD=70
CONFIG_TEMP_HIGH_RAPPEL=60
# CONFIG_PLL_VERBOSE is not set
# CONFIG_PFILTER_VERBOSE is not set
# CONFIG_WRC_VERBOSE is not set
# CONFIG_VLAN is not set
CONFIG_VLAN_NR=0
CONFIG_VLAN_1_FOR_CLASS7=0
CONFIG_VLAN_2_FOR_CLASS7=0
CONFIG_VLAN_FOR_CLASS6=0
# CONFIG_HOST_PROCESS is not set
CONFIG_LM32=y
CONFIG_EMBEDDED_NODE=y
# CONFIG_WR_NODE_PCS16 is not set # CONFIG_WR_NODE_PCS16 is not set
CONFIG_STACKSIZE=2048 CONFIG_STACKSIZE=2048
CONFIG_PPSI=y CONFIG_PPSI=y
CONFIG_UART=y
CONFIG_W1=y CONFIG_W1=y
CONFIG_ETHERBONE=y CONFIG_LATENCY_ETHTYPE=291
CONFIG_WRNIC=y # CONFIG_P2P is not set
CONFIG_IP=y
# CONFIG_CMD_CONFIG is not set # CONFIG_CMD_CONFIG is not set
CONFIG_NIC_PFILTER=y # CONFIG_SYSLOG is not set
CONFIG_SNMP=y
CONFIG_SNMP_SET=y
# CONFIG_BUILD_INIT is not set
CONFIG_INIT_COMMAND=""
CONFIG_HAS_BUILD_INIT=0
CONFIG_HAS_FLASH_INIT=1
CONFIG_FLASH_INIT=y
# CONFIG_AUX_DIAG is not set
CONFIG_SDB_STORAGE=y
CONFIG_GENSDBFS=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_WR_DIAG is not set
# CONFIG_WR_NODE_SIM is not set
# CONFIG_ABSCAL is not set
# CONFIG_LLDP is not set
# #
# wrpc-sw is tainted if you change the following options # wrpc-sw is tainted if you change the following options
# #
CONFIG_DEVELOPER=y CONFIG_DEVELOPER=y
# CONFIG_CMD_LL is not set CONFIG_CMD_LL=y
# CONFIG_DAC_LOG is not set
# CONFIG_CHECK_RESET is not set # CONFIG_CHECK_RESET is not set
# CONFIG_SPLL_FIFO_LOG is not set
CONFIG_PRINTF_IS_XINT=y
# CONFIG_PRINTF_IS_FULL is not set
# CONFIG_PRINTF_IS_MINI is not set
# CONFIG_PRINTF_IS_NONE is not set
CONFIG_ASSERT=y
# CONFIG_DETERMINISTIC_BINARY is not set
# CONFIG_NET_VERBOSE is not set
# CONFIG_SNMP_VERBOSE is not set
# CONFIG_FAKE_TEMPERATURES is not set
# CONFIG_LATENCY_PROBE is not set
CONFIG_DEFAULT_PRINT_TASK_TIME_THRESHOLD=0
CONFIG_VLAN_ARRAY_SIZE=1
CONFIG_PRINTF_XINT=y
# CONFIG_PRINTF_FULL is not set # CONFIG_PRINTF_FULL is not set
# CONFIG_PRINTF_MINI is not set # CONFIG_PRINTF_MINI is not set
# CONFIG_PRINTF_NONE is not set # CONFIG_PRINTF_NONE is not set
# CONFIG_DETERMINISTIC_BINARY is not set
# CONFIG_UART_SW is not set
# CONFIG_SDB_STORAGE is not set
CONFIG_LEGACY_EEPROM=y
CONFIG_VLAN_ARRAY_SIZE=1
...@@ -55,7 +55,7 @@ void sdb_print_devices(void) ...@@ -55,7 +55,7 @@ void sdb_print_devices(void)
/* To save a little size, we enumerate our vendors */ /* To save a little size, we enumerate our vendors */
#define VID_CERN 0x0000ce42LL #define VID_CERN 0x0000ce42LL
#define VID_GSI 0x00000651LL #define VID_GSI 0x00000651LL
#define VID_THU 0x00001103LL #define VID_THU 0x00746875LL
struct wrc_device { struct wrc_device {
unsigned char **base; unsigned char **base;
......
...@@ -195,8 +195,9 @@ int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size, ...@@ -195,8 +195,9 @@ int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
EXPLODE_WR_TIMESTAMP(raw_ts, counter_r, counter_f); EXPLODE_WR_TIMESTAMP(raw_ts, counter_r, counter_f);
if (counter_r > 3 * REF_CLOCK_FREQ_HZ / 4 // if (counter_r > 3 * REF_CLOCK_FREQ_HZ / 4
&& counter_ppsg < 250000000) // && counter_ppsg < 250000000)
if (counter_ppsg < counter_r*(REF_CLOCK_PERIOD_PS / 1000))
sec--; sec--;
hwts->sec = sec; hwts->sec = sec;
......
...@@ -70,14 +70,16 @@ void shw_pps_gen_set_time(uint64_t seconds, uint32_t nanoseconds, int counter) ...@@ -70,14 +70,16 @@ void shw_pps_gen_set_time(uint64_t seconds, uint32_t nanoseconds, int counter)
{ {
ppsg_write(ADJ_UTCLO, (uint32_t) (seconds & 0xffffffffLL)); ppsg_write(ADJ_UTCLO, (uint32_t) (seconds & 0xffffffffLL));
ppsg_write(ADJ_UTCHI, (uint32_t) (seconds >> 32) & 0xff); ppsg_write(ADJ_UTCHI, (uint32_t) (seconds >> 32) & 0xff);
if (counter == PPSG_SET_SEC)
ppsg_write(ESCR, (ppsg_read(ESCR) & 0xffffffe7) | PPSG_ESCR_SEC_SET);
return;
ppsg_write(ADJ_NSEC, ppsg_write(ADJ_NSEC,
(int32_t) ((int64_t) nanoseconds * 1000LL / (int32_t) ((int64_t) nanoseconds * 1000LL /
(int64_t) REF_CLOCK_PERIOD_PS)); (int64_t) REF_CLOCK_PERIOD_PS));
if (counter == PPSG_SET_ALL) if (counter == PPSG_SET_ALL)
ppsg_write(CR, (ppsg_read(CR) & 0xfffffffb) | PPSG_CR_CNT_SET); ppsg_write(CR, (ppsg_read(CR) & 0xfffffffb) | PPSG_CR_CNT_SET);
else if (counter == PPSG_SET_SEC)
ppsg_write(ESCR, (ppsg_read(ESCR) & 0xffffffe7) | PPSG_ESCR_SEC_SET);
else if (counter == PPSG_SET_NSEC) else if (counter == PPSG_SET_NSEC)
ppsg_write(ESCR, (ppsg_read(ESCR) & 0xffffffe7) | PPSG_ESCR_NSEC_SET); ppsg_write(ESCR, (ppsg_read(ESCR) & 0xffffffe7) | PPSG_ESCR_NSEC_SET);
} }
...@@ -127,10 +129,24 @@ int shw_pps_gen_enable_output(int enable) ...@@ -127,10 +129,24 @@ int shw_pps_gen_enable_output(int enable)
uint32_t escr = ppsg_read(ESCR); uint32_t escr = ppsg_read(ESCR);
if (enable) if (enable)
ppsg_write(ESCR, ppsg_write(ESCR,
escr | PPSG_ESCR_PPS_VALID | PPSG_ESCR_TM_VALID); escr | PPSG_ESCR_PPS_VALID);
else else
ppsg_write(ESCR, ppsg_write(ESCR,
escr & ~(PPSG_ESCR_PPS_VALID | PPSG_ESCR_TM_VALID)); escr & ~(PPSG_ESCR_PPS_VALID));
return 0;
}
/* Time valid or unvalid */
int shw_pps_gen_time_valid(int valid)
{
uint32_t escr = ppsg_read(ESCR);
if (valid)
ppsg_write(ESCR,
escr | PPSG_ESCR_TM_VALID);
else
ppsg_write(ESCR,
escr & ~(PPSG_ESCR_TM_VALID));
return 0; return 0;
} }
......
...@@ -195,6 +195,7 @@ int rxts_calibration_update(uint32_t *t24p_value, int port) ...@@ -195,6 +195,7 @@ int rxts_calibration_update(uint32_t *t24p_value, int port)
int measure_t24p(uint32_t *value, int port) int measure_t24p(uint32_t *value, int port)
{ {
int rv; int rv;
int retry_cnt;
pp_printf("Waiting for link...\n"); pp_printf("Waiting for link...\n");
while (!ep_link_up(NULL, port)) while (!ep_link_up(NULL, port))
timer_delay_ms(100); timer_delay_ms(100);
...@@ -202,7 +203,12 @@ int measure_t24p(uint32_t *value, int port) ...@@ -202,7 +203,12 @@ int measure_t24p(uint32_t *value, int port)
spll_init(SPLL_MODE_SLAVE, port, 1); spll_init(SPLL_MODE_SLAVE, port, 1);
pp_printf("Locking PLL...\n"); pp_printf("Locking PLL...\n");
while (!spll_check_lock(0)) while (!spll_check_lock(0))
{
timer_delay_ms(100); timer_delay_ms(100);
retry_cnt++;
if (retry_cnt>400)
return -1;
}
pp_printf("\n"); pp_printf("\n");
pp_printf("Calibrating RX timestamper...\n"); pp_printf("Calibrating RX timestamper...\n");
...@@ -223,14 +229,6 @@ static int calib_t24p_master(uint32_t *value, int port) ...@@ -223,14 +229,6 @@ static int calib_t24p_master(uint32_t *value, int port)
return rv; return rv;
} }
pp_printf("port %d t24p read from storage: %d ps\n", port,*value); pp_printf("port %d t24p read from storage: %d ps\n", port,*value);
if ((*value)>100000)
{
pp_printf("Port %d Measuring t2/t4 phase transition...\n", port);
measure_t24p(value, port);
rv=storage_phtrans(value, 1, port);
pp_printf("Wrote new t24p value: %d ps (%s)\n", *value,
rv < 0 ? "Failed" : "Success");
}
return rv; return rv;
} }
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#include "endpoint.h" #include "endpoint.h"
#include "arp.h" #include "arp.h"
#include "ptpd_netif.h"
#include "hw/tcpip-config.h" #include "hw/tcpip-config.h"
#include "tcpip_config.h" #include "tcpip_config.h"
#include "lib/ipv4.h"
extern uint8_t tcpip_status = TCPIP_NULL; extern uint8_t tcpip_status = TCPIP_NULL;
...@@ -25,18 +27,16 @@ void tcpip_init(void) ...@@ -25,18 +27,16 @@ void tcpip_init(void)
uint8_t tmp_ip_addr[4]; uint8_t tmp_ip_addr[4];
if (!tcpip_present()) if (!tcpip_present())
{
pp_printf("No TCPIP module is found!\n");
return; return;
}
get_mac_addr(tcpip_mac_addr, 0); get_mac_addr(tcpip_mac_addr, 0);
memcpy((uint8_t *)(BASE_TCPIP_CFG + TCPIP_MAC_HIGH16 + 2), (uint8_t *)tcpip_mac_addr, 2); memcpy((uint8_t *)(BASE_TCPIP_CFG + TCPIP_MAC_HIGH16 + 2), (uint8_t *)tcpip_mac_addr, 2);
memcpy((uint8_t *)(BASE_TCPIP_CFG + TCPIP_MAC_LOW32), (uint8_t *)tcpip_mac_addr+2, 4); memcpy((uint8_t *)(BASE_TCPIP_CFG + TCPIP_MAC_LOW32), (uint8_t *)tcpip_mac_addr+2, 4);
// default udp tx dst/src port // default udp tx dst/src port
tcpip_tx_dst_port(60000); tcpip_tx_src_port(2000);
tcpip_tx_src_port(60000); tcpip_tx_dst_port(2000);
// tcpip_rx_tcp_port(8000);
getIP(tmp_ip_addr, 0); getIP(tmp_ip_addr, 0);
// tcpip module, default IP // tcpip module, default IP
...@@ -49,7 +49,6 @@ void tcpip_init(void) ...@@ -49,7 +49,6 @@ void tcpip_init(void)
// tcpip module, default subnet mask // tcpip module, default subnet mask
tmp_ip_addr[0]=0xff;tmp_ip_addr[1]=0xff;tmp_ip_addr[2]=0xff;tmp_ip_addr[3]=0x00; tmp_ip_addr[0]=0xff;tmp_ip_addr[1]=0xff;tmp_ip_addr[2]=0xff;tmp_ip_addr[3]=0x00;
tcpip_subnet_addr(tmp_ip_addr); tcpip_subnet_addr(tmp_ip_addr);
} }
void tcpip_ip_addr(uint8_t *ip) void tcpip_ip_addr(uint8_t *ip)
...@@ -113,30 +112,37 @@ void tcpip_get_hisMAC(uint8_t mac_addr[]) ...@@ -113,30 +112,37 @@ void tcpip_get_hisMAC(uint8_t mac_addr[])
memcpy(mac_addr+2, (uint8_t *)(BASE_TCPIP_CFG + TCPIP_UDP_TX_DST_MAC_LOW32), 4); memcpy(mac_addr+2, (uint8_t *)(BASE_TCPIP_CFG + TCPIP_UDP_TX_DST_MAC_LOW32), 4);
} }
void tcpip_rx_tcp_port(uint16_t port) // void tcpip_rx_tcp_port(uint16_t port)
{ // {
volatile unsigned int *rtp = // volatile unsigned int *rtp =
(unsigned int *)(BASE_TCPIP_CFG + TCPIP_TCP_LOCAL_PORT); // (unsigned int *)(BASE_TCPIP_CFG + TCPIP_TCP_LOCAL_PORT);
*rtp = (uint32_t)port; // *rtp = (uint32_t)port;
} // }
uint8_t tcpip_poll() uint8_t tcpip_poll()
{ {
uint8_t * ip; uint8_t * ip;
static uint16_t arp_count = 0; static uint32_t last_jiffies;
if (tcpip_status == TCPIP_OK) if (link_status[0]!=LINK_UP)
return 0; return 0;
if (tcpip_status == TCPIP_ARP) if(ip_status == IP_TRAINING)
arp_count++; return 0;
if (tcpip_status != TCPIP_ARP)
return 0;
if (!last_jiffies)
last_jiffies = timer_get_tics() - 1 - TICS_PER_SECOND;
if (arp_count<65530) if (time_before(timer_get_tics(), last_jiffies + TICS_PER_SECOND))
return 0; return 0;
last_jiffies = timer_get_tics();
tcpip_get_hisIP(ip); tcpip_get_hisIP(ip);
send_arp(ip, 0); send_arp(ip, 0);
arp_count=0; return 1;
} }
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#define UART_BAUDRATE 115200ULL #define UART_BAUDRATE 115200ULL
/* Maximum number of simultaneously created sockets */ /* Maximum number of simultaneously created sockets */
#define NET_MAX_SOCKETS 12 #define NET_MAX_SOCKETS 8
/* Socket buffer size, determines the max. RX packet size */ /* Socket buffer size, determines the max. RX packet size */
#define NET_MAX_SKBUF_SIZE 512 #define NET_MAX_SKBUF_SIZE 512
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#define TCPIP_GATEWAY 28 #define TCPIP_GATEWAY 28
#define TCPIP_SUBNET_MASK 32 #define TCPIP_SUBNET_MASK 32
#define TCPIP_UDP_RX_PORT 36 #define TCPIP_UDP_RX_PORT 36
#define TCPIP_UDP_TX_SRC_PORT 40 #define TCPIP_UDP_TX_DST_PORT 40
#define TCPIP_UDP_TX_DST_PORT 44 #define TCPIP_UDP_TX_SRC_PORT 44
#define TCPIP_UDP_TX_DST_IP 48 #define TCPIP_UDP_TX_DST_IP 48
#define TCPIP_UDP_TX_DST_MAC_HIGH16 52 #define TCPIP_UDP_TX_DST_MAC_HIGH16 52
#define TCPIP_UDP_TX_DST_MAC_LOW32 56 #define TCPIP_UDP_TX_DST_MAC_LOW32 56
......
...@@ -26,6 +26,9 @@ int shw_pps_gen_busy(void); ...@@ -26,6 +26,9 @@ int shw_pps_gen_busy(void);
/* Enables/disables PPS Generator PPS output */ /* Enables/disables PPS Generator PPS output */
int shw_pps_gen_enable_output(int enable); int shw_pps_gen_enable_output(int enable);
/* Time valid */
int shw_pps_gen_time_valid(int valid);
/* Masks/unmasks PPS output when link is down (useful in master mode) */ /* Masks/unmasks PPS output when link is down (useful in master mode) */
int shw_pps_gen_unmask_output(int unmask); int shw_pps_gen_unmask_output(int unmask);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
void tcpip_init(void);
void tcpip_ip_addr(uint8_t *ip); void tcpip_ip_addr(uint8_t *ip);
void tcpip_gateway_addr(uint8_t *gw); void tcpip_gateway_addr(uint8_t *gw);
void tcpip_subnet_addr(uint8_t *sn); void tcpip_subnet_addr(uint8_t *sn);
......
...@@ -86,4 +86,7 @@ extern uint32_t __div64_32(uint64_t *n, uint32_t base); ...@@ -86,4 +86,7 @@ extern uint32_t __div64_32(uint64_t *n, uint32_t base);
#define wr_num_ports 1 #define wr_num_ports 1
#endif #endif
// pps delay between ext pps in and pps out
int ext_pps_latency_ps;
#endif /* __WRC_H__ */ #endif /* __WRC_H__ */
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define WRC_MODE_MASTER 2 #define WRC_MODE_MASTER 2
#define WRC_MODE_SLAVE 3 #define WRC_MODE_SLAVE 3
#define WRC_MODE_ABSCAL 4 #define WRC_MODE_ABSCAL 4
#define WRC_MODE_CASCADED 5
extern int ptp_mode[wr_num_ports]; extern int ptp_mode[wr_num_ports];
......
...@@ -38,11 +38,23 @@ static void arp_init(void) ...@@ -38,11 +38,23 @@ static void arp_init(void)
PTPD_SOCK_RAW_ETHERNET, 0, port); PTPD_SOCK_RAW_ETHERNET, 0, port);
} }
static int process_arp(uint8_t * buf, int len) static void dp_arp_init(void)
{
struct wr_sockaddr saddr;
int port=1;
/* Configure socket filter */
memset(&saddr, 0, sizeof(saddr));
// memset(&saddr.mac, 0xFF, 6); /* Broadcast */
saddr.ethertype = htons(0x0806); /* ARP */
arp_socket[port] = ptpd_netif_create_socket(&__static_arp_socket[port], &saddr,
PTPD_SOCK_RAW_ETHERNET, 0, port);
}
static int process_arp(uint8_t * buf, int len, int port)
{ {
uint8_t hisMAC[6]; uint8_t hisMAC[6];
uint8_t hisIP[4]; uint8_t hisIP[4];
int port=0;
uint8_t myIP[2][4]; uint8_t myIP[2][4];
if (len < ARP_END) if (len < ARP_END)
...@@ -69,7 +81,7 @@ static int process_arp(uint8_t * buf, int len) ...@@ -69,7 +81,7 @@ static int process_arp(uint8_t * buf, int len)
buf[ARP_OPER + 0] = 0; buf[ARP_OPER + 0] = 0;
buf[ARP_OPER + 1] = 2; buf[ARP_OPER + 1] = 2;
// my MAC // my MAC
get_mac_addr(buf + ARP_SHA, 0); get_mac_addr(buf + ARP_SHA, port);
for (port = 0; port < wr_num_ports; ++port) for (port = 0; port < wr_num_ports; ++port)
{ {
...@@ -105,14 +117,36 @@ static int arp_poll(void) ...@@ -105,14 +117,36 @@ static int arp_poll(void)
int port=0; int port=0;
int ret; int ret;
if (ip_status[port] == IP_TRAINING) if ((link_status[port]!=LINK_UP) || (ip_status[port] == IP_TRAINING))
return 0; /* can't do ARP w/o an address... */ return 0;
ret = 0;
if ((len = ptpd_netif_recvfrom(arp_socket[port],
&addr, buf, sizeof(buf), 0, port)) > 0)
{
if ((len = process_arp(buf, len, port)) > 0)
ptpd_netif_sendto(arp_socket[port], &addr, buf, len, 0, port);
ret = 1;
}
return ret;
}
static int dp_arp_poll(void)
{
uint8_t buf[ARP_END + 100];
struct wr_sockaddr addr;
int len;
int port=1;
int ret;
if ((link_status[port]!=LINK_UP) || (ip_status[port] == IP_TRAINING))
return 0;
ret = 0; ret = 0;
if ((len = ptpd_netif_recvfrom(arp_socket[port], if ((len = ptpd_netif_recvfrom(arp_socket[port],
&addr, buf, sizeof(buf), 0, port)) > 0) &addr, buf, sizeof(buf), 0, port)) > 0)
{ {
if ((len = process_arp(buf, len)) > 0) if ((len = process_arp(buf, len, port)) > 0)
ptpd_netif_sendto(arp_socket[port], &addr, buf, len, 0, port); ptpd_netif_sendto(arp_socket[port], &addr, buf, len, 0, port);
ret = 1; ret = 1;
} }
...@@ -153,3 +187,10 @@ DEFINE_WRC_TASK(arp) = { ...@@ -153,3 +187,10 @@ DEFINE_WRC_TASK(arp) = {
.init = arp_init, .init = arp_init,
.job = arp_poll, .job = arp_poll,
}; };
DEFINE_WRC_TASK(dp_arp) = {
.name = "dp-arp",
.enable = &(link_status[1]),
.init = dp_arp_init,
.job = dp_arp_poll,
};
...@@ -86,24 +86,24 @@ static void ipv4_init(void) ...@@ -86,24 +86,24 @@ static void ipv4_init(void)
int port=0; int port=0;
/* Bootp: use UDP engine activated by function arguments */ /* Bootp: use UDP engine activated by function arguments */
bootp_socket = ptpd_netif_create_socket(&__static_bootp_socket, NULL, // bootp_socket = ptpd_netif_create_socket(&__static_bootp_socket, NULL,
PTPD_SOCK_UDP, 68 /* bootpc */, 0); // PTPD_SOCK_UDP, 68 /* bootpc */, port);
/* time (rdate): UDP */ /* time (rdate): UDP */
rdate_socket = ptpd_netif_create_socket(&__static_rdate_socket, NULL, rdate_socket = ptpd_netif_create_socket(&__static_rdate_socket, NULL,
PTPD_SOCK_UDP, 37 /* time */, 0); PTPD_SOCK_UDP, 37 /* time */, port);
/* remote update (remote_update): UDP */ /* remote update (remote_update): UDP */
remote_update_socket = ptpd_netif_create_socket(&__static_remote_update_socket, NULL, remote_update_socket = ptpd_netif_create_socket(&__static_remote_update_socket, NULL,
PTPD_SOCK_UDP, 71 /* remote update */, 0); PTPD_SOCK_UDP, 71 /* remote update */, port);
/* ICMP: specify raw (not UDP), with IPV4 ethtype */ /* ICMP: specify raw (not UDP), with IPV4 ethtype */
memset(&saddr, 0, sizeof(saddr)); memset(&saddr, 0, sizeof(saddr));
saddr.ethertype = htons(0x0800); saddr.ethertype = htons(0x0800);
// All SNMPs go through port 0 // All SNMPs go through port 0
icmp_socket[0] = ptpd_netif_create_socket(&__static_icmp_socket[0], &saddr, icmp_socket[port] = ptpd_netif_create_socket(&__static_icmp_socket[port], &saddr,
PTPD_SOCK_RAW_ETHERNET, 0, 0); PTPD_SOCK_RAW_ETHERNET, 0, port);
syslog_init(); // syslog_init();
} }
static int bootp_retry = 0; static int bootp_retry = 0;
...@@ -137,21 +137,18 @@ static int icmp_poll() ...@@ -137,21 +137,18 @@ static int icmp_poll()
{ {
struct wr_sockaddr addr; struct wr_sockaddr addr;
uint8_t buf[128]; uint8_t buf[128];
int len;
int port=0; int port=0;
int len;
len = ptpd_netif_recvfrom(icmp_socket[0], &addr, len = ptpd_netif_recvfrom(icmp_socket[port], &addr,
buf, sizeof(buf), NULL, 0); buf, sizeof(buf), NULL, port);
if (len <= 0) if (len <= 0)
return 0; return 0;
/* check the destination IP */ /* check the destination IP */
for (port= 0;port<wr_num_ports;++port) if(check_dest_ip(buf, port)==0){
{ if ((len = process_icmp(buf, len, port)) > 0)
if(check_dest_ip(buf, port)==0){ ptpd_netif_sendto(icmp_socket[port], &addr, buf, len, 0, port);
if ((len = process_icmp(buf, len, port)) > 0) return 1;
ptpd_netif_sendto(icmp_socket[0], &addr, buf, len, 0, 0);
return 1;
}
} }
return 0; return 0;
} }
...@@ -192,6 +189,7 @@ static int remote_update_poll(void) ...@@ -192,6 +189,7 @@ static int remote_update_poll(void)
int len; int len;
uint32_t type; uint32_t type;
uint32_t data_addr; uint32_t data_addr;
static uint32_t prog_data_addr;
uint8_t* reg_addr; uint8_t* reg_addr;
int data_size; int data_size;
int port; int port;
...@@ -201,7 +199,6 @@ static int remote_update_poll(void) ...@@ -201,7 +199,6 @@ static int remote_update_poll(void)
if (len <= 0) if (len <= 0)
return 0; return 0;
/* check the destination IP */ /* check the destination IP */
if (check_dest_ip(buf, 0)) if (check_dest_ip(buf, 0))
return 0; return 0;
...@@ -209,14 +206,14 @@ static int remote_update_poll(void) ...@@ -209,14 +206,14 @@ static int remote_update_poll(void)
if (check_magic_udp(buf)<0) if (check_magic_udp(buf)<0)
{ {
// magic data error // magic data error
memset(buf+UDP_END, 0x00000001, 4); memset(buf+UDP_END, 0xfe, 1);
len = UDP_END + 4 + 64; len = UDP_END + 12 + 64;
} }
else if (check_magic_udp(buf)>0) else if (check_magic_udp(buf)>0)
{ {
// udp checksum err // udp checksum err
memset(buf+UDP_END, 0xffff0000, 4); memset(buf+UDP_END, 0xff, 1);
len = UDP_END + 4 + 64; len = UDP_END + 12 + 64;
return 0; return 0;
} }
else else
...@@ -225,19 +222,30 @@ static int remote_update_poll(void) ...@@ -225,19 +222,30 @@ static int remote_update_poll(void)
switch(type) switch(type)
{ {
case FLASH_ERASE: case FLASH_ERASE:
wrc_ptp_set_mode(WRC_MODE_MASTER, 0);
for (port = 0; port < wr_num_ports; ++port) for (port = 0; port < wr_num_ports; ++port)
wrc_ptp_run(0,port); wrc_ptp_run(0,port);
data_addr = (buf[UDP_END+8]<<24)+(buf[UDP_END+9]<<16)+(buf[UDP_END+10]<<8)+buf[UDP_END+11]; data_addr = (buf[UDP_END+8]<<24)+(buf[UDP_END+9]<<16)+(buf[UDP_END+10]<<8)+buf[UDP_END+11];
data_size = (buf[UDP_END+12]<<24)+(buf[UDP_END+13]<<16)+(buf[UDP_END+14]<<8)+buf[UDP_END+15]; data_size = (buf[UDP_END+12]<<24)+(buf[UDP_END+13]<<16)+(buf[UDP_END+14]<<8)+buf[UDP_END+15];
flash_erase(data_addr,data_size); flash_erase(data_addr,data_size);
memset(buf+UDP_END+12, 0x00000000, 4); prog_data_addr = data_addr;
len = UDP_END + 16 + 64; memset(buf+UDP_END, 0x00, 1);
len = UDP_END + 12 + 64;
break;
case FLASH_WRITE: case FLASH_WRITE:
data_addr = (buf[UDP_END+8]<<24)+(buf[UDP_END+9]<<16)+(buf[UDP_END+10]<<8)+buf[UDP_END+11]; data_addr = (buf[UDP_END+8]<<24)+(buf[UDP_END+9]<<16)+(buf[UDP_END+10]<<8)+buf[UDP_END+11];
data_size = (buf[UDP_END+12]<<24)+(buf[UDP_END+13]<<16)+(buf[UDP_END+14]<<8)+buf[UDP_END+15]; data_size = (buf[UDP_END+12]<<24)+(buf[UDP_END+13]<<16)+(buf[UDP_END+14]<<8)+buf[UDP_END+15];
flash_write(data_addr,buf+UDP_END+16,data_size); if (prog_data_addr==data_addr)
memset(buf+UDP_END+12, 0x00000000, 4); {
len = UDP_END + 16 + 64 ; flash_write(data_addr,buf+UDP_END+16,data_size);
prog_data_addr=prog_data_addr+256;
memset(buf+UDP_END, 0x00, 1);
} else {
pp_printf("Prog addr error %x\n",data_addr);
// reply lose error
memset(buf+UDP_END, 0xfd, 1);
}
len = UDP_END + 12 + 64 ;
break; break;
case FLASH_READ: case FLASH_READ:
data_addr = (buf[UDP_END+8]<<24)+(buf[UDP_END+9]<<16)+(buf[UDP_END+10]<<8)+buf[UDP_END+11]; data_addr = (buf[UDP_END+8]<<24)+(buf[UDP_END+9]<<16)+(buf[UDP_END+10]<<8)+buf[UDP_END+11];
...@@ -259,8 +267,8 @@ static int remote_update_poll(void) ...@@ -259,8 +267,8 @@ static int remote_update_poll(void)
len = UDP_END + 16 + data_size + 64; len = UDP_END + 16 + data_size + 64;
break; break;
default: default:
// type error // operation type error
memset(buf+UDP_END, 0x00000002, 4); memset(buf+UDP_END, 0xfc, 1);
len = UDP_END + 4 + 64; len = UDP_END + 4 + 64;
} }
} }
...@@ -274,9 +282,10 @@ static int ipv4_poll(void) ...@@ -274,9 +282,10 @@ static int ipv4_poll(void)
{ {
int ret = 0; int ret = 0;
if (link_status[0] == LINK_WENT_UP && ip_status[0] == IP_OK_BOOTP) if (link_status[0]!=LINK_UP)
ip_status[0] = IP_TRAINING; return 0;
ret = bootp_poll();
// ret = bootp_poll();
ret += icmp_poll(); ret += icmp_poll();
...@@ -284,7 +293,19 @@ static int ipv4_poll(void) ...@@ -284,7 +293,19 @@ static int ipv4_poll(void)
ret += remote_update_poll(); ret += remote_update_poll();
ret += syslog_poll(); // ret += syslog_poll();
return ret != 0;
}
static int dp_ipv4_poll(void)
{
int ret = 0;
if (link_status[1]!=LINK_UP)
return 0;
ret = dp_icmp_poll();
return ret != 0; return ret != 0;
} }
...@@ -296,7 +317,7 @@ void getIP(unsigned char *IP, int port) ...@@ -296,7 +317,7 @@ void getIP(unsigned char *IP, int port)
DEFINE_WRC_TASK(ipv4) = { DEFINE_WRC_TASK(ipv4) = {
.name = "ipv4", .name = "ipv4",
.enable = &link_status[0], .enable = &(link_status[0]),
.init = ipv4_init, .init = ipv4_init,
.job = ipv4_poll, .job = ipv4_poll,
}; };
......
...@@ -219,6 +219,9 @@ static int latency_poll_tx(void) ...@@ -219,6 +219,9 @@ static int latency_poll_tx(void)
* Send three frames -- lazily in native byte order. Possibly * Send three frames -- lazily in native byte order. Possibly
* subtract a fake delay, to trigger reporting. * subtract a fake delay, to trigger reporting.
*/ */
if (link_status[0]!=LINK_UP)
return 0;
memset(&frame, 0, sizeof(frame)); memset(&frame, 0, sizeof(frame));
frame.sequence = sequence++; frame.sequence = sequence++;
...@@ -274,7 +277,7 @@ static int latency_poll(void) ...@@ -274,7 +277,7 @@ static int latency_poll(void)
return latency_poll_tx(); return latency_poll_tx();
} }
DEFINE_WRC_TASK(uptime) = { DEFINE_WRC_TASK(latency) = {
.name = "latency-probe", .name = "latency-probe",
.init = latency_init, .init = latency_init,
.job = latency_poll, .job = latency_poll,
......
...@@ -245,6 +245,9 @@ static int lldp_poll(void) ...@@ -245,6 +245,9 @@ static int lldp_poll(void)
uint8_t new_mac[ETH_ALEN]; uint8_t new_mac[ETH_ALEN];
static uint8_t old_mac[ETH_ALEN]; static uint8_t old_mac[ETH_ALEN];
if (link_status[0]!=LINK_UP)
return 0;
/* periodic tasks */ /* periodic tasks */
if (ticks > LLDP_TX_TICK_INTERVAL) { if (ticks > LLDP_TX_TICK_INTERVAL) {
get_mac_addr(new_mac); get_mac_addr(new_mac);
......
...@@ -62,9 +62,9 @@ struct wrpc_socket *ptpd_netif_create_socket(struct wrpc_socket *sock, ...@@ -62,9 +62,9 @@ struct wrpc_socket *ptpd_netif_create_socket(struct wrpc_socket *sock,
pp_printf("%s: no socket slots left\n", __func__); pp_printf("%s: no socket slots left\n", __func__);
return NULL; return NULL;
} }
net_verbose("%s: socket %p for %04x:%04x, slot %i\n", __func__, net_verbose("%s: socket %p for %04x:%04x, slot %i, port %d\n", __func__,
sock, ntohs(bind_addr->ethertype), sock, ntohs(bind_addr->ethertype),
udpport, i); udpport, i, port);
switch(port){ switch(port){
case 0: port_name="wr0";break; case 0: port_name="wr0";break;
...@@ -321,7 +321,7 @@ static int update_rx_queues() ...@@ -321,7 +321,7 @@ static int update_rx_queues()
int recvd, i, q_required; int recvd, i, q_required;
static uint8_t buffer[NET_MAX_SKBUF_SIZE - 32]; static uint8_t buffer[NET_MAX_SKBUF_SIZE - 32];
uint8_t *payload = buffer; uint8_t *payload = buffer;
uint16_t size, port; uint16_t size, udpport;
uint16_t ethtype, tag; uint16_t ethtype, tag;
recvd = recvd =
...@@ -349,9 +349,9 @@ static int update_rx_queues() ...@@ -349,9 +349,9 @@ static int update_rx_queues()
/* Prepare for IP/UDP checks */ /* Prepare for IP/UDP checks */
if (payload[IP_VERSION] == 0x45 && payload[IP_PROTOCOL] == 17) if (payload[IP_VERSION] == 0x45 && payload[IP_PROTOCOL] == 17)
port = payload[UDP_DPORT] << 8 | payload[UDP_DPORT + 1]; udpport = payload[UDP_DPORT] << 8 | payload[UDP_DPORT + 1];
else else
port = 0; udpport = 0;
for (i = 0; i < ARRAY_SIZE(socks[0]); i++) { for (i = 0; i < ARRAY_SIZE(socks[0]); i++) {
s = socks[0][i]; s = socks[0][i];
...@@ -359,9 +359,9 @@ static int update_rx_queues() ...@@ -359,9 +359,9 @@ static int update_rx_queues()
continue; continue;
if (hdr.ethtype != s->bind_addr.ethertype) if (hdr.ethtype != s->bind_addr.ethertype)
continue; continue;
if (!port && !s->bind_addr.udpport) if (!udpport && !s->bind_addr.udpport)
raws = s; /* match with raw socket */ raws = s; /* match with raw socket */
if (port && s->bind_addr.udpport == port) if (udpport && s->bind_addr.udpport == udpport)
udps = s; /* match with udp socket */ udps = s; /* match with udp socket */
} }
s = udps; s = udps;
...@@ -413,7 +413,7 @@ static int update_dp_rx_queues(void) ...@@ -413,7 +413,7 @@ static int update_dp_rx_queues(void)
int recvd, i, q_required; int recvd, i, q_required;
static uint8_t buffer[NET_MAX_SKBUF_SIZE - 32]; static uint8_t buffer[NET_MAX_SKBUF_SIZE - 32];
uint8_t *payload = buffer; uint8_t *payload = buffer;
uint16_t size, port; uint16_t size, udpport;
uint16_t ethtype, tag; uint16_t ethtype, tag;
recvd = minic_rx_frame(&hdr, buffer, sizeof(buffer), &hwts, 1); recvd = minic_rx_frame(&hdr, buffer, sizeof(buffer), &hwts, 1);
...@@ -438,9 +438,9 @@ static int update_dp_rx_queues(void) ...@@ -438,9 +438,9 @@ static int update_dp_rx_queues(void)
/* Prepare for IP/UDP checks */ /* Prepare for IP/UDP checks */
if (payload[IP_VERSION] == 0x45 && payload[IP_PROTOCOL] == 17) if (payload[IP_VERSION] == 0x45 && payload[IP_PROTOCOL] == 17)
port = payload[UDP_DPORT] << 8 | payload[UDP_DPORT + 1]; udpport = payload[UDP_DPORT] << 8 | payload[UDP_DPORT + 1];
else else
port = 0; udpport = 0;
for (i = 0; i < ARRAY_SIZE(socks[1]); i++) { for (i = 0; i < ARRAY_SIZE(socks[1]); i++) {
s = socks[1][i]; s = socks[1][i];
...@@ -448,9 +448,9 @@ static int update_dp_rx_queues(void) ...@@ -448,9 +448,9 @@ static int update_dp_rx_queues(void)
continue; continue;
if (hdr.ethtype != s->bind_addr.ethertype) if (hdr.ethtype != s->bind_addr.ethertype)
continue; continue;
if (!port && !s->bind_addr.udpport) if (!udpport && !s->bind_addr.udpport)
raws = s; /* match with raw socket */ raws = s; /* match with raw socket */
if (port && s->bind_addr.udpport == port) if (udpport && s->bind_addr.udpport == udpport)
udps = s; /* match with udp socket */ udps = s; /* match with udp socket */
} }
s = udps; s = udps;
......
...@@ -43,11 +43,10 @@ int wrpc_get_port_state(struct hal_port_state *state, const char *port_name) ...@@ -43,11 +43,10 @@ int wrpc_get_port_state(struct hal_port_state *state, const char *port_name)
int port = atoi(&port_name[2]); int port = atoi(&port_name[2]);
int wrc_mode = wrc_ptp_get_mode(port); int wrc_mode = wrc_ptp_get_mode(port);
if(port == 0) if(wrc_mode == WRC_MODE_SLAVE)
if(wrc_mode == WRC_MODE_SLAVE) state->mode = HEXP_PORT_MODE_WR_SLAVE;
state->mode = HEXP_PORT_MODE_WR_SLAVE; else
else state->mode = HEXP_PORT_MODE_WR_MASTER;
state->mode = HEXP_PORT_MODE_WR_MASTER;
/* all deltas are added anyway */ /* all deltas are added anyway */
ep_get_deltas(&state->calib.delta_tx_board, &state->calib.delta_rx_board, port); ep_get_deltas(&state->calib.delta_tx_board, &state->calib.delta_rx_board, port);
......
...@@ -1653,6 +1653,9 @@ static int snmp_poll(void) ...@@ -1653,6 +1653,9 @@ static int snmp_poll(void)
uint8_t buf[200]; uint8_t buf[200];
int len; int len;
if (link_status[0]!=LINK_UP)
return 0;
/* no need to wait for IP address: we won't get queries */ /* no need to wait for IP address: we won't get queries */
len = ptpd_netif_recvfrom(snmp_socket, &addr, len = ptpd_netif_recvfrom(snmp_socket, &addr,
buf, sizeof(buf), NULL, 0/*port*/); buf, sizeof(buf), NULL, 0/*port*/);
......
...@@ -120,10 +120,10 @@ int wrc_mon_gui(void) ...@@ -120,10 +120,10 @@ int wrc_mon_gui(void)
if (!last_jiffies) if (!last_jiffies)
last_jiffies = timer_get_tics() - 1 - wrc_ui_refperiod; last_jiffies = timer_get_tics() - 1 - wrc_ui_refperiod;
if (time_before(timer_get_tics(), last_jiffies + wrc_ui_refperiod) if (time_before(timer_get_tics(), last_jiffies + wrc_ui_refperiod)
&& last_servo_count == s[port]->update_count) && last_servo_count == s[0]->update_count)
return 0; return 0;
last_jiffies = timer_get_tics(); last_jiffies = timer_get_tics();
last_servo_count = s[port]->update_count; last_servo_count = s[0]->update_count;
term_clear(); term_clear();
...@@ -179,9 +179,7 @@ int wrc_mon_gui(void) ...@@ -179,9 +179,7 @@ int wrc_mon_gui(void)
continue; continue;
} }
if (port==0) switch (ptp_mode[port]) {
{
switch (ptp_mode[port]) {
case WRC_MODE_GM: case WRC_MODE_GM:
case WRC_MODE_MASTER: case WRC_MODE_MASTER:
cprintf(C_WHITE, "WR Master "); cprintf(C_WHITE, "WR Master ");
...@@ -191,11 +189,8 @@ int wrc_mon_gui(void) ...@@ -191,11 +189,8 @@ int wrc_mon_gui(void)
break; break;
default: default:
cprintf(C_RED, "WR Unknown "); cprintf(C_RED, "WR Unknown ");
}
} else {
cprintf(C_WHITE, "WR Master ");
} }
if (state.locked) if (state.locked)
cprintf(C_GREEN, "Locked "); cprintf(C_GREEN, "Locked ");
else else
......
ppsi @ e3a99db4
Subproject commit 4e567b8e8497488f2a919b27d21209af0a613840 Subproject commit e3a99db489b7e2b590c2f9ba657128a1fa92afd9
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#include "storage.h" #include "storage.h"
#include "syscon.h" #include "syscon.h"
#include "rxts_calibrator.h" #include "rxts_calibrator.h"
#include "ptpd_netif.h"
extern int ext_pps_latency_ps=4000;
static int cmd_calibration(const char *args[]) static int cmd_calibration(const char *args[])
{ {
...@@ -28,6 +31,7 @@ static int cmd_calibration(const char *args[]) ...@@ -28,6 +31,7 @@ static int cmd_calibration(const char *args[])
if (args[0] && !strcasecmp(args[0], "force")) { if (args[0] && !strcasecmp(args[0], "force")) {
for (port = 0; port < wr_num_ports; port++) { for (port = 0; port < wr_num_ports; port++) {
if (link_status[port] == LINK_DOWN) continue;
pp_printf("Port %d Measuring t2/t4 phase transition...\n", port); pp_printf("Port %d Measuring t2/t4 phase transition...\n", port);
if (measure_t24p(&trans[port], port) < 0) if (measure_t24p(&trans[port], port) < 0)
ret = -1; ret = -1;
...@@ -37,22 +41,27 @@ static int cmd_calibration(const char *args[]) ...@@ -37,22 +41,27 @@ static int cmd_calibration(const char *args[])
} }
} }
return ret; return ret;
} else if (!args[0]) { } else if (args[0] && !strcasecmp(args[0], "ext")) {
ext_pps_latency_ps = atoi(args[1]);
}
else {
for (port = 0; port < wr_num_ports; port++) { for (port = 0; port < wr_num_ports; port++) {
if (storage_phtrans(&trans[port], 0, port) > 0) { if (storage_phtrans(&trans[port], 0, port) > 0) {
pp_printf("Port %d Found phase transition in EEPROM: %dps\n", pp_printf("Port %d Found phase transition in EEPROM: %dps\n",
port, trans[port]); port, trans[port]);
cal_phase_transition[port] = trans[port]; cal_phase_transition[port] = trans[port];
} else { } else {
if (link_status[port] == LINK_DOWN) continue;
pp_printf("Port %d Measuring t2/t4 phase transition...\n", port); pp_printf("Port %d Measuring t2/t4 phase transition...\n", port);
if (measure_t24p(&trans[port], port) < 0) if (measure_t24p(&trans[port], port) < 0)
ret =-1; ret =-1;
else { else {
cal_phase_transition[port] = trans[port]; cal_phase_transition[port] = trans[port];
ret = storage_phtrans(&trans[port], 1, port); ret = storage_phtrans(&trans[port], 1, port);
} }
} }
} }
pp_printf("Ext PPS input delay %d\n", ext_pps_latency_ps);
} }
return ret; return ret;
} }
......
...@@ -74,11 +74,6 @@ static int cmd_ip(const char *args[]) ...@@ -74,11 +74,6 @@ static int cmd_ip(const char *args[])
ip_status[port] = IP_OK_STATIC; ip_status[port] = IP_OK_STATIC;
decode_ip(args[1], ip); decode_ip(args[1], ip);
setIP(ip, port); setIP(ip, port);
if (port==0) {
ip[3]=ip[3]+1;
setIP(ip, 1);
ip_status[1] = IP_OK_STATIC;
}
print_ip(); print_ip();
} else { } else {
return -EINVAL; return -EINVAL;
......
...@@ -26,6 +26,7 @@ struct subcmd { ...@@ -26,6 +26,7 @@ struct subcmd {
{"gm", wrc_ptp_set_mode, WRC_MODE_GM}, {"gm", wrc_ptp_set_mode, WRC_MODE_GM},
{"master", wrc_ptp_set_mode, WRC_MODE_MASTER}, {"master", wrc_ptp_set_mode, WRC_MODE_MASTER},
{"slave", wrc_ptp_set_mode, WRC_MODE_SLAVE}, {"slave", wrc_ptp_set_mode, WRC_MODE_SLAVE},
{"cascaded", wrc_ptp_set_mode, WRC_MODE_CASCADED},
#ifdef CONFIG_ABSCAL #ifdef CONFIG_ABSCAL
{"abscal", wrc_ptp_set_mode, WRC_MODE_ABSCAL}, {"abscal", wrc_ptp_set_mode, WRC_MODE_ABSCAL},
#endif #endif
...@@ -34,7 +35,7 @@ struct subcmd { ...@@ -34,7 +35,7 @@ struct subcmd {
static char *is_run[] = {"stopped", "running"}; static char *is_run[] = {"stopped", "running"};
static char *is_mech[] = {[PP_E2E_MECH] = "e2e", [PP_P2P_MECH] = "p2p"}; static char *is_mech[] = {[PP_E2E_MECH] = "e2e", [PP_P2P_MECH] = "p2p"};
static char *is_mode[] = {[WRC_MODE_GM] = "gm", [WRC_MODE_MASTER] = "master", static char *is_mode[] = {[WRC_MODE_GM] = "gm", [WRC_MODE_MASTER] = "master",
[WRC_MODE_SLAVE] = "slave" [WRC_MODE_SLAVE] = "slave", [WRC_MODE_CASCADED] = "cascaded"
#ifdef CONFIG_ABSCAL #ifdef CONFIG_ABSCAL
, [WRC_MODE_ABSCAL] = "abscal" , [WRC_MODE_ABSCAL] = "abscal"
#endif #endif
......
...@@ -6,39 +6,39 @@ ...@@ -6,39 +6,39 @@
#include "tcpip_config.h" #include "tcpip_config.h"
#include "shell.h" #include "shell.h"
void tcpip_help()
{
pp_printf("help\n");
}
static int cmd_tcpip(const char *args[]) static int cmd_tcpip(const char *args[])
{ {
unsigned char ip[4]; unsigned char ip[4];
uint16_t port; uint16_t port;
if (!args[0]) if (!args[0]) {
tcpip_help(); return -EINVAL;
else if (!strcasecmp(args[0], "tcp") && args[1]) { // else if (!strcasecmp(args[0], "tcp") && args[1] && args[2]) {
port = (uint16_t)args[1]; // if (!strcasecmp(args[1],"rxp"))
tcpip_rx_tcp_port(port); // {
// port = atoi(args[2]);
// tcpip_rx_tcp_port(port);
// }
} else if (!strcasecmp(args[0], "udp") && args[1] && args[2]) { } else if (!strcasecmp(args[0], "udp") && args[1] && args[2]) {
if (!strcasecmp(args[1],"rxport")) if (!strcasecmp(args[1],"rxp"))
{ {
port = (uint16_t)args[2]; port = atoi(args[2]);
tcpip_rx_dst_port(port); tcpip_rx_dst_port(port);
} else if (!strcasecmp(args[1], "txport")) { } else if (!strcasecmp(args[1], "txp")) {
port = (uint16_t)args[2]; port = atoi(args[2]);
tcpip_tx_dst_port(port); tcpip_tx_dst_port(port);
} else if (!strcasecmp(args[1], "txip")) { }
decode_ip(args[2], ip); } else if (!strcasecmp(args[0], "dstip")) {
decode_ip(args[1], ip);
tcpip_set_hisIP(ip); tcpip_set_hisIP(ip);
} else if (!strcasecmp(args[1], "txgw")) { } else if (!strcasecmp(args[0], "gateway")) {
decode_ip(args[2], ip); decode_ip(args[1], ip);
tcpip_gateway_addr(ip); tcpip_gateway_addr(ip);
} else if (!strcasecmp(args[1], "txsn")) { } else if (!strcasecmp(args[0], "subnet")) {
decode_ip(args[2], ip); decode_ip(args[1], ip);
tcpip_subnet_addr(ip); tcpip_subnet_addr(ip);
} }
} else { else {
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
......
...@@ -19,7 +19,7 @@ obj-$(CONFIG_EMBEDDED_NODE) += \ ...@@ -19,7 +19,7 @@ obj-$(CONFIG_EMBEDDED_NODE) += \
shell/cmd_ptrack.o \ shell/cmd_ptrack.o \
obj-$(CONFIG_IP) += shell/cmd_ip.o obj-$(CONFIG_IP) += shell/cmd_ip.o shell/cmd_tcpip.o
obj-$(CONFIG_PPSI) += shell/cmd_verbose.o obj-$(CONFIG_PPSI) += shell/cmd_verbose.o
obj-$(CONFIG_CMD_CONFIG) += shell/cmd_config.o obj-$(CONFIG_CMD_CONFIG) += shell/cmd_config.o
obj-$(CONFIG_CMD_SLEEP) += shell/cmd_sleep.o obj-$(CONFIG_CMD_SLEEP) += shell/cmd_sleep.o
......
...@@ -341,7 +341,8 @@ void spll_init(int mode, int slave_ref_channel, int align_pps) ...@@ -341,7 +341,8 @@ void spll_init(int mode, int slave_ref_channel, int align_pps)
} }
if(mode == SPLL_MODE_FREE_RUNNING_MASTER) if(mode == SPLL_MODE_FREE_RUNNING_MASTER)
PPSG->ESCR = PPSG_ESCR_PPS_VALID | PPSG_ESCR_TM_VALID; // PPSG->ESCR = PPSG_ESCR_PPS_VALID | PPSG_ESCR_TM_VALID;
PPSG->ESCR = PPSG_ESCR_PPS_VALID;
for (i = 0; i < spll_n_chan_ref; i++) for (i = 0; i < spll_n_chan_ref; i++)
ptracker_init(&s->ptrackers[i], i, PTRACKER_AVERAGE_SAMPLES); ptracker_init(&s->ptrackers[i], i, PTRACKER_AVERAGE_SAMPLES);
...@@ -487,13 +488,13 @@ void spll_show_stats() ...@@ -487,13 +488,13 @@ void spll_show_stats()
statename = "<Unknown>"; statename = "<Unknown>";
if (softpll.mode > 0) if (softpll.mode > 0)
pp_printf("softpll: irqs %d seq %s mode %d " pp_printf("softpll: irqs %d seq %s mode %d "
"alignment_state %d HL%d ML%d HY=%d MY=%d DelCnt=%d\n", "alignment_state %d HL%d ML%d HY=%d MY=%d DelCnt=%d\n",
s->irq_count, statename, s->irq_count, statename,
s->mode, s->ext.align_state, s->mode, s->ext.align_state,
s->helper.ld.locked, s->mpll.ld.locked, s->helper.ld.locked, s->mpll.ld.locked,
s->helper.pi.y, s->mpll.pi.y, s->helper.pi.y, s->mpll.pi.y,
s->delock_count); s->delock_count);
} }
int spll_shifter_busy(int channel) int spll_shifter_busy(int channel)
......
...@@ -13,15 +13,13 @@ ...@@ -13,15 +13,13 @@
#include <wrc.h> #include <wrc.h>
#include "softpll_ng.h" #include "softpll_ng.h"
#include "irq.h" #include "irq.h"
#include "pps_gen.h"
#define ALIGN_SAMPLE_PERIOD 100000 #define ALIGN_SAMPLE_PERIOD 100000
#define ALIGN_TARGET 0 #define ALIGN_TARGET 0
#define EXT_PERIOD_NS 100 #define EXT_PERIOD_NS 100
#define EXT_FREQ_HZ 10000000 #define EXT_FREQ_HZ 10000000
#define EXT_PPS_LATENCY_PS 30000 // fixme: make configurable
void external_init(volatile struct spll_external_state *s, int ext_ref, void external_init(volatile struct spll_external_state *s, int ext_ref,
int realign_clocks) int realign_clocks)
...@@ -38,8 +36,7 @@ void external_init(volatile struct spll_external_state *s, int ext_ref, ...@@ -38,8 +36,7 @@ void external_init(volatile struct spll_external_state *s, int ext_ref,
void external_start(struct spll_external_state *s) void external_start(struct spll_external_state *s)
{ {
helper_start(s->helper); helper_start(s->helper);
SPLL->ECCR = SPLL_ECCR_EXT_EN; SPLL->ECCR = SPLL_ECCR_EXT_EN;
s->align_state = ALIGN_STATE_WAIT_CLKIN; s->align_state = ALIGN_STATE_WAIT_CLKIN;
...@@ -121,8 +118,8 @@ int external_align_fsm(volatile struct spll_external_state *s) ...@@ -121,8 +118,8 @@ int external_align_fsm(volatile struct spll_external_state *s)
case ALIGN_STATE_START_MAIN: case ALIGN_STATE_START_MAIN:
SPLL->AL_CR = 2; SPLL->AL_CR = 2;
if(s->helper->ld.locked && s->main->ld.locked) { if(s->helper->ld.locked && s->main->ld.locked) {
PPSG->CR = PPSG_CR_CNT_EN | PPSG_CR_PWIDTH_W(10); PPSG->CR = PPSG_CR_CNT_EN | PPSG_CR_PWIDTH_W(PPS_WIDTH);
PPSG->ADJ_NSEC = 3; PPSG->ADJ_NSEC = 5;
PPSG->ESCR = PPSG_ESCR_SYNC; PPSG->ESCR = PPSG_ESCR_SYNC;
s->align_state = ALIGN_STATE_INIT_CSYNC; s->align_state = ALIGN_STATE_INIT_CSYNC;
pll_verbose("EXT: DMTD locked.\n"); pll_verbose("EXT: DMTD locked.\n");
...@@ -132,7 +129,7 @@ int external_align_fsm(volatile struct spll_external_state *s) ...@@ -132,7 +129,7 @@ int external_align_fsm(volatile struct spll_external_state *s)
case ALIGN_STATE_INIT_CSYNC: case ALIGN_STATE_INIT_CSYNC:
if (PPSG->ESCR & PPSG_ESCR_SYNC) { if (PPSG->ESCR & PPSG_ESCR_SYNC) {
PPSG->ESCR = PPSG_ESCR_PPS_VALID; // enable PPS output (even though it's not aligned yet) shw_pps_gen_enable_output(1); // enable PPS output (even though it's not aligned yet)
s->align_timer = timer_get_tics() + 2 * TICS_PER_SECOND; s->align_timer = timer_get_tics() + 2 * TICS_PER_SECOND;
s->align_state = ALIGN_STATE_WAIT_CSYNC; s->align_state = ALIGN_STATE_WAIT_CSYNC;
done_sth++; done_sth++;
...@@ -154,7 +151,7 @@ int external_align_fsm(volatile struct spll_external_state *s) ...@@ -154,7 +151,7 @@ int external_align_fsm(volatile struct spll_external_state *s)
if(v == 0 || v >= ALIGN_SAMPLE_PERIOD / 2) { if(v == 0 || v >= ALIGN_SAMPLE_PERIOD / 2) {
s->align_target = EXT_PERIOD_NS; s->align_target = EXT_PERIOD_NS;
s->align_step = -100; s->align_step = -100;
} else if (s > 0) { } else if (v > 0) {
s->align_target = 0; s->align_target = 0;
s->align_step = 100; s->align_step = 100;
} }
...@@ -172,8 +169,8 @@ int external_align_fsm(volatile struct spll_external_state *s) ...@@ -172,8 +169,8 @@ int external_align_fsm(volatile struct spll_external_state *s)
s->align_shift += s->align_step; s->align_shift += s->align_step;
mpll_set_phase_shift(s->main, s->align_shift); mpll_set_phase_shift(s->main, s->align_shift);
} else if (v == s->align_target) { } else if (v == s->align_target) {
s->align_shift += EXT_PPS_LATENCY_PS; s->align_shift += ext_pps_latency_ps;
mpll_set_phase_shift(s->main, s->align_shift); mpll_set_phase_shift(s->main, s->align_shift);
s->align_state = ALIGN_STATE_COMPENSATE_DELAY; s->align_state = ALIGN_STATE_COMPENSATE_DELAY;
} }
done_sth++; done_sth++;
...@@ -182,8 +179,9 @@ int external_align_fsm(volatile struct spll_external_state *s) ...@@ -182,8 +179,9 @@ int external_align_fsm(volatile struct spll_external_state *s)
case ALIGN_STATE_COMPENSATE_DELAY: case ALIGN_STATE_COMPENSATE_DELAY:
if(!mpll_shifter_busy(s->main)) { if(!mpll_shifter_busy(s->main)) {
pll_verbose("EXT: Align done.\n"); pp_printf("EXT: Align done.\n");
s->align_state = ALIGN_STATE_LOCKED; s->align_state = ALIGN_STATE_LOCKED;
shw_pps_gen_time_valid(1);
done_sth++; done_sth++;
} }
break; break;
......
...@@ -413,6 +413,7 @@ void pfilter_init_novlan(char *fname) ...@@ -413,6 +413,7 @@ void pfilter_init_novlan(char *fname)
pfilter_cmp(11, 0x0011, 0x00ff, MOV, FRAME_UDP); pfilter_cmp(11, 0x0011, 0x00ff, MOV, FRAME_UDP);
pfilter_logic2(FRAME_UDP, FRAME_UDP, AND, FRAME_IP_OK); pfilter_logic2(FRAME_UDP, FRAME_UDP, AND, FRAME_IP_OK);
pfilter_cmp(11, 0x0006, 0x00ff, MOV, FRAME_TCP); pfilter_cmp(11, 0x0006, 0x00ff, MOV, FRAME_TCP);
pfilter_logic2(FRAME_TCP, FRAME_TCP, AND, FRAME_IP_OK);
/* For CPU: arp or icmp unicast or ptp (or latency) */ /* For CPU: arp or icmp unicast or ptp (or latency) */
pfilter_logic2(FRAME_FOR_CPU, FRAME_TYPE_ARP, OR, FRAME_TYPE_PTP2); pfilter_logic2(FRAME_FOR_CPU, FRAME_TYPE_ARP, OR, FRAME_TYPE_PTP2);
......
...@@ -127,14 +127,8 @@ static void wrc_initialize(void) ...@@ -127,14 +127,8 @@ static void wrc_initialize(void)
wrc_ui_mode = UI_SHELL_MODE; wrc_ui_mode = UI_SHELL_MODE;
_endram = ENDRAM_MAGIC; _endram = ENDRAM_MAGIC;
for (port=1; port<wr_num_ports;port++) wrc_ptp_set_mode(WRC_MODE_MASTER, 0);
wrc_ptp_set_mode(WRC_MODE_MASTER, port);
wrc_ptp_set_mode(WRC_MODE_SLAVE, 0);
for (port=0; port<wr_num_ports;port++) {
wrc_ptp_start(port);
}
shw_pps_gen_get_time(NULL, &prev_nanos_for_profile); shw_pps_gen_get_time(NULL, &prev_nanos_for_profile);
/* get tics */ /* get tics */
prev_ticks_for_profile = timer_get_tics(); prev_ticks_for_profile = timer_get_tics();
...@@ -158,7 +152,19 @@ static int wrc_check_link(void) ...@@ -158,7 +152,19 @@ static int wrc_check_link(void)
if (first_run==0) if (first_run==0)
{ {
for(port=0; port<wr_num_ports; port++) { for(port=0; port<wr_num_ports; port++) {
sfp_match(port);
calib_t24p(WRC_MODE_MASTER, &cal_phase_transition[port],port);
prev_state[port] = -1; prev_state[port] = -1;
state[port] = ep_link_up(NULL, port);
if (state[port])
{
wrc_ptp_start(port);
link_status[port] = LINK_UP;
if (port==0) gpio_out(GPIO_LED_LINK, 1);
} else {
link_status[port] = LINK_DOWN;
if (port==0) gpio_out(GPIO_LED_LINK, 0);
}
} }
first_run++; first_run++;
} else { } else {
...@@ -178,13 +184,7 @@ static int wrc_check_link(void) ...@@ -178,13 +184,7 @@ static int wrc_check_link(void)
if (port==0) gpio_out(GPIO_LED_LINK, 0); if (port==0) gpio_out(GPIO_LED_LINK, 0);
link_status[port] = LINK_WENT_DOWN; link_status[port] = LINK_WENT_DOWN;
wrc_ptp_stop(port); wrc_ptp_stop(port);
timer_delay_ms(1);
minic_init(port); minic_init(port);
/* special case */
if (port==0) {
spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1);
shw_pps_gen_enable_output(1);
}
rv = 1; rv = 1;
} else { } else {
link_status[port] = (state[port] ? LINK_UP : LINK_DOWN); link_status[port] = (state[port] ? LINK_UP : LINK_DOWN);
......
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