![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
usb_cdc interrupt? |
Posted: Fri Feb 21, 2014 6:45 am |
|
|
Hello!
I want to interrupt my main routine when I receive data trough usb_cdc equivalent to INT_RDA.
I am using usb_cdc.
Is there interrupt handler for usb_cdc?
#int_usb doesnt work for me, I dont know why. . . _________________ A person who never made a mistake never tried anything new. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Fri Feb 21, 2014 9:21 am |
|
|
Because INT_USB is being used all the time by the driver.....
Key to remember is that USB, does not involve just the characters you send arriving.
If you look at the USB driver, it provides the ability to do what you want.
pic18_usb.c
#INT_USB is the main interrupt handler.
You will see that it has to handle USB errors, attached/detached, stall, reset, idle, start of frame etc. etc.. If you want to handle the USB interrupt, your handler has to handle all of these....
However the key is the define 'USB_CDC_ISR'.
If you declare a function with this name, the compiler automatically adds the code to call _this_ when data is available.
So:
Code: |
void USB_CDC_ISR(void);
//Then the USB includes after this is prototyped
#include <usb_cdc.h>
void USB_CDC_ISR(void)
{
//do what you want here when data arrives - use the usb_getc
//function to get the data etc.
}
|
Your USB_CDC_ISR function will then be _added_ to the INT_USB function, and will only be called when data is available.
It needs to be prototyped before the USB code is loaded, but only defined afterwards (otherwise it can't call things like usb_cdc_getc....)
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Sat Feb 22, 2014 6:21 am |
|
|
First, Thank you again, now it works! The information you pointed me is available in usb_cdc.h
Quote: |
//// USB_CDC_ISR()can be defined if you want a specific routine to ////
//// be called when there is incoming CDC (virtual com port) data. ////
//// This is useful if you want to update legacy RS232 code that ////
//// was using #int_rda to handle incoming data in the RS232 ISR. |
BTW, in pic18_usb.h I found something new for me. It is
Code: | #if defined(USB_CDC_ISR) | USB_CDC_ISR is the interrupt handler function, right?
I wasn't able to see #if defined(my_func) explanation in CCS Manual. I also made a google search for #if defined and the result was this: Quote: | #ifdef MACRO.
defined is useful when you wish to test more than one macro for existence at once. For example,
#if defined (__vax__) || defined (__ns16000__) |
So, if can be used only for macros, then what I saw(#if defined(USB_CDC_ISR)) in pic18_usb.h is not interrupt handler verification, but macros verification. Let me make the question simpler. Is it legal in C to check if my_func exist this way:
Code: | #if defined(my_func) | ?
I know it is C programming issue, but after long search I wasn't able to see the relation to my code. _________________ A person who never made a mistake never tried anything new. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Sat Feb 22, 2014 7:52 am |
|
|
Actually well done, on spotting this....
The 'defined' test, will test for a 'label' being defined, as well as a #define. So provided the function is prototyped before you load the usb_cdc driver, the #if returns true. I agree it 'disagrees' with the manual, so I tried it (always the safest thing), and proved that #if defined, does return true if a function with the name exists.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Sat Feb 22, 2014 1:59 pm |
|
|
It is very useful and applicable operation. It should has been described into the "manual". Anyway, you did clarify "the picture" for me. I am very grateful! _________________ A person who never made a mistake never tried anything new. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|