Go Down

Topic: Source code of standard fonction (Read 818 times) previous topic - next topic

dammien

Hello,

I'm sorry to ask such a question.

I am hopelessly looking for the source code of the standards functions of Arduino.
Of course I have downloaded (or try to) everything that refers to "sources" on Arduino Main site.
However I can't find the code of (for example) micros(), tone(), etc...

Can you please tell me where do you find it ?

Thanks.


bubulindo

On my computer it's:

C:\Users\bubulindo\Documents\arduino-1.0.1\hardware\arduino\cores
And
C:\Users\bubulindo\Documents\arduino-1.0.1\llibraries

This... is a hobby.

dammien

Thank you.

I found the files I was looking for in :
C:\arduino-1.0\hardware\arduino\cores\arduino

Now I have another question :)
Is it possible, in my programs, to use variables I see in these source files?
For example I am thinking about "timer0_overflow_count". At the present time, when I try to use it, Arduino tells me that it does not exist.


PaulS

Quote
Is it possible, in my programs, to use variables I see in these source files?

Maybe. Maybe not. You need to be more specific.

Which source file? Which variable? How?

Typically, the answer is no, but there are almost always ways to access the same values.

AWOL

#4
Oct 02, 2012, 03:54 pm Last Edit: Oct 02, 2012, 03:58 pm by AWOL Reason: 1
Yes, the variable has global scope, so you'd have to add an "extern" to make it visible in your sketch.
But, I have to ask, why?

Code: [Select]
extern volatile unsigned long timer0_overflow_count;

void setup ()
{}

void loop () {
  unsigned long a = timer0_overflow_count;
}
 
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

tuxduino


Is it possible, in my programs, to use variables I see in these source files?


Short answer: don't do it.

There's one thing that is called encapsulation. When you write a library, you design a "public" interface, i.e. a set of functions that a user of the library is supposed to call to perform whatever service your library provides. To achieve this, you might need some module-scoped(*) variables that can be accessed by the library code at your will without worrying about someone else tampering with them. If someone _does_ step in and modify those variable's value when he shouldn't, the library code might crash or produce wrong results.
Whatever you try to achieve by accessing a library-scoped variable via "extern" in your sketch is either doable by "properly" using the library or needs to be rethought.


(*) that is, variables that might be used by all functions in the library but that are not supposed to be visible outside it.

dammien

Thank you for all your answers,

I understand that I should not try to access directly these variables.

Why would I try to do that ?
For example  If I want to write my own "pseudo micros() function", in order to fulfill my specific requirements. It's just an example.

Concerning this specific time - question, I finished with using directly TCNT0, because I am on a very time-critical program and I realised that I can probably do it with 8bit variables, which saves me a lot of time on these little Arduinos :).

But I also ask the question in a more general way, and I thank you for the answers.  ;)


Go Up