#include <stdio.h>
#define AHB_HTRANS_IDLE 0x00
#define AHB_HTRANS_BUSY 0x01
#define AHB_HTRANS_NONSEQ 0x02
#define AHB_HTRANS_SEQ 0x03
#define AHB_HBURST_SINGLE 0x0
#define AHB_HBURST_INCR 0x1
#define AHB_HBURST_WRAP4 0x2
#define AHB_HBURST_INCR4 0x3
#define AHB_HBURST_WRAP8 0x4
#define AHB_HBURST_INCR8 0x5
#define AHB_HBURST_WRAP16 0x6
#define AHB_HBURST_INCR16 0x7
#define AHB_HWRITE_READ 0x0
#define AHB_HWRITE_WRITE 0x1
FILE *fp;
char* sig_name = "sig_mout(0)";
int wait_for = 20;
int period = 20;
struct signal{
int htrans;
int* haddr;
int hwdata;
int hburst;
int hsize;
int hwrite;
int hbusreq;
int hlock;
int hprot;
};
struct signal curr, next;
void initSignal(struct signal* s){
s->htrans = AHB_HTRANS_IDLE;
s->haddr = (int*)0x00000000;
s->hburst = AHB_HBURST_SINGLE;
s->hsize = 0;
s->hwrite = AHB_HWRITE_READ;
s->hbusreq = 0;
s->hlock = 0;
s->hprot = 1;
s->hwdata = 0;
}
void setWriteDataInt32(int* addr, int data){
printf("-- ADDR_PHASE WRITE: %08x = %08x\n",addr,data);
curr.htrans = AHB_HTRANS_NONSEQ;
curr.haddr = addr;
curr.hbusreq = 1;
curr.hwrite = AHB_HWRITE_WRITE;
next.htrans = AHB_HTRANS_IDLE;
next.hwdata = data;
next.hbusreq = 1;
wait_for = period;
}
void setReadDataInt32(int* addr){
printf("-- ADDR_PHASE READ: %08x\n",addr);
curr.htrans = AHB_HTRANS_NONSEQ;
curr.haddr = addr;
curr.hbusreq = 1;
curr.hwrite = AHB_HWRITE_READ;
next.htrans = AHB_HTRANS_IDLE;
//next.hwdata = data;
next.hbusreq = 1;
wait_for = period;
}
void setWaitFor(int delay){
initSignal(&next);
wait_for = delay;
}
void advanceClock(){
//curr <= next, init next
memcpy((void*)&curr,(void*)&next,sizeof(curr));
initSignal(&next);
}
void convHexToBinary(char* dst, int data, int size){
int index = 0,i;
char quote;
if(size == 1)
quote = '\'';
else
quote = '"';
if(size > 1)
dst[index++] = 'b';
else
dst[index++] = ' ';
dst[index++] = quote;
for(i = 0; i < size; ++i){
char c = '0' + ((data>>i) & 0x00000001);
dst[size + 3 - index++] = c;
}
dst[index++] = quote;
dst[index] = '\0';
}
void convHexToHex(char* dst, int data, int size){
char tmp[100];
sprintf(tmp,"x\"%%0%dx\"",size);
sprintf(dst,tmp,data);
}
void printSignal(void){
char htrans[100];
char haddr[100];
char hburst[100];
char hsize[100];
char hwrite[100];
char hbusreq[100];
char hlock[100];
char hprot[100];
char hwdata[100];
convHexToBinary(htrans,curr.htrans,2);
convHexToHex(haddr,(int)curr.haddr,8);
convHexToBinary(hburst,curr.hburst,3);
convHexToBinary(hsize,curr.hsize,3);
convHexToBinary(hwrite,curr.hwrite,1);
convHexToBinary(hbusreq,curr.hbusreq,1);
convHexToBinary(hlock,curr.hlock,1);
convHexToBinary(hprot,curr.hprot,4);
convHexToHex(hwdata,curr.hwdata,8);
fprintf(fp,"%s.htrans\t<= %s;\n",sig_name,htrans);
fprintf(fp,"%s.haddr\t<= %s;\n",sig_name,haddr);
fprintf(fp,"%s.hburst\t<= %s;\n",sig_name,hburst);
fprintf(fp,"%s.hsize\t<= %s;\n",sig_name,hsize);
fprintf(fp,"%s.hwrite\t<= %s;\n",sig_name,hwrite);
fprintf(fp,"%s.hbusreq\t<= %s;\n",sig_name,hbusreq);
fprintf(fp,"%s.hlock\t<= %s;\n",sig_name,hlock);
fprintf(fp,"%s.hprot\t<= %s;\n",sig_name,hprot);
fprintf(fp,"%s.hwdata\t<= %s;\n",sig_name,hwdata);
fprintf(fp,"wait for %d ns;\n",wait_for);
advanceClock();
}
int main(){
fp = fopen("/dev/stdout","w");
//first init
initSignal(&curr);
initSignal(&next);
printSignal();
setWriteDataInt32((int*)0x9000000,0x00000030);
printSignal();
setWaitFor(200);
printSignal();
setReadDataInt32((int*)0x9000000);
printSignal();
setWaitFor(200);
printSignal();
setWriteDataInt32((int*)0x9010000,0x0000000a);
printSignal();
setWriteDataInt32((int*)0x9010004,0x00000002);
printSignal();
setWriteDataInt32((int*)0x9000000,0x00000003);
printSignal();
setWaitFor(200);
printSignal();
}