Skip to content

Commit 358089f

Browse files
committed
further ATmegaxxxx port alignment
1 parent 95ff5d9 commit 358089f

File tree

3 files changed

+26
-74
lines changed

3 files changed

+26
-74
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=FreeRTOS
2-
version=10.3.0-7
2+
version=10.3.0-8
33
author=Richard Barry <[email protected]>
44
maintainer=Phillip Stevens <[email protected]>
55
sentence=<h3>FreeRTOS Real Time Operating System implemented for AVR (Uno, Nano, Leonardo, Mega).</h3>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Testing with the Software Serial library shows some incompatibilities at low bau
6666
* ATmega2560 @ 16MHz : Arduino Mega, Arduino ADK
6767
* ATmega2560 @ 16MHz : Seeed Studio ADK
6868

69-
The new megaAVR 0-Series devices are not compatible with this library. They are not yet supported by avr-libc and their interrupt structure is substantially different to previous devices. It may be a while until the avr-libc is updated, but when that happens further support can be added.
69+
The new megaAVR 0-Series devices (eg. ATmega4809) are not fully compatible with this library. Their Timer configuration and structure is substantially different from previous devices, and forms part of a new __avr8x__ architecture. It may be a while until avr-libc is updated to include support, but when that happens further workd can be added here.
7070

7171
## Files & Configuration
7272

src/port.c

Lines changed: 24 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/sleep.h>
3234
#include <avr/wdt.h>
@@ -380,17 +382,6 @@ static void prvSetupTimerInterrupt( void );
380382
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
381383
{
382384
uint16_t usAddress;
383-
384-
/* Place a few bytes of known values on the bottom of the stack.
385-
This is just useful for debugging. */
386-
387-
*pxTopOfStack = 0x11;
388-
pxTopOfStack--;
389-
*pxTopOfStack = 0x22;
390-
pxTopOfStack--;
391-
*pxTopOfStack = 0x33;
392-
pxTopOfStack--;
393-
394385
/* Simulate how the stack would look after a call to vPortYield() generated by
395386
the compiler. */
396387

@@ -415,7 +406,6 @@ uint16_t usAddress;
415406
* In order to do this properly, we would need to get a full 3-byte pointer to
416407
* pxCode. That requires a change to GCC. Not likely to happen any time soon.
417408
*/
418-
419409
*pxTopOfStack = 0;
420410
pxTopOfStack--;
421411
#endif
@@ -447,51 +437,9 @@ uint16_t usAddress;
447437

448438
/* Now the remaining registers. The compiler expects R1 to be 0. */
449439
*pxTopOfStack = ( StackType_t ) 0x00; /* R1 */
450-
pxTopOfStack--;
451-
*pxTopOfStack = ( StackType_t ) 0x02; /* R2 */
452-
pxTopOfStack--;
453-
*pxTopOfStack = ( StackType_t ) 0x03; /* R3 */
454-
pxTopOfStack--;
455-
*pxTopOfStack = ( StackType_t ) 0x04; /* R4 */
456-
pxTopOfStack--;
457-
*pxTopOfStack = ( StackType_t ) 0x05; /* R5 */
458-
pxTopOfStack--;
459-
*pxTopOfStack = ( StackType_t ) 0x06; /* R6 */
460-
pxTopOfStack--;
461-
*pxTopOfStack = ( StackType_t ) 0x07; /* R7 */
462-
pxTopOfStack--;
463-
*pxTopOfStack = ( StackType_t ) 0x08; /* R8 */
464-
pxTopOfStack--;
465-
*pxTopOfStack = ( StackType_t ) 0x09; /* R9 */
466-
pxTopOfStack--;
467-
*pxTopOfStack = ( StackType_t ) 0x10; /* R10 */
468-
pxTopOfStack--;
469-
*pxTopOfStack = ( StackType_t ) 0x11; /* R11 */
470-
pxTopOfStack--;
471-
*pxTopOfStack = ( StackType_t ) 0x12; /* R12 */
472-
pxTopOfStack--;
473-
*pxTopOfStack = ( StackType_t ) 0x13; /* R13 */
474-
pxTopOfStack--;
475-
*pxTopOfStack = ( StackType_t ) 0x14; /* R14 */
476-
pxTopOfStack--;
477-
*pxTopOfStack = ( StackType_t ) 0x15; /* R15 */
478-
pxTopOfStack--;
479-
*pxTopOfStack = ( StackType_t ) 0x16; /* R16 */
480-
pxTopOfStack--;
481-
*pxTopOfStack = ( StackType_t ) 0x17; /* R17 */
482-
pxTopOfStack--;
483-
*pxTopOfStack = ( StackType_t ) 0x18; /* R18 */
484-
pxTopOfStack--;
485-
*pxTopOfStack = ( StackType_t ) 0x19; /* R19 */
486-
pxTopOfStack--;
487-
*pxTopOfStack = ( StackType_t ) 0x20; /* R20 */
488-
pxTopOfStack--;
489-
*pxTopOfStack = ( StackType_t ) 0x21; /* R21 */
490-
pxTopOfStack--;
491-
*pxTopOfStack = ( StackType_t ) 0x22; /* R22 */
492-
pxTopOfStack--;
493-
*pxTopOfStack = ( StackType_t ) 0x23; /* R23 */
494-
pxTopOfStack--;
440+
441+
/* Leave R2 - R23 untouched */
442+
pxTopOfStack -= 23;
495443

496444
/* Place the parameter on the stack in the expected location. */
497445
usAddress = ( uint16_t ) pvParameters;
@@ -500,20 +448,9 @@ uint16_t usAddress;
500448

501449
usAddress >>= 8;
502450
*pxTopOfStack = ( StackType_t ) ( usAddress & ( uint16_t ) 0x00ff );
503-
pxTopOfStack--;
504451

505-
*pxTopOfStack = ( StackType_t ) 0x26; /* R26 X */
506-
pxTopOfStack--;
507-
*pxTopOfStack = ( StackType_t ) 0x27; /* R27 */
508-
pxTopOfStack--;
509-
*pxTopOfStack = ( StackType_t ) 0x28; /* R28 Y */
510-
pxTopOfStack--;
511-
*pxTopOfStack = ( StackType_t ) 0x29; /* R29 */
512-
pxTopOfStack--;
513-
*pxTopOfStack = ( StackType_t ) 0x30; /* R30 Z */
514-
pxTopOfStack--;
515-
*pxTopOfStack = ( StackType_t ) 0x031; /* R31 */
516-
pxTopOfStack--;
452+
/* Leave register R26 - R31 untouched */
453+
pxTopOfStack -= 7;
517454

518455
return pxTopOfStack;
519456
}
@@ -560,6 +497,21 @@ void vPortYield( void )
560497
}
561498
/*-----------------------------------------------------------*/
562499

