From 7c263419a88682663788170edb2b845fd5a985bc Mon Sep 17 00:00:00 2001 From: mariusmonton Date: Sun, 13 Jan 2019 18:39:35 +0100 Subject: [PATCH] documentation --- README.md | 7 ++++--- inc/Timer.h | 29 +++++++++++++++++++++++------ src/Timer.cpp | 17 +---------------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 6ee8ebf..4898096 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Brief description of the modules: * Simulator: Top-level entity that builds & starts the simulation * BusCtrl: Simple bus manager * Trace: Simple trace peripheral +* Timer: Simple IRQ programable real-time counter peripheral Helper classes: * Performance: Performance indicators stores here (singleton class) @@ -90,9 +91,9 @@ In the asm directory there are some basic assembly examples. I "compile" one file with the follwing command: ``` $ cd asm -$ riscv32-unknown-linux-gnu-as EternalLoop.asm -o EternalLoop.o -$ riscv32-unknown-linux-gnu-ld -T ../my_linker_script.ld EternalLoop.o -o EternalLoop.elf -$ objcopy -O ihex EternalLoop.elf EternalLoop.hex +$ riscv32-unknown-elf-as EternalLoop.asm -o EternalLoop.o +$ riscv32-unknown-elf-ld -T ../my_linker_script.ld EternalLoop.o -o EternalLoop.elf +$ riscv32-unknown-elf-objcopy -O ihex EternalLoop.elf EternalLoop.hex $ cd .. $ ./RISCV_SCTLM asm/EternalLoop.hex ``` diff --git a/inc/Timer.h b/inc/Timer.h index e33140e..7f3de2f 100644 --- a/inc/Timer.h +++ b/inc/Timer.h @@ -36,19 +36,36 @@ public: tlm_utils::simple_target_socket socket; sc_out timer_irq; - // Constructor + /** + * + * @brief Constructor + * @param name module name + */ Timer(sc_module_name name); + /** + * @brief Waits for event timer_event and triggers an IRQ + * + * Waits for event timer_event and triggers an IRQ (if it is not already + * triggered). + * After that, it posts the timer_event to 20 ns in the future to clear the IRQ + * line. + * + */ void run(); - // TLM-2 blocking transport method + /** + * + * @brief TLM-2.0 socket implementaiton + * @param trans TLM-2.0 transaction + * @param delay transactino delay time + */ virtual void b_transport( tlm::tlm_generic_payload& trans, sc_time& delay ); private: - sc_uint<64> m_mtime; - sc_uint<64> m_mtimecmp; - sc_event timer_event; - bool irq_value; + sc_uint<64> m_mtime; /**< mtime register */ + sc_uint<64> m_mtimecmp; /**< mtimecmp register */ + sc_event timer_event; /**< event */ }; #endif diff --git a/src/Timer.cpp b/src/Timer.cpp index cc0e927..60f528f 100644 --- a/src/Timer.cpp +++ b/src/Timer.cpp @@ -2,22 +2,16 @@ SC_HAS_PROCESS(Timer); Timer::Timer(sc_module_name name): sc_module(name) - ,socket("timer_socket"), m_mtime(0), m_mtimecmp(0), irq_value(false) { + ,socket("timer_socket"), m_mtime(0), m_mtimecmp(0) { socket.register_b_transport(this, &Timer::b_transport); SC_THREAD(run); } -/** - * @brief Waits for event timer_event and triggers an IRQ - * - */ void Timer::run() { while(true) { - // timer_event.notify( sc_time(10000, SC_NS) ); - wait(timer_event); if (timer_irq.read() == true) { @@ -32,12 +26,6 @@ void Timer::run() { } } -/** - * - * @brief TLM-2.0 socket implementaiton - * @param trans TLM-2.0 transaction - * @param delay transactino delay time - */ void Timer::b_transport( tlm::tlm_generic_payload& trans, sc_time& delay ) { tlm::tlm_command cmd = trans.get_command(); sc_dt::uint64 addr = trans.get_address(); @@ -66,9 +54,6 @@ void Timer::b_transport( tlm::tlm_generic_payload& trans, sc_time& delay ) { m_mtimecmp.range(63,32) = aux_value; // notify needs relative time, mtimecmp works in absolute time notify_time = m_mtimecmp - m_mtime; - // cout << "time: " << sc_core::sc_time_stamp() - // << ": interrupt will be in " << dec << notify_time - // << " ns" << endl; timer_event.notify( sc_time(notify_time, SC_NS) ); break; }