📄 ep3_iso.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 ServiceEP3IN(void);
void ServiceEP3OUT(void);
// Variable Declarations
unsigned char FrameCount = 0x00;
/*
** ServiceEP3IN
*
* FILENAME: EP3_ISO.c
*
* PARAMETERS: None
*
* DESCRIPTION: When called, loads EP3 IN with data and frame count
* to send to HOST. data is stored in a buffer (EP2Buffer)
* and is actually A/D data repeated 7 times.
*
* RETURNS: Nothing
*
*/
void ServiceEP3IN(void){
if ( !USBFlags.Configured ){ // If device is not configured, then don't do this
return; // as it will cause problems
}
ep3il = FrameCount++; // load the frame count
ep3il = EP2Buffer[0]; // and load the data
ep3il = EP2Buffer[0]; //
ep3il = EP2Buffer[0]; //
ep3il = EP2Buffer[0]; //
ep3il = EP2Buffer[0]; //
ep3il = EP2Buffer[0]; //
ep3il = EP2Buffer[0]; //
ep3ics = 0x0108; // Set IN_BUF_RDY and ISO bit so send data out
// ISO bit must be set every time data is transfered
// using ISO
}
/*
** ServiceEP3OUT
*
* FILENAME: EP3_ISO.c
*
* PARAMETERS:
*
* DESCRIPTION:
*
* RETURNS:
*
*/
void ServiceEP3OUT(void){
unsigned int i,j;
if ( !USBFlags.Configured ){ // If device is not configured, then don't do this
return; // as it will cause problems
}
/* Keep track of how many times we have entered this routine. */
iso_out_xfers++;
/* read out the number of bytes just sent */
amount_sent = ep3wcl;
// read them out of the fifo
for( i = 0; i < amount_sent; i++ )
iso_buffer[i] = ep3ol;
total_count += amount_sent;
/* Clear OUT_PKT_RDY bit and set iso bit for endpoint 3 */
/* NOTE: You MUST set the iso bit every time as done here. */
ep3ocs = 0x0820;
/* Send info to the display buffer to get displayed */
i = 0; // use to index tmp_buffer
/* output the mouse coordinates */
/* the packet format should be....
Byte Value
0,1 Packet Count
2,3 X Coordinates
4,5 Y Coordinates
*/
/********* X *********/
j = iso_buffer[2] * 256;
j += iso_buffer [3];
tmp_buffer[ i++ ] = (j / 100) + '0';
j = j % 100;
tmp_buffer[ i++ ] = (j / 10) + '0';
tmp_buffer[ i++ ] = (j % 10) + '0';
/******** COMMA ********/
tmp_buffer[ i++ ] = ',';
/********* Y *********/
j = iso_buffer[4] * 256;
j += iso_buffer [5];
tmp_buffer[ i++ ] = (j / 100) + '0';
j = j % 100;
tmp_buffer[ i++ ] = (j / 10) + '0';
tmp_buffer[ i++ ] = (j % 10) + '0';
/******* CR LF *******/
tmp_buffer[ i++ ] = '\n';
tmp_buffer[ i++ ] = '\r';
j = 0;
/* check for buffer roll over */
if( (next_empty + i) <= 256 ) {
/* no roll over so just copy straight in */
for( ; i > 0 ;i-- )
disp_buffer[ next_empty++ ] = tmp_buffer[j++];
}
else {
/* you must roll over to begining of the buffer */
for( ; i > 0 ;i-- ) {
disp_buffer[ next_empty++ ] = tmp_buffer[j++];
next_empty &= 0xFF; // this will auto roll you back to the begining
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -