Problem with header files

A catchall for PSoC5 discussions not captured by the other forums.

Moderator: ericb

Problem with header files

Postby hjvanderlinden on Mon Apr 02, 2012 8:17 pm

I have been fighting for a couple of hours with a weird problem I got after splitting my code.

During the initialization of my system I place a call to a function that should write the channel offset code
to my DAC. However when I have the function call in my code the code compiles but afterwards almost all
the variables which you normal get on a mouseover during debug are 0!
If I deactivate the function call with //. The code also compiles fine but now I get the correct value for the
variables on a mouseover!

The prototype for the function I call has been defined in a header file for the DAC part and this header file
has been placed correctly I believe.

Any questions on resolving this issue are most welcome!

Heiko
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby danadak on Tue Apr 03, 2012 3:29 am

Did you define this in your own header file or in the tool generated
header file ? If the later it gets overwritten on build. You can always
move the prototype to main.c

Regards, Dana.
Field Application Engineer
KB1RHB Mostly listen :)
Semi Retired
User avatar
danadak
The Big Cheese
The Big Cheese
 
Posts: 1831
Joined: Thu Dec 27, 2007 8:42 am
Location: New Hampshire

Re: Problem with header files

Postby hjvanderlinden on Tue Apr 03, 2012 4:02 am

Hi Dana,

Big thumbs up for being so helpful!!

I have made my own header file so there should be no problem with the function prototype being overwritten.

I have included the prototype before my Initializer() function in Initializer.c but to no avail.

I am going to check out the object files to find a clue but I am starting to think something is wrong in the IDE

Heiko
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby hjvanderlinden on Tue Apr 03, 2012 4:13 am

I tried to find the files that were generated by the compiler but cannot find them...


On another line: the prototype and the function that I call

prototype:
void DenseDAC_ChannelWrite(uint8 DAC_Channel, uint16 DAC_Data_uint16);

function call:
DenseDAC_ChannelWrite(Envelope_1_DAC_Channel, EnvelopeOutputValue);

The function does not work from main() and Initializer() but it does work from a function called EnvelopeGenerator().

Heiko
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby bobmarlowe on Tue Apr 03, 2012 6:57 am

Heiko, would you mind to upload the complete project here, so that we all can have a look at it? Errors in the IDE concerning non-functionig-code are rather rare (I do not know of one right now), so I presume that you made some definition- or declaration-error in your code.
To upload a project:
"Build->Clean Project"
"File->Create Workspace Bundle(minimal)"
and finally upload the .ZIP file here.

Bob

You are probably from Germany, so we're in the same timezone, can help you til 23:00h
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1185
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: Problem with header files

Postby hjvanderlinden on Tue Apr 03, 2012 8:29 am

Hi Bob,

thanks for helping me out! It is much appreciated! And yes we are in the same time zone.
I am a little more to the west in the Netherlands...

I have attached the code here and it is also posted on the Cypress forum.

Heiko
Attachments
HEADER BUG-000.cywrk.Archive01.zip
(628.94 KiB) Downloaded 32 times
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby bobmarlowe on Tue Apr 03, 2012 8:56 am

OK, I just had a look at and did not change anything yet (That's up to you :mrgreen: ).

1st. When I open the project with my designer version I receive the message that most of your modules you use have an updated version. Although the update is not co-existent with your current version, I would suggest to update to latest.

2nd. There are a couple of warnings concerning clock accuracy. Only warnings, but I would try to get rid of all of them.

3rd. And this is an C-Design error: Header files are organized in a way so that they might be included independently from different modules without disturbing each other AND without errormessages stating that something is defined the second time. But this has to be made by the user (You). Give ALL your header-files the following structure:

#ifndef __Filename_H
#define __Filename_H
// here goes the body of the header file
#endif

This will prevent you (and your program) from any mishaps resulting in doubly expanded definitions. Have a look (and compare) at some of the generated .h-files, there is the same structure used.

Happy coding
Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1185
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: Problem with header files

Postby hjvanderlinden on Tue Apr 03, 2012 10:29 am

Hi Bob,

Thanks a lot for the detailed answer! I am going to work on implementing the #ifndef statements...

Heiko
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby hjvanderlinden on Tue Apr 03, 2012 10:49 am

Hi Bob,

I have implemented the include guards. I get two types of errors:

1) macro names must be identifiers
2) unterminated #ifndef (2 times)

I don't understand the first error. The second error has something to do with the fact that the #ifndef for "System Modules.h" is not followed by an #endif
before the next #ifndef starts but I don't know how to resolve this... What's the general structure to include multiple header files with include guards?

Heiko

Code:

#ifndef "System Modules.h"
#define "System Modules.h"

#ifndef "DenseDAC.h"
#define "DenseDAC.h"

#ifndef DAC_Channels.h
#define DAC_Channels.h

HEADER BODY HERE

#endif
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby bobmarlowe on Tue Apr 03, 2012 12:11 pm

I did not use quotes, you did. I did not use a dot (.) I used underscore (_) i preponed the symbol with two underscores to create a symbol that can not be generated by accident.
I did not tell to use multiple #ifndefs etc. in one file. again: the structure is:

#ifndef __Filename_H
#define __Filename_H
// here goes the body of the header file with Filename.h
#endif

Sorry, when I was unprecise in my last post, but do have a look at the module's generated header-files.

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1185
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: Problem with header files

Postby hjvanderlinden on Wed Apr 04, 2012 4:25 am

Hi Bob,

I tried the way how you described the include guard process but I can't get it to work.

About your code:
#ifndef __Filename_H
#define __Filename_H
// here goes the body of the header file with Filename.h
#endif

