#include "project.h"
#include <stdio.h>
#include <FS.h>
#define BUFFER_LEN 64u
struct tagFILE
{
uint8 accmd;
uint32 sz;
FS_FILE* fp;
char tFileName[64];
};
static struct tagFILE tFILE;
char8 *parity[] = { "None", "Odd", "Even", "Mark", "Space" };
char8 *stop[] = { "1", "1.5", "2" };
void ready_USB_UART_tx(void);
int main(void)
{
uint8_t buffer[5000];
uint16_t i;
char usb_tx[BUFFER_LEN];
FS_Init();
FS_Mount(0);
FS_FAT_SupportLFN();
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
CyDelay(500);
FS_DIR* pDir;
USBUART_1_Start(0u, USBUART_1_3V_OPERATION);
ready_USB_UART_tx();
pDir = FS_OpenDir("");
sprintf(tFILE.tFileName,"Harry_potter_Goblet_of_Fire.txt");
tFILE.fp = FS_FOpen(tFILE.tFileName, "rb");
tFILE.sz = FS_GetFileSize (tFILE.fp);
sprintf(usb_tx,"File size : %5lu\n\r",tFILE.sz);
while(USBUART_1_CDCIsReady() == 0u); /* Wait till component is ready to send more data to the PC */
USBUART_1_PutString(usb_tx); /* Send data back to PC */
FS_FSeek(tFILE.fp,0,0);
FS_Read(tFILE.fp, buffer, 5000);
for (i=0;i<5000;i++)
{
while(USBUART_1_CDCIsReady() == 0u); /* Wait till component is ready to send more data to the PC */
USBUART_1_PutChar(buffer[i]); /* Send data back to PC */
}
//proc_USB_UART();
for(;;)
{
/* Place your application code here. */
}
}
void ready_USB_UART_tx(void)
{
uint16 count;
uint8 state,led_st=0,cnt_USB_UART_con=0;;
uint8 buffer[BUFFER_LEN];
char tx_buffer[BUFFER_LEN];
/* Main Loop: */
for(;;)
{
if(USBUART_1_IsConfigurationChanged() != 0u) /* Host could send double SET_INTERFACE request */
{
if(USBUART_1_GetConfiguration() != 0u) /* Init IN endpoints when device configured */
{
/* Enumeration is done, enable OUT endpoint for receive data from Host */
USBUART_1_CDC_Init();
}
}
if(USBUART_1_GetConfiguration() != 0u) /* Service USB CDC when device configured */
{
if(USBUART_1_DataIsReady() != 0u) /* Check for input data from PC */
{
count = USBUART_1_GetAll(buffer); /* Read received data and re-enable OUT endpoint */
if(count != 0u)
{
while(USBUART_1_CDCIsReady() == 0u); /* Wait till component is ready to send more data to the PC */
USBUART_1_PutData(buffer, count); /* Send data back to PC */
/* If the last sent packet is exactly maximum packet size,
* it shall be followed by a zero-length packet to assure the
* end of segment is properly identified by the terminal.
*/
if(count == BUFFER_LEN)
{
while(USBUART_1_CDCIsReady() == 0u); /* Wait till component is ready to send more data to the PC */
USBUART_1_PutData(NULL, 0u); /* Send zero-length packet to PC */
}
}
}
state = USBUART_1_IsLineChanged(); /* Check for Line settings changed */
if(state != 0u)
{
if(state & USBUART_1_LINE_CODING_CHANGED) /* Show new settings */
{
sprintf(tx_buffer,"BR:%4ld,DB:%d\n\r",USBUART_1_GetDTERate(),(uint16)USBUART_1_GetDataBits());
sprintf(tx_buffer,"SB:%s,Parity:%s\n\r", stop[(uint16)USBUART_1_GetCharFormat()], \
parity[(uint16)USBUART_1_GetParityType()]);
}
if(state & USBUART_1_LINE_CONTROL_CHANGED) /* Show new settings */
{
state = USBUART_1_GetLineControl();
sprintf(tx_buffer,"DTR:%s,RTS:%s\n\r", (state & USBUART_1_LINE_CONTROL_DTR) ? "ON" : "OFF", \
(state & USBUART_1_LINE_CONTROL_RTS) ? "ON" : "OFF");
cnt_USB_UART_con++;
if (cnt_USB_UART_con > 1)
break;
}
}
}
}
}