IAR AVR Port

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

Moderators: utzig, tfAteba

handaza
Posts: 9
Joined: Fri May 04, 2012 7:54 am

IAR AVR Port

Postby handaza » Fri Nov 30, 2012 10:08 am

Hi,

I need to have port for IAR compiler for AVR micros, if any one has a port, kindly share it with me.

is there any plans from ChibiOS development team to make one?

if there is no port, I will make one.

I need to know the usage of function _port_thread_start as I found it defined in every port, but when I searched the code I didn't find any usage for it, do I miss something?

thanks.

mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

Re: IAR AVR Port

Postby mabl » Fri Nov 30, 2012 10:17 am

I've not yet heart of any IAR AVR port. Isn't the AVR world mostly governed by gcc based toolchains? Even AVR Studio uses gcc - and there are even standard linker scripts. Also avr-gcc is included in every Linux distribution. Just wondering why...

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

Re: IAR AVR Port

Postby Giovanni » Fri Nov 30, 2012 11:04 am

Hi,

_port_thread_start is the trampoline code that is used to start a thread. I don't have plans for an IAR port but it should very easy to do starting from the GCC code.

Giovanni

handaza
Posts: 9
Joined: Fri May 04, 2012 7:54 am

Re: IAR AVR Port

Postby handaza » Fri Nov 30, 2012 11:06 am

I don't want to start a thread about GCC but lets say that I have bad experience with GCC, with all my respects to it, but GCC behave strangely when optimization -os is used, look at http://forums.adafruit.com/viewtopic.php?f=11&t=4343 as a small example,I also faced many of these problems, I don't want to spend time on these kind of problems again.

kindly I am still need answers for my questions in my first post.

regards.

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

Re: IAR AVR Port

Postby Giovanni » Fri Nov 30, 2012 2:29 pm

Giovanni wrote:Hi,

_port_thread_start is the trampoline code that is used to start a thread. I don't have plans for an IAR port but it should very easy to do starting from the GCC code.

Giovanni


I posted just before you, do you need more details?

Giovanni

handaza
Posts: 9
Joined: Fri May 04, 2012 7:54 am

Re: IAR AVR Port

Postby handaza » Mon Dec 03, 2012 11:36 am

thank you Mr. Giovanni for answering my questions.

kindly I need more information.

I noticed that Chibios is different than other RTOS by providing two ways for context switching, one from interrupt and other by calling OS APIs like chThdSleep, this way makes chibios faster in context switching as it does not have to wait time tick interrupt or use software interrupt to make context switch, am I right in this conclusion?

but to do this, I found that port_switch save group of registers while PORT_IRQ_PROLOGUE save another group registers, and I noticed this in all ports.

my questions is how to decide which registers to save in port_switch[/b and what to save in [b]PORT_IRQ_PROLOGUE ?
I am asking this because IAR avr is different than GCC as it have two stacks and different parameter register assignment.

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

Re: IAR AVR Port

Postby Giovanni » Mon Dec 03, 2012 11:43 am

Hi,

You are correct in you assumption, this is one of the things that make ChibiOS particularly efficient at switching tasks.

It is very simple, in port_switch() you save the registers that are preserved during function calls, it is useless to save the others because the compiler expects them altered anyway. This set of registers are described by the intctx structure.

In the interrupt handler you usually save the other registers instead but you have to verify what the IAR compiler exactly saves in ISR functions exactly and populate the extctx structure with those registers.

Giovanni

handaza
Posts: 9
Joined: Fri May 04, 2012 7:54 am

Re: IAR AVR Port

Postby handaza » Fri Dec 07, 2012 1:07 am

Hi Mr Giovani,

thank you too much as your answers helped me to finish the context switch on IAR AVR although it was very tricky as it took me 3 days because IAR AVR uses two stacks Cstack and Rstack.

when I try to include the HAL, the code does not compile, is the HAl Generic or it depend on AVR GCC?
also I followed your way in STM8s port to define PORT_IRQ_HANDLER, but the compiler does not accept it and the only way to compile and run is to add __ pragma and __interrupt directly to the timer ISR function in the board, how can I fix it as I need to follow the template?

regards.

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

Re: IAR AVR Port

Postby Giovanni » Fri Dec 07, 2012 9:46 am

Hi,

The HAL itself is generic but the driver implementations use the AVRGCC headers, you may need to make changes there if you want drivers compilable with GCC and IAR. Note that in most other platforms drivers are written to be compatible with all compilers.

About ISRs, you should try to encapsulate all the details into the macros or your ISRs will not be compatible across the various compilers. Can you post an example of ISR?

Giovanni

handaza
Posts: 9
Joined: Fri May 04, 2012 7:54 am

Re: IAR AVR Port

Postby handaza » Fri Dec 07, 2012 1:27 pm

hi,

here is the example of timer0 compare interrupt.

Code: Select all

 #pragma vector = TIMER0_COMP_vect
  __interrupt void TIMER0_COMP_vect_ISR(void)
{

  CH_IRQ_PROLOGUE();

  chSysLockFromIsr();
  chSysTimerHandlerI();
  chSysUnlockFromIsr();

  CH_IRQ_EPILOGUE();
}



and here is the Macro I made but the compiler refuse it.

Code: Select all

#define STRINGVECTOR(x) #x
#define VECTOR_ID(x) STRINGVECTOR(vector=(x))

/**
 * @brief   IRQ handler function declaration.
 * @note    @p id can be a function name or a vector number depending on the
 *          port implementation.
 */
#define PORT_IRQ_HANDLER(id) \
_Pragma(VECTOR_ID(id)) \
__interrupt void vector##id(void)


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 1 guest