Page 1 of 2

AVR tick-less (freerunning) for RT

Posted: Tue Jul 14, 2015 10:28 pm
by rfrankla
Hi, I am using a forked git copy of 3.0.0 and have NIL-periodic, NIL-freerunning, and RT-periodic working.
But, it looks like RT-freerunning is missing the necessary ports/AVR/chcore (chcore_timer) functions to communicate with HAL timer functions.

Is anyone working on this? do they need help? ...or is it still waiting to be started?

If no one has started, I can get started myself, and publish what I have to GIthub.

Please let me know the status of RT-freerunning, and what I may do to help.

Thank you. Rick.

Re: AVR tick-less (freerunning) for RT

Posted: Tue Jul 14, 2015 10:36 pm
by utzig
I had tested all of these options and all seemed to work. I'll recheck if some recent change has broken anything.

Cheers,
Fabio Utzig

Re: AVR tick-less (freerunning) for RT

Posted: Tue Jul 14, 2015 10:55 pm
by utzig
Rick, you are right. There was some code missing. I already have a patch ready but I'm not able to test it myself because I don't have any AVR powered boards here. Can you test it and confirm it works?

Re: AVR tick-less (freerunning) for RT

Posted: Wed Jul 15, 2015 7:28 am
by rfrankla
Hi, yes I can do some testing. Just let me know how to get the patch.
I'm currently forking from the primary Github location.
Thanks. Rick.

Re: AVR tick-less (freerunning) for RT

Posted: Wed Jul 15, 2015 11:37 am
by utzig
Hi Rick, I was confident enough that it should work that I already commited the changes to SVN! The github mirror should be updated soon.

The patch is here: https://gist.github.com/utzig/52213b644be8ffb27077

Cheers,
Fabio Utzig

Re: AVR tick-less (freerunning) for RT

Posted: Wed Jul 15, 2015 11:23 pm
by rfrankla
Thank you. I'll use that. It may take a day or two while I work on this.
Then I'll report back and let you know how everything is.

Thanks. Rick.

Re: AVR tick-less (freerunning) for RT

Posted: Sat Jul 18, 2015 7:58 pm
by utzig
Hi,

Just go my Arduino back and tested RT with freerunning. Seems to be working!

Cheers,
Fabio Utzig

Re: AVR tick-less (freerunning) for RT

Posted: Sun Jul 19, 2015 3:31 pm
by rfrankla
Hi,
Yes, I have it working also. All the tests reported success to the serial port.

I am using an Arduino MEGA2560 board (I changed MCU = atmega2560 in the Makefile) and the build gives the following warning:

Code: Select all

Compiling C: ../../../os/rt/src/chthreads.c
avr-gcc -c -mmcu=atmega2560 -I. -gdwarf-2 -DF_CPU=16000000UL -O2 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./../../../os/rt/src/chthreads.lst -I../../../os/rt/ports/AVR -I../../../os/rt/ports/AVR/compilers/GCC -I../../../os/rt/include -I../../../test/rt -I../../../os/hal/include -I../../../os/hal/osal/rt -I../../../os/hal/ports/AVR -I../../../os/hal/boards/ARDUINO_MEGA -I../../../os/various -std=gnu11 -mrelax -Wundef -MMD -MP -MF .dep/chthreads.o.d ../../../os/rt/src/chthreads.c -o ../../../os/rt/src/chthreads.o
In file included from ../../../os/rt/include/ch.h:74:0,
                 from ../../../os/rt/src/chthreads.c:55:
../../../os/rt/src/chthreads.c: In function ‘chThdCreateI’:
../../../os/rt/ports/AVR/chcore.h:162:49: warning: right shift count >= width of type [enabled by default]
                                   sizeof(struct port_intctx));              \
                                                 ^
../../../os/rt/src/chthreads.c:187:3: note: in expansion of macro ‘PORT_SETUP_CONTEXT’
   PORT_SETUP_CONTEXT(tp, wsp, size, pf, arg);
   ^


This is caused by trying to shift the function pointer by 16. This is not needed. pcx should be set to zero.
i.e. change

Code: Select all

  tp->p_ctx.sp->pcx = (int)_port_thread_start >> 16;                        \

to

Code: Select all

  tp->p_ctx.sp->pcx = 0;                                                    \


All function addresses created by the avr compiler are 16 bit.
If the function ends up being linked above 128 KiB a trampoline is used, this ends up as two jumps instead on one, a little extra time, but that is the price to pay for a HUGE program. The linker takes care of all this.

EXCEPT, there is a problem with the linker. (see: https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html the section 3.17.5.1 EIND and Devices with More Than 128 Ki Bytes of Flash)
so the following should be added to the appropriate sections in the Makefile when using atmega2560 or any other mcu with >128 KiB flash:

Code: Select all

CFLAGS += -mrelax
CPPFLAGS += -mrelax


This is the theory anyway. I have not created a program with function in very high memory, that may be something I'll try next weekend.

Rick.

Re: AVR tick-less (freerunning) for RT

Posted: Sun Jul 19, 2015 3:35 pm
by Giovanni
Hi Fabio,

Could you add all the changes to the readme.txt? it is required for the release note.

When SourceForge starts working again of course...

Giovanni

Re: AVR tick-less (freerunning) for RT

Posted: Mon Jul 20, 2015 1:44 pm
by utzig
As soon as SVN is back I'll change pcx and add -mrelax.

You should also read my latest post on the previous ATmega2560 thread:

viewtopic.php?f=21&t=2642#p21203

What do you think?

Giovanni wrote:Could you add all the changes to the readme.txt? it is required for the release note.


Will do.

Cheers,
Fabio Utzig