500+
/*
501+
* Manual context switch callable from ISRs. The first thing we do is save
502+
* the registers so we can use a naked attribute.
503+
*/
504+
void vPortYieldFromISR(void) __attribute__ ( ( hot, flatten, naked ) );
505+
void vPortYieldFromISR(void)
506+
{
507+
portSAVE_CONTEXT();
508+
vTaskSwitchContext();
509+
portRESTORE_CONTEXT();
510+
511+
__asm__ __volatile__ ( "reti" );
512+
}
513+
/*-----------------------------------------------------------*/
514+
563515
/*
564516
* Context switch function used by the tick. This must be identical to
565517
* vPortYield() from the call to vTaskSwitchContext() onwards. The only
@@ -577,7 +529,7 @@ void vPortYieldFromTick( void )
577529
}
578530
portRESTORE_CONTEXT();
579531

580-
__asm__ __volatile__ ( "ret" );
532+
__asm__ __volatile__ ( "reti" );
581533
}
582534
/*-----------------------------------------------------------*/
583535

@@ -610,7 +562,6 @@ void prvSetupTimerInterrupt( void )
610562
ISR(portSCHEDULER_ISR)
611563
{
612564
vPortYieldFromTick();
613-
__asm__ __volatile__ ( "reti" );
614565
}
615566
#else
616567

@@ -629,3 +580,4 @@ void prvSetupTimerInterrupt( void )
629580
xTaskIncrementTick();
630581
}
631582
#endif
583+

0 commit comments

Comments
 (0)