From 19a3c524ee7748fc017c9ce59671d0d4a8024c91 Mon Sep 17 00:00:00 2001 From: Kelvin Lawson Date: Sat, 20 Feb 2010 18:14:51 +0000 Subject: [PATCH] ATmega port: Support CPUs with 3 byte program counter. Support devices which use TIMSK1 instead of TIMSK. --- ports/avr/atomport.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ports/avr/atomport.c b/ports/avr/atomport.c index 19a1d3c..ecdbf16 100644 --- a/ports/avr/atomport.c +++ b/ports/avr/atomport.c @@ -186,6 +186,19 @@ void archThreadContextInit (ATOM_TCB *tcb_ptr, void *stack_top, void (*entry_poi *stack_ptr-- = (uint8_t)((uint16_t)thread_shell & 0xFF); *stack_ptr-- = (uint8_t)(((uint16_t)thread_shell >> 8) & 0xFF); + /** + * Devices with 3 byte program counters (e.g. Atmega25x, Xmega) + * must have 3 bytes stacked for the entry point. In GCC + * function pointers are still 16-bits, however, so we cannot + * actually pass entry points at > 64KB in memory space. This + * means that the thread_shell() function must be located + * in the bottom 64KB. You may need to modify linker scripts to + * force this. + */ +#ifdef __AVR_3_BYTE_PC__ + *stack_ptr-- = 0; +#endif + /** * For the AVR port the parameter registers (R25-R24) are not * saved and restored by the context switch routines. This means @@ -262,7 +275,11 @@ void avrInitSystemTickTimer ( void ) OCR1A = (AVR_CPU_HZ / 256 / SYSTEM_TICKS_PER_SEC); /* Enable compare match 1A interrupt */ +#ifdef TIMSK TIMSK = _BV(OCIE1A); +#else + TIMSK1 = _BV(OCIE1A); +#endif /* Set prescaler 256 */ TCCR1B = _BV(CS12) | _BV(WGM12);