OpenCores
URL https://opencores.org/ocsvn/tv80/tv80/trunk

Subversion Repositories tv80

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /tv80/trunk
    from Rev 103 to Rev 104
    Reverse comparison

Rev 103 → Rev 104

/sc_env/app_localcfg/load_ihex.h
0,0 → 1,16
/*
* load_ihex.h
*
* Created on: Feb 15, 2011
* Author: hutch
*/
 
#ifndef LOAD_IHEX_H
#define LOAD_IHEX_H
 
#include <stdint.h>
 
int load_ihex (char *filename, uint8_t *buffer, int max);
 
#endif
 
/sc_env/app_localcfg/it_cfg_monitor.cpp
0,0 → 1,33
/*
* it_cfg_monitor.cpp
*
* Created on: Feb 15, 2011
* Author: hutch
*/
 
#include "it_cfg_monitor.h"
 
void it_cfg_monitor::event()
{
if (reset_n == 0) {
cfgo_trdy = 0;
cfgo_rd_data = 0;
} else {
if (cfgo_irdy) {
if (delay_cnt == -1)
delay_cnt = rand() % 10 + 1;
else delay_cnt--;
 
if (delay_cnt == 0) {
cfgo_trdy = 1;
if (cfgo_write) {
cfgo_rd_data = rand();
printf ("itmon: read value %x\n", cfgo_rd_data.read());
} else {
printf ("itmon: wrote value %x\n", cfgo_wr_data.read());
}
} else
cfgo_trdy = 0;
}
}
}
/sc_env/app_localcfg/it_cfg_driver.cpp
0,0 → 1,40
#include "it_cfg_driver.h"
 
void it_cfg_driver::add_queue (uint32_t d)
{
send_queue.push (d);
}
 
void it_cfg_driver::event()
{
if (reset_n == 0) {
cfgi_irdy = 0;
cfgi_addr = 0;
cfgi_write = 0;
cfgi_wr_data = 0;
} else {
if (cfgi_irdy == 0) {
// check the send queue
if (!send_queue.empty()) {
cfgi_irdy = 1;
cfgi_addr = addr++;
cfgi_wr_data = send_queue.front();
send_queue.pop();
cfgi_write = 1;
}
} else {
if (cfgi_trdy == 1) {
// check the send queue and send data
if (!send_queue.empty()) {
cfgi_irdy = 1;
cfgi_addr = addr++;
cfgi_wr_data = send_queue.front();
send_queue.pop();
cfgi_write = 1;
} else {
cfgi_irdy = 0;
}
}
}
}
}
/sc_env/app_localcfg/it_cfg_monitor.h
0,0 → 1,41
/*
* it_cfg_monitor.h
*
* Created on: Feb 15, 2011
* Author: hutch
*/
 
#ifndef IT_CFG_MONITOR_H_
#define IT_CFG_MONITOR_H_
 
#include <stdint.h>
#include "systemc.h"
#include <stdlib.h>
 
SC_MODULE(it_cfg_monitor)
{
private:
int delay_cnt;
 
public:
sc_in<bool> clk;
sc_in<bool> reset_n;
 
sc_in<bool> cfgo_irdy;
sc_out<bool> cfgo_trdy;
sc_in<uint32_t> cfgo_addr;
sc_in<bool> cfgo_write;
sc_in<uint32_t> cfgo_wr_data;
sc_out<uint32_t> cfgo_rd_data;
 
 
void event();
 
SC_CTOR(it_cfg_monitor) {
SC_METHOD(event);
sensitive << clk.pos();
delay_cnt = -1;
}
};
 
#endif /*IT_CFG_monitor_H_*/
/sc_env/app_localcfg/app_env_top.cpp
0,0 → 1,157
#include "systemc.h"
#include "systemperl.h"
//#include "env_memory.h"
 
//#include "SpTraceVcd.h"
#include "verilated_vcd_sc.h"
#include <unistd.h>
#include "it_cfg_driver.h"
#include "it_cfg_monitor.h"
#include "Vlcfg.h"
#include "load_ihex.h"
 
