//@C Copyright Notice //@C ================ //@C This file is part of CPSW. It is subject to the license terms in the LICENSE.txt //@C file found in the top-level directory of this distribution and at //@C https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. //@C //@C No part of CPSW, including this file, may be copied, modified, propagated, or //@C distributed except according to the terms contained in the LICENSE.txt file. #include #include #include #include #define __STDC_FORMAT_MACROS #include #include #include static const char *yaml= "#schemaversion 3.0.0\n" "AxiVersion: &AxiVersion\n" " class: MMIODev\n" " configPrio: 1\n" " description: AXI-Lite Version Module\n" " size: 0x1000\n" " children:\n" " #########################################################\n" " FpgaVersion:\n" " at:\n" " offset: 0x00\n" " class: IntField\n" " mode: RO\n" " description: FPGA Firmware Version Number\n" " #########################################################\n" " ScratchPad:\n" " at:\n" " offset: 0x04\n" " class: IntField\n" " mode: RW\n" " description: Register to test reads and writes\n" " #########################################################\n" " DeviceDna:\n" " at:\n" " offset: 0x08\n" " class: IntField\n" " sizeBits: 64\n" " mode: RO\n" " description: Xilinx Device DNA value burned into FPGA\n" " #########################################################\n" " FdSerial:\n" " at:\n" " offset: 0x10\n" " class: IntField\n" " sizeBits: 64\n" " mode: RO\n" " description: Board ID value read from DS2411 chip\n" " #########################################################\n" " MasterReset:\n" " at:\n" " offset: 0x18\n" " class: IntField\n" " mode: WO\n" " sizeBits: 1\n" " description: Optional User Reset\n" " #########################################################\n" " FpgaReload:\n" " at:\n" " offset: 0x1C\n" " class: IntField\n" " mode: RW\n" " sizeBits: 1\n" " description: Optional Reload the FPGA from the attached PROM\n" " #########################################################\n" " FpgaReloadAddress:\n" " at:\n" " offset: 0x20\n" " class: IntField\n" " mode: RW\n" " description: Reload start address\n" " #########################################################\n" " Counter:\n" " at:\n" " offset: 0x24\n" " class: IntField\n" " mode: RO\n" " description: Free running counter\n" " #########################################################\n" " FpgaReloadHalt:\n" " at:\n" " offset: 0x28\n" " class: IntField\n" " mode: RW\n" " sizeBits: 1\n" " description: Used to halt automatic reloads via AxiVersion\n" " #########################################################\n" " UpTimeCnt:\n" " at:\n" " offset: 0x2C\n" " class: IntField\n" " mode: RO\n" " description: Number of seconds since last reset\n" " #########################################################\n" " DeviceId:\n" " at:\n" " offset: 0x30\n" " class: IntField\n" " mode: RO\n" " description: Device Identification\n" " #########################################################\n" " UserConstants:\n" " at:\n" " offset: 0x400\n" " nelms: 64\n" " class: IntField\n" " mode: RO\n" " description: Optional user input values\n" " #########################################################\n" " BuildStamp:\n" " at:\n" " offset: 0x800\n" " nelms: 123\n" " class: IntField\n" " sizeBits: 8\n" " mode: RO\n" " description: Firmware Build String\n" " #########################################################\n" "RssiCore: &RssiCore\n" " class: MMIODev\n" " configPrio: 1\n" " description: RSSI module\n" " size: 0x100\n" " children:\n" " OpenConn:\n" " at:\n" " offset: 0x00\n" " class: IntField\n" " name: OpenConn\n" " sizeBits: 1\n" " lsBit: 0\n" " mode: RW\n" " description: Open Connection Request (Server goes to listen state, Client actively\n" " requests the connection by sending SYN segment)\n" " CloseConn:\n" " #########################################################\n" " at:\n" " offset: 0x00\n" " class: IntField\n" " name: CloseConn\n" " sizeBits: 1\n" " lsBit: 1\n" " mode: RW\n" " description: Close Connection Request (Send a RST Segment to peer and close\n" " the connection)\n" " Mode:\n" " #########################################################\n" " at:\n" " offset: 0x00\n" " class: IntField\n" " name: Mode\n" " sizeBits: 1\n" " lsBit: 2\n" " mode: RW\n" " description: 'Mode:''0'': Use internal parameters from generics,''1'': Use parameters\n" " from registers'\n" " HeaderChksumEn:\n" " #########################################################\n" " at:\n" " offset: 0x00\n" " class: IntField\n" " name: HeaderChksumEn\n" " sizeBits: 1\n" " lsBit: 3\n" " mode: RW\n" " description: 'Header checksum: ''1'': Enable calculation and check, ''0'': Disable\n" " check and insert 0 in place of header checksum'\n" " InjectFault:\n" " #########################################################\n" " at:\n" " offset: 0x00\n" " class: IntField\n" " name: InjectFault\n" " sizeBits: 1\n" " lsBit: 4\n" " mode: RW\n" " description: Inject fault to the next packet header checksum (Default '0').\n" " Acts on rising edge - injects exactly one fault in next segment\n" " InitSeqN:\n" " #########################################################\n" " at:\n" " offset: 0x04\n" " class: IntField\n" " name: InitSeqN\n" " sizeBits: 8\n" " mode: RW\n" " description: Initial sequence number [7:0]\n" " Version:\n" " #########################################################\n" " at:\n" " offset: 0x08\n" " class: IntField\n" " name: Version\n" " sizeBits: 4\n" " mode: RW\n" " description: Version register [3:0]\n" " MaxOutsSeg:\n" " #########################################################\n" " at:\n" " offset: 0x0C\n" " class: IntField\n" " name: MaxOutsSeg\n" " sizeBits: 8\n" " mode: RW\n" " description: Maximum out standing segments [7:0]\n" " MaxSegSize:\n" " #########################################################\n" " at:\n" " offset: 0x10\n" " class: IntField\n" " name: MaxSegSize\n" " sizeBits: 16\n" " mode: RW\n" " description: Maximum segment size [15:0]\n" " RetransTimeout:\n" " #########################################################\n" " at:\n" " offset: 0x14\n" " class: IntField\n" " name: RetransTimeout\n" " sizeBits: 16\n" " mode: RW\n" " description: Retransmission timeout [15:0]\n" " CumAckTimeout:\n" " #########################################################\n" " at:\n" " offset: 0x18\n" " class: IntField\n" " name: CumAckTimeout\n" " sizeBits: 16\n" " mode: RW\n" " description: Cumulative acknowledgment timeout [15:0]\n" " NullSegTimeout:\n" " #########################################################\n" " at:\n" " offset: 0x1C\n" " class: IntField\n" " name: NullSegTimeout\n" " sizeBits: 16\n" " mode: RW\n" " description: Null segment timeout [15:0]\n" " MaxNumRetrans:\n" " #########################################################\n" " at:\n" " offset: 0x20\n" " class: IntField\n" " name: MaxNumRetrans\n" " sizeBits: 8\n" " mode: RW\n" " description: Maximum number of retransmissions [7:0]\n" " MaxCumAck:\n" " #########################################################\n" " at:\n" " offset: 0x24\n" " class: IntField\n" " name: MaxCumAck\n" " sizeBits: 8\n" " mode: RW\n" " description: Maximum cumulative acknowledgments [7:0]\n" " MaxOutOfSeq:\n" " #########################################################\n" " at:\n" " offset: 0x28\n" " class: IntField\n" " name: MaxOutOfSeq\n" " sizeBits: 8\n" " mode: RW\n" " description: Max out of sequence segments (EACK) [7:0]\n" " ConnectionActive:\n" " #########################################################\n" " at:\n" " offset: 0x40\n" " class: IntField\n" " name: ConnectionActive\n" " sizeBits: 1\n" " lsBit: 0\n" " mode: RO\n" " description: Connection Active\n" " ErrMaxRetrans:\n" " #########################################################\n" " at:\n" " offset: 0x40\n" " class: IntField\n" " name: ErrMaxRetrans\n" " sizeBits: 1\n" " lsBit: 1\n" " mode: RO\n" " description: Maximum retransmissions exceeded retransMax.\n" " ErrNullTout:\n" " #########################################################\n" " at:\n" " offset: 0x40\n" " class: IntField\n" " name: ErrNullTout\n" " sizeBits: 1\n" " lsBit: 2\n" " mode: RO\n" " description: Null timeout reached (server) nullTout.\n" " ErrAck:\n" " #########################################################\n" " at:\n" " offset: 0x40\n" " class: IntField\n" " name: ErrAck\n" " sizeBits: 1\n" " lsBit: 3\n" " mode: RO\n" " description: Error in acknowledgment mechanism.\n" " ErrSsiFrameLen:\n" " #########################################################\n" " at:\n" " offset: 0x40\n" " class: IntField\n" " name: ErrSsiFrameLen\n" " sizeBits: 1\n" " lsBit: 4\n" " mode: RO\n" " description: SSI Frame length too long\n" " ErrConnTout:\n" " #########################################################\n" " at:\n" " offset: 0x40\n" " class: IntField\n" " name: ErrConnTout\n" " sizeBits: 1\n" " lsBit: 5\n" " mode: RO\n" " description: 'Connection to peer timed out. Timeout defined in generic PEER_CONN_TIMEOUT_G\n" " (Default: 1000 ms)'\n" " ParamRejected:\n" " #########################################################\n" " at:\n" " offset: 0x40\n" " class: IntField\n" " name: ParamRejected\n" " sizeBits: 1\n" " lsBit: 6\n" " mode: RO\n" " description: Client rejected the connection (parameters out of range), Server\n" " proposed new parameters (parameters out of range)\n" " ValidCnt:\n" " #########################################################\n" " at:\n" " offset: 0x44\n" " class: IntField\n" " name: ValidCnt\n" " sizeBits: 32\n" " mode: RO\n" " description: Number of valid segments [31:0]\n" " DropCnt:\n" " ######################################################### \n" " at:\n" " offset: 0x48\n" " class: IntField\n" " name: DropCnt\n" " sizeBits: 32\n" " mode: RO\n" " description: Number of dropped segments [31:0]\n" " RetransmitCnt:\n" " #########################################################\n" " at:\n" " offset: 0x4C\n" " class: IntField\n" " name: RetransmitCnt\n" " sizeBits: 32\n" " mode: RO\n" " description: Counts all retransmission requests within the active connection\n" " [31:0]\n" " ReconnectCnt:\n" " ######################################################### \n" " at:\n" " offset: 0x50\n" " class: IntField\n" " name: ReconnectCnt\n" " sizeBits: 32\n" " mode: RO\n" " description: Counts all reconnections from reset [31:0]\n" " FrameRate:\n" " ######################################################### \n" " at:\n" " offset: 0x54\n" " nelms: 2\n" " stride: 4\n" " class: IntField\n" " name: FrameRate\n" " sizeBits: 32\n" " mode: RO\n" " description: Frame Rate (in units of Hz)\n" " ######################################################### \n" " Bandwidth:\n" " at:\n" " offset: 0x5C\n" " nelms: 2\n" " stride: 8\n" " class: IntField\n" " sizeBits: 64\n" " mode: RO\n" " description: Bandwidth (in units of bytes per second)\n" " ######################################################### \n" " C_OpenConn:\n" " class: SequenceCommand\n" " at:\n" " offset: 0x0\n" " description: Open connection request\n" " sequence:\n" " - entry: OpenConn\n" " value: 0x1\n" " - entry: OpenConn\n" " value: 0x0\n" " #########################################################\n" " C_CloseConn:\n" " class: SequenceCommand\n" " at:\n" " offset: 0x0\n" " description: Close connection request\n" " sequence:\n" " - entry: CloseConn\n" " value: 0x1\n" " - entry: CloseConn\n" " value: 0x0\n" " #########################################################\n" " C_InjectFault:\n" " class: SequenceCommand\n" " at:\n" " offset: 0x0\n" " description: Inject a single fault(for debug and test purposes only). Corrupts\n" " checksum during transmission\n" " sequence:\n" " - entry: InjectFault\n" " value: 0x1\n" " - entry: InjectFault\n" " value: 0x0\n" "UdpEngineClient: &UdpEngineClient\n" " description: UdpEngineClient\n" " class: MMIODev\n" " configPrio: 1\n" " size: 0x8\n" " #########\n" " children:\n" " #########\n" " #########################################################\n" " ClientRemotePort:\n" " at:\n" " offset: 0x00\n" " class: IntField\n" " sizeBits: 16\n" " mode: RW\n" " description: ClientRemotePort (big-Endian configuration)\n" " #########################################################\n" " ClientRemoteIp:\n" " at:\n" " offset: 0x04\n" " class: IntField\n" " sizeBits: 32\n" " mode: RW\n" " description: ClientRemoteIp (big-Endian configuration)\n" " #########################################################\n" "UdpEngineServer: &UdpEngineServer\n" " description: UdpEngineServer\n" " class: MMIODev\n" " configPrio: 1\n" " size: 0x8\n" " #########\n" " children:\n" " #########\n" " #########################################################\n" " ServerRemotePort:\n" " at:\n" " offset: 0x00\n" " class: IntField\n" " sizeBits: 16\n" " mode: RO\n" " description: ServerRemotePort (big-Endian configuration)\n" " #########################################################\n" " ServerRemoteIp:\n" " at:\n" " offset: 0x04\n" " class: IntField\n" " sizeBits: 32\n" " mode: RO\n" " description: ServerRemoteIp (big-Endian configuration)\n" " #########################################################\n" "AmcCarrierCore: &AmcCarrierCore\n" " name: AmcCarrierCore\n" " description: AmcCarrierCore\n" " class: MMIODev\n" " configPrio: 1\n" " size: 0x80000000 # 2GB address space for core firmware\n" " ######### \n" " children:\n" " ##################################################\n" " AMC_CARRIER_CORE_VERSION_C:\n" " at:\n" " offset: 0x00000400\n" " class: IntField\n" " mode: RO\n" " description: AMC Carrier Core Version Number\n" " ##################################################\n" " AxiVersion:\n" " <<: *AxiVersion\n" " at:\n" " offset: 0x00000000\n" " ##################################################\n" " RssiServerSw:\n" " <<: *RssiCore\n" " at:\n" " offset: 0x0A020000\n" " nelms: 2\n" " stride: 0x1000\n" " description: Server RSSI Software\n" " ##################################################\n" " UdpEngineClient:\n" " <<: *UdpEngineClient\n" " at:\n" " offset: 0x0A010000\n" " nelms: 2\n" " stride: 8\n" " description: 'ClientConfig[1:0]'\n" " ##################################################\n" " UdpEngineServer:\n" " <<: *UdpEngineServer\n" " at:\n" " offset: 0x0A010800\n" " nelms: 5\n" " stride: 8\n" " description: 'ServerConfig[4:0]'\n" " ##################################################\n" "mmio: &mmio\n" " size: 0x100000000 # 4GB of address space\n" " class: MMIODev\n" " configPrio: 1\n" " children:\n" " AmcCarrierCore:\n" " <<: *AmcCarrierCore\n" " at:\n" " offset: 0x00000000\n" " ##################################################\n" "NetIODev:\n" " ipAddr: 10.0.1.105\n" " class: NetIODev\n" " configPrio: 1\n" " children:\n" " mmio:\n" " <<: *mmio\n" " at:\n" " SRP:\n" " protocolVersion: SRP_UDP_V2\n" " UDP:\n" " port: 8192\n"; class IYamlSetIP : public IYamlFixup { public: IYamlSetIP( const char* ipAddr ) : ipAddr_(ipAddr) {} virtual void operator()(YAML::Node &node) { node["ipAddr"] = ipAddr_; } virtual ~IYamlSetIP() {} private: std::string ipAddr_; }; static void usage(const char *name) { fprintf(stderr, "usage: %s [-h] [-a ip_address]\n", name); fprintf(stderr, " -h: This message\n"); fprintf(stderr, " -a ip_addr: IP address of target\n"); } int main(int argc, char **argv) { std::string ipAddr = "192.168.2.10"; int opt; int rval = 1; while ( (opt = getopt(argc, argv, "ha:")) > 0 ) { switch ( opt ) { case 'h': rval = 0; default: usage( argv[0] ); return rval; case 'a': ipAddr = optarg; break; } } try { uint8_t str[123]; uint8_t u8[123]; uint16_t u16; uint32_t u32; uint64_t u64; unsigned rssiCount = 0; unsigned connectionActive = 0; IYamlSetIP setIP( ipAddr.c_str() ); Path p = IPath::loadYamlStream( yaml, "NetIODev", NULL, &setIP ); Path pAxiVersion = p->findByName("mmio/AmcCarrierCore/AxiVersion"); ScalVal_RO fpgaVersion = IScalVal_RO::create( pAxiVersion->findByName("FpgaVersion") ); ScalVal_RO buildStamp = IScalVal_RO::create( pAxiVersion->findByName("BuildStamp") ); ScalVal_RO fdSerial = IScalVal_RO::create( pAxiVersion->findByName("FdSerial") ); ScalVal_RO dnaValue = IScalVal_RO::create( pAxiVersion->findByName("DeviceDna") ); Path pRssi = p->findByName("mmio/AmcCarrierCore/RssiServerSw"); rssiCount = pRssi->getNelms(); ScalVal_RO rssiVersion = IScalVal_RO::create( pRssi->findByName("Version") ); ScalVal_RO rssiConnectionActive = IScalVal_RO::create( pRssi->findByName("ConnectionActive") ); buildStamp->getVal( str, sizeof(str)/sizeof(str[0]) ); printf("AxiVersion:\n %s\n", (char*)str); fpgaVersion->getVal( &u64 ); printf(" FpgaVersion: %"PRIu64"\n", u64); fdSerial->getVal( &u64, 1 ); printf(" Serial #: 0x%"PRIx64"\n", u64); dnaValue->getVal( &u64, 1 ); printf(" DNA #: 0x%"PRIx64"\n", u64); printf("RssiServerSw:\n"); printf(" nelms: %u\n", rssiCount); // IndexRange rng( 0 ); // rssiVersion->getVal( &u64, 1, &rng ); for ( unsigned i = 0; i < rssiCount; i++ ){ printf(" server: %u\n", i); rssiVersion->getVal( u8, rssiCount ); printf(" Version: %u\n", u8[i]); rssiConnectionActive->getVal( u8, rssiCount ); printf(" Connection Active: %u\n", u8[i]); connectionActive |= u8[i]; } if ( connectionActive ) { printf("\n\n\nWARNING: At least one RSSI connection is active\n\n\n"); } } catch ( CPSWError &e ) { std::cerr << "CPSWError: " << e.getInfo().c_str() << std::endl; } catch ( const std::exception &e ) { std::cerr << "Error occurred: " << e.what() << std::endl; } catch ( ... ) { std::cerr << "Unknown failure occurred. Possible memory corruption" << std::endl; } }