Commit 5967e9f1 authored by Leon Hiemstra's avatar Leon Hiemstra

Now reading CCFG from ROM, not from file

parent 49002611
......@@ -262,7 +262,7 @@ CMDstatus CMD::Mread(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
generic.add_options()
("help,h", "shows this help text")
("offs", po::value<uint>(),"offset from base address (per dword) (default=0)")
("nvalues", po::value<uint>(),"number of dwords to read (default=all)")
("nvalues", po::value<int>(),"number of dwords to read (default=all)")
;
po::options_description hidden("hidden options");
hidden.add_options()
......@@ -298,7 +298,7 @@ CMDstatus CMD::Mread(int argc, char* argv[], TermOutput& termout, Serverdat *sd)
if(vm.count("file")) { addr_str = vm["file"].as<string>(); }
if(vm.count("offs")) { offs = vm["offs"].as<uint>(); }
if(vm.count("nvalues")) { nvalues = vm["nvalues"].as<int>(); }
if(sd->unb->read(termout, addr_str, offs,nvalues)) ret.status = CMD_STATUS_OK;
if(sd->unb->read(termout, addr_str, offs, nvalues)) ret.status = CMD_STATUS_OK;
} else throw runtime_error("missing argument(s)");
} catch(po::error& e) {
......
......@@ -125,7 +125,7 @@ bool Common::read(TermOutput& termout, const string addr, const uint offs, const
if(type == "mm") {
RegisterMap *regmap = node->get_RegisterMap(termout.strout);
uint32_t nvalues = (len<0 ? (regmap->getSpan(relative_addr) / sizeof(uint32_t)) : len);
uint32_t nvalues = (len<0 ? regmap->getSpan(relative_addr) : len);
std::vector<int> datavec;
if(node->mread(termout.strout, relative_addr, offs, datavec, nvalues)) {
retcnt++;
......
......@@ -49,7 +49,6 @@ class TCPCSSocket {
TCPCSSocket(int descr = -1);
~TCPCSSocket();
void Shutdown() { shutdown(sock,SHUT_RDWR); }
void Close() { close(sock); }
size_t rx(unsigned char* buf, size_t size) throw(const char*);
size_t _rx(unsigned char* buf, size_t size) throw(const char*);
size_t tx(const unsigned char* data, size_t size) throw(const char*);
......
......@@ -43,7 +43,6 @@ UNBos::UNBos(const std::string ipaddr)
bool UNBos::TransmitRead(const uint32_t opcode, const uint32_t addr, const uint nvalues)
{
//cout << "UNBos::TransmitRead() addr=" << (unsigned)addr << " nrvals=" << (unsigned)nvalues << endl;
size_t pktlength = sizeof(struct unbos_cmd_struct);
uint8_t *pkt = new uint8_t[pktlength];
memset(pkt, 0, pktlength);
......@@ -104,19 +103,20 @@ void random_sleep(double tmax_in_sec)
bool UNBos::Read(const uint32_t opcode, const uint32_t addr, const uint nvalues,
uint32_t *buf)
bool UNBos::Read(const uint32_t opcode, const uint32_t addr, const uint nvalues, uint32_t *buf)
{
if(buf==NULL || nvalues==0) throw runtime_error("UNBos::Read buf=NULL");
int retries=0;
int retstat=0;
uint nreceived=0;
cout << "UNBos::Read from addr=0x" << hex << addr << " span=" << dec << nvalues << endl;
while(nreceived < nvalues) {
uint _nvalues = nvalues-nreceived;
if(_nvalues>UCP_BLOCK_SZ) _nvalues=UCP_BLOCK_SZ;
uint32_t _addr=addr+(nreceived*sizeof(uint32_t));
uint32_t _addr=(addr) + (nreceived*sizeof(uint32_t));
while(retries < 3) {
TransmitRead(opcode, _addr, _nvalues);
......@@ -138,10 +138,6 @@ bool UNBos::Read(const uint32_t opcode, const uint32_t addr, const uint nvalues,
bool UNBos::TransmitWrite(const uint32_t opcode, const uint32_t addr, const uint nvalues,
const uint32_t *buf)
{
//cout << "UNBos::TransmitWrite() addr=" << (unsigned)addr << " nrvals=" << (unsigned)nvalues << endl;
//for(uint i=0;i<nvalues;i++) cout << (unsigned)buf[i] << " ";
//cout << endl;
size_t pktlength = sizeof(struct unbos_cmd_struct) + nvalues*sizeof(uint32_t);
uint8_t *pkt = new uint8_t[pktlength];
memset(pkt, 0, pktlength);
......@@ -192,11 +188,13 @@ bool UNBos::Write(const uint32_t opcode, const uint32_t addr, const uint nvalues
int retstat=0;
uint nsent=0;
cout << "UNBos::Write to addr=0x" << hex << addr << " span=" << dec << nvalues << endl;
while(nsent < nvalues) {
uint _nvalues = nvalues-nsent;
if(_nvalues>UCP_BLOCK_SZ) _nvalues=UCP_BLOCK_SZ;
uint32_t _addr=addr+(nsent*sizeof(uint32_t));
uint32_t _addr=(addr) + (nsent*sizeof(uint32_t));
while(retries < 3) {
TransmitWrite(opcode, _addr, _nvalues, &buf[nsent]);
......
......@@ -40,22 +40,14 @@ extern int debug;
Periph_system::Periph_system(UNBos &commdev, const string design_name) : unbos(commdev)
{
// TODO ----------------------------------------------^ needed as input?
// later read file from ROM
string ccfg_fname = design_name + ".ccfg";
cout << "ccfg filename: " << ccfg_fname << endl;
ifstream ifs;
ifs.open(ccfg_fname);
if (!ifs.is_open()) {
cerr << "Error opening config file: " << ccfg_fname << " using old version" << endl;
registerMap = new RegisterMap(read_reg_map()); // used old version style
} else {
registerMap = new RegisterMap(import_ccfg_file(ifs));
registerMap->add_register("dev/name", 0, 0, 0xffffffff, 0, "RO");
registerMap->add_register("dev/stamps", 0, 0, 0xffffffff, 0, "RO");
registerMap->add_register("dev/note", 0, 0, 0xffffffff, 0, "RO");
registerMap->add_register("dev/sensors", 0, 0, 0xffffffff, 0, "RO");
}
registerMap = new RegisterMap(read_reg_map());
// Add composite registers:
registerMap->add_register("dev/system", 0, 0, 0xffffffff, 0, "RO");
registerMap->add_register("dev/name", 0, 0, 0xffffffff, 0, "RO");
registerMap->add_register("dev/stamps", 0, 0, 0xffffffff, 0, "RO");
registerMap->add_register("dev/note", 0, 0, 0xffffffff, 0, "RO");
registerMap->add_register("dev/sensors", 0, 0, 0xffffffff, 0, "RO");
}
bool Periph_system::Read(const string addr_str, const uint32_t offset, const uint32_t nvalues, uint32_t *data_ptr)
......@@ -119,7 +111,6 @@ bool Periph_system::read_system_info(ostringstream& strs)
}
char str[1000];
// FIXME: get rid of magic constants in masks:
sprintf(str," g_sim = %d\n", ((data & 0x00000400) != 0)); strs << str;
sprintf(str," Firmware version = %d.%d\n",(data & 0x00F00000) >> 20,
(data & 0x000F0000) >> 16); strs << str;
sprintf(str," Hardware version = %d\n", ((data & 0x00000300) >> 8)); strs << str;
......@@ -166,7 +157,7 @@ bool Periph_system::mwrite(std::ostringstream& strs, const std::string addr,
string Periph_system::read_design_name(void)
{
uint32_t nof_design_name_regs = 8;
uint32_t nof_design_name_regs = 4;
uint32_t nvalues = nof_design_name_regs;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)+1];
bool retval = Read("mm/system/info/info", 2, nvalues, data);
......@@ -178,10 +169,10 @@ string Periph_system::read_design_name(void)
string Periph_system::read_design_note(void)
{
uint32_t nof_design_name_regs = 8;
uint32_t nof_design_name_regs = 4;
uint32_t nvalues = nof_design_name_regs;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)+1];
bool retval = Read("mm/system/info/info", 13, nvalues,data);
bool retval = Read("mm/system/info/info", 20, nvalues,data);
data[nvalues] = 0; // add end of string char
char *str_ptr = (char *)data;
string note = string(str_ptr);
......@@ -194,7 +185,7 @@ bool Periph_system::read_stamps(ostringstream& strs)
uint32_t nof_regs = 3;
uint32_t nvalues = nof_regs;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)+1];
bool retval = Read("mm/system/info/info", 10, nvalues, data);
bool retval = Read("mm/system/info/info", 15, nvalues, data);
strs << " Stamp: date=" << data[0] << endl;
strs << " Stamp: time=" << data[1] << endl;
......@@ -252,14 +243,11 @@ bool Periph_system::write_wdi_override(ostringstream& strs)
return Write("mm/wdi/wdi/reset_word", 0, 1, &data);
}
/*
* Obsolete function for backwards compatibility
*/
RegisterMap Periph_system::read_reg_map(void)
{
RegisterMap reg;
uint32_t nvalues = 1024;
uint32_t addr = reg.getValidAddr("mm/rom_system/info/info", 0, nvalues);
uint32_t nvalues = REG_ADDR_ROM_SYSTEM_SPAN;
uint32_t addr = REG_ADDR_ROM_SYSTEM;
uint32_t *data = new uint32_t[nvalues * sizeof(uint32_t)];
if(!unbos.readRegister(addr, nvalues, data)) {
delete[] data;
......@@ -267,40 +255,23 @@ RegisterMap Periph_system::read_reg_map(void)
}
for(uint i=0; i < nvalues; i++) {
/*
cout << "data[" << dec << i << "]=0x" << hex << std::setw(8) << std::setfill('0') << data[i] << " ";
for(int j=0;j<4;j++) {
char c = (char)(data[i]>>(8*j)) ;
if (c=='\0') printf("\\0"); else cout << c;
}
cout << endl;
*/
data[i] = ntohl(data[i]);
}
char *str_ptr = (char *)data;
string reg_map_str(str_ptr);
cout << "Periph_system::read_reg_map:\n" << reg_map_str << endl;
delete[] data;
istringstream vecstr(reg_map_str);
string regname;
uint base, span;
RegisterMap newRegisterMap;
try {
while (!vecstr.eof()) {
vecstr >> regname;
if (vecstr.fail() || vecstr.bad()) {
throw runtime_error("Invalid regname");
}
vecstr >> hex >> base;
vecstr >> dec >> span;
if (vecstr.fail() || vecstr.bad()) {
throw runtime_error("Invalid base/span");
}
if(base==0 || span==0) {
throw runtime_error("Corrupt base/span on "+regname+
" "+to_string(base)+" "+to_string(span));
}
newRegisterMap.add_register(regname, base, span, 0xffffffff, 0, "RW");
}
} catch(runtime_error& e) {
cerr << "Periph_system::read_reg_map: " << e.what() << endl;
syslog(LOG_ERR,"Periph_system::read_reg_map: %s\n", e.what());
throw;
}
return newRegisterMap;
istringstream iss_regmap(reg_map_str);
return ccfg_to_regmap(iss_regmap);
}
......@@ -87,7 +87,7 @@ std::vector<std::string> RegisterMap::getRegnames_full(std::string prefix)
uint32_t RegisterMap::getValidAddr(const std::string name, const uint32_t offset, const uint32_t size)
{
uint32_t _offset = offset * sizeof(uint32_t);
uint32_t end = (size + offset) * sizeof(uint32_t);
uint32_t end = (size + offset);// * sizeof(uint32_t);
uint32_t base = getBaseAddr(name);
uint32_t span = getSpan(name);
......
......@@ -23,6 +23,9 @@
#include <map>
#include <vector>
#define REG_ADDR_ROM_SYSTEM (0x10000)
#define REG_ADDR_ROM_SYSTEM_SPAN (8192)
class RegisterMap {
......
......@@ -31,7 +31,7 @@ using namespace std;
using namespace boost::numeric::ublas;
RegisterMap import_ccfg_file(std::ifstream& ifs)
RegisterMap ccfg_to_regmap(std::istringstream& iss)
{
RegisterMap regmap;
ostringstream err_str;
......@@ -60,7 +60,7 @@ RegisterMap import_ccfg_file(std::ifstream& ifs)
BlockRAM_re = string(RE_CCFG_LINE_BlockRAM);
char line[250];
while(ifs.getline(line, sizeof(line))) {
while(iss.getline(line, sizeof(line))) {
if (regex_match(line, comment_re)) {
//cout << "import_ccfg_file match: comment ok" << endl;
......@@ -75,14 +75,14 @@ RegisterMap import_ccfg_file(std::ifstream& ifs)
// DistrRAM 0x00000000 len=32 RO system info info
ss >> prefx;
ss >> hex >> base;
base *= 4; // to byte addresses
ss >> hex >> base; // in dword addresses
//base *= 4; // to byte addresses
ss >> c; // 'l'
ss >> c; // 'e'
ss >> c; // 'n'
ss >> c; // '='
ss >> dec >> span;
span *= 4; // to bytes
ss >> dec >> span; // in dwords
//span *= 4; // to bytes
ss >> perm;
ss >> peripheral;
ss >> regname;
......@@ -104,8 +104,8 @@ RegisterMap import_ccfg_file(std::ifstream& ifs)
// BitField 0x000000E0 b[31:0] WO ctrl pio_wdi nios_reset
ss >> prefx;
ss >> hex >> base;
base *= 4; // to byte addresses
ss >> hex >> base; // in dword addresses
//base *= 4; // to byte addresses
ss >> c; // 'b'
ss >> c; // '['
ss >> dec >> mask_to;
......@@ -121,8 +121,8 @@ RegisterMap import_ccfg_file(std::ifstream& ifs)
//cout << "mask_to=" << dec << mask_to << " mask_from=" << mask_from << endl;
//cout << " mask=0x" << hex << mask << endl;
span=1;
span *= 4; // to bytes
span = 1; // in dwords
//span *= 4; // to bytes
ss >> perm;
ss >> peripheral;
ss >> regname;
......@@ -142,14 +142,14 @@ RegisterMap import_ccfg_file(std::ifstream& ifs)
// BlockRAM 0x00001000 len=1024 RW eth1g eth data
ss >> prefx;
ss >> hex >> base;
base *= 4; // to byte addresses
ss >> hex >> base; // in dword addresses
//base *= 4; // to byte addresses
ss >> c; // 'l'
ss >> c; // 'e'
ss >> c; // 'n'
ss >> c; // '='
ss >> dec >> span;
span *= 4; // to bytes
ss >> dec >> span; // in dwords
//span *= 4; // to bytes
ss >> perm;
ss >> peripheral;
ss >> regname;
......@@ -164,10 +164,9 @@ RegisterMap import_ccfg_file(std::ifstream& ifs)
cerr << "import_ccfg_file: error! illegal line: [" << line << "]" << endl;
}
}
ifs.close();
//cout << "regmap:" << endl;
//regmap.print_screen();
cout << "regmap:" << endl;
regmap.print_screen();
return regmap;
}
......
......@@ -33,6 +33,6 @@
namespace ublas = boost::numeric::ublas;
RegisterMap import_ccfg_file(std::ifstream& ifs);
RegisterMap ccfg_to_regmap(std::istringstream& iss);
#endif
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