OpenCores
URL https://opencores.org/ocsvn/iso7816_3_master/iso7816_3_master/trunk

Subversion Repositories iso7816_3_master

[/] [iso7816_3_master/] [trunk/] [sources/] [RxCore.v] - Diff between revs 5 and 7

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 5 Rev 7
Line 25... Line 25...
   output reg dataOutReadyFlag, //new data available
   output reg dataOutReadyFlag, //new data available
   output reg frameErrorFlag,           //bad parity or bad stop bits
   output reg frameErrorFlag,           //bad parity or bad stop bits
   output reg endOfRx,                          //one cycle pulse: 1 during last cycle of last stop bit
   output reg endOfRx,                          //one cycle pulse: 1 during last cycle of last stop bit
   output reg run,                                      //rx is definitely started, one of the three flag will be set
   output reg run,                                      //rx is definitely started, one of the three flag will be set
   output wire startBit,                        //rx is started, but we don't know yet if real rx or just a glitch
   output wire startBit,                        //rx is started, but we don't know yet if real rx or just a glitch
        output wire stopBit,                            //rx is over but still in stop bits
        output reg stopBit,                             //rx is over but still in stop bits
        input wire [CLOCK_PER_BIT_WIDTH-1:0] clocksPerBit,
        input wire [CLOCK_PER_BIT_WIDTH-1:0] clocksPerBit,
        input wire stopBit2,//0: 1 stop bit, 1: 2 stop bits
        input wire stopBit2,//0: 1 stop bit, 1: 2 stop bits
        input wire oddParity, //if 1, parity bit is such that data+parity have an odd number of 1
        input wire oddParity, //if 1, parity bit is such that data+parity have an odd number of 1
   input wire msbFirst,  //if 1, bits order is: startBit, b7, b6, b5...b0, parity
   input wire msbFirst,  //if 1, bits order is: startBit, b7, b6, b5...b0, parity
        input wire ackFlags,
        input wire ackFlags,
Line 40... Line 40...
        output reg [CLOCK_PER_BIT_WIDTH-1:0] bitClocksCounterCompare,
        output reg [CLOCK_PER_BIT_WIDTH-1:0] bitClocksCounterCompare,
        output reg bitClocksCounterInc,
        output reg bitClocksCounterInc,
        output reg bitClocksCounterClear,
        output reg bitClocksCounterClear,
        output wire bitClocksCounterInitVal,
        output wire bitClocksCounterInitVal,
   input wire bitClocksCounterEarlyMatch,
   input wire bitClocksCounterEarlyMatch,
        input wire bitClocksCounterMatch
        input wire bitClocksCounterMatch,
 
        input wire [CLOCK_PER_BIT_WIDTH-1:0] bitClocksCounter
    );
    );
 
 
//parameters to override
//parameters to override
parameter CLOCK_PER_BIT_WIDTH = 13;     //allow to support default speed of ISO7816
parameter CLOCK_PER_BIT_WIDTH = 13;     //allow to support default speed of ISO7816
 
