Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------------------------------------------------------------
- * RL-ARM - USB
- *----------------------------------------------------------------------------
- * Name: usbd_user_cdc.c
- * Purpose: Communication Device Class User module
- * Rev.: V4.60
- *----------------------------------------------------------------------------
- * This code is part of the RealView Run-Time Library.
- * Copyright (c) 2004-2012 KEIL - An ARM Company. All rights reserved.
- *---------------------------------------------------------------------------*/
- #include <RTL.h>
- #include <rl_usb.h>
- unsigned short ser_lineState = 0; /* ((RSECR << 12) | (FR)) */
- /*----------------------------------------------------------------------------
- open the serial port
- *----------------------------------------------------------------------------*/
- void usbd_cdc_ser_openport (void) {
- // SCU->PCGR1 |= (1 << 17); /* GPIO3 peripheral clock enable */
- // SCU->PRR1 |= (1 << 17); /* GPIO3 peripheral not in reset */
- // SCU->PCGR1 |= (1 << 3); /* UART0 peripheral clock enable */
- // SCU->PRR1 |= (1 << 3); /* UART0 peripheral not in reset */
- // SCU->GPIOOUT[3] &= 0xFFF3;
- // SCU->GPIOOUT[3] |= 0x0008; /* P3.1 output UART0 TX (alt output2) */
- // SCU->GPIOIN[3] &= 0xFE;
- // SCU->GPIOIN[3] |= 0x01; /* P3.0 input UART0 RX (alt input1 ) */
- }
- /*----------------------------------------------------------------------------
- close the serial port
- *----------------------------------------------------------------------------*/
- void usbd_cdc_ser_closeport (void) {
- // SCU->PCGR1 &= ~(1 << 3); /* UART0 peripheral clock disable */
- // SCU->PRR1 &= ~(1 << 3); /* UART0 peripheral in reset */
- // SCU->GPIOOUT[3] &= 0xFFF3;
- // SCU->GPIOIN[3] &= 0xFE;
- // /* Disable the interrupt in the VIC and UART controllers */
- // UART0->IMSC = 0x00; /* Disable UART ints */
- // VIC1->INTECR = (0x01 << (UART0_ITLine - 16)); /* Disable VIC int */
- }
- /*----------------------------------------------------------------------------
- initialize the serial port
- *----------------------------------------------------------------------------*/
- void usbd_cdc_ser_initport (U32 baudrate, U32 databits, U32 parity, U32 stopbits) {
- // unsigned short lcr_p, lcr_s, lcr_d;
- // unsigned long BRDi = 0, BRDf = 0;
- // unsigned long long UARTClk = UART_CLK; /* BRCLK is 96.0 MHz */
- // switch (databits) {
- // case 5: /* 5 Data bits */
- // lcr_d = UART_WordLength_5D;
- // break;
- // case 6: /* 6 Data bits */
- // lcr_d = UART_WordLength_6D;
- // break;
- // case 7: /* 7 Data bits */
- // lcr_d = UART_WordLength_7D;
- // break;
- // case 8: /* 8 Data bits */
- // default:
- // lcr_d = UART_WordLength_8D;
- // break;
- // }
- // switch (stopbits) {
- // case 1: /* 1,5 Stop bits */
- // case 2: /* 2 Stop bits */
- // lcr_s = UART_StopBits_2;
- // break;
- // case 0: /* 1 Stop bit */
- // default:
- // lcr_s = 0x0000;
- // break;
- // }
- // switch (parity) {
- // case 1: /* Parity Odd */
- // lcr_p = UART_Parity_Odd;
- // break;
- // case 2: /* Parity Even */
- // lcr_p = UART_Parity_Even;
- // break;
- // case 3: /* Parity Mark */
- // lcr_p = UART_Parity_OddStick;
- // break;
- // case 4: /* Parity Space */
- // lcr_p = UART_Parity_EvenStick;
- // break;
- // case 0: /* Parity None */
- // default:
- // lcr_p = UART_Parity_No;
- // break;
- // }
- // if ((SCU->CLKCNTR & SCU_BRCLK_Div2) != SCU_BRCLK_Div2) {
- // UARTClk /= 2; /* set UART Clock acc. BRSEL */
- // }
- // /* baudrate calculation */
- // BRDi = ((100 * UARTClk) / (16 * baudrate)); /* calculate the integer part */
- // BRDf = BRDi - (100 * (BRDi / 100)); /* calculate the fractal part */
- // UART0->CR &= 0xFFFE; /* disable UART */
- // UART0->IBRD = BRDi / 100; /* set the integer part */
- // UART0->FBRD = ((((BRDf * 64) + 50) / 100)); /* set the fractal part */
- // UART0->LCR = lcr_d | lcr_p | lcr_s; /* Data bits,Parity, Stop bit */
- // UART0->CR = UART_Mode_Rx | UART_Mode_Tx | 0x0001; /* TX, RX, UART Enable */
- // UART0->IMSC = UART_IT_Transmit |UART_IT_Receive; /* Enable Tx, Rx Int */
- // ser_txRestart = 1; /* TX fifo is empty */
- // /* Set up and enable the UART interrupt in the VIC */
- // VIC0->DVAR = (unsigned int)def_irq; /* Set default interrupt func */
- // VIC1->DVAR = (unsigned int)def_irq;
- // VIC1->VAiR[3] = (unsigned long)usbd_cdc_ser_irq_1; /* Set interrupt func */
- // VIC1->INTSR &= ~(0x01 << (UART0_ITLine - 16)); /* generate an IRQ interrupt*/
- // VIC1->VCiR[3] = 0x20 | (UART0_ITLine - 16); /* enable vetored int No 0 */
- // VIC1->INTER |= (0x01 << (UART0_ITLine - 16)); /* enable the interrupt */
- }
- /*----------------------------------------------------------------------------
- read data from serial port
- *----------------------------------------------------------------------------*/
- S32 usbd_cdc_ser_read (S8 *buffer, const S32 *length) {
- S32 bytesToRead, bytesRead;
- /* Read *length bytes, block if *bytes are not avaialable */
- bytesToRead = *length;
- bytesRead = bytesToRead;
- // while (bytesToRead--) {
- // while (SER_BUF_EMPTY(ser_in)); /* Block until data is available */
- // SER_BUF_RD(ser_in, *buffer++);
- // }
- return (bytesRead);
- }
- /*----------------------------------------------------------------------------
- write data to the serial port
- *----------------------------------------------------------------------------*/
- S32 usbd_cdc_ser_write (const S8 *buffer, S32 *length) {
- S32 bytesToWrite, bytesWritten;
- /* Write *length bytes */
- bytesToWrite = *length;
- bytesWritten = bytesToWrite;
- // while (!SER_BUF_EMPTY(ser_out)); /* Block until space is available */
- // while (bytesToWrite) {
- // SER_BUF_WR(ser_out, *buffer++); /* Read Rx FIFO to buffer */
- // bytesToWrite--;
- // }
- // if (ser_txRestart) {
- // ser_txRestart = 0;
- // SER_BUF_RD(ser_out, UART0->DR); /* Write to the Tx Register */
- // }
- return (bytesWritten);
- }
- /*----------------------------------------------------------------------------
- check if character(s) are available at the serial interface
- *----------------------------------------------------------------------------*/
- void usbd_cdc_ser_availchar (S32 *availChar) {
- // *availChar = SER_BUF_COUNT(ser_in) | SER_BUF_FULL(ser_in);
- *availChar = 0;
- }
- /*----------------------------------------------------------------------------
- read the line state of the serial port
- *----------------------------------------------------------------------------*/
- void usbd_cdc_ser_linestate (U16 *lineState) {
- *lineState = ser_lineState;
- ser_lineState = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement