Pages: [1] 2   Go Down
Author Topic: summary of predefined names, routines, macros?  (Read 1393 times)
0 Members and 1 Guest are viewing this topic.
Delray Beach, FL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a web page or pdf file somewhere that summarizes all the magical predefined "things" that you can use in sketches? Code like this appears all over the place in examples: TIFR1 = _BV(TOV1); or TCCR2B = _BV(WGM22) | _BV(CS20); Where are all these magical things listed? How do you discover these names?
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Probably the best thing is to download the datasheet:

http://atmel.com/dyn/resources/prod_documents/8271S.pdf

Most of the names are identical to what is in the datasheet. And things like:

Code:
_BV(WGM22)

means "the WGM22 bit".

So something like this:

Code:
TCCR2B = _BV(WGM22) | _BV(CS20)

Means: in the TCCR2B register (read the datasheet to see what it does) set the WGM22 and CS20 bits.
Logged


Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8856
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Those are register names.  TIFR1 = "Timer/Counter1 Interrupt Flag Register". TCCR2B = "Timer/Counter Control Register B"

Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Delray Beach, FL USA
Offline Offline
Full Member
***
Karma: 0
Posts: 113
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh well, I was afraid I might have to plough through the datasheet. I was hoping for a nice summary web page somewhere :-). Thanks.
Logged


Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8856
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There may be a summary of the names somewhere but without the information in the datasheet of what bits do what the summary would not be of much use.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4808
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some anyway:
http://www.nongnu.org/avr-libc/user-manual/globals.html

and if you didn't know about that then bookmark this as well:
http://www.nongnu.org/avr-libc/user-manual/modules.html
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

West Des Moines, Iowa USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Consider downloading the ctags utility and an editor with ctags capability. What this allows you to do (typically) is to place the cursor on an identifier, hit a hotkey, and have the source file in which that identifier is defined pop up in an edit window.

It may take an hour to set up, but it's worlds faster than almost any other method of finding definitions. I think it'll be worth your time to investigate, install, and learn to use.
Logged

There's always a better way!

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's funny you should mention that Morris. I was playing with ctags yesterday. Although the one that comes with the Mac isn't very good. I got Exuberant Ctags from here:

http://ctags.sourceforge.net/

Then I found that if you weren't careful doing a full recursive ctags got all the bootloaders and stuff. So what worked for me was something like:

Code:
cd   # go home
ctags -R /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino
ctags -R -a /Applications/Arduino.app/Contents/Resources/Java/libraries

Your paths may vary.

The idea is to put a "tags" file in the home directory, consisting of the Arduino cores, and then append (-a) the libraries. Then using vi:

Code:
vi -t digitalWrite

In a split second, it opens "/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/wiring_digital.c" and puts the cursor at the start of that function. Pretty handy. Then move the cursor over some sub-function, hit Ctrl+] and it opens the file containing that function. And so on.
Logged


West Des Moines, Iowa USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was introduced to ctags back in the 90's when I worked on my first really large system (the trading system at the Philadelphia Stock exchange) and became an instant fan.

Since I'm somewhat of a packrat, over the years I've stashed away nearly all of the code I've written - migrating source from paper tape -> cards -> 8"FD -> 5-1/4"FD -> 3-1/2"FD -> CD -> DVD -> FLASH and now have about half of it on my iMac to minimize the amount of time spent re-inventing old wheels. My TAGS file is about 44MB and the ctags capability makes instant access to everything possible. All I have to do is remember the name of the module, the name of a module that called the one I'm interested in, or (worst case) the name of any module in a system that incorporated the module.

I'm also using exuberant ctags, and it's working well for me.
Logged

There's always a better way!

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@Morris - apart from firing up vim, is there another way of finding which file function X is in? (Also apart from simply editing the tags file, of course, and searching).
Logged


West Des Moines, Iowa USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Before ctags there was grep.

In a terminal window, man grep

Warning!
You're approaching a very slippery slope which could lead to non-return from POSIX land   smiley-mr-green
Logged

There's always a better way!

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm familiar with grep, but it has some limitations. For example, doing a recursive directory search isn't trivial. Also looking up something like digitalWrite is going to lead to all the places is it used rather than where it is defined.
Logged


West Des Moines, Iowa USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, that's why ctags is so convenient. There are ways to unclutter grep results. For example you can search for "void digitalWrite(int" instead of just "digitalWrite" - and if you're comfortable with regex patterns, they can be used to enhance grep's search capability.
Logged

There's always a better way!

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure, but it can get fiddly. For example, you may not know what type digitalWrite returns. Or what type arguments it takes.

I just wrote a little helper function that reads the tags file into a Lua table, and then displays them, filtered on what you type:



Then when you choose one it opens Crimson Editor for the relevant file, copies the chosen word to the clipboard, so you can search to find it inside that file. Now *that* should save a bit of time!
« Last Edit: March 25, 2012, 07:57:25 pm by Nick Gammon » Logged


West Des Moines, Iowa USA
Offline Offline
Sr. Member
****
Karma: 2
Posts: 428
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I like it!   smiley-mr-green
Logged

There's always a better way!

Pages: [1] 2   Go Up
Jump to: