Pages: [1]   Go Down
Author Topic: Source code of standard fonction  (Read 664 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

'round the world...
Offline Offline
Faraday Member
**
Karma: 42
Posts: 3293
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you.

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

Now I have another question smiley
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.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50452
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26525
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
extern volatile unsigned long timer0_overflow_count;

void setup ()
{}

void loop () {
  unsigned long a = timer0_overflow_count;
}
 
« Last Edit: October 02, 2012, 08:58:40 am by AWOL » Logged

"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.

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley.

But I also ask the question in a more general way, and I thank you for the answers.  smiley-wink

Logged

Pages: [1]   Go Up
Jump to: