📄 ep1_bulk.c
字号:
/*******************************************************************
*
* DESCRIPTION: M30245 Mit_USB Demonstration Application
*
* AUTHOR: Mitsubishi DEC-E
*
* HISTORY: 0.5 5/30/02 Initial creation for NC30
* 1.0 6/18/02 First official release
* 1.1 6/27/02 Updated ISO routines
* 1.2 8/07/02 Updated for Rev B Starter Kit Board
*
*******************************************************************/
/** include files **/
#include "sfr245.h"
#include "extern.h"
// Function Prototypes
void ServiceEP1Out(void);
void LoadEP1IN(void);
void ServiceEP1IN(void);
/*
** ServiceEp1Out
*
* FILENAME: ep1_bulk.c
*
* PARAMETERS: None
*
* DESCRIPTION: Receives BULK data from the HOST here and stores it into RAM
* for transfer back later. Buffer is only 128 bytes deep. Any
* data that exceeds that limit prior to transfer to the HOST is
* flushed from the FIFO
*
* RETURNS: Nothing
*
*/
void ServiceEP1Out(void){
unsigned char i;
unsigned char PacketSize;
if ( !USBFlags.Configured ){ // Device needs to be configured to perform this
return; // otherwise problems could arise.
}
PacketSize = ep1wcl; // Get the size of the packet sent
for ( i = 0; (i < PacketSize) && (BufferSize <= 127); i++){ // add data sent to buffer
BulkBuffer[BufferSize] = ep1ol; // append if data already in buffer
BufferSize ++;
}
if ( (BufferSize == 128) && (PacketSize != 0x00) ){ // If buffer is full and there is
out1csr10 = 1; // more data, then just flush remaining and exit
} // this will reset OBR flags for us
else{
out1csr5 = 1; // Otherwise we can take more data
}
}
/*
** LoadEP1IN
*
* FILENAME: ep1_bulk.c
*
* PARAMETERS: None
*
* DESCRIPTION: Loads EP1 IN with the BULK data in the buffer and sends it
* out until the buffer is empty. This is triggered by a control
* transfer. Data is sent until the buffer is empty.
*
* RETURNS: Nothing
*
*/
void LoadEP1IN(void){
unsigned char i;
if (BufferSize == 0){ // There's no data in buffer so send NULL
in1csr3 = 1; // Set IN_BUF_RDY
}
else if (BufferSize >= 64){ // If there is more that 64 bytes of data in buffer
for (i = 0; i <= 63; i++){ // Then send first packet
ep1il = BulkBuffer[i];
}
in1csr3 = 1; // Send this packet out
BufferSize -= 64; // Get new buffer size
if( BufferSize == 0 ) // Was last packet exacly 64 bytes
BufferSize = -1; // If so signal to send a NULL packet
}
else { // Less than 64 bytes in buffer
for (i = 0; i < BufferSize; i++){ // Load up FIFO w/ data
ep1il = BulkBuffer[i];
}
in1csr3 = 1; // Send this packet out
BufferSize = 0; // Zero out variable so no more data is sent
}
}
/*
** ServiceEP1IN
*
* FILENAME: ep1_bulk.c
*
* PARAMETERS: None
*
* DESCRIPTION: Loads second packet to EP1 IN if necessary.
*
* RETURNS: Nothing
*
*/
void ServiceEP1IN(void){
unsigned char i;
if (BufferSize == 0){ // If data has already been sent, then just exit function
DataTransferFlags.EP1DataTransmit = 0; // Reset flag from ISR
return;
}
else if(BufferSize == -1){ // If a null packet is needed then send it here
in1csr3 = 1; // Set IN_BUF_RDY
BufferSize = 0; // Zero out variable for no more data
}
else { // Must have been more than 64 bytes here
for (i = 0; i <BufferSize; i++){ // Load FIFO with second packet
ep1il = BulkBuffer[64 + i];
}
in1csr3 = 1; // Set IN_BUF_RDY
BufferSize = 0; // Zero out buffer since this must be last packet
if( i == 64 ){ // If last packet was exacly 64 bytes
BufferSize = -1; // then signal to send a NULL packet
}
}
DataTransferFlags.EP1DataTransmit = 0; // Reset flag from ISR
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -