|
| 1 | +#ifdef EDGE_DETECTOR_AT_EN |
| 2 | +#ifndef SOBEL_EDGE_DETECTOR_CPP |
| 3 | +#define SOBEL_EDGE_DETECTOR_CPP |
| 4 | + |
| 5 | +#include "sobel_edge_detector_at_model.hpp" |
| 6 | + |
| 7 | +void Edge_Detector::write() |
| 8 | +{ |
| 9 | + wr_t.notify(5, SC_NS); |
| 10 | +} |
| 11 | + |
| 12 | +void Edge_Detector::wr() |
| 13 | +{ |
| 14 | + while (true) |
| 15 | + { |
| 16 | + wait(wr_t); |
| 17 | + if ((address.read() - SOBEL_INPUT_0) == 0) |
| 18 | + { |
| 19 | + int j = 0; |
| 20 | + for (int i = 0; i < 8; i++) |
| 21 | + { |
| 22 | + localWindow[0][0][i] = data.read()[i + (j * 8)]; |
| 23 | + } |
| 24 | + j++; |
| 25 | + for (int i = 0; i < 8; i++) |
| 26 | + { |
| 27 | + localWindow[0][1][i] = data.read()[i + (j * 8)]; |
| 28 | + } |
| 29 | + j++; |
| 30 | + for (int i = 0; i < 8; i++) |
| 31 | + { |
| 32 | + localWindow[0][2][i] = data.read()[i + (j * 8)]; |
| 33 | + } |
| 34 | + j++; |
| 35 | + for (int i = 0; i < 8; i++) |
| 36 | + { |
| 37 | + localWindow[1][0][i] = data.read()[i + (j * 8)]; |
| 38 | + } |
| 39 | + j++; |
| 40 | + for (int i = 0; i < 8; i++) |
| 41 | + { |
| 42 | + localWindow[1][1][i] = data.read()[i + (j * 8)]; |
| 43 | + } |
| 44 | + j++; |
| 45 | + for (int i = 0; i < 8; i++) |
| 46 | + { |
| 47 | + localWindow[1][2][i] = data.read()[i + (j * 8)]; |
| 48 | + } |
| 49 | + j++; |
| 50 | + for (int i = 0; i < 8; i++) |
| 51 | + { |
| 52 | + localWindow[2][0][i] = data.read()[i + (j * 8)]; |
| 53 | + } |
| 54 | + j++; |
| 55 | + for (int i = 0; i < 8; i++) |
| 56 | + { |
| 57 | + localWindow[2][1][i] = data.read()[i + (j * 8)]; |
| 58 | + } |
| 59 | + gotLocalWindow.notify(0, SC_NS); |
| 60 | + } |
| 61 | + else if ((address.read() - SOBEL_INPUT_1) == 0) |
| 62 | + { |
| 63 | + for (int i = 0; i < 8; i++) |
| 64 | + { |
| 65 | + localWindow[2][2][i] = data.read()[i]; |
| 66 | + } |
| 67 | + gotLocalWindow.notify(0, SC_NS); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +void Edge_Detector::read() |
| 73 | +{ |
| 74 | + rd_t.notify(5, SC_NS); |
| 75 | +} |
| 76 | + |
| 77 | +void Edge_Detector::rd() |
| 78 | +{ |
| 79 | + while (true) |
| 80 | + { |
| 81 | + wait(rd_t); |
| 82 | + if ((address.read() - SOBEL_OUTPUT) == 0) |
| 83 | + { |
| 84 | + data = (sc_uint<32>(0), resultSobelGradientY, resultSobelGradientX); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +void Edge_Detector::compute_sobel_gradient_x() |
| 90 | +{ |
| 91 | + while (true) |
| 92 | + { |
| 93 | + wait(gotLocalWindow); |
| 94 | + |
| 95 | + mult_x.notify(delay_multiplier, SC_NS); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +void Edge_Detector::compute_sobel_gradient_y() |
| 100 | +{ |
| 101 | + while (true) |
| 102 | + { |
| 103 | + wait(gotLocalWindow); |
| 104 | + |
| 105 | + mult_y.notify(delay_multiplier, SC_NS); |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +void Edge_Detector::perform_mult_gradient_x() |
| 110 | +{ |
| 111 | + while (true) |
| 112 | + { |
| 113 | + wait(mult_x); |
| 114 | + |
| 115 | + for (int i = 0; i < 3; i++) |
| 116 | + { |
| 117 | + for (int j = 0; j < 3; j++) |
| 118 | + { |
| 119 | + localMultX[i][j] = localWindow[i][j] * sobelGradientX[i][j]; |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + sum_x.notify(delay_full_adder, SC_NS); |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +void Edge_Detector::perform_mult_gradient_y() |
| 128 | +{ |
| 129 | + while (true) |
| 130 | + { |
| 131 | + wait(mult_y); |
| 132 | + |
| 133 | + for (int i = 0; i < 3; i++) |
| 134 | + { |
| 135 | + for (int j = 0; j < 3; j++) |
| 136 | + { |
| 137 | + localMultY[i][j] = localWindow[i][j] * sobelGradientY[i][j]; |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + sum_y.notify(delay_full_adder, SC_NS); |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +void Edge_Detector::perform_sum_gradient_x() |
| 146 | +{ |
| 147 | + while (true) |
| 148 | + { |
| 149 | + wait(sum_x); |
| 150 | + resultSobelGradientX = 0; |
| 151 | + |
| 152 | + for (int i = 0; i < 3; i++) |
| 153 | + { |
| 154 | + for (int j = 0; j < 3; j++) |
| 155 | + { |
| 156 | + resultSobelGradientX += localMultX[i][j]; |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | +} |
| 161 | + |
| 162 | +void Edge_Detector::perform_sum_gradient_y() |
| 163 | +{ |
| 164 | + while (true) |
| 165 | + { |
| 166 | + wait(sum_y); |
| 167 | + resultSobelGradientY = 0; |
| 168 | + |
| 169 | + for (int i = 0; i < 3; i++) |
| 170 | + { |
| 171 | + for (int j = 0; j < 3; j++) |
| 172 | + { |
| 173 | + resultSobelGradientY += localMultY[i][j]; |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +#endif // SOBEL_EDGE_DETECTOR_CPP |
| 180 | +#endif // EDGE_DETECTOR_AT_EN |
0 commit comments