#avr | Logs for 2013-07-05

Back
[04:14:52] <antto> how long (roughly) would a loop like this take: while (c < (F_CPU/2)) { ++c; }
[05:23:32] <antto> in stk500v2 bootloader, someone has made a nice function called __jumpMain(), yet it is NOT used anywhere
[06:41:10] <nickjohnson_> antto: That depends on a lot of things
[06:47:28] <antto> i mean, there are 3 places in the bootloader where it decides to jump to the firmware
[06:47:47] <antto> and all three of them use the same asm code (which is rather short)
[06:48:29] <antto> yet, above main, someone has written this __jumpMain() function which uses a rather longer piece of asm code
[06:48:55] <antto> it looks "better" (i'm judging by the comments on it, but i have no idea about ASM)
[07:19:50] <braincracker> h
[07:26:14] <HylianSavior> i
[07:27:15] <antto> f
[08:56:19] <johey> Using avr-gcc, I have a an array A of struct with a callback C to a function. From main(), if I call A[0].C(), it works fine. Also, if I declare a variable uint8_t V=0 just before calling A[V].C() it works fine. But if I declare V early in main() and call A[V].C() later in main(), main() just runs itself.
[08:57:06] <johey> This is just bare instanity, isn't it?
[09:07:11] <cart_man> whats the size of a short in AVR?
[09:08:38] <cart_man> or rather...how do I declare a 16bit short or int ?
[09:10:19] <OndraSter__> uint_16t
[09:10:24] <OndraSter__> and similar
[09:15:34] <antto> uint16_t
[09:17:11] <johey> Ah, never mind. Maybe I should stick to switch statements instead of using callbacks. This way it works and I save a few program bytes. :)
[09:17:34] <johey> Still disturbing the fact that I don't understand why this doesn't work.
[09:19:14] <Casper> it may be a bug, or it may be a sane gcc programmer that got an idea
[09:21:20] <johey> Just found this which seems similar. http://stackoverflow.com/questions/1950246/function-pointer-location-not-getting-passed
[09:22:00] <johey> He gets it right when disabling optimization. I cannot verify, as my code gets too big for my mega8 if I do.
[09:22:27] <Casper> using -O3 ? or -O2?
[09:22:33] <johey> I can live with it if I know it is a bug and not me. :)
[09:23:07] <johey> I've tried -O1 and -O2. Both reproduce the fenomenon. -O0 gives too big binary.
[09:23:36] <Casper> k
[09:23:43] <Casper> -O3 is known to cause issues
[09:24:08] <johey> Hm. How big is a void (*foo)()?
[09:24:44] <johey> Ah, never mind. Guess I need to look at the object code to see what is really happening.
[09:25:54] <johey> Without callbacks, finally, my Super Nintendo controller for the Amiga with CD32 emulation. :)
[09:26:09] <johey> s/for/works for/
[09:42:35] <Casper> johey: sound like a big code for such an easy task
[10:33:45] <johey> Casper: Well, it's not that easy. CD32 emulation is very timing critical. You have to simulate a shift register timed with an external clock.
[10:35:12] <johey> Casper: And I failed when building the hardware. I should have put the clock signal on an interrupt pin, but I didn't. So I have to do everything in a loop. And as I have to do things while waiting for the clock to change state, it is not that easy task.
[10:38:14] <johey> ... And now I'm about to add a feature where you can set the joystick in a mouse mode, simulating an Amiga mouse for convenience. Hope I can fit that into the little memory area I have left.
[10:43:49] <Casper> :D
[10:44:27] <Casper> johey: do you use alot of _delay_ms() or *_us() of the same length?
[10:48:43] <johey> Casper: No. The clock pulse from the CD32 is too fast, so I have no ms over. I haven't tried using us though.
[10:49:58] <johey> I use while() for waiting.
[10:51:56] <johey> Had to change the osc from 1 to 2 MHz to be able to do ONE comparison BEFORE entering the wait loop. Quite critical. :)
[11:05:38] <Casper> johey: the reason why I asked is that the _delay_ms/us() code is quite big, and is inlined
[11:06:12] <Casper> so if you was using it, with always the same value, I'ld have suggested to put it in a function if it do not screw up the timing too much
[11:06:26] <johey> Ah ok.
[11:06:38] <Casper> that would have reduced the code size, but cause the timing to be off by about 12 cycles
[11:07:19] <johey> I may be able shrinking the code down a bit by replacing my macros with functions. I made them macros to save some cycles, but now as I run it in 2 MHz I guess I have time to do function calls.
[11:53:33] <cart_man> how can I join chars together ? for instance existing chars1[3] and chars2[3] ... I want to insert them all into 1 UNIChar[16] = char1[3] + " " + char2[3] ??
[11:53:44] <cart_man> RikusW: how can I join chars together ? for instance existing chars1[3] and chars2[3] ... I want to insert them all into 1 UNIChar[16] = char1[3] + " " + char2[3] ??
[11:53:59] <RikusW> astrcpy + strcat
[11:54:02] <RikusW> strcpy
[11:54:14] <Tom_itx> cut n paste
[11:55:22] <Tom_itx> strcpy might not work if he want's to be selective
[11:56:17] <cart_man> does astrcpy work like append ?
[11:56:31] <cart_man> and what does strcat do ? concatenate?
[11:56:33] <Tom_itx> UNIChar[0] = char1[3]; UNIChar[1] = char2[3];
[11:58:09] <cart_man> I think I read about function strcpy somewhere
[11:58:28] <cart_man> it can be used like strcpy(Char1,UniChar,6)
[11:58:47] <cart_man> if you want it to start cpying char1 to UniChar[6] right?
[12:06:08] <cart_man> The strcat function concatenates or appends src to dest. All characters from src are copied including the terminating null character. ??
[12:06:19] <cart_man> terminating null char..whats the use of the append then?
[12:08:28] <Tom_itx> one reason i suggested assignment
[12:09:28] <Tom_itx> unless it's smart enough to move the null char when it does
[12:10:01] <johey> cart_man: sprintf() maybe?
[12:10:53] <johey> It's like printf() but writes to a given string buffer instead of to stdout.
[12:11:19] <johey> Don't know if it's a part of avr-gcc though.
[12:12:01] <johey> Thinking of it, I don't even know what programming language you're using. :)
[12:14:16] <cart_man> AVRs included compiler in C
[12:14:39] <Tom_itx> avrgcc
[12:18:54] <BJfreeman> http://www.nongnu.org/avr-libc/user-manual/