Added entire system incl. terminal and MCP3008 ADC connected via SPI

This commit is contained in:
2018-07-23 22:15:38 +02:00
parent a899d30556
commit 100822810f
18 changed files with 423 additions and 50 deletions

View File

@ -0,0 +1,47 @@
/*
* mcp3008.h
*
* Created on: 17.07.2018
* Author: eyck
*/
#ifndef RISCV_SC_INCL_SYSC_GENERAL_MCP3008_H_
#define RISCV_SC_INCL_SYSC_GENERAL_MCP3008_H_
#include "scc/signal_target_mixin.h"
#include "scc/signal_initiator_mixin.h"
#include "sysc/tlm_extensions.h"
#include <tlm/tlm_signal.h>
#include "cci_configuration"
#include <sysc/utils/sc_vector.h>
#include <sysc/kernel/sc_module.h>
namespace sysc {
class mcp3008: public sc_core::sc_module {
public:
SC_HAS_PROCESS(mcp3008);
scc::tlm_signal_logic_in sck_i;
scc::tlm_signal_logic_out miso_o;
scc::tlm_signal_logic_in mosi_i;
scc::tlm_signal_logic_in cs_i;
sc_core::sc_in<double> vref_i;
sc_core::sc_vector<sc_core::sc_in<double>> ch_i;
mcp3008(sc_core::sc_module_name nm);
virtual ~mcp3008();
private:
tlm::tlm_sync_enum receive(tlm::tlm_signal_gp<sc_dt::sc_logic> &, tlm::tlm_phase &, sc_core::sc_time &);
void do_conversion();
unsigned idx, rx_bits;
std::array<uint8_t, 3> rx_bytes, tx_bytes;
sc_dt::sc_logic mosi_v, miso_v, cs_v;
sysc::tlm_signal_spi_extension* ext, tx_ext;
sc_core::sc_time last_tx_start;
};
} /* namespace sysc */
#endif /* RISCV_SC_INCL_SYSC_GENERAL_MCP3008_H_ */

View File

@ -10,6 +10,7 @@
#include "sysc/SiFive/platform.h"
#include "sysc/General/terminal.h"
#include "sysc/General/mcp3008.h"
#include <systemc>
namespace sysc {
@ -24,8 +25,11 @@ public:
private:
sc_core::sc_vector<tlm::tlm_signal<sc_dt::sc_logic>> s_gpio;
sc_core::sc_signal<bool> s_rst_n;
sc_core::sc_signal<double> s_vref;
sc_core::sc_vector<sc_core::sc_signal<double>> s_ana;
sysc::platform i_platform;
sysc::terminal i_terminal;
sysc::mcp3008 i_adc;
void gen_por();
};

View File

@ -32,8 +32,10 @@ public:
cci::cci_param<bool> write_to_ws;
protected:
std::vector<uint8_t> queue;
void before_end_of_elaboration();
void receive(tlm::tlm_signal_gp<sc_dt::sc_logic>& gp, sc_core::sc_time& delay);
std::vector<uint8_t> queue;
std::shared_ptr<sysc::WsHandler> handler;
sc_core::sc_time last_tx_start=sc_core::SC_ZERO_TIME;
};