extern char *optarg;
extern int optind, opterr, optopt;
 
#define FILENAME_SZ 80
#define MAX_MEM_SIZE 8192
 
int sc_main(int argc, char *argv[])
{
bool dumping = false;
bool memfile = false;
int index;
char dumpfile_name[FILENAME_SZ];
char mem_src_name[FILENAME_SZ];
uint8_t memory[MAX_MEM_SIZE];
VerilatedVcdSc *tfp;
//z80_decoder dec0 ("dec0");
 
sc_clock clk("clk125", 8, SC_NS, 0.5);
 
sc_signal<bool> reset_n;
sc_signal<bool> lcfg_init;
sc_signal<bool> lcfg_proc_reset;
 
sc_signal<bool> cfgi_irdy;
sc_signal<bool> cfgi_trdy;
sc_signal<uint32_t> cfgi_addr;
sc_signal<bool> cfgi_write;
sc_signal<uint32_t> cfgi_wr_data;
sc_signal<uint32_t> cfgi_rd_data;
 
// outgoing config interface to system
// configuration bus
sc_signal<bool> cfgo_irdy;
sc_signal<bool> cfgo_trdy;
sc_signal<uint32_t> cfgo_addr;
sc_signal<bool> cfgo_write;
sc_signal<uint32_t> cfgo_wr_data;
sc_signal<uint32_t> cfgo_rd_data;
 
// clear program memory
for (int i=0; i<MAX_MEM_SIZE; i++) memory[i] = 0;
 
while ( (index = getopt(argc, argv, "d:i:k")) != -1) {
printf ("DEBUG: getopt optind=%d index=%d char=%c\n", optind, index, (char) index);
if (index == 'd') {
strncpy (dumpfile_name, optarg, FILENAME_SZ);
dumping = true;
printf ("VCD dump enabled to %s\n", dumpfile_name);
} else if (index == 'i') {
strncpy (mem_src_name, optarg, FILENAME_SZ);
memfile = true;
}
}
 
Vlcfg lcfg ("lcfg");
lcfg.clk (clk);
lcfg.reset_n(reset_n);
lcfg.lcfg_init (lcfg_init);
lcfg.lcfg_proc_reset (lcfg_proc_reset);
 
lcfg.cfgi_irdy(cfgi_irdy);
lcfg.cfgi_trdy(cfgi_trdy);
lcfg.cfgi_addr(cfgi_addr);
lcfg.cfgi_write(cfgi_write);
lcfg.cfgi_rd_data(cfgi_rd_data);
lcfg.cfgi_wr_data(cfgi_wr_data);
 
lcfg.cfgo_irdy(cfgo_irdy);
lcfg.cfgo_trdy(cfgo_trdy);
lcfg.cfgo_addr(cfgo_addr);
lcfg.cfgo_write(cfgo_write);
lcfg.cfgo_rd_data(cfgo_rd_data);
lcfg.cfgo_wr_data(cfgo_wr_data);
 
it_cfg_driver driver ("driver");
driver.clk (clk);
driver.reset_n(reset_n);
 
driver.cfgi_irdy(cfgi_irdy);
driver.cfgi_trdy(cfgi_trdy);
driver.cfgi_addr(cfgi_addr);
driver.cfgi_write(cfgi_write);
driver.cfgi_rd_data(cfgi_rd_data);
driver.cfgi_wr_data(cfgi_wr_data);
 
it_cfg_monitor monitor ("monitor");
monitor.clk (clk);
monitor.reset_n(reset_n);
 
monitor.cfgo_irdy(cfgo_irdy);
monitor.cfgo_trdy(cfgo_trdy);
monitor.cfgo_addr(cfgo_addr);
monitor.cfgo_write(cfgo_write);
monitor.cfgo_rd_data(cfgo_rd_data);
monitor.cfgo_wr_data(cfgo_wr_data);
 
 
//env_memory env_memory0("env_memory0");
 
// Start Verilator traces
if (dumping) {
Verilated::traceEverOn(true);
tfp = new VerilatedVcdSc;
lcfg.trace (tfp, 99);
tfp->open (dumpfile_name);
}
 
// check for command line argument
if (memfile) {
int max, bused = 0;
uint32_t cword;
max = load_ihex (mem_src_name, memory, MAX_MEM_SIZE);
printf ("Loading IHEX file %s, max addr=%d\n", mem_src_name, max);
while (bused <= max) {
cword = 0;
for (int i=0; i<4; i++) cword |= (memory[bused++] << (i*8));
printf ("Queueing %x\n", cword);
driver.add_queue (cword);
}
}
 
// set reset to 0 before sim start
reset_n.write (0);
lcfg_proc_reset.write(1);
 
//sc_time *runtime = new sc_time(100, SC_NS);
sc_time time100(100, SC_NS);
sc_start(time100);
 
reset_n.write (1);
 
//delete runtime; runtime = new sc_time (1000, SC_NS);
sc_start (sc_time(2500,SC_NS));
lcfg_proc_reset.write(0);
 
sc_start (sc_time(5000, SC_NS));
 
/*
sc_close_vcd_trace_file (trace_file);
*/
if (dumping)
tfp->close();
 
return 0;
}
/sc_env/app_localcfg/it_cfg_driver.h
0,0 → 1,42
#ifndef IT_CFG_DRIVER_H_
#define IT_CFG_DRIVER_H_
 
