Advertisement
Guest User

usbs_user_cdc.c

a guest
Nov 15th, 2012
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.93 KB | None | 0 0
  1. /*----------------------------------------------------------------------------
  2.  *      RL-ARM - USB
  3.  *----------------------------------------------------------------------------
  4.  *      Name:    usbd_user_cdc.c
  5.  *      Purpose: Communication Device Class User module
  6.  *      Rev.:    V4.60
  7.  *----------------------------------------------------------------------------
  8.  *      This code is part of the RealView Run-Time Library.
  9.  *      Copyright (c) 2004-2012 KEIL - An ARM Company. All rights reserved.
  10.  *---------------------------------------------------------------------------*/
  11.  
  12. #include <RTL.h>
  13. #include <rl_usb.h>
  14.  
  15. unsigned short         ser_lineState = 0;   /* ((RSECR << 12) | (FR))             */
  16.  
  17. /*----------------------------------------------------------------------------
  18.   open the serial port
  19.  *----------------------------------------------------------------------------*/
  20. void usbd_cdc_ser_openport (void) {
  21.    
  22. //   SCU->PCGR1      |= (1 << 17);         /* GPIO3 peripheral clock enable      */
  23. //   SCU->PRR1       |= (1 << 17);         /* GPIO3 peripheral not in reset      */
  24. //   SCU->PCGR1      |= (1 <<  3);         /* UART0 peripheral clock enable      */
  25. //   SCU->PRR1       |= (1 <<  3);         /* UART0 peripheral not in reset      */
  26.  
  27. //   SCU->GPIOOUT[3] &= 0xFFF3;
  28. //   SCU->GPIOOUT[3] |= 0x0008;            /* P3.1 output UART0 TX (alt output2) */
  29. //   SCU->GPIOIN[3]  &= 0xFE;
  30. //   SCU->GPIOIN[3]  |= 0x01;              /* P3.0 input  UART0 RX (alt input1 ) */
  31. }
  32.  
  33. /*----------------------------------------------------------------------------
  34.   close the serial port
  35.  *----------------------------------------------------------------------------*/
  36. void usbd_cdc_ser_closeport (void) {
  37. //   SCU->PCGR1      &= ~(1 <<  3);        /* UART0 peripheral clock disable     */
  38. //   SCU->PRR1       &= ~(1 <<  3);        /* UART0 peripheral      in reset     */
  39.  
  40. //   SCU->GPIOOUT[3] &= 0xFFF3;
  41. //   SCU->GPIOIN[3]  &= 0xFE;
  42.  
  43. //   /* Disable the interrupt in the VIC and UART controllers                    */
  44. //   UART0->IMSC      = 0x00;                          /* Disable UART ints      */
  45. //   VIC1->INTECR     = (0x01 << (UART0_ITLine - 16)); /* Disable VIC int        */
  46. }
  47.  
  48. /*----------------------------------------------------------------------------
  49.   initialize the serial port
  50.  *----------------------------------------------------------------------------*/
  51. void usbd_cdc_ser_initport (U32 baudrate, U32 databits, U32 parity, U32 stopbits) {
  52. //   unsigned short     lcr_p, lcr_s, lcr_d;
  53. //   unsigned long      BRDi = 0, BRDf = 0;
  54. //   unsigned long long UARTClk = UART_CLK;               /* BRCLK is 96.0 MHz */
  55.  
  56. //   switch (databits) {
  57. //     case 5:                             /* 5 Data bits                        */
  58. //       lcr_d = UART_WordLength_5D;
  59. //     break;
  60. //     case 6:                             /* 6 Data bits                        */
  61. //       lcr_d = UART_WordLength_6D;
  62. //     break;
  63. //     case 7:                             /* 7 Data bits                        */
  64. //       lcr_d = UART_WordLength_7D;
  65. //     break;
  66. //     case 8:                             /* 8 Data bits                        */
  67. //     default:
  68. //       lcr_d = UART_WordLength_8D;
  69. //     break;
  70. //   }
  71.  
  72. //   switch (stopbits) {
  73. //     case 1:                             /* 1,5 Stop bits                      */
  74. //     case 2:                             /* 2   Stop bits                      */
  75. //       lcr_s = UART_StopBits_2;
  76. //     break;
  77. //     case 0:                             /* 1   Stop bit                       */
  78. //     default:
  79. //       lcr_s = 0x0000;
  80. //     break;
  81. //   }
  82.  
  83. //   switch (parity) {
  84. //     case 1:                             /* Parity Odd                         */
  85. //       lcr_p = UART_Parity_Odd;
  86. //     break;
  87. //     case 2:                             /* Parity Even                        */
  88. //       lcr_p = UART_Parity_Even;
  89. //     break;
  90. //     case 3:                             /* Parity Mark                        */
  91. //       lcr_p = UART_Parity_OddStick;
  92. //     break;
  93. //     case 4:                             /* Parity Space                       */
  94. //       lcr_p = UART_Parity_EvenStick;
  95. //     break;
  96. //     case 0:                             /* Parity None                        */
  97. //     default:
  98. //       lcr_p = UART_Parity_No;
  99. //     break;
  100. //   }
  101.  
  102. //   if ((SCU->CLKCNTR & SCU_BRCLK_Div2) != SCU_BRCLK_Div2) {
  103. //     UARTClk /= 2;                       /* set UART Clock acc. BRSEL          */
  104. //   }
  105.  
  106. //   /* baudrate calculation                                                     */
  107. //   BRDi = ((100 * UARTClk) / (16 * baudrate));   /* calculate the integer part */
  108. //   BRDf = BRDi - (100 * (BRDi / 100));           /* calculate the fractal part */
  109.  
  110. //   UART0->CR  &= 0xFFFE;                         /* disable UART               */
  111. //   UART0->IBRD = BRDi / 100;                     /* set the integer part       */
  112. //   UART0->FBRD = ((((BRDf * 64) + 50) / 100));   /* set the fractal part       */
  113. //   UART0->LCR  = lcr_d | lcr_p | lcr_s;          /* Data bits,Parity, Stop bit */
  114. //   UART0->CR   = UART_Mode_Rx | UART_Mode_Tx | 0x0001;  /* TX, RX, UART Enable */
  115. //   UART0->IMSC =  UART_IT_Transmit |UART_IT_Receive;    /* Enable Tx, Rx Int   */
  116.  
  117. //   ser_txRestart = 1;                            /* TX fifo is empty           */
  118.  
  119. //   /* Set up and enable the UART interrupt in the VIC                          */
  120. //   VIC0->DVAR = (unsigned int)def_irq;           /* Set default interrupt func */
  121. //   VIC1->DVAR = (unsigned int)def_irq;    
  122.  
  123. //   VIC1->VAiR[3] = (unsigned long)usbd_cdc_ser_irq_1;  /* Set interrupt func   */
  124. //   VIC1->INTSR  &= ~(0x01 << (UART0_ITLine - 16)); /* generate an IRQ interrupt*/
  125. //   VIC1->VCiR[3] =    0x20 | (UART0_ITLine - 16);  /* enable vetored int No 0  */
  126. //   VIC1->INTER  |=  (0x01 << (UART0_ITLine - 16)); /* enable the interrupt     */
  127.  
  128. }
  129.  
  130. /*----------------------------------------------------------------------------
  131.   read data from serial port
  132.  *----------------------------------------------------------------------------*/
  133. S32 usbd_cdc_ser_read (S8 *buffer, const S32 *length) {
  134.   S32 bytesToRead, bytesRead;
  135.  
  136.   /* Read *length bytes, block if *bytes are not avaialable                   */
  137.   bytesToRead = *length;
  138.   bytesRead = bytesToRead;
  139.  
  140. //   while (bytesToRead--) {
  141. //     while (SER_BUF_EMPTY(ser_in));      /* Block until data is available      */
  142. //     SER_BUF_RD(ser_in, *buffer++);
  143. //   }
  144.    
  145.   return (bytesRead);
  146. }
  147.  
  148. /*----------------------------------------------------------------------------
  149.   write data to the serial port
  150.  *----------------------------------------------------------------------------*/
  151. S32 usbd_cdc_ser_write (const S8 *buffer, S32 *length) {
  152.   S32 bytesToWrite, bytesWritten;
  153.  
  154.   /* Write *length bytes */
  155.   bytesToWrite = *length;
  156.   bytesWritten = bytesToWrite;
  157.  
  158. //   while (!SER_BUF_EMPTY(ser_out));      /* Block until space is available     */
  159. //   while (bytesToWrite) {
  160. //     SER_BUF_WR(ser_out, *buffer++);     /* Read Rx FIFO to buffer             */  
  161. //     bytesToWrite--;
  162. //   }
  163.  
  164. //   if (ser_txRestart) {
  165. //     ser_txRestart = 0;
  166. //     SER_BUF_RD(ser_out, UART0->DR);     /* Write to the Tx Register           */
  167. //   }
  168.  
  169.   return (bytesWritten);
  170. }
  171.  
  172. /*----------------------------------------------------------------------------
  173.   check if character(s) are available at the serial interface
  174.  *----------------------------------------------------------------------------*/
  175. void usbd_cdc_ser_availchar (S32 *availChar) {
  176.  
  177. //   *availChar = SER_BUF_COUNT(ser_in) | SER_BUF_FULL(ser_in);
  178.     *availChar = 0;
  179.  
  180. }
  181.  
  182. /*----------------------------------------------------------------------------
  183.   read the line state of the serial port
  184.  *----------------------------------------------------------------------------*/
  185. void usbd_cdc_ser_linestate (U16 *lineState) {
  186.  
  187.   *lineState = ser_lineState;
  188.   ser_lineState = 0;
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement