It is currently Thu May 23, 2013 5:14 am

All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: New board with Atmega2560
PostPosted: Wed Jan 12, 2011 1:59 pm 
Offline

Joined: Sun Dec 12, 2010 3:18 pm
Posts: 6
Thanks Luca,
I'll download the svn image.

For the question related to the process part that I posted in the prevoius message,
do you have any suggestion?

Thanks
J


Top
 Profile  
 
 Post subject: Re: New board with Atmega2560
PostPosted: Wed Jan 12, 2011 6:01 pm 
Offline
User avatar

Joined: Tue May 04, 2010 4:15 pm
Posts: 55
jaws wrote:
An update of my board:
I tested, debug and timer also with external memory (undef _PROC_) : everithing works!
Introducing a thread on the code (define _PROC_) I see a continuous restart printing on the serial port: Hello wolrd continuosly.
Any suggestions?



Hi jaws,
I'm glad that external memory works!

Regarding the kernel issue, I don't understand if the micro resets or you just see the 'Hello world' print from main process. If you see the '*** Bertos debug start ***' mark each time, then the micro is resetting itself.

If the micro doesn't reset and you only see 'Hello world', try to enable kernel signals as explained in the developer's FAQ.

I'm in a hurry, more on this later.

Cheers,
Luca


Top
 Profile  
 
 Post subject: Re: New board with Atmega2560
PostPosted: Mon Feb 06, 2012 1:08 am 
Offline

Joined: Mon Feb 06, 2012 12:49 am
Posts: 3
Hi Jaws and Luca,

I'm facing same behavior described by Jaws!!! Whenever timer_delay() executes, the board is resetting itself!

I'm using an Arduino Mega2560 with the sample code created with wizard (considering Arduino1280 wizard creation). It just blinks a led and prints monitor_report. But resets during timer_delay().

I created (via wizard) the same sample for Arduino UNO (considering Arduino 2009 creation), and the sample worked perfectly!

Please, do you have any idea about this problem?

Thanks in advance,


Top
 Profile  
 
 Post subject: Re: New board with Atmega2560
PostPosted: Tue Feb 07, 2012 2:56 am 
Offline

Joined: Mon Feb 06, 2012 12:49 am
Posts: 3
Yep! It seems to be related to EIND. It should be pushed onto stack with funcaddr for both ATmega2560/2561.

From "ATmega640/1280/1281/2560/2561 Preliminary", item "7.6 Stack Pointer":
"The Stack Pointer is decremented by one when data is pushed onto the Stack with the PUSH instruction, and it is decremented by two for ATmega640/1280/1281 and three for
ATmega2560/2561 when the return address is pushed onto the Stack with subroutine call or
interrupt. The Stack Pointer is incremented by one when data is popped from the Stack with the POP instruction, and it is incremented by two for ATmega640/1280 /1281 and three for ATmega2560/2561 when data is popped from the Stack with return from subroutine RET or return from interrupt RETI."

So, in bertos\cpu\frame.h, edit proper CPU_PUSH_CALL_FRAME to:

#if CPU_AVR_ATMEGA2560 || CPU_AVR_ATMEGA2561
#define CPU_PUSH_CALL_FRAME(sp, func) \
do { \
uint16_t funcaddr = (uint16_t)(func); \
CPU_PUSH_WORD((sp), funcaddr); \
CPU_PUSH_WORD((sp), funcaddr>>8); \
CPU_PUSH_WORD((sp), EIND); \
} while (0)
#else
#define CPU_PUSH_CALL_FRAME(sp, func) \
do { \
uint16_t funcaddr = (uint16_t)(func); \
CPU_PUSH_WORD((sp), funcaddr); \
CPU_PUSH_WORD((sp), funcaddr>>8); \
} while (0)
#endif

Don't forget:
#if CPU_AVR_ATMEGA2560 || CPU_AVR_ATMEGA2561
#include <avr/io.h>
#endif

Does anyone knows any other side effect of this 3 bytes onto stack?

Thanks,


Top
 Profile  
 
 Post subject: Re: New board with Atmega2560
PostPosted: Fri Feb 10, 2012 10:45 am 
Offline
User avatar

Joined: Tue May 04, 2010 4:15 pm
Posts: 55
Hi led,
I think you will need to change the context switching routine to take into account for 3 bytes stack pointer. The file is located in cpu/avr/hw/switch_ctx_avr.S

Apart from that, I don't see any other problem in the patch.


Top
 Profile  
 
 Post subject: Re: New board with Atmega2560
PostPosted: Fri Feb 10, 2012 4:54 pm 
Offline

Joined: Mon Feb 06, 2012 12:49 am
Posts: 3
Hi Lucca,

Please, could you point me where to change that file. I reviewed it, but I didn't find where the proc address is saved/restored. I am pretty new to avr processors and its risc (or, 'risky'? :D ) assembly language.

Thanks in advance,


Top
 Profile  
 
 Post subject: Re: New board with Atmega2560
PostPosted: Fri Feb 10, 2012 6:26 pm 
Offline
User avatar

Joined: Tue May 04, 2010 4:15 pm
Posts: 55
Actually, it seems that stack pointers are always 2 bytes in all Mega AVRs, but you have two extra registers to access the flash memory (RAMPZ and EIND), so I guess they both should be saved.

You could do something like this in bertos/cpu/avr/hw/switch_ctx_avr.S:
Code:
   push   r28
   push   r29
        push RAMPZ
        push EIND

        ....


and below, when restoring the context (line 94):
Code:
   out   SPL-__SFR_OFFSET,r18   ; SP = *new_sp
   out   SPH-__SFR_OFFSET,r19
   out   SREG-__SFR_OFFSET,r0   ; Restore previous IRQ state
        pop EIND
        pop RAMPZ
        pop r29
....


Of course you will need to add a
CPU_PUSH_WORD((sp), RAMPZ); \
to account for the extra register.

I don't have a Mega2560 to test the code, I hope you can make it work correctly!
Cheers,
Luca


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group