module SendInfo (BrightRow, BrightCol, Bank, XbusState, LaserPoint, clk, Rst, DataOut, WakeUpSignal) ; // // Input signals // input [7:0] BrightRow ; input [7:0] BrightCol ; input [1:0] Bank ; input [3:0] XbusState ; input LaserPoint; input clk ; // // Output signals // output Rst ; output [7:0] DataOut ; // // Inout signal // inout WakeUpSignal ; // // Registered outputs and local variables // reg Rst ; reg [7:0] DataOut ; reg PreviousBank ; reg WakeUpSignal ; reg [3:0] State ; reg [3:0] NextState ; // Data Send States => We are simplifying this module because we assume // that the entire Xbus transaction will occur in MUCH, MUCH LESS time // than it takes for a new image to be ready from the camera. Thus, our // brightRow and brightCol information will be valid throughout the // entire operation of our state machine, so we don't need to keep them // as local variables to ensure constant data. parameter Idle = 0, CheckLaserPoint = 1, SetResetHighForRow = 2, //SetResetLowForRow = 8, SendRowData = 3, WaitForXbusAfterRow = 4, SetResetHighForCol = 5, //SetResetLowForCol = 9, SendColData = 6, ColReadStartSignal = 7, WaitForXbusAfterCol = 8; // // STATE MACHINE => Provides functionality for the state transitions // in the state machine below. Also, the previous // bank is always set to be the current bank at each // clock cycle so we can detect when the monitor bank // is set to a new bank -> this means that an image is // done being analyzed and ready to be sent over the // Xbus (as long as there is a laser point in the image). // always @ (posedge clk) begin State <= NextState; PreviousBank <= Bank ; end //end always // // STATE MACHINE => Send the bright row information across the Xbus and // then sends the bright column information across the // Xbus. It will not send row and col data if there is // no laser spot detected in the current image. The // state machine will execute it's functionality every // time another image is done being written to memory // and has been analyzed by the LaserSpot module. // always @ ( State or Bank or PreviousBank or BrightRow or BrightCol or LaserPoint ) begin NextState = State; //Stay in same state by default // Do we need this????????????????????????????????????????????????????? Rst = 0; //Reset signal is off by default case (State) Idle: begin if ( (PreviousBank != Bank) ) //We have changed banks, so the data is ready to send to the Xbus as long // as we have a valid laser spot in the current image. We check for the // valid laser spot in the next state. begin NextState = CheckLaserPoint; end end //end Idle state // I could have put this check in the idle state, but I needed to wait // one clock cycle to ensure that the LaserSpot module is outputing // the correct data for this image. So this extra state provides the // extra clock cycle waiting period. We have plenty of time to transmit // this data over the Xbus before the next data is ready, so this one // cycle delay isn't critical. :) CheckLaserPoint: begin if ( LaserPoint == 1 ) //There is a valid laser point in this image. NextState = SetResetHighForRow; //Continue to the next state else NextState = Idle; //There isn't a laser point in the image, so go back to idle. end //end CheckLaserPoint state SetResetHighForRow: begin if ( XbusState == 0 ) //The Xbus is idle and waiting right now begin Rst = 1'b1; //Signal Xbus to reset NextState = SendRowData; //SetResetLowForRow; end //IMPLIED ELSE BLOCK //else // NextState = State ; end //end // I don't think this extra state is necessary, take out later!!!!!!!!!!!!!!!! // SetResetLowForRow: // begin // Rst = 1'b0; //Reset the Rst signal to low // NextState = SendRowData; //We are ready to send the row data to the Xbus now // end SendRowData: begin Rst = 1'b0; //Reset the reset signal to low WakeUpSignal = 1'b1; //Let the microcont know it needs to wake up and // READ new data. The microcont will reset this // wire to 0 when it sees the signal (so I don't // need to worry about it). DataOut = BrightRow; //Send row data to Xbus NextState = WaitForXbusAfterRow; end WaitForXbusAfterRow: begin if ( (XbusState == 0) && (WakeUpSignal == 0) ) //The Xbus is done sending the row and ready to send column begin DataOut = 0; //Set DataOut to zero for testing purposes NextState = SetResetHighForCol; end //IMPLIED ELSE BLOCK //else // NextState = State ; end // By definition, the reset signal doesn't need to be sent again, since // the state of the Xbus is 0. However, this is provided to make sure // that the microcontroller doesn't try something funny right after the // row read- like trying to write data. So, we'll just make sure that // the Xbus is reset before we send data. :) SetResetHighForCol: begin if ( XbusState == 0 ) //The Xbus is idle and waiting right now begin Rst = 1'b1; //Signal Xbus to reset NextState = SendColData;//SetResetLowForCol; end //IMPLIED ELSE BLOCK //else // NextState = State ; end //end SetResetHighForCol state // I don't think this extra state is necessary, take out later!!!!!!!!!!!!!!!! // SetResetLowForCol: // begin // Rst = 1'b0; //Reset the Rst signal to low // NextState = SendColData; //We are ready to send the col data to the Xbus now // end //end SetResetLowForCol state SendColData: begin Rst = 1'b0; //Reset the reset signal to low DataOut = BrightCol; //Send col data to Xbus NextState = ColReadStartSignal; end // end SendColData state ColReadStartSignal: begin if ( WakeUpSignal == 1 ) //The microController is starting to read the col data NextState = WaitForXbusAfterCol; //IMPLIED ELSE BLOCK //else // NextState = State ; end //end WaitForReadStartSignal state WaitForXbusAfterCol: begin if ( (XbusState == 0) && (WakeUpSignal == 0) ) //The Xbus is done sending the col so we're done!!! begin DataOut = 0; //Set DataOut to zero for testing purposes NextState = Idle; end //IMPLIED ELSE BLOCK //else // NextState = State ; end //end WaitForXbusAfterCol state default: //We should NEVER get here!!! ;) begin NextState = Idle; end endcase end //end always endmodule