DSP

omam138/upp/fpga

2019-07-13 15:51发布

 uPP通信(2)---FPGA篇 2013-01-13 09:59:32 分类: 嵌入式   系统架构   本系统组成如下图,FPGA挨个读取24AD通道中的数据,然后通过UPP方式传送给OMAPL138中的DSP核,经过一系列运算,DSP核通过DSPLINK方式将数据送到ARM核。     FPGA数据读取、存储、传送、数据识别问题   因为OMAPL138需要识别传送上来的数据是对应哪个通道的。所以FPGA对数据必须做一些处理以便于OMAPL138对数据分门别类。 方法一: FPGA中生成一个FIFO,挨个读取24AD通道中的数据按次序存放到FIFO中,FIFO中存放满预定大小的数据量时再上传给OMAPL138,这样OMAPL138就知道第一个数据是对应通道1的,第二个数据是对应通道2的。 优点:简单,容易实现 缺点:如果其中一个数据出错或者漏传,那后面的一大堆数据都会被错误归类。 方法二: AD通道输出数据是16位,将其扩展为32位,高16位作为标志位。例如,如果第一个AD通道读出来的0xDE33,那扩展为32位时其数据为0x0001DE33OMAPL138通过其高16位辨别这个数据是哪个通道的。 优点:不再像方法一担心数据传错了,传错也不会危害到整体。 缺点:OMAPL138UPP通信时16位的数据线,原来是需要传送数据,现在还要传送标志数据,这样直接导致传输效率打5折。但是对于能够到达150MB/s吞吐量的UPP来说,就算传输只能达到50%,也是能满足我目前这个系统的。     读取AD 以下是读取ad的代码,状态机的状态比较多,比较麻烦。
点击(此处)折叠或打开
  1. module ads_ddio (
  2.                         clk,
  3.                         rst,
  4.                         eoc,
  5.                         datain,
  6.                         dataout,
  7.                         f_ncs,
  8.                         f_nrd,
  9.                         fifo_wr,
  10.                         f_c1,
  11.                         f_c2,
  12.                         f_c3,
  13.                         f_c4,
  14.                         f_c5,
  15.                         f_c6
  16.                     );

  17.                 
  18. input             clk,rst;
  19. input[1:0]        eoc;
  20. input[15:0]     datain;
  21. output             f_c1, f_c2, f_c3, f_c4, f_c5, f_c6;
  22. output[1:0]      f_ncs;
  23. output[1:0]             f_nrd;
  24. output fifo_wr;
  25. output[31:0]     dataout;


  26. reg[7:0] counter;
  27. reg[31:0] data_reg;
  28. reg state;
  29. reg[1:0] eoc1;
  30. reg[5:0] cstate,nstate;
  31. reg[1:0] f_nrd_reg,f_ncs_reg;
  32. reg fifo_wr_reg;

  33. parameter     SET_COUNT          = 8'hff, 

  34.                 SET_CSRD_C1UA = 8'd23,
  35.                 SET_DATA_C1UA = 8'd24,
  36.                 SET_CSRD_C1UB = 8'd26,
  37.                 SET_DATA_C1UB = 8'd27,
  38.                 SET_CSRD_C1UC = 8'd29,
  39.                 SET_DATA_C1UC = 8'd30,
  40.                 SET_CSRD_C1IA = 8'd32,
  41.                 SET_DATA_C1IA = 8'd33,
  42.                 SET_CSRD_C1IB = 8'd35,
  43.                 SET_DATA_C1IB = 8'd36,
  44.                 SET_CSRD_C1IC = 8'd38,
  45.                 SET_DATA_C1IC = 8'd39,    
  46.                 
  47.                 SET_CSRD_C2UA = 8'd41,
  48.                 SET_DATA_C2UA = 8'd42,
  49.                 SET_CSRD_C2UB = 8'd44,
  50.                 SET_DATA_C2UB = 8'd45,            
  51.                 SET_CSRD_C2UC = 8'd47,
  52.                 SET_DATA_C2UC = 8'd48,    
  53.                 SET_CSRD_C2IA = 8'd50,
  54.                 SET_DATA_C2IA = 8'd51,            
  55.                 SET_CSRD_C2IB = 8'd53,
  56.                 SET_DATA_C2IB = 8'd54,
  57.                 SET_CSRD_C2IC = 8'd56,
  58.                 SET_DATA_C2IC = 8'd57,
  59.                     
  60.                 SET_FIFO_DATA = 8'd60, //上个状态+3
  61.                 
  62.                 SET_IDLE          = 8'd62;
  63.                 
  64.                 
  65. parameter     IDLE                 = 6'd0,
  66.                 CSRDN_C1UA        = 6'd1,
  67.                 DATA_C1UA         = 6'd2,
  68.                 DATA1_C1UA = 6'd3,
  69.                 CSRDN_C1UB        = 6'd4,
  70.                 DATA_C1UB         = 6'd5,
  71.                 DATA1_C1UB = 6'd6,
  72.                 CSRDN_C1UC        = 6'd7,
  73.                 DATA_C1UC         = 6'd8,
  74.                 DATA1_C1UC = 6'd9,
  75.                 CSRDN_C1IA        = 6'd10,
  76.                 DATA_C1IA         = 6'd11,
  77.                 DATA1_C1IA = 6'd12,
  78.                 CSRDN_C1IB        = 6'd13,
  79.                 DATA_C1IB         = 6'd14,
  80.                 DATA1_C1IB = 6'd15,
  81.                 CSRDN_C1IC        = 6'd16,
  82.                 DATA_C1IC         = 6'd17,
  83.                 DATA1_C1IC = 6'd18,
  84.                 
  85.                 CSRDN_C2UA        = 6'd19,
  86.                 DATA_C2UA         = 6'd20,
  87.                 DATA1_C2UA = 6'd21,
  88.                 CSRDN_C2UB        = 6'd22,
  89.                 DATA_C2UB         = 6'd23,
  90.                 DATA1_C2UB = 5'd24,
  91.                 CSRDN_C2UC        = 6'd25,
  92.                 DATA_C2UC         = 6'd26,
  93.                 DATA1_C2UC = 6'd27,
  94.                 CSRDN_C2IA        = 6'd28,
  95.                 DATA_C2IA         = 6'd29,
  96.                 DATA1_C2IA = 6'd30,
  97.                 CSRDN_C2IB        = 6'd31,
  98.                 DATA_C2IB         = 6'd32,
  99.                 DATA1_C2IB = 6'd33,
  100.                 CSRDN_C2IC        = 6'd34,
  101.                 DATA_C2IC         = 6'd35,
  102.                 DATA1_C2IC = 6'd36,
  103.                 FIFO_DATA = 6'd37;                


  104. wire csrd_n_c1ua_req;
  105. wire csrd_n_c1ub_req;
  106. wire csrd_n_c1uc_req;
  107. wire csrd_n_c1ia_req;
  108. wire csrd_n_c1ib_req;
  109. wire csrd_n_c1ic_req;

  110. wire csrd_n_c2ua_req;
  111. wire csrd_n_c2ub_req;
  112. wire csrd_n_c2uc_req;
  113. wire csrd_n_c2ia_req;
  114. wire csrd_n_c2ib_req;
  115. wire csrd_n_c2ic_req;


  116. wire data_c1ua_req;
  117. wire data_c1ub_req;
  118. wire data_c1uc_req;
  119. wire data_c1ia_req;
  120. wire data_c1ib_req;
  121. wire data_c1ic_req;

  122. wire data_c2ua_req;
  123. wire data_c2ub_req;
  124. wire data_c2uc_req;
  125. wire data_c2ia_req;
  126. wire data_c2ib_req;
  127. wire data_c2ic_req;

  128. wire fifo_data_req;

  129. wire idle_req;

  130. assign f_c1 = 1'b1;
  131. assign f_c2 = 1'b0;
  132. assign f_c3 = 1'b1; 
  133. assign f_c4 = 1'b0;
  134. assign f_c5 = 1'b0;
  135. assign f_c6 = 1'b0;

  136. assign dataout = data_reg;

  137. assign csrd_n_c1ua_req = (counter == SET_CSRD_C1UA);
  138. assign csrd_n_c1ub_req = (counter == SET_CSRD_C1UB);
  139. assign csrd_n_c1uc_req = (counter == SET_CSRD_C1UC);
  140. assign csrd_n_c1ia_req = (counter == SET_CSRD_C1IA);
  141. assign csrd_n_c1ib_req = (counter == SET_CSRD_C1IB);
  142. assign csrd_n_c1ic_req = (counter == SET_CSRD_C1IC);

  143. assign csrd_n_c2ua_req = (counter == SET_CSRD_C2UA);
  144. assign csrd_n_c2ub_req = (counter == SET_CSRD_C2UB);
  145. assign csrd_n_c2uc_req = (counter == SET_CSRD_C2UC);
  146. assign csrd_n_c2ia_req = (counter == SET_CSRD_C2IA);
  147. assign csrd_n_c2ib_req = (counter == SET_CSRD_C2IB);
  148. assign csrd_n_c2ic_req = (counter == SET_CSRD_C2IC);


  149. assign data_c1ua_req = (counter == SET_DATA_C1UA);
  150. assign data_c1ub_req = (counter == SET_DATA_C1UB);
  151. assign data_c1uc_req = (counter == SET_DATA_C1UC);
  152. assign data_c1ia_req = (counter == SET_DATA_C1IA);
  153. assign data_c1ib_req = (counter == SET_DATA_C1IB);
  154. assign data_c1ic_req = (counter == SET_DATA_C1IC);

  155. assign data_c2ua_req = (counter == SET_DATA_C2UA);
  156. assign data_c2ub_req = (counter == SET_DATA_C2UB);
  157. assign data_c2uc_req = (counter == SET_DATA_C2UC);
  158. assign data_c2ia_req = (counter == SET_DATA_C2IA);
  159. assign data_c2ib_req = (counter == SET_DATA_C2IB);
  160. assign data_c2ic_req = (counter == SET_DATA_C2IC);


  161. assign fifo_data_req = (counter == SET_FIFO_DATA);
  162. assign idle_req = (counter == SET_IDLE);
  163. assign f_nrd[0] = (cstate == DATA_C1UA || cstate == CSRDN_C1UA || cstate == DATA_C1UB || cstate == CSRDN_C1UB || cstate == DATA_C1UC || cstate == CSRDN_C1UC || cstate == DATA_C1IA || cstate == CSRDN_C1IA || cstate == DATA_C1IB || cstate == CSRDN_C1IB || cstate == DATA_C1IC || cstate == CSRDN_C1IC ) ? f_nrd_reg[0] : 1'b1; 
  164. assign f_ncs[0] = (cstate == DATA_C1UA || cstate == CSRDN_C1UA || cstate == DATA_C1UB || cstate == CSRDN_C1UB || cstate == DATA_C1UC || cstate == CSRDN_C1UC || cstate == DATA_C1IA || cstate == CSRDN_C1IA || cstate == DATA_C1IB || cstate == CSRDN_C1IB || cstate == DATA_C1IC || cstate == CSRDN_C1IC ) ? f_ncs_reg[0] : 1'b1; 
  165. assign f_nrd[1] = (cstate == DATA_C2UA || cstate == CSRDN_C2UA || cstate == DATA_C2UB || cstate == CSRDN_C2UB || cstate == DATA_C2UC || cstate == CSRDN_C2UC || cstate == DATA_C2IA || cstate == CSRDN_C2IA || cstate == DATA_C2IB || cstate == CSRDN_C2IB || cstate == DATA_C2IC || cstate == CSRDN_C2IC ) ? f_nrd_reg[1] : 1'b1;
  166. assign f_ncs[1] = (cstate == DATA_C2UA || cstate == CSRDN_C2UA || cstate == DATA_C2UB || cstate == CSRDN_C2UB || cstate == DATA_C2UC || cstate == CSRDN_C2UC || cstate == DATA_C2IA || cstate == CSRDN_C2IA || cstate == DATA_C2IB || cstate == CSRDN_C2IB || cstate == DATA_C2IC || cstate == CSRDN_C2IC ) ? f_ncs_reg[1] : 1'b1;
  167. assign fifo_wr = ( /* cstate ==DATA_C1UA ||*/ cstate == DATA_C1UB || cstate == DATA_C1UC || cstate == DATA_C1IA || cstate == DATA_C1IB || cstate == DATA_C1IC || cstate == DATA_C2UA || cstate == DATA_C2UB || cstate == DATA_C2UC || cstate == DATA_C2IA || cstate == DATA_C2IB || cstate == DATA_C2IC ||cstate == FIFO_DATA ) ? fifo_wr_reg : 1'b0; 



  168. always @ (posedge clk or negedge rst)
  169.     if(!rst) 
  170.         cstate <= IDLE;
  171.     else
  172.         cstate <= nstate;

  173. always @ (cstate or fifo_data_req or csrd_n_c1ua_req or data_c1ub_req or csrd_n_c1uc_req or data_c1ia_req or data_c1ib_req or data_c1ic_req or csrd_n_c2ua_req or data_c2ub_req or csrd_n_c2uc_req or data_c2ia_req or data_c2ib_req or data_c2ic_req) 
  174.     case (cstate)
  175.         IDLE: 
  176.             if(csrd_n_c1ua_req)
  177.                 nstate <= CSRDN_C1UA;
  178.             else
  179.                 nstate <= IDLE;
  180.          CSRDN_C1UA:
  181.             if(data_c1ua_req)
  182.                 nstate <= DATA_C1UA;
  183.             else
  184.                 nstate <= CSRDN_C1UA;
  185.          DATA_C1UA:
  186.             nstate <= DATA1_C1UA;
  187.          DATA1_C1UA:
  188.             if(csrd_n_c1ub_req)
  189.                 nstate <= CSRDN_C1UB;
  190.             else
  191.                 nstate <= DATA1_C1UA;
  192.          CSRDN_C1UB:
  193.             if(data_c1ub_req)
  194.                 nstate <= DATA_C1UB;
  195.             else
  196.                 nstate <= CSRDN_C1UB;
  197.          DATA_C1UB:
  198.             nstate <= DATA1_C1UB;
  199.          DATA1_C1UB:
  200.             if(csrd_n_c1uc_req)
  201.                 nstate <= CSRDN_C1UC;
  202.             else
  203.                 nstate <= DATA1_C1UB;        
  204.          CSRDN_C1UC:
  205.             if(data_c1uc_req)
  206.