-
Notifications
You must be signed in to change notification settings - Fork 0
/
apb_bfm.cpp
80 lines (66 loc) · 1.59 KB
/
apb_bfm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// MIT license
// Copyright (c) 2019 Cyril Jean
// SPDX-License-Identifier: MIT
#include "apb_bfm.h"
ApbBfm::ApbBfm(Vtop * in_top) {
top = in_top;
state = IDLE;
top->psel = 0;
top->penable = 0;
top->pwrite = 0;
top->pwdata = 0x00000000;
};
ApbBfm::~ApbBfm() {
};
void ApbBfm::write(uint32_t address, uint32_t value) {
curr_address = address;
curr_value = value;
state = WRITE_SETUP;
};
uint32_t ApbBfm::read(uint32_t address) {
curr_address = address;
state = READ_SETUP;
return 0;
};
void ApbBfm::drive_bus(int clock) {
switch(state) {
case IDLE:
if(!top->clk) {
top->psel = 0;
top->penable = 0;
};
break;
case WRITE_SETUP:
if(!top->clk) {
top->paddr = curr_address;
top->pwdata = curr_value;
top->pwrite = 1;
top->psel = 1;
state = WRITE_ACCESS;
};
break;
case WRITE_ACCESS:
if(!top->clk) {
top->penable = 1;
state = IDLE;
};
break;
case READ_SETUP:
if(!top->clk) {
top->pwrite = 0;
top->paddr = curr_address;
top->psel = 1;
state = READ_ACCESS;
}
break;
case READ_ACCESS:
if(!top->clk) {
top->penable = 1;
state = IDLE;
};
break;
default:
state = IDLE;
break;
};
};