Embedded Includes

Go To Last Post
21 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am very new to C++ and AVR Studio so please be gentle. A friend of mine wrote some code for me using eclipse. I have no idea what I was doing with that program and found it very hard to use. I have found AVR Studio a lot more user friendly.

 

I was having problems compiling the code as it was coming up with errors stating that the include file could not be found. After setting the directory properly and downloading a few include files it would get further and then come up with the same error with a different file name. My question is, do I have to go through every include file and download each include file which is mentioned in each of the include files? Or is there an automatic dependency downloader like there is in most Linux distributions? I hope all that makes sense. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to include header file for controller.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have no idea what you mean. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Or is there an automatic dependency downloader

Nope you have to fix this manually.

 

If the project really does have header files spread out over many locations then it must be pretty complex?

 

Anyway what you need to do is ensure that the compiler is given a -I to direct it to each directory that contains used headers that would not be found in the normal default search path.

 

Is it the case that each header is in its own directory or something? Otherwise you seldom have more than about 5..10 -I's pointing to the 5..10 directories that contain headers. It can be a pain to locate and set all the -I locations but it is a one time only thing and just something you need to do. In fact you can pre-empt it. You know where you have placed the .h files involved. So rather than building and waiting to see the errors why not start by setting up the 5..10 directories where you know the headers should be then any further error will just be to mop up the one or two last ones you missed.

 

Once the headers can all be found it's true that the build then generates .dep/.d files to keep track of all the headers being used. It does this simply so it can spot any that are edited and therefore need to force a rebuild on the next "make". But ./dep/.d cannot even be created until you cna build cleanly at least once. What the C pre-processor is not going to do (and you most definitely would not want this!) is to go trawling across your entire hard drive trying to locate .h files. Apart from anything else you might have three different copies of a foo.h on your hard drive. If the pre-processor went hunting how could it possibly know which as the one you mean to use? Only you know that.

Last Edited: Mon. May 18, 2015 - 10:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

windoze_killa wrote:
do I have to go through every include file and download each include file which is mentioned in each of the include files?

All of the required header files must be accessible to the file system on the PC.

 

Normally, if someone is providing software to you, they should give you all the files required - or, at least, tell you what files are required, and where to obtain them.

 

Quote:
Or is there an automatic dependency downloader

Not for source code.

 

Quote:
like there is in most Linux distributions?

Is there? 

 

Quote:
 I hope all that makes sense

Not entirely.

 

It sounds like you have jumped in at the deep end, and are out of your depth.

 

It would probably be better to start from something simpler, and actually intended for learning/teaching...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there? 

Andy, I think he's talking about thinks like .deb's and apt-get. A .deb says what it is dependent on so when you "apt-get install firefox" it pulls in the 30 other .deb's that it might be reliant on. That all works because .deb's have (require!) that they contain info about what they are dependent on.

 

A simple .c or .h file has no such "meta information". If anything such meta info is contained in the .atsln or .vcproj XML files where records of which header directories a project uses are encoded. That is the very -I information I'm talking about above which the end user enters under "directories" for the C/Prepro.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will try and clarify what I mean.

 

The friend wrote Tacho.cpp file. It has an include that he wrote, tacho.h which in turn has and include Arduino.h which in turn has an include binary.h. 

 

Tacho.cpp includes

 

#include "Tacho.h"
#include <PinChangeInt.h>
#include <avr/eeprom.h>

 

Tacho.h includes

 

#ifndef Tacho_H_
#define Tacho_H_
#include <Arduino.h>
//add your includes for the project Tacho here
#include <avr/interrupt.h>
#include <avr/eeprom.h>

 

Arduino.h includes

 

#include <stdlib.h>
#include <string.h>
#include <math.h>

#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>

#include "binary.h"

 

My understanding is that includes in <> are system includes and "" are local includes. 

 

Also my learning curve at the moment is very steep and I have been thrown in at the deep end as this friend has wiped his hands of it. He is way too busy with paying jobs.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My understanding is that includes in <> are system includes

They are. That actually means that <Arduino.h> and <PinChangeInt.h> are wrong and should be "Arduino.h" etc. because those headers are not part of what's supplied by the compiler and C library.

 

While everything in <> should "just be found" because the compiler knows where to look and those things are always in fixed positions in any installation of the compiler involved it's the things in "" that you need to cater for.  If "binary.h" and/or "Tacho.h" are not in the same sirectory as the .c/.cpp file that includes them then you will need to pass a -I command to the preprocessor to tell it the other places to look.

 

But if it is just "Tacho.h" and "binary.h" then surely the job of setting up such -I's is not that onerous is it?

 

BTW there's always an argument to be had for/against this but say "binary.h" and "Tacho.h" are in a directory "near" the files where they are included you could encode a relative path to them in the #include itself like:

#include "../../miancode/headers/Tacho.h"
#include "../utils/headers/binary.h"

or wherever it is that they are located relative to the point they are being used. The other argument says just put:

#include "Tacho.h"
#include "binary.h"

in the C and then:

-I "../../miancode/headers"
-I "../utils/headers"

passed as compilation options so that after the preprocessor has tried looking in the current directory it looks in each of these directories in turn to try and find the named header file.

Last Edited: Mon. May 18, 2015 - 10:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you. It is slowly making sense. Is there a list of the installed includes somewhere? When I look at my install I can only find 3 .h files in the include directory. 

 

With regards to my problem I have managed to get all the includes and it no longer has errors for the includes. I now need to find out why a few of the variables haven't been declared.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there a list of the installed includes somewhere? When I look at my install I can only find 3 .h files

I cannot help thinking you were looking in the wrong place. The base of the system header include directory holds <stdio.h> and other headers mentioned in K&R.

avr/include$ find . -name \*.h
./setjmp.h
./avr/iom645a.h
./avr/iom48p.h
./avr/iox16d4.h
./avr/iom3290pa.h
./avr/io4434.h
./avr/iom64hve2.h
./avr/iotn24a.h
./avr/iotn87.h
./avr/iox128c3.h
./avr/iom325pa.h
./avr/io43u32x.h
./avr/sfr_defs.h
./avr/xmega.h
./avr/iom2560.h
./avr/io43u35x.h
./avr/ioa5272.h
./avr/iox32a4u.h
./avr/iom16hvb.h
./avr/iom64a.h
./avr/iox384c3.h
./avr/iom3250p.h
./avr/iom16u2.h
./avr/iox64d4.h
./avr/iox128a1u.h
./avr/iox256a3u.h
./avr/ioat94k.h
./avr/iotn9.h
./avr/iomxx4.h
./avr/iom8u2.h
./avr/iom32hvb.h
./avr/iom164p.h
./avr/iotn45.h
./avr/iom48.h
./avr/io2313.h
./avr/common.h
./avr/iox256a3.h
./avr/iom17.h
./avr/iotn84a.h
./avr/iom649a.h
./avr/iom6450p.h
./avr/ioa5831.h
./avr/iom3290a.h
./avr/iom644.h
./avr/iox16c4.h
./avr/ioa5790n.h
./avr/iom16hva2.h
./avr/iom329pa.h
./avr/iox256d3.h
./avr/iom324p.h
./avr/iom2561.h
./avr/io90pwm316.h
./avr/io90pwm2b.h
./avr/iotnx5.h
./avr/iom128a.h
./avr/io4414.h
./avr/iox256c3.h
./avr/iom32a.h
./avr/iotn10.h
./avr/iom32c1.h
./avr/iom6490p.h
./avr/iom6450a.h
./avr/iom88a.h
./avr/iotn828.h
./avr/iox32c4.h
./avr/iotn4313.h
./avr/iox128b3.h
./avr/builtins.h
./avr/eeprom.h
./avr/iom644a.h
./avr/io1200.h
./avr/iom64m1.h
./avr/iousb82.h
./avr/iotn441.h
./avr/io8535.h
./avr/iousb1287.h
./avr/iom162.h
./avr/iom645p.h
./avr/iox64a1u.h
./avr/iom644pa.h
./avr/iotn11.h
./avr/iom8a.h
./avr/iom88.h
./avr/iousbxx2.h
./avr/iotn15.h
./avr/iom165.h
./avr/iotn44a.h
./avr/iom8535.h
./avr/iotn85.h
./avr/ioa6612c.h
./avr/iom48pa.h
./avr/iom16m1.h
./avr/fuse.h
./avr/iotn261a.h
./avr/iom168a.h
./avr/iom169pa.h
./avr/io86r401.h
./avr/io8534.h
./avr/iox128a4u.h
./avr/io2343.h
./avr/iox16e5.h
./avr/iom3000.h
./avr/iom323.h
./avr/ioa6616c.h
./avr/iousb162.h
./avr/io90pwm216.h
./avr/iox128a3.h
./avr/iotnx61.h
./avr/signal.h
./avr/iom168.h
./avr/iom324a.h
./avr/ioa6617c.h
./avr/sleep.h
./avr/iocan64.h
./avr/iom3250pa.h
./avr/io76c711.h
./avr/iotnx4.h
./avr/iom32u2.h
./avr/iox192c3.h
./avr/cpufunc.h
./avr/iom406.h
./avr/ioa5790.h
./avr/iotn261.h
./avr/iotn25.h
./avr/iox128d3.h
./avr/delay.h
./avr/iom640.h
./avr/io90pwmx.h
./avr/iox32d3.h
./avr/ioa664251.h
./avr/iom16u4.h
./avr/iox32d4.h
./avr/iotn20.h
./avr/iocan128.h
./avr/iom169.h
./avr/iox128d4.h
./avr/iom164pa.h
./avr/iom328p.h
./avr/iox128a1.h
./avr/ioa6614q.h
./avr/ioa6289.h
./avr/iotn461a.h
./avr/iom165a.h
./avr/iotn841.h
./avr/iom169p.h
./avr/io4433.h
./avr/iom16.h
./avr/io90pwm1.h
./avr/iox32a4.h
./avr/iom649p.h
./avr/iotn2313.h
./avr/ioa6286.h
./avr/iotn5.h
./avr/iox128a3u.h
./avr/io2333.h
./avr/iotn28.h
./avr/iom16hva.h
./avr/parity.h
./avr/iom32.h
./avr/iom128rfa1.h
./avr/iotn40.h
./avr/iotn22.h
./avr/iom128rfr2.h
./avr/iox384d3.h
./avr/iotn24.h
./avr/iom163.h
./avr/ioa6285.h
./avr/iotn167.h
./avr/iom1281.h
./avr/iousbxx6_7.h
./avr/iom16hvbrevb.h
./avr/boot.h
./avr/io90pwm3b.h
./avr/iotn88.h
./avr/io90pwm161.h
./avr/iom64hve.h
./avr/iom128.h
./avr/iom325.h
./avr/iom328.h
./avr/iousb647.h
./avr/iom329a.h
./avr/iotn48.h
./avr/iom64c1.h
./avr/iocanxx.h
./avr/iom32u6.h
./avr/pgmspace.h
./avr/iomxx0_1.h
./avr/iom6490.h
./avr/iom164a.h
./avr/iox64a1.h
./avr/iousb646.h
./avr/iotn4.h
./avr/iom48a.h
./avr/iom103.h
./avr/iox192a3.h
./avr/iom16a.h
./avr/iom329.h
./avr/iom1280.h
./avr/iotn2313a.h
./avr/iom64.h
./avr/iom168pa.h
./avr/power.h
./avr/iox64d3.h
./avr/iom3250a.h
./avr/iom88pa.h
./avr/iom165p.h
./avr/iox16a4u.h
./avr/iotn861.h
./avr/iom32m1.h
./avr/iox256a3b.h
./avr/iom8.h
./avr/iox192d3.h
./avr/interrupt.h
./avr/io90pwm81.h
./avr/iotn13a.h
./avr/ioa6613c.h
./avr/iom32hvbrevb.h
./avr/iox64a3u.h
./avr/iox32c3.h
./avr/iom8515.h
./avr/iom2564rfr2.h
./avr/ioa5795.h
./avr/iom644rfr2.h
./avr/iom3290.h
./avr/iom329p.h
./avr/iom64rfr2.h
./avr/iox192a3u.h
./avr/iom164.h
./avr/ioa5505.h
./avr/iox64b1.h
./avr/iousb1286.h
./avr/iom256rfr2.h
./avr/crc16.h
./avr/version.h
./avr/iom169a.h
./avr/iotn43u.h
./avr/iom325a.h
./avr/iox16a4.h
./avr/iom645.h
./avr/portpins.h
./avr/iotn44.h
./avr/iox64a4u.h
./avr/iox64a3.h
./avr/iom1284rfr2.h
./avr/iom161.h
./avr/iom32u4.h
./avr/iox32e5.h
./avr/iom165pa.h
./avr/lock.h
./avr/io.h
./avr/iom168p.h
./avr/iom6450.h
./avr/iom324pa.h
./avr/iotn12.h
./avr/iomxxhva.h
./avr/iom88p.h
./avr/iotn1634.h
./avr/iom1284.h
./avr/iom325p.h
./avr/iox64b3.h
./avr/iom3250.h
./avr/io2323.h
./avr/iox8e5.h
./avr/iox128b1.h
./avr/iocan32.h
./avr/iom1284p.h
./avr/wdt.h
./avr/io8515.h
./avr/iotn84.h
./avr/iom6490a.h
./avr/iox64c3.h
./avr/iom8hva.h
./avr/signature.h
./avr/iom644p.h
./avr/iotn461.h
./avr/iomx8.h
./avr/iotn861a.h
./avr/io90scr100.h
./avr/iom649.h
./avr/iox256a3bu.h
./avr/iotn13.h
./avr/iotn26.h
./inttypes.h
./errno.h
./string.h
./stdlib.h
./stdio.h
./math.h
./ctype.h
./alloca.h
./util/twi.h
./util/setbaud.h
./util/delay.h
./util/atomic.h
./util/parity.h
./util/crc16.h
./util/delay_basic.h
./assert.h
./stdint.h
./compat/twi.h
./compat/ina90.h
./compat/deprecated.h
./stdfix-avrlibc.h

