[数据传输] 利用CY7C68013A遇到的问题

[复制链接]
3613|3
 楼主| nuageux 发表于 2017-8-30 11:20 | 显示全部楼层 |阅读模式
最近一直在做CY7C68013数据传输项目,目的是为了将FPGA开发板产生的随机数信号通过USB接口传至PC机,目前Bulkloop.c代码修改过了,fifo_wr.v也写好了,但是写入开发板后,EZ-USB的pipe不对,因为我设置的是EP2 IN 但是界面显示EP2 OUT  不知道哪里代码哪里修改错了,希望大佬指点。附上Bulkloop.c的代码和fifo_wr.v的代码。
  1. //-----------------------------------------------------------------------------
  2. //   File:      bulkloop.c
  3. //   Contents:  Hooks required to implement USB peripheral function.
  4. //
  5. // $Archive: /USB/Examples/FX2LP/bulkloop/bulkloop.c $
  6. //
  7. //
  8. //-----------------------------------------------------------------------------
  9. // Copyright (c) 2011, Cypress Semiconductor Corporation All rights reserved
  10. //-----------------------------------------------------------------------------
  11. #pragma NOIV               // Do not generate interrupt vectors

  12. #include "..\inc\fx2.h"
  13. #include "..\inc\fx2regs.h"
  14. #include "..\inc\syncdly.h"            // SYNCDELAY macro

  15. extern BOOL GotSUD;             // Received setup data flag
  16. extern BOOL Sleep;
  17. extern BOOL Rwuen;
  18. extern BOOL Selfpwr;

  19. BYTE Configuration;             // Current configuration
  20. BYTE AlternateSetting;          // Alternate settings

  21. #define VR_NAKALL_ON    0xD0
  22. #define VR_NAKALL_OFF   0xD1

  23. //-----------------------------------------------------------------------------
  24. // Task Dispatcher hooks
  25. //   The following hooks are called by the task dispatcher.
  26. //-----------------------------------------------------------------------------

  27. void TD_Init(void)             // Called once at startup
  28. {
  29.      // set the CPU clock to 48MHz, Default 12MHz(Page 333)
  30.     //CPUCS = 0x02;  //12MHZ CLKOUT ENALBE   
  31.   //CPUCS = 0x0a;  //24MHZ CLKOUT ENALBE
  32.   CPUCS = 0x12;  //48MHZ CLKOUT ENALBE,时钟不反向,CLKOUT PIN驱动,有时钟输出;     
  33.     SYNCDELAY;   
  34.    
  35. //Interface Configure(Page 334)
  36.     IFCONFIG =0x03;    //选择为外部时钟,且时钟频率为30MHz,且为同步slaveFIFO模式,输入IFCLK(5~48MHz)(0000_0011)
  37.     //IFCONFIG =0x0B;//选择为外部时钟,且为异步slaveFIFO模式,不需要IFCLK
  38.     SYNCDELAY;
  39.    
  40. //Configure REVCTL for Chip Revision Control(Page 344)
  41.     REVCTL = 0x03;        //Cypress highly recommends setting both bits to 1
  42.     SYNCDELAY;

  43.     Rwuen = TRUE; // Enable remote-wakeup


  44.   // Registers which require a synchronization delay, see section 15.14
  45.   // FIFORESET        FIFOPINPOLAR
  46.   // INPKTEND         OUTPKTEND
  47.   // EPxBCH:L         REVCTL
  48.   // GPIFTCB3         GPIFTCB2
  49.   // GPIFTCB1         GPIFTCB0
  50.   // EPxFIFOPFH:L     EPxAUTOINLENH:L
  51.   // EPxFIFOCFG       EPxGPIF**SEL
  52.   // PINFLAGSxx       EPxFIFOIRQ
  53.   // EPxFIFOIE        GPIFIRQ
  54.   // GPIFIE           GPIFADRH:L
  55.   // UDMACRCH:L       EPxGPIFTRIG
  56.   // GPIFTRIG
  57.   
  58.   // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well...
  59.   //      ...these have been replaced by GPIFTC[B3:B0] registers

  60.   // default: all endpoints have their VALID bit set
  61.   // default: TYPE1 = 1 and TYPE0 = 0 --> BULK  
  62.   // default: EP2 and EP4 DIR bits are 0 (OUT direction)
  63.   // default: EP6 and EP8 DIR bits are 1 (IN direction)
  64.   // default: EP2, EP4, EP6, and EP8 are double buffered

  65.   


  66.   // we are just using the default values, yes this is not necessary...
  67.   EP1OUTCFG = 0xA0;
  68.   EP1INCFG = 0xA0;
  69.   SYNCDELAY;                    // see TRM section 15.14
  70.   EP2CFG = 0xE0;
  71.   SYNCDELAY;                    
  72.   EP4CFG = 0x60;        // disabled...
  73.   SYNCDELAY;                    
  74.   EP6CFG = 0x60;        // disabled...
  75.   SYNCDELAY;                    
  76.   EP8CFG = 0x60;        // disabled...



  77.   //=========================大大的分割线=================================//
  78.      //复位FIFO,先复位端点,再清空端点(Page 340)
  79.     SYNCDELAY;
  80.     FIFORESET = 0x80;// activate NAK-ALL to avoid race conditions
  81.     SYNCDELAY;
  82.     FIFORESET = 0x02;// reset, FIFO 2
  83.     SYNCDELAY;
  84.      FIFORESET = 0x04;// reset, FIFO 4
  85.     SYNCDELAY;
  86.     FIFORESET = 0x06;// reset, FIFO 6
  87.     SYNCDELAY;
  88.   FIFORESET = 0x08;// reset, FIFO 8
  89.     SYNCDELAY;
  90.     FIFORESET = 0x00;// deactivate NAK-AL
  91.     SYNCDELAY;


  92. //Configure the EPxFIFOCFG(Page 349)
  93.     EP2FIFOCFG = 0x08;     // autoin, 8 Bit Wide,0000_1000  自动使能IN
  94. //    EP2FIFOCFG = 0x09;     // autoin, 16 Bit Wide
  95.     SYNCDELAY;            
  96.     EP4FIFOCFG = 0x00;    // no-autoOUT, bytewide
  97.     SYNCDELAY;                     
  98.     EP6FIFOCFG = 0x00;     // no-autoOUT, bytewide
  99.     SYNCDELAY;                     
  100.     EP8FIFOCFG = 0x00;    // no-autoOUT, bytewide
  101.     SYNCDELAY;   
  102.    
  103. //--------------------------------------------------------


  104. //Configure PIN Polarity
  105.     PORTACFG = 0x40;    //IFCOG[1:0] = 11(Slave FIFO Mode), Set PORTACFG[6] to USE PA7-SLCS (Page 275) 0100_0000
  106.     SYNCDELAY;   
  107.     FIFOPINPOLAR = 0x04;    //BIT[5:0] = {PKTEND, SLOE, SLRD, SLWR, EMPTY, FULL}--0000_0100
  108.                             //Set SLWR High Valid; PKTEND,SLOE,SLRD EMPTY, FULL Low Active(Page 342)
  109.     SYNCDELAY;
  110.    
  111.    
  112. //--------------------------------------------------------
  113. //设置为Autoin时的自动传输包大小(Page 239)
  114.     SYNCDELAY;
  115.      EP2AUTOINLENH = 0x02; // EZ-USB automatically commits data in 512-byte chunks  0000_0010
  116. //     EP2AUTOINLENH = 0x04; // EZ-USB automatically commits data in 1024-byte chunks
  117.     SYNCDELAY;
  118.      EP2AUTOINLENL = 0x00;
  119.     SYNCDELAY;

  120. //Set Autopointer, enable dual autopointer(Page 215-216)
  121.     AUTOPTRSETUP = 0x01;  


  122. //FLAGA - User-Programmable Level; FLAGB - FIFO Full, FLAGC - FIFO Empty: (L: Valid)(Page 223)
  123.     PINFLAGSAB = 0x00;//0x8a;
  124.     SYNCDELAY;  
  125.     PINFLAGSCD = 0x00;//0x08;
  126.     SYNCDELAY;            





  127.   //===========================大大的分割线===============================//
  128. /*
  129.     // out endpoints do not come up armed
  130.   
  131.   // since the defaults are double buffered we must write dummy byte counts twice
  132.   SYNCDELAY;                    
  133.   EP2BCL = 0x80;                // arm EP2OUT by writing byte count w/skip.
  134.   SYNCDELAY;                    
  135.   EP2BCL = 0x80;
  136.   SYNCDELAY;                    
  137.   EP4BCL = 0x80;                // arm EP4OUT by writing byte count w/skip.
  138.   SYNCDELAY;                    
  139.   EP4BCL = 0x80;

  140. */  

  141.   // enable dual autopointer feature
  142.   //AUTOPTRSETUP |= 0x01;

  143. }


  144. void TD_Poll(void)              // Called repeatedly while the device is idle
  145. {
  146.   
  147. }

  148. BOOL TD_Suspend(void)          // Called before the device goes into suspend mode
  149. {
  150.    return(TRUE);
  151. }

  152. BOOL TD_Resume(void)          // Called after the device resumes
  153. {
  154.    return(TRUE);
  155. }

  156. //-----------------------------------------------------------------------------
  157. // Device Request hooks
  158. //   The following hooks are called by the end point 0 device request parser.
  159. //-----------------------------------------------------------------------------

  160. BOOL DR_GetDescriptor(void)
  161. {
  162.    return(TRUE);
  163. }

  164. BOOL DR_SetConfiguration(void)   // Called when a Set Configuration command is received
  165. {
  166.    Configuration = SETUPDAT[2];
  167.    return(TRUE);            // Handled by user code
  168. }

  169. BOOL DR_GetConfiguration(void)   // Called when a Get Configuration command is received
  170. {
  171.    EP0BUF[0] = Configuration;
  172.    EP0BCH = 0;
  173.    EP0BCL = 1;
  174.    return(TRUE);            // Handled by user code
  175. }

  176. BOOL DR_SetInterface(void)       // Called when a Set Interface command is received
  177. {
  178.    AlternateSetting = SETUPDAT[2];
  179.    return(TRUE);            // Handled by user code
  180. }

  181. BOOL DR_GetInterface(void)       // Called when a Set Interface command is received
  182. {
  183.    EP0BUF[0] = AlternateSetting;
  184.    EP0BCH = 0;
  185.    EP0BCL = 1;
  186.    return(TRUE);            // Handled by user code
  187. }

  188. BOOL DR_GetStatus(void)
  189. {
  190.    return(TRUE);
  191. }

  192. BOOL DR_ClearFeature(void)
  193. {
  194.    return(TRUE);
  195. }

  196. BOOL DR_SetFeature(void)
  197. {
  198.    return(TRUE);
  199. }

  200. BOOL DR_VendorCmnd(void)
  201. {
  202.   BYTE tmp;
  203.   
  204.   switch (SETUPDAT[1])
  205.   {
  206.      case VR_NAKALL_ON:
  207.         tmp = FIFORESET;
  208.         tmp |= bmNAKALL;      
  209.         SYNCDELAY;                    
  210.         FIFORESET = tmp;
  211.         break;
  212.      case VR_NAKALL_OFF:
  213.         tmp = FIFORESET;
  214.         tmp &= ~bmNAKALL;      
  215.         SYNCDELAY;                    
  216.         FIFORESET = tmp;
  217.         break;
  218.      default:
  219.         return(TRUE);
  220.   }

  221.   return(FALSE);
  222. }

  223. //-----------------------------------------------------------------------------
  224. // USB Interrupt Handlers
  225. //   The following functions are called by the USB interrupt jump table.
  226. //-----------------------------------------------------------------------------

  227. // Setup Data Available Interrupt Handler
  228. void ISR_Sudav(void) interrupt 0
  229. {
  230.    GotSUD = TRUE;            // Set flag
  231.    EZUSB_IRQ_CLEAR();
  232.    USBIRQ = bmSUDAV;         // Clear SUDAV IRQ
  233. }

  234. // Setup Token Interrupt Handler
  235. void ISR_Sutok(void) interrupt 0
  236. {
  237.    EZUSB_IRQ_CLEAR();
  238.    USBIRQ = bmSUTOK;         // Clear SUTOK IRQ
  239. }

  240. void ISR_Sof(void) interrupt 0
  241. {
  242.    EZUSB_IRQ_CLEAR();
  243.    USBIRQ = bmSOF;            // Clear SOF IRQ
  244. }

  245. void ISR_Ures(void) interrupt 0
  246. {
  247.    // whenever we get a USB reset, we should revert to full speed mode
  248.    pConfigDscr = pFullSpeedConfigDscr;
  249.    ((CONFIGDSCR xdata *) pConfigDscr)->type = CONFIG_DSCR;
  250.    pOtherConfigDscr = pHighSpeedConfigDscr;
  251.    ((CONFIGDSCR xdata *) pOtherConfigDscr)->type = OTHERSPEED_DSCR;

  252.    EZUSB_IRQ_CLEAR();
  253.    USBIRQ = bmURES;         // Clear URES IRQ
  254. }

  255. void ISR_Susp(void) interrupt 0
  256. {
  257.    Sleep = TRUE;
  258.    EZUSB_IRQ_CLEAR();
  259.    USBIRQ = bmSUSP;
  260. }

  261. void ISR_Highspeed(void) interrupt 0
  262. {
  263.    if (EZUSB_HIGHSPEED())
  264.    {
  265.       pConfigDscr = pHighSpeedConfigDscr;
  266.       ((CONFIGDSCR xdata *) pConfigDscr)->type = CONFIG_DSCR;
  267.       pOtherConfigDscr = pFullSpeedConfigDscr;
  268.       ((CONFIGDSCR xdata *) pOtherConfigDscr)->type = OTHERSPEED_DSCR;
  269.    }

  270.    EZUSB_IRQ_CLEAR();
  271.    USBIRQ = bmHSGRANT;
  272. }
  273. void ISR_Ep0ack(void) interrupt 0
  274. {
  275. }
  276. void ISR_Stub(void) interrupt 0
  277. {
  278. }
  279. void ISR_Ep0in(void) interrupt 0
  280. {
  281. }
  282. void ISR_Ep0out(void) interrupt 0
  283. {
  284. }
  285. void ISR_Ep1in(void) interrupt 0
  286. {
  287. }
  288. void ISR_Ep1out(void) interrupt 0
  289. {
  290. }
  291. void ISR_Ep2inout(void) interrupt 0
  292. {
  293. }
  294. void ISR_Ep4inout(void) interrupt 0
  295. {
  296. }
  297. void ISR_Ep6inout(void) interrupt 0
  298. {
  299. }
  300. void ISR_Ep8inout(void) interrupt 0
  301. {
  302. }
  303. void ISR_Ibn(void) interrupt 0
  304. {
  305. }
  306. void ISR_Ep0pingnak(void) interrupt 0
  307. {
  308. }
  309. void ISR_Ep1pingnak(void) interrupt 0
  310. {
  311. }
  312. void ISR_Ep2pingnak(void) interrupt 0
  313. {
  314. }
  315. void ISR_Ep4pingnak(void) interrupt 0
  316. {
  317. }
  318. void ISR_Ep6pingnak(void) interrupt 0
  319. {
  320. }
  321. void ISR_Ep8pingnak(void) interrupt 0
  322. {
  323. }
  324. void ISR_Errorlimit(void) interrupt 0
  325. {
  326. }
  327. void ISR_Ep2piderror(void) interrupt 0
  328. {
  329. }
  330. void ISR_Ep4piderror(void) interrupt 0
  331. {
  332. }
  333. void ISR_Ep6piderror(void) interrupt 0
  334. {
  335. }
  336. void ISR_Ep8piderror(void) interrupt 0
  337. {
  338. }
  339. void ISR_Ep2pflag(void) interrupt 0
  340. {
  341. }
  342. void ISR_Ep4pflag(void) interrupt 0
  343. {
  344. }
  345. void ISR_Ep6pflag(void) interrupt 0
  346. {
  347. }
  348. void ISR_Ep8pflag(void) interrupt 0
  349. {
  350. }
  351. void ISR_Ep2eflag(void) interrupt 0
  352. {
  353. }
  354. void ISR_Ep4eflag(void) interrupt 0
  355. {
  356. }
  357. void ISR_Ep6eflag(void) interrupt 0
  358. {
  359. }
  360. void ISR_Ep8eflag(void) interrupt 0
  361. {
  362. }
  363. void ISR_Ep2fflag(void) interrupt 0
  364. {
  365. }
  366. void ISR_Ep4fflag(void) interrupt 0
  367. {
  368. }
  369. void ISR_Ep6fflag(void) interrupt 0
  370. {
  371. }
  372. void ISR_Ep8fflag(void) interrupt 0
  373. {
  374. }
  375. void ISR_GpifComplete(void) interrupt 0
  376. {
  377. }
  378. void ISR_GpifWaveform(void) interrupt 0
  379. {
  380. }




Verilog--fifo_wr.v
  1. module fifo_wr(
  2.     clk    ,
  3.     rst_n  ,
  4.     //Other signal

  5.     //input
  6.     fifo_full   ,//flag
  7.     load        ,
  8.    // fifo_empty  ,//flag
  9.     //output
  10.     fifo_wr     ,//fifo_wr signal  
  11.     fifo_data   ,//fifo write data
  12.     fifoadr      //select fifo
  13.     );

  14.     //参数定义
  15.     parameter      DATA_W   =  8;
  16.     parameter      STATE_W  =  3;

  17.     parameter      IDLE     =  0;
  18.     parameter      S1       =  1;
  19.     parameter      S2       =  2;
  20.     parameter      S3       =  3;
  21.     parameter      S4       =  4;


  22.     //输入信号定义
  23.     input               clk         ;
  24.     input               rst_n       ;

  25.     input               fifo_full   ;
  26.     input               load        ;
  27.     //input               fifo_empty  ;

  28.     //输出信号定义
  29.     output              fifo_wr     ;
  30.     output[DATA_W-1:0]  fifo_data   ;
  31.     output[2-1:0]       fifoadr     ;

  32.     //输出信号reg定义
  33.     reg                 fifo_wr     ;
  34.     reg   [DATA_W-1:0]  fifo_data   ;
  35.     reg   [2-1:0]       fifoadr     ;

  36.     //中间信号定义
  37.    reg                  clkin       ;
  38.    reg    [STATE_W-1:0] state_c     ;
  39.    reg   [STATE_W-1:0] state_n     ;

  40.    wire                 start_s3    ;
  41.    wire                 end_s4    ;

  42.    wire  [DATA_W-1:0]   rand_num;


  43.   //First div clk by 2
  44.    always  @(posedge clk or negedge rst_n)begin
  45.        if(rst_n==1'b0)begin
  46.            clkin <= 'b1;
  47.        end
  48.        else begin
  49.            clkin<= ~clkin;
  50.        end
  51.    end

  52.    
  53.    //三段式状态机
  54.     //第一个进程,同步时序always模块,格式化描述次态寄存器迁移到现态寄存器(不需更改)
  55.     always@(posedge clkin or negedge rst_n)begin
  56.         if(!rst_n)begin
  57.             state_c <= IDLE;
  58.         end
  59.         else begin
  60.             state_c <= state_n;
  61.         end
  62.     end

  63.     //第二个进程,组合逻辑always模块,描述状态转移条件判断
  64.     always@(*)begin
  65.         case(state_c)
  66.             IDLE:begin
  67.                  state_n = S1;
  68.             end
  69.             S1:begin
  70.                 state_n = S2   ;
  71.             end
  72.             S2:begin
  73.                 if(start_s3)begin
  74.                     state_n = S3;
  75.                 end
  76.                 else begin
  77.                     state_n = state_c;
  78.                 end
  79.             end
  80.             S3:begin
  81.                 state_n = S4;
  82.             end
  83.             S4:begin
  84.                 if(end_s4)begin
  85.                     state_n = S2;
  86.                 end
  87.                 else begin
  88.                     state_n = IDLE;
  89.                 end
  90.             end
  91.             default:begin
  92.                 state_n = IDLE;
  93.             end
  94.         endcase
  95.     end
  96.     //assign start_s1 = state_c==IDLE && ;
  97.     assign start_s3 = state_c==S2   && fifo_full;
  98.     assign end_s4 = state_c==S3   && fifo_full;
  99.     //assign end_s2   = state_c==S2   && ;

  100.    
  101.     //第三个进程,同步时序always模块,格式化描述寄存器输出(可有多个输出)
  102.    
  103.     //fifoadr 此处应该考虑写状态fifoadr和非写状态的fifoadr是不一样的
  104.     always  @(posedge clkin or negedge rst_n)begin
  105.         if(rst_n==1'b0 )begin
  106.             fifoadr <= 2'b 10;
  107.         end
  108.         else begin
  109.             fifoadr <= 2'b 10;//10指的是EP6
  110.         end
  111. //else if(state_c==S1)begin
  112.         //    fifoadr <= 2'b00;//目前还不知道具体选哪个
  113.        // end
  114.     end

  115.     //fifo_wr
  116.     always  @(posedge clkin or negedge rst_n)begin
  117.         if(!rst_n)begin
  118.             fifo_wr <=1'b0;      //初始化
  119.         end
  120.         else if(state_c==S3)begin
  121.             fifo_wr <= 1'b1;
  122.         end
  123.         else begin
  124.             fifo_wr <= 1'b0;
  125.         end
  126.     end
  127.    
  128.    

  129.     //fifo_data
  130.     always  @(posedge clkin or negedge rst_n)begin
  131.         if(rst_n==1'b0)begin
  132.             fifo_data <= 'hff;
  133.         end
  134.         else if(state_c == S3)begin
  135.             fifo_data <= rand_num ;
  136.         end
  137.     end
  138.    

  139.     //例化RanGen
  140.     RanGen  uut_RanGen(
  141.             .clk                (clk     ),
  142.             .rst_n              (rst_n   ),
  143.             .load               (load    ),
  144.             .rand_num           (rand_num)
  145.    
  146.    
  147.    
  148.     );


  149.     endmodule



 楼主| nuageux 发表于 2017-8-31 14:37 | 显示全部楼层
没有大佬吗?
光电人生 发表于 2018-1-20 19:54 | 显示全部楼层
问题解决了么?我觉得还是固件的问题,看看配置寄存器有没有设对
liuweisword 发表于 2018-2-6 17:27 | 显示全部楼层
KEIL 项目里有个 汇编写的 A51文件, 你要改里面的内容才行,只配寄存器没有用。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

4

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部