Understanding USB interruptions
Posted: 21 Aug 2010 22:38
Hi,
I'm analizing a small piece of a program example that communicates a PC with a device through USB port, and saw a couple of things that can`t understand completely.
Look at that example:
#include "D:\MikroCNew\Audidsc.c"
// Function prototypes and variable declarations.
unsigned char Read_buffer[64];
unsigned char Write_buffer[64];
unsigned char Num;
void main(void);
void Conf_Init(void);
// Function definitions
********************************************* til there: all OK
void interrupt() /* Handles interruptions */
{
INTCON.INT0IE=0; // Disables INT0 interrupt
HID_InterruptProc();
TMR0L=46; // Reload timer0 with 100
INTCON.TMR0IF=0; // Resets TMR0 interrupt flag
INTCON.INT0IE=1; // Enables INT0 interrupt
}
*******************************************til there: code understandable but can't see the purpose
void Conf_Init()
{
.....
.....// port configurations..
....
UCFG=0x14; /* On-chip USB transceiver enabled, Full speed and pull-up conected */
TRISC=0x0; /* RC7..RC4 configured as DI, the other pins as outputs */
PORTC=0x00;
RCON.IPEN=1; // Enable priority levels of interrupts
***************************************************** til there: all ok
//Configure Timer0 for 3.3 mS interrupt interval.
// Timer0 is in 8 bits mode by default,
T0CON=0x47; // 256 prescaler value
TMR0L=100;
INTCON.TMR0IE=1; //Enable TMR0 interrupt.
T0CON.TMR0ON=1; // Run TMR0
INTCON=0x0E;
*******************************************til there:code understandable but can't see the purpose
}
void main()
{
Conf_Init();
Hid_Enable(&Read_buffer,&Write_buffer);
Delay_ms(1000);
Delay_ms(1000);
.........
USB reading and writing.......
.........
Hid_Disable();
}
Questions:
It is mandatory jump to interrupt handler and call "HID_InterruptProc();" all the time, why?
Why speceficaly every 3.3 mS? It's the time limit there -What would it be?
This time interval depends on what?
I've read a lot of material on Internet finding out an explanation to my questions and the only I understood is that USB device after 3 mS bus inactivity goes in suspend state to save energy. After that if the host (PC) wants to awake a device it should set a proper signal at least 20 mS to give device time to go in "Work state" an then every 1 ms host sends to device a signal "keep a live" to prevent the device goes in suspend state meanwhile the communication is active.
But I can't see the relationship between this info and 3.3 ms calls in the code above.
Does any body could help me, please?
I'm analizing a small piece of a program example that communicates a PC with a device through USB port, and saw a couple of things that can`t understand completely.
Look at that example:
#include "D:\MikroCNew\Audidsc.c"
// Function prototypes and variable declarations.
unsigned char Read_buffer[64];
unsigned char Write_buffer[64];
unsigned char Num;
void main(void);
void Conf_Init(void);
// Function definitions
********************************************* til there: all OK
void interrupt() /* Handles interruptions */
{
INTCON.INT0IE=0; // Disables INT0 interrupt
HID_InterruptProc();
TMR0L=46; // Reload timer0 with 100
INTCON.TMR0IF=0; // Resets TMR0 interrupt flag
INTCON.INT0IE=1; // Enables INT0 interrupt
}
*******************************************til there: code understandable but can't see the purpose
void Conf_Init()
{
.....
.....// port configurations..
....
UCFG=0x14; /* On-chip USB transceiver enabled, Full speed and pull-up conected */
TRISC=0x0; /* RC7..RC4 configured as DI, the other pins as outputs */
PORTC=0x00;
RCON.IPEN=1; // Enable priority levels of interrupts
***************************************************** til there: all ok
//Configure Timer0 for 3.3 mS interrupt interval.
// Timer0 is in 8 bits mode by default,
T0CON=0x47; // 256 prescaler value
TMR0L=100;
INTCON.TMR0IE=1; //Enable TMR0 interrupt.
T0CON.TMR0ON=1; // Run TMR0
INTCON=0x0E;
*******************************************til there:code understandable but can't see the purpose
}
void main()
{
Conf_Init();
Hid_Enable(&Read_buffer,&Write_buffer);
Delay_ms(1000);
Delay_ms(1000);
.........
USB reading and writing.......
.........
Hid_Disable();
}
Questions:
It is mandatory jump to interrupt handler and call "HID_InterruptProc();" all the time, why?
Why speceficaly every 3.3 mS? It's the time limit there -What would it be?
This time interval depends on what?
I've read a lot of material on Internet finding out an explanation to my questions and the only I understood is that USB device after 3 mS bus inactivity goes in suspend state to save energy. After that if the host (PC) wants to awake a device it should set a proper signal at least 20 mS to give device time to go in "Work state" an then every 1 ms host sends to device a signal "keep a live" to prevent the device goes in suspend state meanwhile the communication is active.
But I can't see the relationship between this info and 3.3 ms calls in the code above.
Does any body could help me, please?