📄 f34x_msd_usb_isr.c
字号:
POLL_WRITE_BYTE(E0CSR, TempReg); // Write mask to E0CSR
}
}
}
}
//----------------------------------------------------------------------------
// Handle_In1
//----------------------------------------------------------------------------
//
// - This routine loads the current value from In_Packet on the Endpoint 1
// fifo, after an interrupt is received from the last packet being
// transmitted
//
// Parameters : ptr_buf - pointer to buffer with in_pocket
// Return Value :
//----------------------------------------------------------------------------
void Handle_In1(BYTE* ptr_buf)
{
BYTE control_reg;
POLL_WRITE_BYTE(INDEX, EP1_IN_IDX); // Set index to endpoint 1 registers
POLL_READ_BYTE(EINCSR1, control_reg); // Read contol register for EP 1
if (Ep_Status[1] == EP_HALT) // If endpoint is currently halted, send a stall
{
POLL_WRITE_BYTE(EINCSR1, rbInSDSTL);
}
else // Otherwise send last updated data to host
{
if (control_reg & rbInSTSTL) // Clear sent stall if last packet returned a stall
{
POLL_WRITE_BYTE(EINCSR1, rbInCLRDT);
}
if (control_reg & rbInUNDRUN) // Clear underrun bit if it was set
{
POLL_WRITE_BYTE(EINCSR1, 0x00);
}
// Put new data on Fifo
// Fifo_Write(FIFO_EP1, EP1_PACKET_SIZE, (BYTE *)IN_PACKET);
Fifo_Write(FIFO_EP1, In_count, (BYTE *)ptr_buf);
POLL_WRITE_BYTE(EINCSR1, rbInINPRDY);
// Set In Packet ready bit, indicating fresh data
} // on Fifo 1
}
//----------------------------------------------------------------------------
// USB_Bulk_Init
//----------------------------------------------------------------------------
//
// Function rests the input and output counters for USB
//
// Parameters :
// Return Value :
//----------------------------------------------------------------------------
void USB_Bulk_Init() {
In_count=0;
Out_Count=0;
}
//----------------------------------------------------------------------------
// USB_In
//----------------------------------------------------------------------------
//
// The function sends the series of characters via USB
//
// Parameters : ptr_buf - pointer to buffer,
// count - number of bytes
// Return Value :
//----------------------------------------------------------------------------
void USB_In(BYTE* ptr_buf,unsigned count) {
DWORD t1=tickcount+500;
while(In_count && (tickcount<t1))
;
if(In_count) {
return;
}
In_count=count;
Handle_In1(ptr_buf);
}
//----------------------------------------------------------------------------
// Handle_Out2
//----------------------------------------------------------------------------
//
// Take the received packet from the host off the fifo and put it into the
// Out_Packet array
//
// Parameters :
// Return Value :
//----------------------------------------------------------------------------
void Handle_Out2() {
BYTE count=0;
BYTE control_reg;
POLL_WRITE_BYTE(INDEX, EP2_OUT_IDX); // Set index to endpoint 2 registers
POLL_READ_BYTE(EOUTCSR1, control_reg);
if (Ep_Status[2] == EP_HALT) // If endpoint is halted, send a stall
{
POLL_WRITE_BYTE(EOUTCSR1, rbOutSDSTL);
}
else // Otherwise read received packet from
// host
{
if (control_reg & rbOutSTSTL) // Clear sent stall bit if last packet
//was a stall
{
POLL_WRITE_BYTE(EOUTCSR1, rbOutCLRDT);
}
POLL_READ_BYTE(EOUTCNTL, count);
Out_Count=count;
POLL_READ_BYTE(EOUTCNTH, count);
Out_Count|=((unsigned)count)<<8;
// FOR MSD, the host does not send EP2_PACKET_SIZE bytes, but rather 31 bytes
// if (count != EP2_PACKET_SIZE) // If host did not send correct packet
// size, flush buffer
// {
// POLL_WRITE_BYTE(EOUTCNTL, rbOutFLUSH);
// }
// else // Otherwise get the data packet
// {
// Fifo_Read(FIFO_EP2, count, (BYTE*)Out_Packet);
// }
// POLL_WRITE_BYTE(EOUTCSR1, 0); // Clear Out Packet ready bit
}
}
//----------------------------------------------------------------------------
// Out2_Get_Data
//----------------------------------------------------------------------------
//
// Enter suspend mode after suspend signalling is present on the bus
//
// Parameters : ptr_buf - pointer to read data destination buffer
// Return Value :
//----------------------------------------------------------------------------
void Out2_Get_Data(BYTE* ptr_buf) {
Fifo_Read(FIFO_EP2, Out_Count, ptr_buf);
}
//----------------------------------------------------------------------------
// Out2_Done
//----------------------------------------------------------------------------
//
// This routine clears out packet ready bit and out_counter to boot
//
// Parameters :
// Return Value :
//----------------------------------------------------------------------------
void Out2_Done() {
POLL_WRITE_BYTE(EOUTCSR1, 0); // Clear Out Packet ready bit
Out_Count=0;
}
//----------------------------------------------------------------------------
// USB_Suspend
//----------------------------------------------------------------------------
//
// Enter suspend mode after suspend signalling is present on the bus
//
// Parameters :
// Return Value :
//----------------------------------------------------------------------------
void USB_Suspend(void)
{ // Add power-down features here if
// you wish to
volatile int k; // reduce power consumption during
// suspend mode
k++;
}
//----------------------------------------------------------------------------
// FIFO Read
//----------------------------------------------------------------------------
//
// Read from the selected endpoint FIFO
//
// Parameters : addr - target address
// u_num_bytes - number of bytes to unload
// ptr_data - read data destination
// Return Value :
//----------------------------------------------------------------------------
#if 1
void Fifo_ReadC(BYTE addr, unsigned int u_num_bytes, BYTE * ptr_data)
{
int i;
if (u_num_bytes) // Check if >0 bytes requested,
{
USB0ADR = (addr); // Set address
USB0ADR |= 0xC0; // Set auto-read and initiate
// first read
// Unload <NumBytes> from the selected FIFO
for(i=0;i<u_num_bytes;i++)
{
while(USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
ptr_data[i] = USB0DAT; // Copy data byte
}
USB0ADR = 0; // Clear auto-read
}
}
#endif
//----------------------------------------------------------------------------
// FIFO Write
//----------------------------------------------------------------------------
//
// Write to the selected endpoint FIFO
//
// Parameters : addr - target address
// u_num_bytes - number of bytes to write
// ptr_data - location of source data
// Return Value :
//----------------------------------------------------------------------------
#if 0
void Fifo_Write(BYTE addr, unsigned int u_num_bytes, BYTE * ptr_data) reentrant
{
int i;
START_SPI_TIMEOUT ;
// If >0 bytes requested,
if (u_num_bytes)
{
while(USB0ADR & 0x80); // Wait for BUSY->'0'
// (register available)
USB0ADR = (addr); // Set address (mask out bits7-6)
// Write <NumBytes> to the selected FIFO
for(i=0;i<u_num_bytes;i++)
{
USB0DAT = ptr_data[i];
while(USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
}
}
STOP_SPI_TIME_OUT;
}
#endif
//----------------------------------------------------------------------------
// Force_Stall
//----------------------------------------------------------------------------
//
// Force a procedural stall to be sent to the host
//
// Parameters :
// Return Value :
//----------------------------------------------------------------------------
void Force_Stall(void)
{
POLL_WRITE_BYTE(INDEX, EP0_IDX);
POLL_WRITE_BYTE(E0CSR, rbSDSTL); // Set the send stall bit
Ep_Status[0] = EP_STALL; // Put the endpoint in stall status
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -