Pages: [1]   Go Down
Author Topic: Trim some fat from twi/Wire!  (Read 617 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I saw today that the "twi.c" file, used to talk to the TWI interface of the Atmega, contains no less than three full-size buffers for TWI data packets. In addition, the "Wire.cpp" file used to wrap the twi.c file in a class interface adds another two buffers!

I think the buffers in Wire could pretty easily be eliminated by implementing the state machine from twi.c into the Wire.cpp class.

Additionally, the code says things like "I have to do this in this order, because I make take an interrupt at any time" -- while I'm sure that's true, it could also just turn off interrupts for the duration of the critical section, and possibly be a little clearer. Dunno if it would actually save any instructions, so that might be of secondary importance.
Logged

0
Offline Offline
Shannon Member
****
Karma: 132
Posts: 10498
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

also it's a good idea to make the library not-locking, or at least implement timeout.
Do you want to be the first to post the modified code?
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My TWI code ended up using other custom functions I have for dieing-on-usage-error, and for scheduling-completion-callback, so it wouldn't fit inside the Arduino framework.
Logged

0
Offline Offline
Shannon Member
****
Karma: 132
Posts: 10498
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

seems a good thing, why should not being implemented?
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is a good thing, but it is totally different from the standard Arduino project.

If we want to turn Arduino into more of a mini-tasking/executive system, and less of a Wiring clone, that would be one thing, but I think that wouldn't be well received. I could be wrong, though!
Logged

Pages: [1]   Go Up
Jump to: