2019-01-13 08:30:49 +08:00
|
|
|
/*!
|
|
|
|
\file Timer.h
|
|
|
|
\brief Basic TLM-2 Timer module
|
|
|
|
\author Màrius Montón
|
|
|
|
\date January 2019
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TIMER_H__
|
|
|
|
#define __TIMER_H__
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#define SC_INCLUDE_DYNAMIC_PROCESSES
|
|
|
|
|
|
|
|
#include "systemc"
|
|
|
|
|
|
|
|
#include "tlm.h"
|
|
|
|
#include "tlm_utils/simple_target_socket.h"
|
|
|
|
|
|
|
|
#include "BusCtrl.h"
|
|
|
|
|
|
|
|
using namespace sc_core;
|
|
|
|
using namespace sc_dt;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Simple timer peripheral
|
|
|
|
*
|
|
|
|
* It runs a 1 ns (nanoseconds) pace
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class Timer: sc_module {
|
|
|
|
public:
|
|
|
|
// TLM-2 socket, defaults to 32-bits wide, base protocol
|
|
|
|
tlm_utils::simple_target_socket<Timer> socket;
|
2019-01-22 19:43:05 +08:00
|
|
|
|
|
|
|
tlm_utils::simple_initiator_socket<Timer> irq_line;
|
|
|
|
//sc_out<bool> timer_irq;
|
2019-01-13 08:30:49 +08:00
|
|
|
|
2019-01-14 01:39:35 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Constructor
|
|
|
|
* @param name module name
|
|
|
|
*/
|
2019-01-13 08:30:49 +08:00
|
|
|
Timer(sc_module_name name);
|
|
|
|
|
2019-01-14 01:39:35 +08:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
*/
|
2019-01-13 08:30:49 +08:00
|
|
|
void run();
|
|
|
|
|
2019-01-14 01:39:35 +08:00
|
|
|
/**
|
|
|
|
*
|
2019-02-11 22:52:48 +08:00
|
|
|
* @brief TLM-2.0 socket implementation
|
2019-01-14 01:39:35 +08:00
|
|
|
* @param trans TLM-2.0 transaction
|
2019-02-11 22:52:48 +08:00
|
|
|
* @param delay transaction delay time
|
2019-01-14 01:39:35 +08:00
|
|
|
*/
|
2019-01-13 08:30:49 +08:00
|
|
|
virtual void b_transport( tlm::tlm_generic_payload& trans, sc_time& delay );
|
|
|
|
|
|
|
|
private:
|
2019-01-14 01:39:35 +08:00
|
|
|
sc_uint<64> m_mtime; /**< mtime register */
|
|
|
|
sc_uint<64> m_mtimecmp; /**< mtimecmp register */
|
|
|
|
sc_event timer_event; /**< event */
|
2019-01-13 08:30:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|