Jens Bauer changed bug 172
What Removed Added
CC   jens-bugzilla@gpio.dk

Comment # 1 on bug 172 from
Having support for this will be highly appreciated.

Especially weak,alias is important on microcontrollers, which have exception
vectors.

Small C Example (this one is for ARM Cortex-M microcontrollers):

---8<-----8<-----8<-----
#define WA(a)   __attribute__((weak, alias(#a)))
#define WE      WA(defaultExceptionHandler)
#define WR      WA(defaultResetHandler)

typedef void (*const VectorFunc)(void);

static void defaultResetHandler(void) __attribute__((__interrupt__));


/* $0000 System Exception Vector Handlers: */
void WR Reset_Handler(void);        /*   1 $0004 Reset */
void WE NMI_Handler(void);          /*   2 $0008 Non Maskable Interrupt */
void WE HardFault_Handler(void);    /*   3 $000c Hard Fault */

...
...

/* Vector Table */
__attribute__((section(".isr_vector"))) VectorFunc g_pfnVectors[] =
{
    (VectorFunc)STACK_ADDRESS,  /*   0 $0000 Initial Stack Pointer */
    Reset_Handler,              /*   1 $0004 Reset Vector */
    NMI_Handler,                /*   2 $0008 Non Maskable Interrupt Vector */
    HardFault_Handler,          /*   3 $000c Hard Fault Vector */

    ...
    ...
};

static void defaultResetHandler(void)
{
    while(1){ asm volatile("wfi"); }
}
--->8----->8----->8-----

The above example demonstrates the use of the section attribute and the use of
the weak+alias attribute.
The weak+alias is used for having default implementations of all the exception
handlers (including Reset_Handler).
This means that the user can just start writing code, but allows customization
in case an implementation, which is either simpler or more advanced than the
provided one is required.


You are receiving this mail because: