No nested namespaces

This commit is contained in:
mariusmonton 2021-11-29 22:21:20 +01:00
parent 8d3d3bb35b
commit d430b23fc6
4 changed files with 158 additions and 152 deletions

View File

@ -21,51 +21,53 @@
#include "BusCtrl.h" #include "BusCtrl.h"
namespace riscv_tlm::peripherals { namespace riscv_tlm {
namespace peripherals {
/** /**
* @brief Simple timer peripheral * @brief Simple timer peripheral
* *
* It runs a 1 ns (nanoseconds) pace * It runs a 1 ns (nanoseconds) pace
* *
*/ */
class Timer : sc_core::sc_module { class Timer : sc_core::sc_module {
public: public:
// TLM-2 socket, defaults to 32-bits wide, base protocol // TLM-2 socket, defaults to 32-bits wide, base protocol
tlm_utils::simple_target_socket<Timer> socket; tlm_utils::simple_target_socket<Timer> socket;
tlm_utils::simple_initiator_socket<Timer> irq_line; tlm_utils::simple_initiator_socket<Timer> irq_line;
/** /**
* *
* @brief Constructor * @brief Constructor
* @param name module name * @param name module name
*/ */
explicit Timer(sc_core::sc_module_name const &name); explicit Timer(sc_core::sc_module_name const &name);
/** /**
* @brief Waits for event timer_event and triggers an IRQ * @brief Waits for event timer_event and triggers an IRQ
* *
* Waits for event timer_event and triggers an IRQ (if it is not already * Waits for event timer_event and triggers an IRQ (if it is not already
* triggered). * triggered).
* After that, it posts the timer_event to 20 ns in the future to clear the IRQ * After that, it posts the timer_event to 20 ns in the future to clear the IRQ
* line. * line.
* *
*/ */
[[noreturn]] void run(); [[noreturn]] void run();
/** /**
* *
* @brief TLM-2.0 socket implementation * @brief TLM-2.0 socket implementation
* @param trans TLM-2.0 transaction * @param trans TLM-2.0 transaction
* @param delay transaction delay time * @param delay transaction delay time
*/ */
virtual void b_transport(tlm::tlm_generic_payload &trans, virtual void b_transport(tlm::tlm_generic_payload &trans,
sc_core::sc_time &delay); sc_core::sc_time &delay);
private: private:
sc_dt::sc_uint<64> m_mtime; /**< mtime register */ sc_dt::sc_uint<64> m_mtime; /**< mtime register */
sc_dt::sc_uint<64> m_mtimecmp; /**< mtimecmp register */ sc_dt::sc_uint<64> m_mtimecmp; /**< mtimecmp register */
sc_core::sc_event timer_event; /**< event */ sc_core::sc_event timer_event; /**< event */
}; };
}
} }
#endif #endif

View File

@ -19,46 +19,48 @@
#include "tlm.h" #include "tlm.h"
#include "tlm_utils/simple_target_socket.h" #include "tlm_utils/simple_target_socket.h"
namespace riscv_tlm::peripherals { namespace riscv_tlm {
/** namespace peripherals {
* @brief Simple trace peripheral
*
* This peripheral outputs to cout any character written to its unique register
*/
class Trace : sc_core::sc_module {
public:
/** /**
* @brief Bus socket * @brief Simple trace peripheral
*/ *
tlm_utils::simple_target_socket<Trace> socket; * This peripheral outputs to cout any character written to its unique register
*/
class Trace : sc_core::sc_module {
public:
/** /**
* @brief Constructor * @brief Bus socket
* @param name Module name */
*/ tlm_utils::simple_target_socket<Trace> socket;
explicit Trace(sc_core::sc_module_name const &name);
/** /**
* @brief Destructor * @brief Constructor
*/ * @param name Module name
~Trace() override; */
explicit Trace(sc_core::sc_module_name const &name);
private: /**
* @brief Destructor
*/
~Trace() override;
// TLM-2 blocking transport method private:
virtual void b_transport(tlm::tlm_generic_payload &trans,
sc_core::sc_time &delay);
void xtermLaunch(char *slaveName) const; // TLM-2 blocking transport method
virtual void b_transport(tlm::tlm_generic_payload &trans,
sc_core::sc_time &delay);
void xtermKill(); void xtermLaunch(char *slaveName) const;
void xtermSetup(); void xtermKill();
int ptSlave{}; void xtermSetup();
int ptMaster{};
int xtermPid{}; int ptSlave{};
}; int ptMaster{};
int xtermPid{};
};
}
} }
#endif #endif

View File

@ -9,7 +9,8 @@
#include <cstdint> #include <cstdint>
#include "Timer.h" #include "Timer.h"
namespace riscv_tlm::peripherals { namespace riscv_tlm {
namespace peripherals {
SC_HAS_PROCESS(Timer); SC_HAS_PROCESS(Timer);
Timer::Timer(sc_core::sc_module_name const &name) : Timer::Timer(sc_core::sc_module_name const &name) :
@ -101,5 +102,5 @@ namespace riscv_tlm::peripherals {
trans.set_response_status(tlm::TLM_OK_RESPONSE); trans.set_response_status(tlm::TLM_OK_RESPONSE);
} }
}
} }

View File

@ -20,97 +20,98 @@
#include "Trace.h" #include "Trace.h"
namespace riscv_tlm::peripherals { namespace riscv_tlm {
namespace peripherals {
void Trace::xtermLaunch(char *slaveName) const { void Trace::xtermLaunch(char *slaveName) const {
char *arg; char *arg;
char *fin = &(slaveName[strlen(slaveName) - 2]); char *fin = &(slaveName[strlen(slaveName) - 2]);
if (nullptr == strchr(fin, '/')) { if (nullptr == strchr(fin, '/')) {
arg = new char[2 + 1 + 1 + 20 + 1]; arg = new char[2 + 1 + 1 + 20 + 1];
sprintf(arg, "-S%c%c%d", fin[0], fin[1], ptMaster); sprintf(arg, "-S%c%c%d", fin[0], fin[1], ptMaster);
} else { } else {
char *slaveBase = ::basename(slaveName); char *slaveBase = ::basename(slaveName);
arg = new char[2 + strlen(slaveBase) + 1 + 20 + 1]; arg = new char[2 + strlen(slaveBase) + 1 + 20 + 1];
sprintf(arg, "-S%s/%d", slaveBase, ptMaster); sprintf(arg, "-S%s/%d", slaveBase, ptMaster);
}
char *argv[3];
argv[0] = (char *) ("xterm");
argv[1] = arg;
argv[2] = nullptr;
execvp("xterm", argv);
} }
char *argv[3]; void Trace::xtermKill() {
argv[0] = (char *) ("xterm");
argv[1] = arg;
argv[2] = nullptr;
execvp("xterm", argv); if (-1 != ptSlave) { // Close down the slave
} close(ptSlave); // Close the FD
ptSlave = -1;
}
void Trace::xtermKill() { if (-1 != ptMaster) { // Close down the master
close(ptMaster);
ptMaster = -1;
}
if (-1 != ptSlave) { // Close down the slave if (xtermPid > 0) { // Kill the terminal
close(ptSlave); // Close the FD kill(xtermPid, SIGKILL);
ptSlave = -1; waitpid(xtermPid, nullptr, 0);
}
if (-1 != ptMaster) { // Close down the master
close(ptMaster);
ptMaster = -1;
}
if (xtermPid > 0) { // Kill the terminal
kill(xtermPid, SIGKILL);
waitpid(xtermPid, nullptr, 0);
}
}
void Trace::xtermSetup() {
ptMaster = open("/dev/ptmx", O_RDWR);
if (ptMaster != -1) {
grantpt(ptMaster);
unlockpt(ptMaster);
char *ptSlaveName = ptsname(ptMaster);
ptSlave = open(ptSlaveName, O_RDWR); // In and out are the same
struct termios termInfo{};
tcgetattr(ptSlave, &termInfo);
termInfo.c_lflag &= ~ECHO;
termInfo.c_lflag &= ~ICANON;
tcsetattr(ptSlave, TCSADRAIN, &termInfo);
xtermPid = fork();
if (xtermPid == 0) {
xtermLaunch(ptSlaveName);
} }
} }
void Trace::xtermSetup() {
ptMaster = open("/dev/ptmx", O_RDWR);
if (ptMaster != -1) {
grantpt(ptMaster);
unlockpt(ptMaster);
char *ptSlaveName = ptsname(ptMaster);
ptSlave = open(ptSlaveName, O_RDWR); // In and out are the same
struct termios termInfo{};
tcgetattr(ptSlave, &termInfo);
termInfo.c_lflag &= ~ECHO;
termInfo.c_lflag &= ~ICANON;
tcsetattr(ptSlave, TCSADRAIN, &termInfo);
xtermPid = fork();
if (xtermPid == 0) {
xtermLaunch(ptSlaveName);
}
}
}
SC_HAS_PROCESS(Trace);
Trace::Trace(sc_core::sc_module_name const &name) :
sc_module(name), socket("socket") {
socket.register_b_transport(this, &Trace::b_transport);
xtermSetup();
}
Trace::~Trace() {
xtermKill();
}
void Trace::b_transport(tlm::tlm_generic_payload &trans,
sc_core::sc_time &delay) {
unsigned char *ptr = trans.get_data_ptr();
delay = sc_core::SC_ZERO_TIME;
ssize_t a = write(ptSlave, ptr, 1);
(void) a;
trans.set_response_status(tlm::TLM_OK_RESPONSE);
}
} }
SC_HAS_PROCESS(Trace);
Trace::Trace(sc_core::sc_module_name const &name) :
sc_module(name), socket("socket") {
socket.register_b_transport(this, &Trace::b_transport);
xtermSetup();
}
Trace::~Trace() {
xtermKill();
}
void Trace::b_transport(tlm::tlm_generic_payload &trans,
sc_core::sc_time &delay) {
unsigned char *ptr = trans.get_data_ptr();
delay = sc_core::SC_ZERO_TIME;
ssize_t a = write(ptSlave, ptr, 1);
(void) a;
trans.set_response_status(tlm::TLM_OK_RESPONSE);
}
} }