Understanding USB interruptions

General discussion on mikroC.
Post Reply
Author
Message
BlackBird
Posts: 6
Joined: 22 Jun 2010 22:19

Understanding USB interruptions

#1 Post by BlackBird » 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 :D
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 :D
//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. :o

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?

User avatar
slavisa.zlatanovic
mikroElektronika team
Posts: 1321
Joined: 07 Apr 2009 09:39

Re: Understanding USB interruptions

#2 Post by slavisa.zlatanovic » 26 Aug 2010 12:30

Hi!

We strongly encourage users to switch to PRO version because non-PRO version is an ancestor of PRO compiler
and is no longer being developed. Every new feature, improvement and bug fix will only affect new versions of PRO compilers.
If you're a registered user you'll receive PRO license key free of charge.
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?
HID_InterruptProc() handles the USB communication and must be called as frequent as possible to maintain a secure connection.
Regarding the 3.3 ms interval:
I checked the examples provided with the latest relase of mikroC for PIC and there was no such strict time interval defined.
Are you referring to some custom user code?
Nevertheless, in my opinion time interval of 3.3ms was obtained empirically in order to meet the requirements of that particular project.

Best regards
Slavisa
Best regards
Slavisa

Post Reply

Return to “mikroC General”