Why do you include an include guard to the file in its own file i.e. __Filename_H is the same as Filename.h?
And where do the first two underscores come from? Are these underscores necessary or are they just part
of how you identify headers?

Also I need to include multiple header files in the file Initializer.c. I still don't see how I should do this if I want
to use include guards?

I have tried:

#ifndef __System Modules_H
#define __System Modules_H
#define __DenseDAC_H
#define __DAC_Channels_H

and I have tried:

#ifndef System Modules_H
#define System Modules_H
#define DenseDAC_H
#define DAC_Channels_H

Both cases don't work and I get 42 errors due to the fact that System Modules.h is not included.

Let me know what your suggestion is!

Heiko
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby bobmarlowe on Wed Apr 04, 2012 4:56 am

OK, I didn't want to edit your files, but now I inserted the required lines.
Watch out for a line containing "****Bob" (without the quotes) it is a line you had forgotten.

With this usual structure you may #include in every c-file the libraries you use in that file without any side-effects.
When talking to Cyprerss I already suggested to include those structures when creating a .h-file automatically, but that will take some time until realized.

What happens with these inserted lines is just creating a unique C-Symbol (filenames are always unique and symbols with two unserscores in the beginning are not generated by the compiler).
When a symbol is not defined, the rest of the file (#defining the symbol and your code) is expanded, if not then the file is not expanded a second time.

Hope to have helped you
Bob
Attachments
HEADER BUG2.zip
(611.27 KiB) Downloaded 40 times
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1185
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: Problem with header files

Postby hjvanderlinden on Wed Apr 04, 2012 5:06 am

Hi Bob,

Thanks for showing the example in my files. I understand what you mean now!

I have compiled the code and turned on the line to the function writing to my DAC
but I still get the same weird error (--> all variables are 0x00) :-S

Do you have a clue? Or a clue to where I should take this problem? It really looks
like and IDE issue...

Thanks a lot for explaining me about include guards,
Heiko
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby bobmarlowe on Wed Apr 04, 2012 6:47 am

I do not have a PSoC5 right now in my test environment, so I just can have a look at your code. Which file and which line do you stop by breakpoint and which function's variables (which file) do you inspect with a mouseover?

A rather stunning fact was: When I tried to set the device to a PSoC3, I got > 350 errors concerning doubly defined symbols and I could not find out where that came from. Are you using any pre-compiled libraries in your project?

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1185
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: Problem with header files

Postby hjvanderlinden on Wed Apr 04, 2012 7:12 am

Hi Bob,

I don't know what you mean by pre-compiled libraries. How can I check this?


Also I have pinpointed the problem and it is most strange! The problem goes away
when I disable a CYGlobalIntEnable statement in line 45 of densedac.c. This makes
my suspicion that this is a IDE problem stronger...

Heiko
Attachments
HEADER BUG-000.cywrk.Archive01.zip
(630.1 KiB) Downloaded 28 times
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby bobmarlowe on Wed Apr 04, 2012 7:37 am

Which file and which line do you stop by breakpoint and which function's variables (which file) do you inspect with a mouseover?

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1185
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: Problem with header files

Postby hjvanderlinden on Wed Apr 04, 2012 7:50 am

I have a breakpoint at line 159 in the file EnvelopeGenerator.c.
When the code works a mouseover over EnvelopeFinished gives 0x0f and a mouseover over ReleaseSlope gives -2.5599999
When the code doesn't work EnvelopeFinished gives 0x00 and ReleaseSlope gives 0.

Heiko
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby hjvanderlinden on Wed Apr 04, 2012 9:24 am

Now I have a new problem that variables that are initialized in Initializer are not updated in LFO.c.
I checked that the header files were used correctly and this checks out. I have had enough of this
IDE and am quitting Cypress products. The above described issue and the issue where a CYGlobalIntEnable
command can screw up the IDE has shown to me that the IDE can't be trusted which makes me very
unhappy after more than 400 hours coding on my product.

I wan't to thank you Bob for helping me out! (weird that no one from Cypress actually took the time
to check this out...)

Heiko
hjvanderlinden
Cheese Wheel
Cheese Wheel
 
Posts: 64
Joined: Sat Jan 14, 2006 6:49 am

Re: Problem with header files

Postby bobmarlowe on Wed Apr 04, 2012 10:05 am

Well, for you it looks like as if there are 2 sets of variables, one correctly initialized and one set with zero values.
When I changed the device to a PSoC3 (3866-40) I received errors concerning doubly defined symbols and EnvelopeFinished was one of it. I could not find at first sight any double definitions at all, so there must be something else wrong.
Since you are not using DMA the switch from PSoC5 to PSoC3 (and back) is easily done what the compilation part concerns (there is an easy to correct error: a CY_ISR has to be changed to CY_ISR_PROTO). So I assume that something with your project structure goes wrong, but don't know yet what. I do not blame the IDE, as far as you can watch the variables everything seems to be o.k. I would try something: define a local var and store EnvelopeFinished to it. Is there a difference?

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1185
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Re: Problem with header files

Postby bobmarlowe on Wed Apr 04, 2012 10:11 am

Just read your last post.
This forum is not so often frequented by Cypress, when you have a serious problem you should file a case (under "Technical support"), they usually help you out. There is another Cypress forum that is more frequent observed by Cypress. Look here: https://secure.cypress.com/?id=2203&source=support you have to register for that.

As i said before: I would not blame the IDE so easily, there is something twisted in your project, try to switch to PSoC3 and start to eliminate all error-messages.

Bob
User avatar
bobmarlowe
The Big Cheese
The Big Cheese
 
Posts: 1185
Joined: Thu Oct 06, 2011 2:03 am
Location: Germany

Next

Return to PSoC5 General

Who is online

Users browsing this forum: No registered users and 0 guests