That is not actually ALL the system headers but it's the majority of them. Documented in the manual here:

 

http://www.nongnu.org/avr-libc/u...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You were 100% right. I was looking in the wrong spot. My brain is obviously a bit fried at the moment. Thanks again. 

 

PS. Would you be interested in looking at my code or do you know of anyone on here that would?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Would you be interested in looking at my code or do you know of anyone on here that would?

Well that's kind of what we're all here for ;-)

 

I'd suggest you just .zip it up and attach to your next post. Those that are interested will no doubt download and comment.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the advise. 

 

Attached is a RAR file for my tacho. The history of this project started when I purchased my motorbike and found it didn't have a tacho. I decided to make one with a few added enhancements. It has the following functions:

 

The tacho part itself uses 7seg LED displays. A

7 seg gear indicator. 

A photo transistor to dim the display at night (micro controlled just for fun)

 

Any assistance would be greatly appreciated.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That code is an Arduino sketch. Why are you trying to build it in Studio? Why not just use Arduino?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Arduino DOES do (some) automatic dependency determination, but ... you have to have the relevant arduino libraries set up the way that it expects them to be set up.

You can probably get the same behavior with Atmel Studio by installing the Visual Micro plugin (which I think also requires that you install Arduino), but ... it sounds like you'd do better using the (simpler) arduino tools, anyway...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well there ya go. Nice of him to tell me. Thanks guys I will install Arduino tonight.

 

Having said that is there a reason why it can't be done in AS6? What would I need to do to change the code? I have found AS6 pretty easy to use for a beginner.

 

clawson, I haven't beed to your part of England but if its anything like Devon or Yorkshire you are a lucky man.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The arduino IDE reads your source code, extracts the #include lines, matches the names against directory names found in its standard library locations, and adds an appropriate -I<dir> line to the compile statement.  Plus the arduino "core" includes like Arduino.h.

 

So if you code contains

#include <SoftwareSerial.h>

#include <PinChangeInt.h>

 

You'd get a compile line like:

  g++ ... -I /xxxx/hardware/arduino/avr/cores/arduino -I /xxxx/hardware/arduino/avr/libraries/SoftwareSerial -I /users/billw/Documents/Arduino/libraries/PinChangeInt ...

 

I'm pretty sure you can't easily do something like that in AS.  (VisualMicro might do it?)  It's not even clear that the Arduino development community thinks it's a great idea...

Otherwise, you just proceed as you were, I guess.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The argument against trying to make this work in AS6 are lines such as:

    uint16_t thisMillis = millis();  // Get the current time

and

	if(revs > conf.redlineValue)
		digitalWrite(overRevPin, HIGH);
	else
		digitalWrite(overRevPin, LOW);

Things like millis() and digitalWrite() just "exist" in Arduino (technically they are components of a static library called libcore.a - but you don't really need to know that). So to make this code work in AS6 you would also need to pull in the code that makes those (and possibly other) library functions available. One way to do that would be to build a simple sketch in Arduino for the right CPU then in the build directory find libcore.a and take that and add it to the AS6 project. But life is just a lot simpler if you just build the code in Arduino land anyway.

As westfw says there's an add-on for AS6 called VisualMicro that aims to make all the Arduino stuff like digitalWrite() easily available. How "easy" it really is I don't know (like other here I dare not install it as it apparently can be a bit of a spam-fest and tricky to remove).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

windoze_killa wrote:
is there a reason why it can't be done in AS6?

I don't think anyone's ever said that it can't be done?

 

Quote:
I have found AS6 pretty easy to use for a beginner

Starting a project from scratch in AS6 (or any other IDE) is one thing; porting a project from a different environment is, as you have found, an entirely different matter!

 

surprise

 

Quote:
if its anything like Devon...

There is nothing quite like Devon!

 

It is God's own county - served by God's Wonderful Railway.

 

laugh

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys. Looks like I will have a play with Arduino. Just downloaded it. It appears pretty basic so will have a play. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

appears pretty basic

That's kind of the point - it attempts to be a minimal subset of everything required to build and program AVR code. IDEs such as AS6 try to be all things to all people and have a raft of setting and menus and stuff of which, in reality, only about 10% is probably regularly used. Arduino just offers that 10% that you need. This makes it much easier for beginners who aren't swamped with 50+ options they don't understand or need.