#include <stdint.h>
#include "systemc.h"
#include <stdlib.h>
#include <queue>
 
using namespace std;
 
SC_MODULE(it_cfg_driver)
{
private:
queue<uint32_t> send_queue;
int addr;
//uint32_t *send_queue;
//int q_sz, q_rptr;
 
public:
sc_in<bool> clk;
sc_in<bool> reset_n;
 
sc_out<bool> cfgi_irdy;
sc_in<bool> cfgi_trdy;
sc_out<uint32_t> cfgi_addr;
sc_out<bool> cfgi_write;
sc_out<uint32_t> cfgi_wr_data;
sc_in<uint32_t> cfgi_rd_data;
 
 
void event();
 
SC_CTOR(it_cfg_driver) {
SC_METHOD(event);
sensitive << clk.pos();
addr = 0;
}
 
void add_queue (uint32_t d);
};
 
#endif /*IT_CFG_DRIVER_H_*/
/sc_env/app_localcfg/load_ihex.cpp
0,0 → 1,64
/*
* load_ihex.cpp
*
* Created on: Feb 15, 2011
* Author: hutch
*/
 
#include "load_ihex.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
 
int inline readline(FILE *fh, char *buf)
{
int c = 1, cnt = 0;
 
if (feof(fh)) {
*buf = (char) 0;
return 0;
}
while (c) {
c = fread (buf, 1, 1, fh);
cnt++;
if (c && (*buf == '\n')) {
buf++;
*buf = (char) 0;
c = 0;
}
else buf++;
}
return cnt;
}
 
 
int load_ihex(char *filename, uint8_t *buffer, int max)
{
FILE *fh;
char line[80];
char *lp;
int rlen, addr, rtyp, databyte;
int rv;
int dcount = 0;
int highest = 0;
 
fh = fopen (filename, "r");
 
rv = readline (fh, line);
while (strlen(line) > 0) {
sscanf (line, ":%02x%04x%02x", &rlen, &addr, &rtyp);
lp = line + 9;
for (int c=0; c<rlen; c++) {
sscanf (lp, "%02x", &databyte);
lp += 2;
buffer[addr+c] = databyte; dcount++;
assert (dcount < max);
if ((addr+c) > highest) highest = addr+c;
}
rv = readline (fh, line);
}
 
fclose (fh);
printf ("ENVMEM : Read %d bytes from %s\n", dcount, filename);
return (highest);
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.