Commit e54a1a4d authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

Merge branch 'BTrain-dev-proposed_master' into proposed_master

parents c00a228c 282c638e
......@@ -246,6 +246,20 @@ config VLAN_FOR_CLASS6
depends on VLAN
int "Route this VLAN too to fabric class 6 (Streamer/NIC)"
config WR_DIAG
depends on WR_NODE
boolean "Write of WRPC diagnostics to dedicated WB registers"
default n
help
This is a software part of new (additional) diagnostics for WR PTP
Core. It allows to access diagnostics values through WB registers
(e.g. PCI bus). It allows the host machine (of SPEC/SVEC/etc.) to
easily access information about the health of WR PTP Core.
Please note that other option to access the status of WRPC, which
is direct access to the WRPC's memory does not provide any mechanism
to ensure the data consistency.
config WR_NODE_SIM
depends on WR_NODE && !HOST_PROCESS
boolean "Build simple software for test of WR PTP Core in simulation"
......@@ -257,7 +271,6 @@ config WR_NODE_SIM
is avoided. The main function sends min-size frames to PTP
MAC address destination and expects the simulation to return
these frames.
#
# This is a set of configuration options that should not be changed by
# normal users. If the "developer" menu is used, the binary is tainted.
......
......@@ -129,7 +129,7 @@ endif
all: tools $(OUTPUT).elf $(arch-files-y)
.PRECIOUS: %.elf %.bin
.PHONY: all tools clean gitmodules $(PPSI)/ppsi.o
.PHONY: all tools clean gitmodules $(PPSI)/ppsi.o extest liblinux
# we need to remove "ptpdump" support for ppsi if RAM size is small and
# we include etherbone
......@@ -207,6 +207,8 @@ clean:
$(MAKE) -C $(PPSI) clean
$(MAKE) -C sdb-lib clean
$(MAKE) -C tools clean
$(MAKE) -C liblinux clean
$(MAKE) -C liblinux/extest clean
distclean: clean
rm -rf include/config
......@@ -217,9 +219,18 @@ distclean: clean
%.o: %.c
${CC} $(CFLAGS) $(PTPD_CFLAGS) $(INCLUDE_DIR) $(LIB_DIR) -c $*.c -o $@
tools: .config gitmodules
liblinux:
$(MAKE) -C liblinux
extest:
$(MAKE) -C liblinux/extest
tools: .config gitmodules liblinux extest
$(MAKE) -C tools
tools-diag: liblinux extest
$(MAKE) -C tools wrpc-diags wrpc-vuart wr-streamers
# if needed, check out the submodules (first time only), so users
# who didn't read carefully the manual won't get confused
gitmodules:
......
......@@ -41,6 +41,7 @@ CONFIG_FLASH_INIT=y
# CONFIG_AUX_DIAG is not set
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_WR_DIAG is not set
# CONFIG_WR_NODE_SIM is not set
#
......
......@@ -39,6 +39,7 @@ CONFIG_FLASH_INIT=y
# CONFIG_AUX_DIAG is not set
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_WR_DIAG is not set
# CONFIG_WR_NODE_SIM is not set
#
......
......@@ -39,6 +39,7 @@ CONFIG_FLASH_INIT=y
# CONFIG_AUX_DIAG is not set
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_WR_DIAG is not set
# CONFIG_WR_NODE_SIM is not set
#
......
......@@ -39,6 +39,7 @@ CONFIG_FLASH_INIT=y
# CONFIG_AUX_DIAG is not set
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_WR_DIAG is not set
# CONFIG_WR_NODE_SIM is not set
#
......
......@@ -39,6 +39,7 @@ CONFIG_FLASH_INIT=y
CONFIG_AUX_DIAG=y
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
CONFIG_WR_DIAG=y
# CONFIG_WR_NODE_SIM is not set
#
......
......@@ -33,6 +33,7 @@ CONFIG_FLASH_INIT=y
# CONFIG_AUX_DIAG is not set
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_WR_DIAG is not set
# CONFIG_WR_NODE_SIM is not set
#
......
......@@ -35,6 +35,7 @@ CONFIG_FLASH_INIT=y
# CONFIG_AUX_DIAG is not set
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_WR_DIAG is not set
# CONFIG_WR_NODE_SIM is not set
#
......
......@@ -36,6 +36,7 @@ CONFIG_FLASH_INIT=y
# CONFIG_AUX_DIAG is not set
CONFIG_SDB_STORAGE=y
# CONFIG_LEGACY_EEPROM is not set
# CONFIG_WR_DIAG is not set
CONFIG_WR_NODE_SIM=y
#
......
......@@ -110,3 +110,79 @@ void net_rst(void)
syscon->GPSR |= SYSC_GPSR_NET_RST;
}
int wdiag_set_valid(int enable)
{
if(enable)
syscon->WDIAG_CTRL |= SYSC_WDIAG_CTRL_DATA_VALID;
if(!enable)
syscon->WDIAG_CTRL &= ~SYSC_WDIAG_CTRL_DATA_VALID;
return (int)(syscon->WDIAG_CTRL & SYSC_WDIAG_CTRL_DATA_VALID);
}
int wdiag_get_valid(void)
{
if(syscon->WDIAG_CTRL & SYSC_WDIAG_CTRL_DATA_VALID)
return 1;
else
return 0;
}
int wdiag_get_snapshot(void)
{
if(syscon->WDIAG_CTRL & SYSC_WDIAG_CTRL_DATA_SNAPSHOT)
return 1;
else
return 0;
}
void wdiags_write_servo_state(int wr_mode, uint8_t servostate, uint64_t mu,
uint64_t dms, int32_t asym, int32_t cko, int32_t setp,
int32_t ucnt)
{
syscon->WDIAG_SSTAT = wr_mode ? SYSC_WDIAG_SSTAT_WR_MODE:0;
syscon->WDIAG_SSTAT |= SYSC_WDIAG_SSTAT_SERVOSTATE_W(servostate);
syscon->WDIAG_MU_MSB = 0xFFFFFFFF & (mu>>32);
syscon->WDIAG_MU_LSB = 0xFFFFFFFF & mu;
syscon->WDIAG_DMS_MSB = 0xFFFFFFFF & (dms>>32);
syscon->WDIAG_DMS_LSB = 0xFFFFFFFF & dms;
syscon->WDIAG_ASYM = asym;
syscon->WDIAG_CKO = cko;
syscon->WDIAG_SETP = setp;
syscon->WDIAG_UCNT = ucnt;
}
void wdiags_write_port_state(int link, int locked)
{
uint32_t val = 0;
val = link ? SYSC_WDIAG_PSTAT_LINK : 0;
val |= locked ? SYSC_WDIAG_PSTAT_LOCKED : 0;
syscon->WDIAG_PSTAT = val;
}
void wdiags_write_ptp_state(uint8_t ptpstate)
{
syscon->WDIAG_PTPSTAT = SYSC_WDIAG_PTPSTAT_PTPSTATE_W(ptpstate);
}
void wdiags_write_aux_state(uint32_t aux_states)
{
syscon->WDIAG_ASTAT = SYSC_WDIAG_ASTAT_AUX_W(aux_states);
}
void wdiags_write_cnts(uint32_t tx, uint32_t rx)
{
syscon->WDIAG_TXFCNT = tx;
syscon->WDIAG_RXFCNT = rx;
}
void wdiags_write_time(uint64_t sec, uint32_t nsec)
{
syscon->WDIAG_SEC_MSB = 0xFFFFFFFF & (sec>>32);
syscon->WDIAG_SEC_LSB = 0xFFFFFFFF & sec;
syscon->WDIAG_NS = nsec;
}
void wdiags_write_temp(uint32_t temp)
{
syscon->WDIAG_TEMP=temp;
}
......@@ -11,7 +11,7 @@
#include "board.h"
#include "uart.h"
#include <hw/wb_vuart.h>
#include <hw/wb_uart.h>
#define CALC_BAUD(baudrate) \
( ((( (unsigned long long)baudrate * 8ULL) << (16 - 7)) + \
......
/*
Register definitions for slave core: Simple Wishbone UART
* File : ../../../../software/include/hw/wb_uart.h
* Author : auto-generated by wbgen2 from uart.wb
* Created : Mon Feb 21 22:25:02 2011
* File : wb_uart.h
* Author : auto-generated by wbgen2 from simple_uart_wb.wb
* Created : Wed Mar 1 17:29:58 2017
* Standard : ANSI C
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE uart.wb
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE simple_uart_wb.wb
DO NOT HAND-EDIT UNLESS IT'S ABSOLUTELY NECESSARY!
*/
#ifndef __WBGEN2_REGDEFS_UART_WB
#define __WBGEN2_REGDEFS_UART_WB
#ifndef __WBGEN2_REGDEFS_SIMPLE_UART_WB_WB
#define __WBGEN2_REGDEFS_SIMPLE_UART_WB_WB
#include <inttypes.h>
......@@ -30,6 +30,7 @@
#define WBGEN2_SIGN_EXTEND(value, bits) (((value) & (1<<bits) ? ~((1<<(bits))-1): 0 ) | (value))
#endif
/* definitions for register: Status Register */
/* definitions for field: TX busy in reg: Status Register */
......@@ -55,24 +56,48 @@
#define UART_RDR_RX_DATA_SHIFT 0
#define UART_RDR_RX_DATA_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define UART_RDR_RX_DATA_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* [0x0]: REG Status Register */
#define UART_REG_SR 0x00000000
/* [0x4]: REG Baudrate control register */
#define UART_REG_BCR 0x00000004
/* [0x8]: REG Transmit data regsiter */
#define UART_REG_TDR 0x00000008
/* [0xc]: REG Receive data regsiter */
#define UART_REG_RDR 0x0000000c
/* definitions for register: Host VUART Tx register */
/* definitions for field: TX Data in reg: Host VUART Tx register */
#define UART_HOST_TDR_DATA_MASK WBGEN2_GEN_MASK(0, 8)
#define UART_HOST_TDR_DATA_SHIFT 0
#define UART_HOST_TDR_DATA_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define UART_HOST_TDR_DATA_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* definitions for field: TX Ready in reg: Host VUART Tx register */
#define UART_HOST_TDR_RDY WBGEN2_GEN_MASK(8, 1)
/* definitions for register: Host VUART Rx register */
/* definitions for field: RX Data in reg: Host VUART Rx register */
#define UART_HOST_RDR_DATA_MASK WBGEN2_GEN_MASK(0, 8)
#define UART_HOST_RDR_DATA_SHIFT 0
#define UART_HOST_RDR_DATA_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define UART_HOST_RDR_DATA_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* definitions for field: RX Ready in reg: Host VUART Rx register */
#define UART_HOST_RDR_RDY WBGEN2_GEN_MASK(8, 1)
/* definitions for field: RX FIFO Count in reg: Host VUART Rx register */
#define UART_HOST_RDR_COUNT_MASK WBGEN2_GEN_MASK(9, 16)
#define UART_HOST_RDR_COUNT_SHIFT 9
#define UART_HOST_RDR_COUNT_W(value) WBGEN2_GEN_WRITE(value, 9, 16)
#define UART_HOST_RDR_COUNT_R(reg) WBGEN2_GEN_READ(reg, 9, 16)
PACKED struct UART_WB {
/* [0x0]: REG Status Register */
uint32_t SR;
/* [0x4]: REG Baudrate control register */
uint32_t BCR;
/* [0x8]: REG Transmit data regsiter */
uint32_t TDR;
/* [0xc]: REG Receive data regsiter */
uint32_t RDR;
/* [0x0]: REG Status Register */
uint32_t SR;
/* [0x4]: REG Baudrate control register */
uint32_t BCR;
/* [0x8]: REG Transmit data regsiter */
uint32_t TDR;
/* [0xc]: REG Receive data regsiter */
uint32_t RDR;
/* [0x10]: REG Host VUART Tx register */
uint32_t HOST_TDR;
/* [0x14]: REG Host VUART Rx register */
uint32_t HOST_RDR;
};
#endif
/*
Register definitions for slave core: Virtual UART
* File : wb_vuart.h
* Author : auto-generated by wbgen2 from wb_virtual_uart.wb
* Created : Wed Apr 6 23:02:01 2011
* Standard : ANSI C
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE wb_virtual_uart.wb
DO NOT HAND-EDIT UNLESS IT'S ABSOLUTELY NECESSARY!
*/
#ifndef __WBGEN2_REGDEFS_WB_VIRTUAL_UART_WB
#define __WBGEN2_REGDEFS_WB_VIRTUAL_UART_WB
#include <inttypes.h>
#if defined( __GNUC__)
#define PACKED __attribute__ ((packed))
#else
#error "Unsupported compiler?"
#endif
#ifndef __WBGEN2_MACROS_DEFINED__
#define __WBGEN2_MACROS_DEFINED__
#define WBGEN2_GEN_MASK(offset, size) (((1<<(size))-1) << (offset))
#define WBGEN2_GEN_WRITE(value, offset, size) (((value) & ((1<<(size))-1)) << (offset))
#define WBGEN2_GEN_READ(reg, offset, size) (((reg) >> (offset)) & ((1<<(size))-1))
#define WBGEN2_SIGN_EXTEND(value, bits) (((value) & (1<<bits) ? ~((1<<(bits))-1): 0 ) | (value))
#endif
/* definitions for register: Status Register */
/* definitions for field: TX busy in reg: Status Register */
#define UART_SR_TX_BUSY WBGEN2_GEN_MASK(0, 1)
/* definitions for field: RX ready in reg: Status Register */
#define UART_SR_RX_RDY WBGEN2_GEN_MASK(1, 1)
/* definitions for register: Baudrate control register */
/* definitions for register: Transmit data regsiter */
/* definitions for field: Transmit data in reg: Transmit data regsiter */
#define UART_TDR_TX_DATA_MASK WBGEN2_GEN_MASK(0, 8)
#define UART_TDR_TX_DATA_SHIFT 0
#define UART_TDR_TX_DATA_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define UART_TDR_TX_DATA_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* definitions for register: Receive data regsiter */
/* definitions for field: Received data in reg: Receive data regsiter */
#define UART_RDR_RX_DATA_MASK WBGEN2_GEN_MASK(0, 8)
#define UART_RDR_RX_DATA_SHIFT 0
#define UART_RDR_RX_DATA_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define UART_RDR_RX_DATA_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* definitions for register: FIFO 'UART TX FIFO' data output register 0 */
/* definitions for field: Char sent by UART to TX in reg: FIFO 'UART TX FIFO' data output register 0 */
#define UART_DEBUG_R0_TX_MASK WBGEN2_GEN_MASK(0, 8)
#define UART_DEBUG_R0_TX_SHIFT 0
#define UART_DEBUG_R0_TX_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define UART_DEBUG_R0_TX_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* definitions for register: FIFO 'UART TX FIFO' control/status register */
/* definitions for field: FIFO full flag in reg: FIFO 'UART TX FIFO' control/status register */
#define UART_DEBUG_CSR_FULL WBGEN2_GEN_MASK(16, 1)
/* definitions for field: FIFO empty flag in reg: FIFO 'UART TX FIFO' control/status register */
#define UART_DEBUG_CSR_EMPTY WBGEN2_GEN_MASK(17, 1)
/* definitions for field: FIFO counter in reg: FIFO 'UART TX FIFO' control/status register */
#define UART_DEBUG_CSR_USEDW_MASK WBGEN2_GEN_MASK(0, 8)
#define UART_DEBUG_CSR_USEDW_SHIFT 0
#define UART_DEBUG_CSR_USEDW_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define UART_DEBUG_CSR_USEDW_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
PACKED struct UART_WB {
/* [0x0]: REG Status Register */
uint32_t SR;
/* [0x4]: REG Baudrate control register */
uint32_t BCR;
/* [0x8]: REG Transmit data regsiter */
uint32_t TDR;
/* [0xc]: REG Receive data regsiter */
uint32_t RDR;
/* [0x10]: REG FIFO 'UART TX FIFO' data output register 0 */
uint32_t DEBUG_R0;
/* [0x14]: REG FIFO 'UART TX FIFO' control/status register */
uint32_t DEBUG_CSR;
};
#endif
This diff is collapsed.
/*
Register definitions for slave core: WR Core Diagnostics
* File : wrc_diags_regs.h
* Author : auto-generated by wbgen2 from wrc_diags_wb.wb
* Created : Tue Jun 20 09:59:03 2017
* Version : 0x00000001
* Standard : ANSI C
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE wrc_diags_wb.wb
DO NOT HAND-EDIT UNLESS IT'S ABSOLUTELY NECESSARY!
*/
#ifndef __WBGEN2_REGDEFS_WRC_DIAGS_WB_WB
#define __WBGEN2_REGDEFS_WRC_DIAGS_WB_WB
#ifdef __KERNEL__
#include <linux/types.h>
#else
#include <inttypes.h>
#endif
#if defined( __GNUC__)
#define PACKED __attribute__ ((packed))
#else
#error "Unsupported compiler?"
#endif
#ifndef __WBGEN2_MACROS_DEFINED__
#define __WBGEN2_MACROS_DEFINED__
#define WBGEN2_GEN_MASK(offset, size) (((1<<(size))-1) << (offset))
#define WBGEN2_GEN_WRITE(value, offset, size) (((value) & ((1<<(size))-1)) << (offset))
#define WBGEN2_GEN_READ(reg, offset, size) (((reg) >> (offset)) & ((1<<(size))-1))
#define WBGEN2_SIGN_EXTEND(value, bits) (((value) & (1<<bits) ? ~((1<<(bits))-1): 0 ) | (value))
#endif
/* version definition */
#define WBGEN2_WRC_DIAGS_VERSION 0x00000001
/* definitions for register: Version register */
/* definitions for field: Version identifier in reg: Version register */
#define WRC_DIAGS_VER_ID_MASK WBGEN2_GEN_MASK(0, 32)
#define WRC_DIAGS_VER_ID_SHIFT 0
#define WRC_DIAGS_VER_ID_W(value) WBGEN2_GEN_WRITE(value, 0, 32)
#define WRC_DIAGS_VER_ID_R(reg) WBGEN2_GEN_READ(reg, 0, 32)
/* definitions for register: Ctrl */
/* definitions for field: WR DIAG data valid in reg: Ctrl */
#define WRC_DIAGS_CTRL_DATA_VALID WBGEN2_GEN_MASK(0, 1)
/* definitions for field: WR DIAG data snapshot in reg: Ctrl */
#define WRC_DIAGS_CTRL_DATA_SNAPSHOT WBGEN2_GEN_MASK(8, 1)
/* definitions for register: WRPC Diag: servo status */
/* definitions for field: WR valid in reg: WRPC Diag: servo status */
#define WRC_DIAGS_WDIAG_SSTAT_WR_MODE WBGEN2_GEN_MASK(0, 1)
/* definitions for field: Servo State in reg: WRPC Diag: servo status */
#define WRC_DIAGS_WDIAG_SSTAT_SERVOSTATE_MASK WBGEN2_GEN_MASK(8, 4)
#define WRC_DIAGS_WDIAG_SSTAT_SERVOSTATE_SHIFT 8
#define WRC_DIAGS_WDIAG_SSTAT_SERVOSTATE_W(value) WBGEN2_GEN_WRITE(value, 8, 4)
#define WRC_DIAGS_WDIAG_SSTAT_SERVOSTATE_R(reg) WBGEN2_GEN_READ(reg, 8, 4)
/* definitions for register: WRPC Diag: Port status */
/* definitions for field: Link Status in reg: WRPC Diag: Port status */
#define WRC_DIAGS_WDIAG_PSTAT_LINK WBGEN2_GEN_MASK(0, 1)
/* definitions for field: PLL Locked in reg: WRPC Diag: Port status */
#define WRC_DIAGS_WDIAG_PSTAT_LOCKED WBGEN2_GEN_MASK(1, 1)
/* definitions for register: WRPC Diag: PTP state */
/* definitions for field: PTP State in reg: WRPC Diag: PTP state */
#define WRC_DIAGS_WDIAG_PTPSTAT_PTPSTATE_MASK WBGEN2_GEN_MASK(0, 8)
#define WRC_DIAGS_WDIAG_PTPSTAT_PTPSTATE_SHIFT 0
#define WRC_DIAGS_WDIAG_PTPSTAT_PTPSTATE_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define WRC_DIAGS_WDIAG_PTPSTAT_PTPSTATE_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* definitions for register: WRPC Diag: AUX state */
/* definitions for field: AUX channel in reg: WRPC Diag: AUX state */
#define WRC_DIAGS_WDIAG_ASTAT_AUX_MASK WBGEN2_GEN_MASK(0, 8)
#define WRC_DIAGS_WDIAG_ASTAT_AUX_SHIFT 0
#define WRC_DIAGS_WDIAG_ASTAT_AUX_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define WRC_DIAGS_WDIAG_ASTAT_AUX_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* definitions for register: WRPC Diag: Tx PTP Frame cnts */
/* definitions for register: WRPC Diag: Rx PTP Frame cnts */
/* definitions for register: WRPC Diag:local time [msb of s] */
/* definitions for register: WRPC Diag: local time [lsb of s] */
/* definitions for register: WRPC Diag: local time [ns] */
/* definitions for register: WRPC Diag: Round trip (mu) [msb of ps] */
/* definitions for register: WRPC Diag: Round trip (mu) [lsb of ps] */
/* definitions for register: WRPC Diag: Master-slave delay (dms) [msb of ps] */
/* definitions for register: WRPC Diag: Master-slave delay (dms) [lsb of ps] */
/* definitions for register: WRPC Diag: Total link asymmetry [ps] */
/* definitions for register: WRPC Diag: Clock offset (cko) [ps] */
/* definitions for register: WRPC Diag: Phase setpoint (setp) [ps] */
/* definitions for register: WRPC Diag: Update counter (ucnt) */
/* definitions for register: WRPC Diag: Board temperature [C degree] */
PACKED struct WRC_DIAGS_WB {
/* [0x0]: REG Version register */
uint32_t VER;
/* [0x4]: REG Ctrl */
uint32_t CTRL;
/* [0x8]: REG WRPC Diag: servo status */
uint32_t WDIAG_SSTAT;
/* [0xc]: REG WRPC Diag: Port status */
uint32_t WDIAG_PSTAT;
/* [0x10]: REG WRPC Diag: PTP state */
uint32_t WDIAG_PTPSTAT;
/* [0x14]: REG WRPC Diag: AUX state */
uint32_t WDIAG_ASTAT;
/* [0x18]: REG WRPC Diag: Tx PTP Frame cnts */
uint32_t WDIAG_TXFCNT;
/* [0x1c]: REG WRPC Diag: Rx PTP Frame cnts */
uint32_t WDIAG_RXFCNT;
/* [0x20]: REG WRPC Diag:local time [msb of s] */
uint32_t WDIAG_SEC_MSB;
/* [0x24]: REG WRPC Diag: local time [lsb of s] */
uint32_t WDIAG_SEC_LSB;
/* [0x28]: REG WRPC Diag: local time [ns] */
uint32_t WDIAG_NS;
/* [0x2c]: REG WRPC Diag: Round trip (mu) [msb of ps] */
uint32_t WDIAG_MU_MSB;
/* [0x30]: REG WRPC Diag: Round trip (mu) [lsb of ps] */
uint32_t WDIAG_MU_LSB;
/* [0x34]: REG WRPC Diag: Master-slave delay (dms) [msb of ps] */
uint32_t WDIAG_DMS_MSB;
/* [0x38]: REG WRPC Diag: Master-slave delay (dms) [lsb of ps] */
uint32_t WDIAG_DMS_LSB;
/* [0x3c]: REG WRPC Diag: Total link asymmetry [ps] */
uint32_t WDIAG_ASYM;
/* [0x40]: REG WRPC Diag: Clock offset (cko) [ps] */
uint32_t WDIAG_CKO;
/* [0x44]: REG WRPC Diag: Phase setpoint (setp) [ps] */
uint32_t WDIAG_SETP;
/* [0x48]: REG WRPC Diag: Update counter (ucnt) */
uint32_t WDIAG_UCNT;
/* [0x4c]: REG WRPC Diag: Board temperature [C degree] */
uint32_t WDIAG_TEMP;
};
#endif
......@@ -3,7 +3,7 @@
* File : wrc_syscon_regs.h
* Author : auto-generated by wbgen2 from wrc_syscon_wb.wb
* Created : Mon Jul 11 14:59:51 2016
* Created : Mon Apr 24 17:41:58 2017
* Standard : ANSI C
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE wrc_syscon_wb.wb
......@@ -14,7 +14,11 @@
#ifndef __WBGEN2_REGDEFS_WRC_SYSCON_WB_WB
#define __WBGEN2_REGDEFS_WRC_SYSCON_WB_WB
#ifdef __KERNEL__
#include <linux/types.h>
#else
#include <inttypes.h>
#endif
#if defined( __GNUC__)
#define PACKED __attribute__ ((packed))
......@@ -176,6 +180,77 @@
#define SYSC_DIAG_CR_RW WBGEN2_GEN_MASK(31, 1)
/* definitions for register: User Diag: data to read/write */
/* definitions for register: WRPC Diag: ctrl */
/* definitions for field: WR DIAG data valid in reg: WRPC Diag: ctrl */
#define SYSC_WDIAG_CTRL_DATA_VALID WBGEN2_GEN_MASK(0, 1)
/* definitions for field: WR DIAG data snapshot in reg: WRPC Diag: ctrl */
#define SYSC_WDIAG_CTRL_DATA_SNAPSHOT WBGEN2_GEN_MASK(8, 1)
/* definitions for register: WRPC Diag: servo status */
/* definitions for field: WR valid in reg: WRPC Diag: servo status */
#define SYSC_WDIAG_SSTAT_WR_MODE WBGEN2_GEN_MASK(0, 1)
/* definitions for field: Servo State in reg: WRPC Diag: servo status */
#define SYSC_WDIAG_SSTAT_SERVOSTATE_MASK WBGEN2_GEN_MASK(8, 4)
#define SYSC_WDIAG_SSTAT_SERVOSTATE_SHIFT 8
#define SYSC_WDIAG_SSTAT_SERVOSTATE_W(value) WBGEN2_GEN_WRITE(value, 8, 4)
#define SYSC_WDIAG_SSTAT_SERVOSTATE_R(reg) WBGEN2_GEN_READ(reg, 8, 4)
/* definitions for register: WRPC Diag: Port status */
/* definitions for field: Link Status in reg: WRPC Diag: Port status */
#define SYSC_WDIAG_PSTAT_LINK WBGEN2_GEN_MASK(0, 1)
/* definitions for field: PLL Locked in reg: WRPC Diag: Port status */
#define SYSC_WDIAG_PSTAT_LOCKED WBGEN2_GEN_MASK(1, 1)
/* definitions for register: WRPC Diag: PTP state */
/* definitions for field: PTP State in reg: WRPC Diag: PTP state */
#define SYSC_WDIAG_PTPSTAT_PTPSTATE_MASK WBGEN2_GEN_MASK(0, 8)
#define SYSC_WDIAG_PTPSTAT_PTPSTATE_SHIFT 0
#define SYSC_WDIAG_PTPSTAT_PTPSTATE_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define SYSC_WDIAG_PTPSTAT_PTPSTATE_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* definitions for register: WRPC Diag: AUX state */
/* definitions for field: AUX channel in reg: WRPC Diag: AUX state */
#define SYSC_WDIAG_ASTAT_AUX_MASK WBGEN2_GEN_MASK(0, 8)
#define SYSC_WDIAG_ASTAT_AUX_SHIFT 0
#define SYSC_WDIAG_ASTAT_AUX_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define SYSC_WDIAG_ASTAT_AUX_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* definitions for register: WRPC Diag: Tx PTP Frame cnts */
/* definitions for register: WRPC Diag: Rx PTP Frame cnts */
/* definitions for register: WRPC Diag:local time [msb of s] */
/* definitions for register: WRPC Diag: local time [lsb of s] */
/* definitions for register: WRPC Diag: local time [ns] */
/* definitions for register: WRPC Diag: Round trip (mu) [msb of ps] */
/* definitions for register: WRPC Diag: Round trip (mu) [lsb of ps] */
/* definitions for register: WRPC Diag: Master-slave delay (dms) [msb of ps] */
/* definitions for register: WRPC Diag: Master-slave delay (dms) [lsb of ps] */
/* definitions for register: WRPC Diag: Total link asymmetry [ps] */
/* definitions for register: WRPC Diag: Clock offset (cko) [ps] */
/* definitions for register: WRPC Diag: Phase setpoint (setp) [ps] */
/* definitions for register: WRPC Diag: Update counter (ucnt) */
/* definitions for register: WRPC Diag: Board temperature [C degree] */
/* [0x0]: REG Syscon reset register */
#define SYSC_REG_RSTR 0x00000000
/* [0x4]: REG GPIO Set/Readback Register */
......@@ -196,4 +271,42 @@
#define SYSC_REG_DIAG_CR 0x00000020
/* [0x24]: REG User Diag: data to read/write */
#define SYSC_REG_DIAG_DAT 0x00000024
/* [0x28]: REG WRPC Diag: ctrl */
#define SYSC_REG_WDIAG_CTRL 0x00000028
/* [0x2c]: REG WRPC Diag: servo status */
#define SYSC_REG_WDIAG_SSTAT 0x0000002c
/* [0x30]: REG WRPC Diag: Port status */
#define SYSC_REG_WDIAG_PSTAT 0x00000030
/* [0x34]: REG WRPC Diag: PTP state */
#define SYSC_REG_WDIAG_PTPSTAT 0x00000034
/* [0x38]: REG WRPC Diag: AUX state */
#define SYSC_REG_WDIAG_ASTAT 0x00000038
/* [0x3c]: REG WRPC Diag: Tx PTP Frame cnts */
#define SYSC_REG_WDIAG_TXFCNT 0x0000003c
/* [0x40]: REG WRPC Diag: Rx PTP Frame cnts */
#define SYSC_REG_WDIAG_RXFCNT 0x00000040
/* [0x44]: REG WRPC Diag:local time [msb of s] */
#define SYSC_REG_WDIAG_SEC_MSB 0x00000044
/* [0x48]: REG WRPC Diag: local time [lsb of s] */
#define SYSC_REG_WDIAG_SEC_LSB 0x00000048
/* [0x4c]: REG WRPC Diag: local time [ns] */
#define SYSC_REG_WDIAG_NS 0x0000004c
/* [0x50]: REG WRPC Diag: Round trip (mu) [msb of ps] */
#define SYSC_REG_WDIAG_MU_MSB 0x00000050
/* [0x54]: REG WRPC Diag: Round trip (mu) [lsb of ps] */
#define SYSC_REG_WDIAG_MU_LSB 0x00000054
/* [0x58]: REG WRPC Diag: Master-slave delay (dms) [msb of ps] */
#define SYSC_REG_WDIAG_DMS_MSB 0x00000058
/* [0x5c]: REG WRPC Diag: Master-slave delay (dms) [lsb of ps] */
#define SYSC_REG_WDIAG_DMS_LSB 0x0000005c
/* [0x60]: REG WRPC Diag: Total link asymmetry [ps] */
#define SYSC_REG_WDIAG_ASYM 0x00000060
/* [0x64]: REG WRPC Diag: Clock offset (cko) [ps] */
#define SYSC_REG_WDIAG_CKO 0x00000064
/* [0x68]: REG WRPC Diag: Phase setpoint (setp) [ps] */
#define SYSC_REG_WDIAG_SETP 0x00000068
/* [0x6c]: REG WRPC Diag: Update counter (ucnt) */
#define SYSC_REG_WDIAG_UCNT 0x0000006c
/* [0x70]: REG WRPC Diag: Board temperature [C degree] */
#define SYSC_REG_WDIAG_TEMP 0x00000070
#endif
......@@ -55,6 +55,25 @@ struct SYSCON_WB {
uint32_t DIAG_NW;
uint32_t DIAG_CR;
uint32_t DIAG_DAT;
uint32_t WDIAG_CTRL;
uint32_t WDIAG_SSTAT;
uint32_t WDIAG_PSTAT;
uint32_t WDIAG_PTPSTAT;
uint32_t WDIAG_ASTAT;
uint32_t WDIAG_TXFCNT;
uint32_t WDIAG_RXFCNT;
uint32_t WDIAG_SEC_MSB;
uint32_t WDIAG_SEC_LSB;
uint32_t WDIAG_NS;
uint32_t WDIAG_MU_MSB;
uint32_t WDIAG_MU_LSB;
uint32_t WDIAG_DMS_MSB;
uint32_t WDIAG_DMS_LSB;
uint32_t WDIAG_ASYM;
uint32_t WDIAG_CKO;
uint32_t WDIAG_SETP;
uint32_t WDIAG_UCNT;
uint32_t WDIAG_TEMP;
};
/*GPIO pins*/
......@@ -113,5 +132,18 @@ int diag_write_word(uint32_t adr, uint32_t val);
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,
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_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);
void wdiags_write_temp(uint32_t temp);
#endif /* CONFIG_WR_NODE */
#endif
This diff is collapsed.
.depend
\ No newline at end of file
# If it exists includes Makefile.specific. In this Makefile, you should put
# specific Makefile code that you want to run before this. For example,
# build a particular environment.
-include Makefile.specific
SUPPORT_CERN_VMEBRIDGE ?= n
LIB = libdevmap.a
LOBJ := devmap.o
GIT_VER ?= $(shell git describe --always --dirty)
GIT_USR ?= $(shell git config --get-all user.name)
CFLAGS = -Wall -ggdb -fPIC -Werror -I./ -I../include
CFLAGS += -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\""
LDFLAGS = -L.
ifeq ($(SUPPORT_CERN_VMEBRIDGE), y)
LIBVME_A = $(VMEBRIDGE)/lib
LIBVME_H = $(VMEBRIDGE)/include
CFLAGS += -I$(LIBVME_H) -I$(LIBVME_A)
CFLAGS += -DSUPPORT_CERN_VMEBRIDGE
LDFLAGS += -L$(LIBVME_A) -lvmebus
LIB_DEP += $(LIBVME_A)/libvmebus.a
endif
%: %.c $(LIB)
$(CC) $(CFLAGS) $*.c $(LDFLAGS) -o $@
$(LIB): $(LOBJ) $(LIB_DEP)
ifeq ($(SUPPORT_CERN_VMEBRIDGE), y)
$(AR) r tmp$@ $(LOBJ)
# transform a thin library into a normal one
echo -e "create $@\naddlib tmp$@\naddlib $(LIBVME_A)/libvmebus.a\nsave\nend" | $(AR) -M
$(RM) tmp$@
else
$(AR) r $@ $^
endif
clean:
rm -f $(LIB) .depend *.o *~
.depend: Makefile $(wildcard *.c *.h ../*.h)
$(CC) $(CFLAGS) -M $(LOBJ:.o=.c) -o $@
-include .depend
/**
* Author: Federico Vaga <federico.vaga@cern.ch>
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <inttypes.h>
#include "libdevmap.h"
static const char * const libdevmap_version_s = "libdevmap version: "
__GIT_VER__ ", by " __GIT_USR__ " " __TIME__ " " __DATE__;
#ifdef SUPPORT_CERN_VMEBRIDGE
#include <libvmebus.h>
struct vmebridge_map_args {
/**
* VME memory map arguments
*/
uint32_t data_width; /**< default register size in bytes */
uint32_t am; /**< VME address modifier to use */
uint64_t addr; /**< physical base address */
};
#endif
#ifdef SUPPORT_CERN_VMEBRIDGE
static struct mapping_desc *cern_vmebridge_dev_map(
struct mapping_args *map_args, int mapping_length)
{
struct mapping_desc *desc;
struct vme_mapping *vme_mapping;
volatile void *ptr_map;
struct vmebridge_map_args *vme_args =
(struct vmebridge_map_args *)map_args->vme_extra_args;
vme_mapping = malloc(sizeof(struct vme_mapping));
if (!vme_mapping)
return NULL;
/* Prepare mmap description */
memset(vme_mapping, 0, sizeof(struct vme_mapping));
vme_mapping->am = vme_args->am;
vme_mapping->data_width = vme_args->data_width;
vme_mapping->sizel = map_args->offset + mapping_length;
vme_mapping->vme_addrl = vme_args->addr;
/* Do mmap */
ptr_map = vme_map(vme_mapping, 1);
if (!ptr_map)
goto out_alloc;
desc = malloc(sizeof(struct mapping_desc));
if (!desc)
goto out_map;
desc->base = ptr_map + map_args->offset;
desc->mmap = (void *)vme_mapping;
return desc;
out_map:
vme_unmap(vme_mapping, 1);
out_alloc:
free(vme_mapping);
return NULL;
}
#endif
/**
* It maps into memory the given device resource
* @parma[in] resource_path path to the resource file which can be mmapped
* @param[in] offset virtual address of the device memory region of interest
* within the resource
*
* @todo make the open more user friendly
*
* @return NULL on error and errno is approproately set.
* On success a mapping descriptor.
*/
struct mapping_desc *dev_map(struct mapping_args *map_args, uint32_t map_length)
{
struct mapping_desc *desc;
off_t pa_offset /*page aligned offset */;
#ifdef SUPPORT_CERN_VMEBRIDGE
if (map_args->vme_extra_args) { //map device through CERN VME_BRIDGE
desc = cern_vmebridge_dev_map(map_args, map_length);
if (!desc) {
return NULL;
}
desc->is_be = 1; /* VME Bus is big endian */
desc->args = map_args;
return desc;
}
#endif
desc = malloc(sizeof(struct mapping_desc));
if (!desc)
goto out_alloc;
desc->fd = open(map_args->resource_file, O_RDWR | O_SYNC);
if (desc->fd <= 0)
goto out_open;
/* offset is page aligned */
pa_offset = map_args->offset & ~(getpagesize() - 1);
desc->map_pa_length = map_length + map_args->offset - pa_offset;
desc->mmap = mmap(NULL, desc->map_pa_length,
PROT_READ | PROT_WRITE,
MAP_SHARED, desc->fd, pa_offset);
if ((long)desc->mmap == -1)
goto out_mmap;
desc->base = desc->mmap + map_args->offset - pa_offset;
/*
* @todo for future VME devices handled via a resource file,
* exposed in standard place (/sys/bus/vme/device/xxx/resource-file)
* the bus type (pci or vme) should be checked to set properly
* the endianess (could be get from the path's resource)
*/
desc->is_be = 0; /* default set to little endian */
return desc;
out_mmap:
close(desc->fd);
out_open:
free(desc);
out_alloc:
return NULL;
}
/**
* It releases the resources allocated by dev_map(). The mapping will
* not be available anymore and the descriptor will be invalidated
* @param[in,out] descriptor token from dev_map()
*/
void dev_unmap(struct mapping_desc *desc)
{
#ifdef SUPPORT_CERN_VMEBRIDGE
if (!desc->fd) { /* cern vmebridge resource */
vme_unmap((struct vme_mapping *)desc->mmap, 1);
free(desc->args->vme_extra_args);
free(desc->args);
free(desc);
return;
}
#endif
munmap(desc->mmap, desc->map_pa_length);
close(desc->fd);
free(desc->args);
free(desc);
}
#ifdef SUPPORT_CERN_VMEBRIDGE
#define CERN_VMEBRIDGE_REQUIRED_ARG_NB 2
#define CERN_VMEBRIDGE 1
static struct option long_options[] = {
{"cern-vmebridge", no_argument, 0, CERN_VMEBRIDGE},
{"address", required_argument, 0, 'a'},
{"offset", required_argument, 0, 'o'},
{"data-width", required_argument, 0, 'w'},
{"am", required_argument, 0, 'm'},
{0, 0, 0, 0}
};
/*
* looks for vme-compat option
* returns 1 if vme-compat is matched, otherwhise 0.
*/
static int cern_vmebridge_match(int argc, char *argv[])
{
int i;
for (i = 0; i < argc; ++i) {
if (!strcmp(argv[i], "--cern-vmebridge")) {
return 1;
}
}
return 0;
}
/*
* Parse mandatory arguments to mmap VME physical address space
* return 0 on sucess, -1 in case of error
*/
static int cern_vmebridge_parse_args(int argc, char *argv[],
struct mapping_args *map_args)
{
struct vmebridge_map_args *vme_args;
int ret, arg_count = 0, c, option_index = 0;
vme_args = calloc(1, sizeof(struct vmebridge_map_args));
if (!vme_args)
return -1;
map_args->vme_extra_args = vme_args;
/* set default values in case they are not provided*/
vme_args->data_width = 32;
vme_args->am = 0x39;
while ((c = getopt_long(argc, argv, "w:o:m:a:CERN_VMEBRIDGE", long_options,
&option_index)) != -1) {
switch(c) {
case CERN_VMEBRIDGE:
// nothing to do
break;
case 'w': /* optional arg */
ret = sscanf(optarg, "%u",
&vme_args->data_width);
if (ret != 1)
return -1;
if ( !(vme_args->data_width == 8 ||
vme_args->data_width == 16 ||
vme_args->data_width == 32 ||
vme_args->data_width == 64) )
return -1;
break;
case 'o': /* mandatory arg */
ret = sscanf(optarg, "0x%"SCNx64, &map_args->offset);
if (ret != 1)
return -1;
++arg_count;
break;
case 'm': /* optional arg */
ret = sscanf(optarg, "0x%x",
&vme_args->am);
if (ret != 1)
return -1;
break;
case 'a': /* mandatory arg */
ret = sscanf(optarg, "0x%"SCNx64,
&vme_args->addr);
if (ret != 1)
return -1;
++arg_count;
break;
case '?':
/* ignore unknown arguments */
break;
}
}
return (arg_count == CERN_VMEBRIDGE_REQUIRED_ARG_NB) ? 0 : -1;
}
#endif
#define REQUIRED_ARG_NB 2
struct mapping_args *dev_parse_mapping_args(int argc, char *argv[])
{
struct mapping_args *map_args;
char c;
int ret, arg_count = 0;
map_args = calloc(1, sizeof(struct mapping_args));
if (!map_args)
return NULL;
/*
* getopt variable: cancel error message printing because we look for
* only mapping options among other options
*/
opterr = 0;
#ifdef SUPPORT_CERN_VMEBRIDGE
if (cern_vmebridge_match(argc, argv)) {
ret = cern_vmebridge_parse_args(argc, argv, map_args);
if (ret < 0) {
goto out;
}
/*
* getopts variable: reset argument index in case application
* needs to parse arguments lokkink for specific args.
*/
optind = 1;
return map_args;
}
#endif
while ((c = getopt (argc, argv, "o:f:")) != -1)
{
switch (c)
{
case 'o':
ret = sscanf(optarg, "0x%x",
(unsigned int *)&map_args->offset);
if (ret != 1) {
goto out;
}
++arg_count;
break;
case 'f':
map_args->resource_file = optarg;
++arg_count;
break;
case '?':
/* ignore unknown arguments */
break;
}
}
if (arg_count != REQUIRED_ARG_NB) {
goto out;
}
/*
* getopts variable: reset argument index in case application needs to
* parse arguments lokkink for specific args.
*/
optind = 1;
return map_args;
out:
free(map_args);
return NULL;
}
const char * const dev_mapping_help()
{
static char help_msg[] =
"Device mapping options: \n"
"\t-f <file resource path> -o 0x<address offset> \n"
#ifdef SUPPORT_CERN_VMEBRIDGE
"Device mapping options for CERN vmebus driver: \n"
"\t--cern-vmebridge -a 0x<VME base address> \n"
"\t-o 0x<address offset> [-w <data-width[8,16,32] default=32>\n"
"\t-m 0x<address modifier default=0x39>]\n"
#endif
;
return help_msg;
}
const char * const dev_get_version()
{
return libdevmap_version_s;
}
# If it exists includes Makefile.specific. In this Makefile, you should put
# specific Makefile code that you want to run before this. For example,
# build a particular environment.
-include Makefile.specific
GIT_VER =? $(shell git describe --always --dirty)
GIT_USR =? $(shell git config --get-all user.name)
LIB = libextest.a
LOBJ := extest.o
CFLAGS = -Wall -ggdb -fPIC -Werror -I./
CFLAGS += -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\""
LDFLAGS = -L. -lextest
%: %.c $(LIB)
$(CC) $(CFLAGS) $*.c $(LDFLAGS) -o $@
$(LIB): $(LOBJ) $(LIB_DEP)
$(AR) r $@ $^
clean:
rm -f $(LIB) .depend *.o *~
.depend: Makefile $(wildcard *.c *.h ../*.h)
$(CC) $(CFLAGS) -M $(LOBJ:.o=.c) -o $@
-include .depend
This diff is collapsed.
/**
* @file extest.h
*
* @brief Common header file for extest's programs
*
* Copyright (C) CERN (www.cern.ch)
* Author: Julian Lewis
* Michel Arruat
*/
#ifndef _EXTEST_H_
#define _EXTEST_H_
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#define MAX_ARG_COUNT 256 //!< maximum command line arguments
#define MAX_ARG_LENGTH 128 //!< max characters per argument
#define F_CLOSED (-1) //!< file closed
#define WHITE_ON_BLACK "\033[40m\033[1;37m"
#define DEFAULT_COLOR "\033[m"
//! Operator ID's
typedef enum {
OprNOOP,
OprNE,
OprEQ,
OprGT,
OprGE,
OprLT,
OprLE,
OprAS,
OprPL,
OprMI,
OprTI,
OprDI,
OprAND,
OprOR,
OprXOR,
OprNOT,
OprNEG,
OprLSH,
OprRSH,
OprINC,
OprDECR,
OprPOP,
OprSTM,
OprOPRS
} oprid_t;
struct operator {
oprid_t id; //!< operator ID (one of @ref oprid_t)
char name[16]; //!< Human form
char help[32]; //!< help string
};
//!< atom types
typedef enum {
Separator = 0, //!< [\t\n\r ,]
Operator = 1, //!< [!#&*+-/:;<=>?]
Open = 2, //!< [(]
Close = 3, //!< [)]
Comment = 4, //!< [%]
Numeric = 5, //!< [0-9]
Alpha = 6, //!< [a-zA-Z_]
Open_index = 7, //!< [\[]
Close_index = 8, //!< [\]]
Illegal_char = 9, //!< all the rest in the ASCII table
Terminator = 10, //!< [@\0]
Bit = 11, //!< [.]
String = 12 //!< ["]
} atom_t;
#define Quotes String
/*! atom container
* Example: 'oprd min 5 0x400' is formed by 4 atoms
*/
struct atom {
unsigned int pos; //!< position if @av_type is @Alpha or @Operator
int val; //!< value if @av_type is @Numeric
atom_t type; //!< atom type
char text[MAX_ARG_LENGTH]; //!< string representation
unsigned int cmd_id; //!< command id (might be built-in or user-defined)
oprid_t oid; //!< operator id (if any)
};
/*! @name Default commands for every test program
*
* Some default commands use ioctl calls to access the driver.
* The user should provide these ioctl numbers to use these commands.
* If a particular ioctl number is not provided, its command won't be issued.
* IOCTL numbers can be obtained using @b debugfs
*/
enum built_in_cmd_id {
CMD_NOCM = 0, //!< llegal command
CMD_QUIT, //!< Quit test program
CMD_HELP, //!< Help on commands
CMD_ATOMS, //!< Atom list commands
CMD_HIST, //!< History
CMD_SLEEP, //!< Sleep sec
CMD_MSLEEP, //!< Sleep millisec
CMD_SHELL, //!< Shell command
CMD_USR //!< first available command for the user
};
//!< Command description
struct cmd_desc {
int valid; //!< show command to the user? (1 - yes, 0 - no)
int id; //!< id (user-defined && @def_cmd_id)
char *name; //!< spelling
char *help; //!< short help string
char *opt; //!< options (if any)
int comp; //!< amount of compulsory options
int (*handle)(struct cmd_desc *, struct atom *); //!< handler
int pa; //!< number of arguments to be passed to the handler
};
/*! @name extest's public API
*/
//@{
//!< User wants verbose command help
#define VERBOSE_HELP (-1)
//! Test program Error return codes
enum extest_error {
TST_NO_ERR, //!< cool
TST_ERR_NOT_IMPL, //!< function not implemented
TST_ERR_NO_PARAM, //!< compulsory parameter is not provided
TST_ERR_WRONG_ARG, //!< wrong command argument
TST_ERR_SYSCALL, //!< system call fails
TST_ERR_LAST //!< error idx
};
int extest_do_yes_no(char *question, char *extra);
int extest_compulsory_ok(struct cmd_desc *cmdd);
int extest_register_user_cmd(struct cmd_desc user_cmdlist[],
int user_cmd_nb);
int extest_run(char* prg_name, void (*user_sighndl)());
int extest_is_last_atom(struct atom *atom);
const char * const extest_get_version();
//@}
#endif /* _EXTEST_H_ */
/**
* Author: Federico Vaga <federico.vaga@cern.ch>
*/
#ifndef __LIBDEVMAP_H__
#define __LIBDEVMAP_H__
#include <stdint.h>
#include <arpa/inet.h>
#define iomemr32(is_be, val) ((is_be) ? ntohl(val) : val)
#define iomemw32(is_be, val) ((is_be) ? htonl(val) : val)
struct mapping_args {
char *resource_file;
uint64_t offset;
void *vme_extra_args;
};
/* device resource mapped into memory */
struct mapping_desc {
int fd;
void *mmap;
int map_pa_length; /* mapped length is page aligned */
volatile void *base; /* address of the concerned memory region */
int is_be; /* tells the device endianess */
struct mapping_args *args;
};
/**
* @defgroup device resource mapping
*@{
*/
extern struct mapping_desc *dev_map(struct mapping_args *map_args,
uint32_t map_length);
extern void dev_unmap(struct mapping_desc *dev);
extern struct mapping_args *dev_parse_mapping_args(int argc, char *argv[]);
extern const char * const dev_mapping_help();
extern const char * const dev_get_version();
/** @}*/
#endif //__LIBDEVMAP_H__
......@@ -25,12 +25,15 @@
#include "shell.h"
#include "revision.h"
#define WRC_DIAG_REFRESH_PERIOD (1 * TICS_PER_SECOND)
extern struct pp_servo servo;
extern struct pp_instance ppi_static;
struct pp_instance *ppi = &ppi_static;
const char *ptp_unknown_str= "unknown";
static void wrc_mon_std_servo(void);
int wrc_wr_diags(void);
#define PRINT64_FACTOR 1000000000LL
static char* print64(uint64_t x, int align)
......@@ -383,7 +386,120 @@ static int wrc_log_stats(void)
return 1;
}
DEFINE_WRC_TASK(stats) = {
.name = "stats",
.job = wrc_log_stats,
};
int wrc_wr_diags(void)
{
struct hal_port_state ps;
static uint32_t last_jiffies;
int tx, rx;
uint64_t sec;
uint32_t nsec;
int n_out;
uint32_t aux_stat=0;
int temp=0, valid=0, snapshot=0,i;
valid = wdiag_get_valid();
snapshot = wdiag_get_snapshot();
/* if the data is snapshot and there is already valid data, do not
* refresh */
if(valid & snapshot)
return 0;
/* ***************** lock data from reading by user **************** */
if (!last_jiffies)
last_jiffies = timer_get_tics() - 1 - WRC_DIAG_REFRESH_PERIOD;
/* stats update condition */
if (time_before(timer_get_tics(), last_jiffies + WRC_DIAG_REFRESH_PERIOD))
return 0;
last_jiffies = timer_get_tics();
/* ***************** lock data from reading by user **************** */
wdiag_set_valid(0);
/* frame statistics */
minic_get_stats(&tx, &rx);
wdiags_write_cnts(tx,rx);
/* local time */
shw_pps_gen_get_time(&sec, &nsec);
wdiags_write_time(sec, nsec);
/* port state (from hal) */
wrpc_get_port_state(&ps, NULL);
wdiags_write_port_state((ps.state ? 1 : 0), (ps.locked ? 1 : 0));
/* port PTP State (from ppsi)
* see:
ppsi/proto-ext-whiterabbit/wr-constants.h
ppsi/include/ppsi/ieee1588_types.h
0 : none
1 : PPS_INITIALIZING
2 : PPS_FAULTY
3 : PPS_DISABLED
4 : PPS_LISTENING
5 : PPS_PRE_MASTER
6 : PPS_MASTER
7 : PPS_PASSIVE
8 : PPS_UNCALIBRATED
9 : PPS_SLAVE
100: WRS_PRESENT
101: WRS_S_LOCK
102: WRS_M_LOCK
103: WRS_LOCKED
104, 108-116:WRS_CALIBRATION
105: WRS_CALIBRATED
106: WRS_RESP_CALIB_REQ
107: WRS_WR_LINK_ON
*/
wdiags_write_ptp_state((uint8_t )ppi->state);
/* servo state (if slave)s */
if(ptp_mode == WRC_MODE_SLAVE){
struct wr_servo_state *ss =
&((struct wr_data *)ppi->ext_data)->servo_state;
int32_t asym = (int32_t)(ss->picos_mu-2LL * ss->delta_ms);
int wr_mode = (ss->flags & WR_FLAG_VALID) ? 1 : 0;
int servostate = ss->state;
/* see ppsi/proto-ext-whiterabbit/wr-constants.c:
0: WR_UNINITIALIZED = 0,
1: WR_SYNC_NSEC,
2: WR_SYNC_TAI,
3: WR_SYNC_PHASE,
4: WR_TRACK_PHASE,
5: WR_WAIT_OFFSET_STABLE */
wdiags_write_servo_state(wr_mode, servostate, ss->picos_mu,
ss->delta_ms, asym, ss->offset,
ss->cur_setpoint,ss->update_count);
}
/* auxiliar channels (if any) */
spll_get_num_channels(NULL, &n_out);
if (n_out > 8) n_out = 8; /* hardware limit. */
for(i = 0; i < n_out; i++) {
aux_stat |= (0x1 & spll_get_aux_status(i)) << i;
}
wdiags_write_aux_state(aux_stat);
/* temperature */
temp = wrc_temp_get("pcb");
wdiags_write_temp(temp);
/* **************** unlock data from reading by user ************** */
wdiag_set_valid(1);
return 1;
}
#ifdef CONFIG_WR_DIAG
DEFINE_WRC_TASK(diags) = {
.name = "diags",
.job = wrc_wr_diags,
};
#endif
......@@ -11,3 +11,6 @@ flash-write
pfilter-builder
wrpc-dump
mapper
wrpc-vuart
wr-streamers
wrpc-diags
EB ?= no
SDBFS ?= no
CFLAGS = -Wall -ggdb -I../include
LDFLAGS = -lutil
CFLAGS = -Wall -ggdb -I../include -I../liblinux -I../liblinux/extest
CFLAGS += -D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\""
LDFLAGS = -lutil -L../liblinux -ldevmap -L../liblinux/extest -lextest
LDFLAGS += -lreadline
ALL = genraminit genramvhd genrammif
ALL += wrpc-w1-read wrpc-w1-write
ALL += pfilter-builder
ALL += wrpc-dump mapper
ALL += wrpc-vuart
ALL += wr-streamers
ALL += wrpc-diags
ifneq ($(EB),no)
ALL += eb-w1-write
......@@ -46,7 +51,15 @@ wrpc-dump: wrpc-dump.c dump-info-host.o
$(CC) $(CFLAGS) -I../ppsi/include -I../ppsi/arch-wrpc/include -I.. \
-I ../softpll \
$^ -o $@ \
-D__GIT_VER__="\"$(GIT_VER)\"" -D__GIT_USR__="\"$(GIT_USR)\""
wr-streamers: wr-streamers.c
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
wrpc-diags: wrpc-diags.c
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
wrpc-vuart: wrpc-vuart.c
$(CC) $(CFLAGS) -Werror $^ $(LDFLAGS) -o $@
pfilter-builder: pfilter-builder.c
$(CC) $(CFLAGS) -include ../include/generated/autoconf.h \
......
......@@ -112,4 +112,4 @@ main()
for(;;);
}
\ No newline at end of file
}
This diff is collapsed.
This diff is collapsed.
/**
* Author: Federico Vaga <federico.vaga@cern.ch>
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <unistd.h>
#include <termios.h>
#include <getopt.h>
#include <errno.h>
#include <hw/wb_uart.h>
#include <libdevmap.h>
static void wrpc_vuart_help(char *prog)
{
const char *mapping_help_str;
mapping_help_str = dev_mapping_help();
fprintf(stderr, "%s [options]\n", prog);
fprintf(stderr, "%s\n", mapping_help_str);
fprintf(stderr, "Vuart specific option: [-k(keep terminal)]\n");
}
/**
* It receives a single byte
* @param[in] vuart token from dev_map()
*
*
*/
static int8_t wr_vuart_rx(struct mapping_desc *vuart)
{
int rdr = ((volatile struct UART_WB *)vuart->base)->HOST_RDR;
if (vuart->is_be)
rdr = ntohl(rdr);
return (rdr & UART_HOST_RDR_RDY) ? UART_HOST_RDR_DATA_R(rdr) : -1;
}
/**
* It transmits a single byte
* @param[in] vuart token from dev_map()
*/
static void wr_vuart_tx(struct mapping_desc *vuart, char data)
{
volatile struct UART_WB *ptr = (volatile struct UART_WB *)vuart->base;
int sr = (vuart->is_be) ? ntohl(ptr->SR) : ptr->SR;
uint32_t val;
while(sr & UART_SR_RX_RDY)
sr = (vuart->is_be) ? ntohl(ptr->SR) : ptr->SR;
val = (vuart->is_be) ? htonl(UART_HOST_TDR_DATA_W(data)) :
UART_HOST_TDR_DATA_W(data);
ptr->HOST_TDR = val;
}
/**
* It reads a number of bytes and it stores them in a given buffer
* @param[in] vuart token from dev_map()
* @param[out] buf destination for read bytes
* @param[in] size numeber of bytes to read
*
* @return the number of read bytes
*/
static size_t wr_vuart_read(struct mapping_desc *vuart, char *buf, size_t size)
{
size_t s = size, n_rx = 0;
int8_t c;
while(s--) {
c = wr_vuart_rx(vuart);
if(c < 0)
return n_rx;
*buf++ = c;
n_rx ++;
}
return n_rx;
}
/**
* It writes a number of bytes from a given buffer
* @param[in] vuart token from dev_map()
* @param[in] buf buffer to write
* @param[in] size numeber of bytes to write
*
* @return the number of written bytes
*/
static size_t wr_vuart_write(struct mapping_desc *vuart, char *buf, size_t size)
{
size_t s = size;
while(s--)
wr_vuart_tx(vuart, *buf++);
return size;
}
static void wrpc_vuart_term_main(struct mapping_desc *vuart, int keep_term)
{
struct termios oldkey, newkey;
//above is place for old and new port settings for keyboard teletype
int need_exit = 0;
fd_set fds;
int ret;
char rx, tx;
fprintf(stderr, "[press C-a to exit]\n");
if(!keep_term) {
tcgetattr(STDIN_FILENO,&oldkey);
newkey.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
newkey.c_iflag = IGNPAR;
newkey.c_oflag = 0;
newkey.c_lflag = 0;
newkey.c_cc[VMIN]=1;
newkey.c_cc[VTIME]=0;
tcflush(STDIN_FILENO, TCIFLUSH);
tcsetattr(STDIN_FILENO,TCSANOW,&newkey);
}
while(!need_exit) {
struct timeval tv = {0, 10000};
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds);
/*
* Check if the STDIN has characters to read
* (what the user writes)
*/
ret = select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv);
switch (ret) {
case -1:
perror("select");
break;
case 0: /* timeout */
break;
default:
if(!FD_ISSET(STDIN_FILENO, &fds))
break;
/* The user wrote something */
do {
ret = read(STDIN_FILENO, &tx, 1);
} while (ret < 0 && errno == EINTR);
if (ret != 1) {
fprintf(stderr, "nothing to read. Port disconnected?\n");
need_exit = 1; /* kill */
}
/* If the user character is C-a, then kill */
if(tx == '\x01')
need_exit = 1;
ret = wr_vuart_write(vuart, &tx, 1);
if (ret != 1) {
fprintf(stderr, "Unable to write (errno: %d)\n", errno);
need_exit = 1;
}
break;
}
/* Print all the incoming charactes */
while((wr_vuart_read(vuart, &rx, 1)) == 1)
fprintf(stderr,"%c", rx);
}
if(!keep_term)
tcsetattr(STDIN_FILENO, TCSANOW, &oldkey);
}
int main(int argc, char *argv[])
{
char c;
int keep_term = 0;
struct mapping_args *map_args;
struct mapping_desc *vuart = NULL;
map_args = dev_parse_mapping_args(argc, argv);
if (!map_args) {
wrpc_vuart_help(argv[0]);
goto out;
}
/* Parse specific args */
while ((c = getopt (argc, argv, "k")) != -1) {
switch (c) {
case 'k':
keep_term = 1;
break;
case 'h':
wrpc_vuart_help(argv[0]);
break;
case '?':
break;
}
}
vuart = dev_map(map_args, sizeof(struct UART_WB));
if (!vuart) {
fprintf(stderr, "%s: vuart_open() failed: %s\n", argv[0],
strerror(errno));
goto out;
}
wrpc_vuart_term_main(vuart, keep_term);
dev_unmap(vuart);
return 0;
out:
return -1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment