AVR tick-less (freerunning) for RT

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderators: utzig, tfAteba

rfrankla
Posts: 5
Joined: Sun Jul 05, 2015 6:18 pm

AVR tick-less (freerunning) for RT

Postby rfrankla » Tue Jul 14, 2015 10:28 pm

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.

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: AVR tick-less (freerunning) for RT

Postby utzig » Tue Jul 14, 2015 10:36 pm

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

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: AVR tick-less (freerunning) for RT

Postby utzig » Tue Jul 14, 2015 10:55 pm

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?

rfrankla
Posts: 5
Joined: Sun Jul 05, 2015 6:18 pm

Re: AVR tick-less (freerunning) for RT

Postby rfrankla » Wed Jul 15, 2015 7:28 am

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.

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: AVR tick-less (freerunning) for RT

Postby utzig » Wed Jul 15, 2015 11:37 am

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

rfrankla
Posts: 5
Joined: Sun Jul 05, 2015 6:18 pm

Re: AVR tick-less (freerunning) for RT

Postby rfrankla » Wed Jul 15, 2015 11:23 pm

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.

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: AVR tick-less (freerunning) for RT

Postby utzig » Sat Jul 18, 2015 7:58 pm

Hi,

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

Cheers,
Fabio Utzig

rfrankla
Posts: 5
Joined: Sun Jul 05, 2015 6:18 pm

Re: AVR tick-less (freerunning) for RT

Postby rfrankla » Sun Jul 19, 2015 3:31 pm

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.

User avatar
Giovanni
Site Admin
Posts: 13008
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 742 times
Been thanked: 620 times
Contact:

Re: AVR tick-less (freerunning) for RT

Postby Giovanni » Sun Jul 19, 2015 3:35 pm

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

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: AVR tick-less (freerunning) for RT

Postby utzig » Mon Jul 20, 2015 1:44 pm

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


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 2 guests