Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 15, 2011, 04:41:32 am
Mikal Hart's Flash library does a fantastic job, and has a pretty simple implementation, there are a couple of things to keep in mind though.

Flash.h  has to be included after Streaming.h , otherwise the defines collide and, for instance, endl becomes a missing symbol.
Flash.h doesn't have include guards, if you need to include it from different files it'll complain.
2  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 14, 2011, 03:35:28 pm
Is there any way to detect the variable was declared with PROGMEM?
Something in the lines of parameter matching, so it would be possible to do something like:

Code:
    void msg_serial(char* msg_line)
    void msg_serial(PROGMEM char* msg_line)

Of course it would be possible to just name the variables, but I would rather have the compiler doing the job for me (and not only out of lazyness:)
3  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 14, 2011, 09:13:21 am
I am thinking in the lines of function inlining or C++ this* preprocessing, where the compiler can get a hint (that being PROGMEM) and try to place the variable in flash and wrap accesses to that memory location with the right copying-to-RAM. Even post-link code patching might do the job.
Not that I am saying it should be done, there might be a million reasons why it shouldn't. But it would be convenient.
Is there any reason from-the-top-of-your-head to not want the feature?
4  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 14, 2011, 02:26:30 am
Yeah, I saw that some time ago, it doesn't seem super user-friendly though. I wonder why the compiler doesn't do it automatically (controlled with a compiler option or a #define or a #pragma or something)
5  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 03:09:34 pm
Code:
[quote]I am not quite sure on how to use PROGMEM in something like
Code:
Serial << "message" << endl;
[/quote]
Me neither.
That's one of the reasons I avoid streaming, and prefer the serial print methods.

Well, I guess I'll have to give up streaming for memory in most cases if I can't find a way (and I'll let you guys know if I do)

Quote
Quote
Moving
Code:
Serial << "mess" to
Code:
Serial.println("mess") doesn't seem to affect available RAM.
I can't imagine why you thought it could.

Me neither, I was thinking about your comment of literals that should "finding their way to flash", I guess you meant "find their way with a bit of a push" smiley

Thanks for all the help!
6  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 02:59:39 pm
I am not quite sure on how to use PROGMEM in something like
Code:
Serial << "message" << endl;

Moving
Code:
Serial << "mess"
to
Code:
Serial.println("mess")
doesn't seem to affect available RAM.
7  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 02:42:42 pm
I didn't see anyone mention this explicitly:

Code:
functions[c]; //Were we go

This will not call the function; it just evaluates to the value of the function pointer. Because that is evaluated but never used, the compiler/linker can actually optimize out the entire functions array[...]in response to a particular command.


Agreed, I ended up mentioning it myself smiley
thanks for the input!
8  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 02:24:59 pm
What do you mean by "it gets copied to before "main" runs?
...and, it sounding like a bad thing, how do I avoid it? smiley
9  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 12:44:44 pm
Any string literals floating in SRAM should find their own places in the FLASH now.

Hi liudr, what do you mean exactly? You are talking about the flash memory I guess, is that something the compiler decides before the code runs? So in theory if can increase the string sizes and have no changes in the available RAM, am I right?
10  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 09:08:15 am
Yeah, I've been thinking about that too, the fact that things only fail when I put several systems together has made me think.
Eventually I've figured out it was a SD information function that was designed to open the SD card from scratch (after it was already open) which was leading to a couple of bad bugs AND the out of memory.
I have added a freemem() function to track things down, I am running at 200 bytes, which I find very, very scary smiley-sad
11  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 08:24:29 am
Quote
Quote
What is funky about it, is that, if I add "()" behind
the program goes from 18960 bytes to 21070 and becomes super unstable.
You are now actually calling the functions, so, of course the size goes up.
Yeah, I didn't think about the compiler optimizing the functions away.

Quote
That your sketch becomes unstable is a surprise. Does it often wobble around and fall over? How can you see that happening?
It sometimes hangs up, sometimes reboots, sometimes displays corrupted data (as, if I try to list the array of char* I see a partly corrupted result.

Quote
Quote
The sketch is a bit involved to upload, but I have a couple of things that are, definitely, not right (or I am doing something very silly or there's something I don't understand)
Developing this much code without an understanding of you are doing is definitely classified as very silly. There is probably a lot that you don't understand.
Sorry, I didn't quite get that comment. I mean that certain behaviors of the program don't make sense. I am not quite a newbie, if that's your assumption smiley
Quote
Perhaps you need to post all of your code, and explain what exactly it is doing wrong.
The main issue that I have is that it doesn't seem to happen with any one system. Only when I use function pointers AND access the SD card do I get issues, it is a bit maddening to be frank.
But if you think that will help and somebody will read it, sure.
12  Using Arduino / Programming Questions / Re: Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 08:05:03 am
What type is commands? If it isn't an array of  bytes, this: sizeofarray(commands) may be giving you trouble. If it isn't evaluating to four, you'll be overrunning  your functions array. That would definitely cause some serious instability.

Commands is a list of char*, such as:
Code:
char* commands[4]           = {"battery", "timedate","sdinfo","readfile"};

In any case,  sizeofarray does take care of granularity, though;
Code:
template<typename T>
int sizeofarray(T& obj)
{
        return sizeof(obj)/sizeof(obj[0]);
};

the result is always four smiley
13  Using Arduino / Programming Questions / Arduino pointer-to-function broken? Compiler Issue? on: September 13, 2011, 06:39:08 am
Hi there!
I am having very strange crashes in when using a combination of Messenger, the SD library and function pointers. The sketch is a bit involved to upload, but I have a couple of things that are, definitely, not right (or I am doing something very silly or there's something I don't understand)

The function pointers look like this:

Code:
typedef void (* HandlerFuncPtr)() ; // this is a typedef to the messenger functions
HandlerFuncPtr functions[4] = {DisplayBatteryData, TimeDate,SDInfo,ReadFile};
with all those functions being global static ones.

I compile my sketch with this function:

Code:
void messageCompleted()
{
    for (unsigned char c = 0; c < sizeofarray(commands); c++)
    {
        if(message.checkString(commands[c]))
        {
            functions[c]; //Were we go
            return;
        }
    }
    Serial << "ERROR: Couldn't parse message, commands are" << endl;
    ListCommands();
}
Which obviously does nothing at the funcion[c], because it is not calling the function itself.

What is funky about it, is that, if I add "()" behind
Code:
functions[c]();
the program goes from 18960 bytes to 21070 and becomes super unstable.

Any ideas?
14  Using Arduino / Motors, Mechanics, and Power / Re: Power FROM Arduino USB on: July 07, 2011, 12:24:38 pm
so that would limit things to laptops and desktops and, what about smartphone-level devices (iPhone? iPad? Android?)
Also... how much power would I be able to drain from the USB?
thanks again!
Damn you guys are fast smiley-grin
15  Using Arduino / Motors, Mechanics, and Power / Re: Power FROM Arduino USB on: July 07, 2011, 12:18:19 pm
Thanks for your answering so quickly!

I was under that impression. But there's one bit that I don't quite understand... I can talk from a computer using that same USB connection, why shouldn't I be able to talk to a e.g. phone?
About those resistors, any place I can get info on that?
thanks!
Pages: [1] 2