Skip to content

Commit db234a6

Browse files
committed
ATmegaxxxx - add megaAVR 0-Series support
1 parent d381f65 commit db234a6

File tree

2 files changed

+23
-74
lines changed

2 files changed

+23
-74
lines changed

portable/GCC/ATmegaxxxx/port.c

Lines changed: 23 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828

2929
#include <stdlib.h>
30+
31+
#include <avr/io.h>
3032
#include <avr/interrupt.h>
3133
#include <avr/wdt.h>
3234

@@ -524,17 +526,6 @@ static void prvSetupTimerInterrupt( void );
524526
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
525527
{
526528
uint16_t usAddress;
527-
528-
/* Place a few bytes of known values on the bottom of the stack.
529-
This is just useful for debugging. */
530-
531-
*pxTopOfStack = 0x11;
532-
pxTopOfStack--;
533-
*pxTopOfStack = 0x22;
534-
pxTopOfStack--;
535-
*pxTopOfStack = 0x33;
536-
pxTopOfStack--;
537-
538529
/* Simulate how the stack would look after a call to vPortYield() generated by
539530
the compiler. */
540531

@@ -590,51 +581,9 @@ uint16_t usAddress;
590581

591582
/* Now the remaining registers. The compiler expects R1 to be 0. */
592583
*pxTopOfStack = ( StackType_t ) 0x00; /* R1 */
593-
pxTopOfStack--;
594-
*pxTopOfStack = ( StackType_t ) 0x02; /* R2 */
595-
pxTopOfStack--;
596-
*pxTopOfStack = ( StackType_t ) 0x03; /* R3 */
597-
pxTopOfStack--;
598-
*pxTopOfStack = ( StackType_t ) 0x04; /* R4 */
599-
pxTopOfStack--;
600-
*pxTopOfStack = ( StackType_t ) 0x05; /* R5 */
601-
pxTopOfStack--;
602-
*pxTopOfStack = ( StackType_t ) 0x06; /* R6 */
603-
pxTopOfStack--;
604-
*pxTopOfStack = ( StackType_t ) 0x07; /* R7 */
605-
pxTopOfStack--;
606-
*pxTopOfStack = ( StackType_t ) 0x08; /* R8 */
607-
pxTopOfStack--;
608-
*pxTopOfStack = ( StackType_t ) 0x09; /* R9 */
609-
pxTopOfStack--;
610-
*pxTopOfStack = ( StackType_t ) 0x10; /* R10 */
611-
pxTopOfStack--;
612-
*pxTopOfStack = ( StackType_t ) 0x11; /* R11 */
613-
pxTopOfStack--;
614-
*pxTopOfStack = ( StackType_t ) 0x12; /* R12 */
615-
pxTopOfStack--;
616-
*pxTopOfStack = ( StackType_t ) 0x13; /* R13 */
617-
pxTopOfStack--;
618-
*pxTopOfStack = ( StackType_t ) 0x14; /* R14 */
619-
pxTopOfStack--;
620-
*pxTopOfStack = ( StackType_t ) 0x15; /* R15 */
621-
pxTopOfStack--;
622-
*pxTopOfStack = ( StackType_t ) 0x16; /* R16 */
623-
pxTopOfStack--;
624-
*pxTopOfStack = ( StackType_t ) 0x17; /* R17 */
625-
pxTopOfStack--;
626-
*pxTopOfStack = ( StackType_t ) 0x18; /* R18 */
627-
pxTopOfStack--;
628-
*pxTopOfStack = ( StackType_t ) 0x19; /* R19 */
629-
pxTopOfStack--;
630-
*pxTopOfStack = ( StackType_t ) 0x20; /* R20 */
631-
pxTopOfStack--;
632-
*pxTopOfStack = ( StackType_t ) 0x21; /* R21 */
633-
pxTopOfStack--;
634-
*pxTopOfStack = ( StackType_t ) 0x22; /* R22 */
635-
pxTopOfStack--;
636-
*pxTopOfStack = ( StackType_t ) 0x23; /* R23 */
637-
pxTopOfStack--;
584+
585+
/* Leave R2 - R23 untouched */
586+
pxTopOfStack -= 23;
638587

639588
/* Place the parameter on the stack in the expected location. */
640589
usAddress = ( uint16_t ) pvParameters;
@@ -643,20 +592,9 @@ uint16_t usAddress;
643592

644593
usAddress >>= 8;
645594
*pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
646-
pxTopOfStack--;
647595

648-
*pxTopOfStack = ( StackType_t ) 0x26; /* R26 X */
649-
pxTopOfStack--;
650-
*pxTopOfStack = ( StackType_t ) 0x27; /* R27 */
651-
pxTopOfStack--;
652-
*pxTopOfStack = ( StackType_t ) 0x28; /* R28 Y */
653-
pxTopOfStack--;
654-
*pxTopOfStack = ( StackType_t ) 0x29; /* R29 */
655-
pxTopOfStack--;
656-
*pxTopOfStack = ( StackType_t ) 0x30; /* R30 Z */
657-
pxTopOfStack--;
658-
*pxTopOfStack = ( StackType_t ) 0x031; /* R31 */
659-
pxTopOfStack--;
596+
/* Leave register R26 - R31 untouched */
597+
pxTopOfStack -= 7;
660598

661599
return pxTopOfStack;
662600
}
@@ -709,6 +647,21 @@ void vPortYield( void )
709647
}
710648
/*-----------------------------------------------------------*/
711649

650+
/*
651+
* Manual context switch callable from ISRs. The first thing we do is save
652+
* the registers so we can use a naked attribute.
653+
*/
654+
void vPortYieldFromISR(void) __attribute__ ( ( hot, flatten, naked ) );
655+
void vPortYieldFromISR(void)
656+
{
657+
portSAVE_CONTEXT();
658+
vTaskSwitchContext();
659+
portRESTORE_CONTEXT();
660+
661+
__asm__ __volatile__ ( "reti" );
662+
}
663+
/*-----------------------------------------------------------*/
664+
712665
/*
713666
* Context switch function used by the tick. This must be identical to
714667
* vPortYield() from the call to vTaskSwitchContext() onwards. The only
@@ -725,7 +678,7 @@ void vPortYieldFromTick( void )
725678
}
726679
portRESTORE_CONTEXT();
727680

728-
__asm__ __volatile__ ( "ret" );
681+
__asm__ __volatile__ ( "reti" );
729682
}
730683
/*-----------------------------------------------------------*/
731684

@@ -776,7 +729,6 @@ uint8_t ucLowByte;
776729
ucLowByte = portTIMSK;
777730
ucLowByte |= portCOMPARE_MATCH_A_INTERRUPT_ENABLE;
778731
portTIMSK = ucLowByte;
779-
780732
}
781733

782734
#endif
@@ -799,7 +751,6 @@ uint8_t ucLowByte;
799751
ISR(portSCHEDULER_ISR)
800752
{
801753
vPortYieldFromTick();
802-
__asm__ __volatile__ ( "reti" );
803754
}
804755
#else
805756

portable/GCC/ATmegaxxxx/portmacro.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ extern "C" {
4545
#include <avr/wdt.h>
4646

4747
/* Type definitions. */
48-
4948
#define portCHAR char
5049
#define portFLOAT float
5150
#define portDOUBLE double
@@ -152,4 +151,3 @@ extern void vPortYield( void ) __attribute__ ( ( naked ) );
152151
#endif
153152

154153
#endif /* PORTMACRO_H */
155-

0 commit comments

Comments
 (0)