Forums

interrupts with FX2

Started by jan0385 October 12, 2010
On 13/10/2010 07:49, jan0385 wrote:
>> On 12/10/2010 15:03, jan0385 wrote: >>> When I don't define this ISR, the firmware is running because.. >>> >>> With my Computer I send bulk requests to the FX2. Ok, and when I define > the >>> ISR the the FX2 don't respond to this requests. When I don't define > this >>> ISR, the FX2 sends an USB message after receiving the bulk request. >>> >>> >>> >>> --------------------------------------- >>> Posted through http://www.EmbeddedRelated.com >> >> In order to make the conversation easier to follow, please quote the >> last message as I am doing. >> >> So I am assuming therefore that the USB part is in some code elsewhere? > > The FX2 is configured, that he should answer to a bulk request by send an > usb message to the bus. > > The source I got from > http://www.triplespark.net/elec/periph/USB-FX2/software/local_examples.html#hello_world_usb > void main(void) > { > Initialize(); > > for(;;) > { > // Wait for the EP6 buffer to become non-full. > if(!(EP6CS& (1<<3))) > { SetUpBufToTransfer(); } > } > } > > In the SetUpBufToTransfer(); function, data is put in the EP buffer and > made ready for transmission. > > >> >> Are you clearing the interrupt flag? If you don't the interrupt will >> keep firing and the rest of the program will never be able to run. >> > > No the flag should be cleared automaticaly(register TCON). Or is this not > 8051 like? This is my interrupt initialization:
If it's cleared automatically then that should be fine.
> // PORTACFG: FLAGD SLCS(*) 0 0 0 0 INT1 INT0 > // INT0 am PortA > PORTACFG = 0x01; SYNCDELAY; // (delay maybe not needed) > > IP = 0x01; SYNCDELAY; > //xxxxxxx1 > // | > // INT0 auf high priority > > IE = 0x81; SYNCDELAY; > //1xxxxxx1 > //| | > //| Enable interrupts for INT0 > //Global interrupt enable > > TCON |= 0x01; > //xxxxxxx1 > // || > // |1=edge sensitive > // Is set when a negaitve cklock edge is detected on the > //INT0 pin and is automaticaly cleared when the FX2 > //vectors to the corresponding ISR. (TRM of FX2)
What is the ISR code?
>On 13/10/2010 07:49, jan0385 wrote: >>> On 12/10/2010 15:03, jan0385 wrote: >>>> When I don't define this ISR, the firmware is running because.. >>>> >>>> With my Computer I send bulk requests to the FX2. Ok, and when I
define
>> the >>>> ISR the the FX2 don't respond to this requests. When I don't define >> this >>>> ISR, the FX2 sends an USB message after receiving the bulk request. >>>> >>>> >>>> >>>> --------------------------------------- >>>> Posted through http://www.EmbeddedRelated.com >>> >>> In order to make the conversation easier to follow, please quote the >>> last message as I am doing. >>> >>> So I am assuming therefore that the USB part is in some code
elsewhere?
>> >> The FX2 is configured, that he should answer to a bulk request by send
an
>> usb message to the bus. >> >> The source I got from >>
http://www.triplespark.net/elec/periph/USB-FX2/software/local_examples.html#hello_world_usb
>> void main(void) >> { >> Initialize(); >> >> for(;;) >> { >> // Wait for the EP6 buffer to become non-full. >> if(!(EP6CS& (1<<3))) >> { SetUpBufToTransfer(); } >> } >> } >> >> In the SetUpBufToTransfer(); function, data is put in the EP buffer and >> made ready for transmission. >> >> >>> >>> Are you clearing the interrupt flag? If you don't the interrupt will >>> keep firing and the rest of the program will never be able to run. >>> >> >> No the flag should be cleared automaticaly(register TCON). Or is this
not
>> 8051 like? This is my interrupt initialization: >If it's cleared automatically then that should be fine. > >> // PORTACFG: FLAGD SLCS(*) 0 0 0 0 INT1 INT0 >> // INT0 am PortA >> PORTACFG = 0x01; SYNCDELAY; // (delay maybe not needed) >> >> IP = 0x01; SYNCDELAY; >> //xxxxxxx1 >> // | >> // INT0 auf high priority >> >> IE = 0x81; SYNCDELAY; >> //1xxxxxx1 >> //| | >> //| Enable interrupts for INT0 >> //Global interrupt enable >> >> TCON |= 0x01; >> //xxxxxxx1 >> // || >> // |1=edge sensitive >> // Is set when a negaitve cklock edge is detected on the >> //INT0 pin and is automaticaly cleared when the FX2 >> //vectors to the corresponding ISR. (TRM of FX2) > >What is the ISR code? > >
Ok, I overlooked the fact, that using ISRs with the FX2 you have to add the line to the main()-file: #pragma NOIV This setting is required to set up EZUSB-specific interrupt vector table. Then you have to put the ISR in another file than the file, where this statement is. The USB tranfer is not disturbed now. Thats an improvement for the problem. But there's a further problem. In the ISR I increment a variable. This variable I send over USB to my PC to see if the ISR ran. But it is not incremented. Incrementing it in a "normal" function is going well. I declared the variable in an extra header file. The two files (file with main() and the file with the ISR) now can see the varibale. static volatile char value=0; By the way, there is no compilation error. Can you see a failure defining the variable or another faliure? --------------------------------------- Posted through http://www.EmbeddedRelated.com
On 13/10/2010 10:53, jan0385 wrote:
>> On 13/10/2010 07:49, jan0385 wrote: >>>> On 12/10/2010 15:03, jan0385 wrote:
<snip>
>> >> What is the ISR code? >> >> > > Ok, I overlooked the fact, that using ISRs with the FX2 you have to add the > line to the main()-file: > > #pragma NOIV > > This setting is required to set up EZUSB-specific interrupt vector table. > > Then you have to put the ISR in another file than the file, where this > statement is. > > The USB tranfer is not disturbed now. Thats an improvement for the problem. > But there's a further problem. > > In the ISR I increment a variable. This variable I send over USB to my PC > to see if the ISR ran. But it is not incremented. Incrementing it in a > "normal" function is going well. > > I declared the variable in an extra header file. The two files (file with > main() and the file with the ISR) now can see the varibale.
The variable should be declared in one of your c files and then extern'd in the header file. It sounds like the way you have done it will create two separate variables with the same name. Even better is to only declare the variable in one of the c files and then create a function to access it from another c file. That way you can protect the variable from erroneous writes, or make it so that it is only readable for example.
> > static volatile char value=0; > > By the way, there is no compilation error. Can you see a failure defining > the variable or another faliure? > > > --------------------------------------- > Posted through http://www.EmbeddedRelated.com
>On 13/10/2010 10:53, jan0385 wrote: >>> On 13/10/2010 07:49, jan0385 wrote: >>>>> On 12/10/2010 15:03, jan0385 wrote: > ><snip> > >>> >>> What is the ISR code? >>> >>> >> >> Ok, I overlooked the fact, that using ISRs with the FX2 you have to add
the
>> line to the main()-file: >> >> #pragma NOIV >> >> This setting is required to set up EZUSB-specific interrupt vector
table.
>> >> Then you have to put the ISR in another file than the file, where this >> statement is. >> >> The USB tranfer is not disturbed now. Thats an improvement for the
problem.
>> But there's a further problem. >> >> In the ISR I increment a variable. This variable I send over USB to my
PC
>> to see if the ISR ran. But it is not incremented. Incrementing it in a >> "normal" function is going well. >> >> I declared the variable in an extra header file. The two files (file
with
>> main() and the file with the ISR) now can see the varibale. > >The variable should be declared in one of your c files and then extern'd >in the header file. It sounds like the way you have done it will create >two separate variables with the same name. > >Even better is to only declare the variable in one of the c files and >then create a function to access it from another c file. That way you >can protect the variable from erroneous writes, or make it so that it is >only readable for example.
could I make it as follows: _______________________ globalVars.h: static volatile char var; static char getVar() { return var; } static incVar() { var++; } ________________________ Whenn accessing the variable from the ISR or main file I call the getVar() fucntion. Does this realization create to variables internaly too?
> >> >> static volatile char value=0; >> >> By the way, there is no compilation error. Can you see a failure
defining
>> the variable or another faliure? >> >> >> --------------------------------------- >> Posted through http://www.EmbeddedRelated.com > >
--------------------------------------- Posted through http://www.EmbeddedRelated.com
On 13/10/2010 12:57, jan0385 wrote:
>> On 13/10/2010 10:53, jan0385 wrote: >>>> On 13/10/2010 07:49, jan0385 wrote: >>>>>> On 12/10/2010 15:03, jan0385 wrote: >> >> <snip> >> >>>> >>>> What is the ISR code? >>>> >>>> >>> >>> Ok, I overlooked the fact, that using ISRs with the FX2 you have to add > the >>> line to the main()-file: >>> >>> #pragma NOIV >>> >>> This setting is required to set up EZUSB-specific interrupt vector > table. >>> >>> Then you have to put the ISR in another file than the file, where this >>> statement is. >>> >>> The USB tranfer is not disturbed now. Thats an improvement for the > problem. >>> But there's a further problem. >>> >>> In the ISR I increment a variable. This variable I send over USB to my > PC >>> to see if the ISR ran. But it is not incremented. Incrementing it in a >>> "normal" function is going well. >>> >>> I declared the variable in an extra header file. The two files (file > with >>> main() and the file with the ISR) now can see the varibale. >> >> The variable should be declared in one of your c files and then extern'd >> in the header file. It sounds like the way you have done it will create >> two separate variables with the same name. >> >> Even better is to only declare the variable in one of the c files and >> then create a function to access it from another c file. That way you >> can protect the variable from erroneous writes, or make it so that it is >> only readable for example. > > could I make it as follows: > _______________________ > globalVars.h: > > static volatile char var; > > static char getVar() > { > return var; > } > > static incVar() > { > var++; > } > > ________________________ > > Whenn accessing the variable from the ISR or main file I call the getVar() > fucntion. Does this realization create to variables internaly too? >
You can't put functions in header files, they go in .c files. So put the above in a .c file and then in a header file put: extern static char getVar(); extern static incVar(); then include this header file in the whichever other .c files need to call the functions.
> > >> >>> >>> static volatile char value=0; >>> >>> By the way, there is no compilation error. Can you see a failure > defining >>> the variable or another faliure? >>> >>> >>> --------------------------------------- >>> Posted through http://www.EmbeddedRelated.com >> >> > > --------------------------------------- > Posted through http://www.EmbeddedRelated.com
"daven" <dave@dave.com> wrote in message
news:i948q7$9jb$1@news.eternal-september.org...
> > You can't put functions in header files, they go in .c files. So put > the above in a .c file and then in a header file put:
Of course you can! Whether it is good practise is a different matter.... Meindert
On Wed, 13 Oct 2010 13:31:02 +0100, daven <dave@dave.com> wrote:


>You can't put functions in header files, they go in .c files.
It's not good practice but it is permitted and might be useful in special circumstances. This is a "should not" rather than a "can not."
> So put >the above in a .c file and then in a header file put: > >extern static char getVar(); >extern static incVar();
The storage class specifier "static" declares that the functions have internal linkage. This can't be paired with the specifier "extern." From 6.9.1 Function Definitions "The storage-class specifier, if any, in the declaration specifiers shall be either extern or static." It is permitted (and common practice) to have the functions declared in the header files as extern and then in exactly one .c file (which includes the header) to write the function definitions. Also: the function prototypes above really ought to have parameter lists. -- Rich Webb Norfolk, VA
On 13/10/2010 13:52, Meindert Sprang wrote:
> "daven"<dave@dave.com> wrote in message > news:i948q7$9jb$1@news.eternal-september.org... >> >> You can't put functions in header files, they go in .c files. So put >> the above in a .c file and then in a header file put: > > Of course you can! Whether it is good practise is a different matter.... > > Meindert > >
Well yes you can but if you then include that header file in more than one .c file things are still not going to work. At risk of starting another "goto" discussion, you can of course use goto but if I saw someone using it I'd tell them they can't! :-)
>"daven" <dave@dave.com> wrote in message >news:i948q7$9jb$1@news.eternal-september.org... >> >> You can't put functions in header files, they go in .c files. So put >> the above in a .c file and then in a header file put: > >Of course you can! Whether it is good practise is a different matter.... > >Meindert > > >
Yes I can. Ok I made the variable static in an extra file. In the file I have function to access this variable by the ISR and the main-file. problem solved. Thank you! --------------------------------------- Posted through http://www.EmbeddedRelated.com
On 13/10/2010 13:55, Rich Webb wrote:
> On Wed, 13 Oct 2010 13:31:02 +0100, daven<dave@dave.com> wrote: > > >> You can't put functions in header files, they go in .c files. > > It's not good practice but it is permitted and might be useful in > special circumstances. This is a "should not" rather than a "can not." > >> So put >> the above in a .c file and then in a header file put: >> >> extern static char getVar(); >> extern static incVar(); > > The storage class specifier "static" declares that the functions have > internal linkage. This can't be paired with the specifier "extern." From > 6.9.1 Function Definitions "The storage-class specifier, if any, in the > declaration specifiers shall be either extern or static."
My bad, I copy and pasted without deleting static! To be clear, the functions must be declared in the .c file without the static specifier as well.
> > It is permitted (and common practice) to have the functions declared in > the header files as extern and then in exactly one .c file (which > includes the header) to write the function definitions. > > Also: the function prototypes above really ought to have parameter > lists. >
Well I'd normally put a void in there but I don't know his compiler and whether it's considerd acceptable/normal to have an empty list.