star111004.cpp revision 12855:588919e0e4aa
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 star111004.cpp -- 23 24 Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38/*############################################################################ 39# Siemens AG copyright 2000 40# All Rights Reserved 41# 42# File name : io_controller.cpp 43# 44# Title : I/O-Controller 45# 46# Purpose : functionality for I/O-Controller-module 47# 48# Author : Hannes Muhr 49# PSE EZE MSA 50# 51############################################################################## 52# Modification History : 53# 54# 55##############################################################################*/ 56 57#include "systemc.h" 58#include "io_controller.h" 59 60#define MII_FRAME_SIZE 400 61 62// ::semaphore(){ 63 64// value = false; 65// } 66 67void io_controller_m::P(){ 68 69 while (value) wait(); 70 value = true; 71} 72 73void io_controller_m::V(){ 74 75 /*if (!value) { 76 cerr << "V-operation on semaphore that is not P'd\n"; 77 exit(-1); 78 }*/ 79 value = false; 80} 81 82bool io_controller_m::get_value(){ 83 84 return value; 85} 86 87/*void sc_trace(sc_trace_file *tf, const semaphore& sem, const std::string& str){ 88 89 sc_trace(tf, sem.get_value(), str); 90}*/ 91 92sc_uint<32> io_controller_m::read_from_memory(sc_uint<32> mp){ 93 94 // read from mbdatm-memory over i486-IF 95 96 addr30_o = mp >> 2; 97 ads_n_o = 0; 98 wr_n_o = 0; 99 wait(); 100 ads_n_o = 1; 101 do { wait(); } while (rdy_n_i == 1); 102 sc_uint<32> data = data32_i.read(); 103 wr_n_o = 1; 104 addr30_o = 0; 105 return data; 106} 107 108void io_controller_m::write_into_memory(sc_uint<32> mp, sc_uint<32> data){ 109 110 addr30_o = mp >> 2; 111 ads_n_o = 0; 112 wr_n_o = 1; 113 wait(); 114 ads_n_o = 1; 115 data32_o = data; 116 do { wait(); } while (rdy_n_i == 1); 117 wr_n_o = 1; 118 addr30_o = 0; 119 data32_o = 0; 120} 121 122void io_controller_m::control_write(){ 123 sc_uint<32> word_cnt; 124 125 if (!res_n_i.read()){ 126 do { wait(); } while (!res_n_i); 127 128 // initialize 129 130 // wait for 1. AR (HWS-Daten) 131 do { wait(); } while (!ar_i); 132 sc_uint<32> hws = data32_i.read(); 133 134 wait(); 135 136 // wait for 2. AR (ACB-Pointer) 137 do { wait(); } while (!ar_i); 138 addr_tx_frame_ptr = data32_i.read(); 139 140 } 141 /* else if (mii_coll_det){ 142 out_fifo_reset = 1; 143 out_fifo_en = 0; 144 out_fifo_data32 = (sc_uint<32>) 0; 145 146 // reset i486-IF 147 addr30_o = 0; 148 data32_io = 0; 149 ads_n_o = 1; 150 wr_n_o = 1; 151 152 // release Semaphore if it is set 153 sem.V(); 154 155 wait(); 156 out_fifo_reset = 0; 157 }*/ 158 159 while(true){ 160 // normally Attention Request - Signal from MBDATM 161 // would wake up IO-Controller to read data from the memory, 162 // but the model from Hr. Wahl said: wait for some ms !!! 163 164 // wait(unsigned ((SCAN_INTERVAL NS)/40e-9)); 165 //do { wait(); } while (ar_i); 166 167 #ifdef LOGGING 168 flog << sc_time_stamp()<<": "<<name()<<"::control_write - Attention Request" << endl; 169 #endif 170 171 P(); 172 sc_uint<32> tx_frame_ptr = read_from_memory(addr_tx_frame_ptr); 173 if (tx_frame_ptr != 0) 174 word_cnt = read_from_memory(tx_frame_ptr+(MII_FIFO_SIZE+1)*4); 175 V(); 176 177 // check, if frame available and frame is full (word_cnt == MII_FRAME_SIZE) 178 179 while (tx_frame_ptr != 0 && word_cnt == MII_FRAME_SIZE){ 180 #ifdef LOGGING 181 flog << sc_time_stamp()<<": "<<name()<<"::control_write - writing mii_frame into out_fifo" << endl; 182 #endif 183 184 185 for (int i = 0; i<MII_FIFO_SIZE; i++){ 186 // reading from i486-IF and writing into 187 // out_fifo is mixed, so read_from_memory could not be applied 188 189 P(); 190 sc_uint<32> data = read_from_memory(tx_frame_ptr+i*4); 191 V(); 192 193 out_fifo_en = 1; 194 out_fifo_data32 = data; 195 wait(); 196 out_fifo_en = 0; 197 198 } 199 200 while (out_fifo_act.read() != 0) wait(2); 201 202 // write 0xFFFFFFFF (>MII_FRAME_SIZE) into tx_frame_ptr 203 // to signal software in mbdatm that io-controller has 204 // read out the frames and sent successfully 205 P(); 206 write_into_memory(tx_frame_ptr+(MII_FIFO_SIZE+1)*4, 0xFFFFFFFF); 207 V(); 208 209 // read next frame_pointer and word_cnt from MBDATM 210 P(); 211 tx_frame_ptr = read_from_memory(tx_frame_ptr+MII_FIFO_SIZE*4); 212 if (tx_frame_ptr != 0) 213 word_cnt = read_from_memory(tx_frame_ptr+(MII_FIFO_SIZE+1)*4); 214 V(); 215 216 217 } 218 219 } 220} 221 222void io_controller_m::control_read(){ 223 224 int arr_ptr = 0; 225 226 while (true){ 227 do { wait(); } while (!control_en); 228 #ifdef LOGGING 229 flog << sc_time_stamp()<<": "<<name()<<"::control_read " << endl; 230 #endif 231 232 // read rx_frame_ptr from MBDATM 233 P(); 234 sc_uint<32> rx_frame_ptr = read_from_memory(rx_ptr_array+arr_ptr*4); 235 V(); 236 /*if (rx_frame_ptr == 0){ 237 cerr << "\nIO-Controller has read NULL-ptr from rx_array in MBDATM\n"; 238 cerr << "MBDATM did not fill rx_array fast enough\n"; 239 exit(-1); 240 }*/ 241 if (++arr_ptr == MII_FIFO_SIZE) 242 arr_ptr = 0; 243 244 // write data from in_fifo into MBDATM-memory 245 for (int i = 0; i < MII_FIFO_SIZE-1; i++){ 246 sc_uint<32> d = control_data32.read(); 247 // grab the semaphore 248 P(); 249 write_into_memory(rx_frame_ptr + i*4, d); 250 // release semaphore 251 V(); 252 do { wait(); } while (!control_en); 253 254 } 255 // separate last loop because we don't want to wait for 256 // another control_en at this time 257 sc_uint<32> d = control_data32.read(); 258 P(); 259 write_into_memory(rx_frame_ptr + (MII_FIFO_SIZE-1)*4, d); 260 V(); 261 262 // write 0xFFFFFFFF into word_cnt from frame 263 // to indicate the software (MBDATM) that frame has been filled 264 P(); 265 write_into_memory(rx_frame_ptr + (MII_FIFO_SIZE+1)*4, 0xFFFFFFFF); 266 V(); 267 } 268} 269 270