Work on bit/mcureg/mcubase

This commit is contained in:
Xavier Del Campo Romero 2020-09-25 03:41:33 +02:00
parent 403a94c241
commit ae58a8d1f5
10 changed files with 150 additions and 40 deletions

View File

@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.0)
project(hw_html CXX)
add_definitions(-g)
add_executable(${PROJECT_NAME} html.cpp main.cpp mcureg.cpp)
add_executable(${PROJECT_NAME} html.cpp main.cpp mcubase.cpp bit.cpp
mcureg.cpp)
add_library(xmlParser xmlParser/xmlParser.cpp)
add_subdirectory(CTML)
target_include_directories(xmlParser PUBLIC xmlParser)

16
hw_html/bit.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <bit.hpp>
#include <iostream>
bit::bit(const std::string &name, const std::string &access,
const std::string &pos) :
mcubase(name, access),
off(get(pos))
{
}
struct bit::off bit::get(const std::string &pos)
{
struct off off = {0};
std::cout << pos + "\n";
return off;
}

20
hw_html/bit.hpp Normal file
View File

@ -0,0 +1,20 @@
#ifndef BIT_HPP
#define BIT_HPP
#include <mcubase.hpp>
#include <string>
class bit : public mcubase
{
public:
bit(const std::string &name, const std::string &access,
const std::string &pos);
virtual ~bit() = default;
protected:
const struct off {unsigned int upper, lower;} off;
static struct off get(const std::string &pos);
std::string comment;
};
#endif /* BIT_HPP */

View File

@ -1,4 +1,5 @@
#include "html.hpp"
#include <html.hpp>
#include <mcubase.hpp>
#include <ctml.hpp>
#include <stdio.h>
#include <string.h>
@ -41,3 +42,8 @@ html::error html::open(const char *const path)
return html::OK;
}
html::error html::add(const mcubase &reg)
{
return html::OK;
}

View File

@ -1,4 +1,8 @@
#ifndef HTML_HPP
#define HTML_HPP
#include <ctml.hpp>
#include <mcubase.hpp>
#include <stdio.h>
class html
@ -15,7 +19,10 @@ public:
html();
virtual ~html();
error open(const char *path);
error add(const mcubase &reg);
protected:
FILE *f;
};
#endif /* HTML_HPP */

View File

@ -1,5 +1,6 @@
#include "html.hpp"
#include "mcureg.hpp"
#include "bit.hpp"
#include <xmlParser.h>
#include <string>
#include <stdio.h>
@ -58,11 +59,13 @@ int main(const int argc, const char *const argv[])
{
const XMLNode reg = module.getChildNode("reg", &n);
const char *const name = reg.getAttribute("name");
const char *const access = reg.getAttribute("protect");
if (!name)
if (!name || !access)
continue;
printf("\treg %s\n", name);
mcureg mcureg(name, access);
int n = 0;
@ -70,41 +73,17 @@ int main(const int argc, const char *const argv[])
{
const XMLNode bits = reg.getChildNode("bits", &n);
const char *const name = bits.getAttribute("name");
mcureg::access access = mcureg::UNDEF;
const char *const access_cs = bits.getAttribute("access");
const char *const access = bits.getAttribute("access");
const char *const pos = bits.getAttribute("pos");
const char *const rst = bits.getAttribute("rst");
if (!access_cs)
printf("\t\tbit=%s, access=%s, pos=%s, rst=%s\n",
name, access, pos, rst);
if (!name || !access || !pos || !rst)
continue;
const std::string access_s = access_cs;
if (access_s == "rsv")
access = mcureg::RSV;
else if (access_s == "w1c")
access = mcureg::W1C;
else if (access_s == "w1s")
access = mcureg::W1S;
else if (access_s == "rc")
access = mcureg::RC;
else if (access_s == "rs")
access = mcureg::RS;
else if (access_s == "rw")
access = mcureg::RW;
else if (access_s == "c")
access = mcureg::C;
else if (access_s == "s")
access = mcureg::S;
else if (access_s == "r")
access = mcureg::R;
else if (access_s == "w")
access = mcureg::W;
if (access == mcureg::UNDEF)
fprintf(stderr, "%s: undefined access\n", name);
else
{
printf("\t\t%s, access %s\n", name, access_cs);
}
mcureg.add(bit(name, access, pos));
}
}
}

View File

@ -1,5 +1,36 @@
#include "mcureg.hpp"
#include "mcubase.hpp"
#include <string>
#include <stdint.h>
mcureg::mcureg(mcureg::access access)
mcubase::mcubase(const std::string &name, const std::string &access) :
name(name),
acc(get(access)),
rst(0)
{
}
mcubase::access mcubase::get(const std::string &access)
{
if (access == "rsv")
return mcubase::RSV;
else if (access == "w1c")
return mcubase::W1C;
else if (access == "w1s")
return mcubase::W1S;
else if (access == "rc")
return mcubase::RC;
else if (access == "rs")
return mcubase::RS;
else if (access == "rw")
return mcubase::RW;
else if (access == "c")
return mcubase::C;
else if (access == "s")
return mcubase::S;
else if (access == "r")
return mcubase::R;
else if (access == "w")
return mcubase::W;
return mcubase::UNDEF;
}

View File

@ -1,8 +1,23 @@
class mcureg
#ifndef MCUBASE_HPP
#define MCUBASE_HPP
#include <stdint.h>
#include <string>
class mcubase
{
public:
enum access {UNDEF, C, R, S, W, RC, RS, RW, RSV, W1C, W1S};
mcubase(const std::string &name, const std::string &access);
explicit mcureg(access access);
virtual ~mcureg() = default;
protected:
mcubase() = default;
const std::string &name;
const access acc;
uint32_t rst;
private:
static access get(const std::string &access);
};
#endif /* MCUBASE_HPP */

15
hw_html/mcureg.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <mcureg.hpp>
#include <mcubase.hpp>
#include <bit.hpp>
#include <list>
#include <string>
mcureg::mcureg(const std::string &name, const std::string &access) :
mcubase(name, access)
{
}
void mcureg::add(const bit &bit)
{
bits.push_back(bit);
}

20
hw_html/mcureg.hpp Normal file
View File

@ -0,0 +1,20 @@
#ifndef MCUREG_HPP
#define MCUREG_HPP
#include <mcubase.hpp>
#include <bit.hpp>
#include <list>
#include <string>
class mcureg : public mcubase
{
public:
mcureg(const std::string &name, const std::string &access);
virtual ~mcureg() = default;
void add(const bit &);
protected:
std::list<bit> bits;
};
#endif /* MCUREG_HPP */