parameter PRECISE_STOP_BIT = 0; //if 1, stopBit signal goes high exactly at start of stop bit instead of middle of parity bit
 
 
//default conventions
//default conventions
parameter START_BIT = 1'b0;
parameter START_BIT = 1'b0;
parameter STOP_BIT1 = 1'b1;
parameter STOP_BIT1 = 1'b1;
parameter STOP_BIT2 = 1'b1;
parameter STOP_BIT2 = 1'b1;
Line 73... Line 75...
 
 
wire internalIn;
wire internalIn;
wire parityError;
wire parityError;
 
 
assign startBit = (nextState == START_STATE);
assign startBit = (nextState == START_STATE);
assign stopBit = (nextState == STOP1_STATE) | (nextState == STOP2_STATE);
//assign stopBit = (nextState == STOP1_STATE) | (nextState == STOP2_STATE);
assign internalIn = serialIn;
assign internalIn = serialIn;
assign parityError= parityBit ^ internalIn ^ 1'b1;
assign parityError= parityBit ^ internalIn ^ 1'b1;
reg flagsSet;
reg flagsSet;
 
 
assign bitClocksCounterInitVal=(nextState==IDLE_STATE);
assign bitClocksCounterInitVal=(nextState==IDLE_STATE);
Line 116... Line 118...
                overrunErrorFlag <= #1 0;
                overrunErrorFlag <= #1 0;
                dataOutReadyFlag <= #1 0;
                dataOutReadyFlag <= #1 0;
                frameErrorFlag <= #1 0;
                frameErrorFlag <= #1 0;
                run <= #1 0;
                run <= #1 0;
      endOfRx <= #1 0;
      endOfRx <= #1 0;
 
                stopBit<= #1 0;
        end else begin
        end else begin
                case(nextState)
                case(nextState)
                        IDLE_STATE: begin
                        IDLE_STATE: begin
                                if(bitClocksCounterEarlyMatch)
                                if(bitClocksCounterEarlyMatch)
               endOfRx <= #1 1'b1;
               endOfRx <= #1 1'b1;
            if(bitClocksCounterMatch)
            if(bitClocksCounterMatch) begin
               endOfRx <= #1 0;
               endOfRx <= #1 0;
 
                                        stopBit <= #1 0;
 
                                end
            if(ackFlags) begin
            if(ackFlags) begin
                                        //overrunErrorFlag is auto cleared at PARITY_STATE
                                        //overrunErrorFlag is auto cleared at PARITY_STATE
                                        //meanwhile, it prevent dataOutReadyFlag to be set by the termination of the lost byte
                                        //meanwhile, it prevent dataOutReadyFlag to be set by the termination of the lost byte
                                        dataOutReadyFlag <= #1 0;
                                        dataOutReadyFlag <= #1 0;
                                        frameErrorFlag <= #1 0;
                                        frameErrorFlag <= #1 0;
Line 187... Line 192...
                                                dataOutReadyFlag <= #1 ~parityError;
                                                dataOutReadyFlag <= #1 ~parityError;
                                        end else if(ackFlags) begin
                                        end else if(ackFlags) begin
                                                frameErrorFlag <= #1 0;
                                                frameErrorFlag <= #1 0;
                                        end
                                        end
                                        flagsSet=1;
                                        flagsSet=1;
 
                                        if(PRECISE_STOP_BIT==0) stopBit <= #1 1;
                                        if(stopBit2)
                                        if(stopBit2)
                                                nextState <= #1 STOP1_STATE;
                                                nextState <= #1 STOP1_STATE;
                                        else
                                        else
                                                nextState <= #1 STOP2_STATE;
                                                nextState <= #1 STOP2_STATE;
                                end else if(ackFlags) begin
                                end else if(ackFlags) begin
Line 210... Line 216...
                                        end
                                        end
                                        nextState <= #1 STOP2_STATE;
                                        nextState <= #1 STOP2_STATE;
                                end else if(ackFlags) begin
                                end else if(ackFlags) begin
                                        frameErrorFlag <= #1 0;
                                        frameErrorFlag <= #1 0;
                                end
                                end
 
                                if(PRECISE_STOP_BIT!=0) begin
 
                                        if(bitClocksCounter==(bitClocksCounterCompare/2)) begin
 
                                                stopBit <= #1 1;
 
                                        end
 
                                end
                        end
                        end
                        STOP2_STATE: begin
                        STOP2_STATE: begin
                                if(ackFlags) begin
                                if(ackFlags) begin
                                        dataOutReadyFlag <= #1 0;
                                        dataOutReadyFlag <= #1 0;
                                end
                                end
Line 225... Line 236...
                                        end
                                        end
                                        nextState <= #1 IDLE_STATE;
                                        nextState <= #1 IDLE_STATE;
                                end else if(ackFlags) begin
                                end else if(ackFlags) begin
                                        frameErrorFlag <= #1 0;
                                        frameErrorFlag <= #1 0;
                                end
                                end
 
                                if(PRECISE_STOP_BIT!=0) begin
 
                                        if(bitClocksCounter==(bitClocksCounterCompare/2)) begin
 
                                                stopBit <= #1 1;
 
                                        end
 
                                end
                        end
                        end
                        default: nextState <= #1 IDLE_STATE;
                        default: nextState <= #1 IDLE_STATE;
                endcase
                endcase
        end
        end
end
end

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.