summaryrefslogtreecommitdiff
path: root/nuttx/arch/avr
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-10-15 01:05:15 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-10-15 01:05:15 +0000
commita5d3d53cc9ac5ddf3c4a74aff4c058f52370d422 (patch)
treeb055c23f8c867d5b247c2bd84baa687af603a802 /nuttx/arch/avr
parent75ab0eb7b94538e29a597617d33b79ae858c0c32 (diff)
downloadpx4-nuttx-a5d3d53cc9ac5ddf3c4a74aff4c058f52370d422.tar.gz
px4-nuttx-a5d3d53cc9ac5ddf3c4a74aff4c058f52370d422.tar.bz2
px4-nuttx-a5d3d53cc9ac5ddf3c4a74aff4c058f52370d422.zip
More context switching logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3016 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/avr')
-rwxr-xr-xnuttx/arch/avr/src/at91uc3/Make.defs2
-rw-r--r--nuttx/arch/avr/src/at91uc3/at91uc3_irq.c2
-rwxr-xr-xnuttx/arch/avr/src/avr32/up_exceptions.S35
-rwxr-xr-xnuttx/arch/avr/src/avr32/up_fullcontextrestore.S7
-rw-r--r--nuttx/arch/avr/src/avr32/up_nommuhead.S1
5 files changed, 35 insertions, 12 deletions
diff --git a/nuttx/arch/avr/src/at91uc3/Make.defs b/nuttx/arch/avr/src/at91uc3/Make.defs
index a3369a606..4318ccf38 100755
--- a/nuttx/arch/avr/src/at91uc3/Make.defs
+++ b/nuttx/arch/avr/src/at91uc3/Make.defs
@@ -39,7 +39,7 @@ HEAD_ASRC = up_nommuhead.S
# Common AVR/AVR32 files
-CMN_ASRCS = up_exceptions.S up_fullcontextrestore.S
+CMN_ASRCS = up_exceptions.S up_fullcontextrestore.S up_switchcontext.S
CMN_CSRCS = up_assert.c up_allocateheap.c up_blocktask.c up_copystate.c \
up_createstack.c up_mdelay.c up_udelay.c up_exit.c up_idle.c \
up_initialize.c up_initialstate.c up_interruptcontext.c \
diff --git a/nuttx/arch/avr/src/at91uc3/at91uc3_irq.c b/nuttx/arch/avr/src/at91uc3/at91uc3_irq.c
index d354bbe47..7f38f4474 100644
--- a/nuttx/arch/avr/src/at91uc3/at91uc3_irq.c
+++ b/nuttx/arch/avr/src/at91uc3/at91uc3_irq.c
@@ -292,7 +292,7 @@ int up_prioritize_irq(int irq, int priority)
*
****************************************************************************/
#warning "Is this safe to call from assembly?"
-unsigned int avr32_int0irqno(unsigned int level)
+unsigned int avr32_intirqno(unsigned int level)
{
/* Get the group that caused the interrupt: "ICRn identifies the group with
* the highest priority that has a pending interrupt of level n. This value
diff --git a/nuttx/arch/avr/src/avr32/up_exceptions.S b/nuttx/arch/avr/src/avr32/up_exceptions.S
index 5e5afd60d..3dbb7d68c 100755
--- a/nuttx/arch/avr/src/avr32/up_exceptions.S
+++ b/nuttx/arch/avr/src/avr32/up_exceptions.S
@@ -44,11 +44,12 @@
* External Symbols
****************************************************************************/
- .global avr32_int0irqno /* Returns the IRQ number of an INT0 interrupt */
- .global avr32_int1irqno /* Returns the IRQ number of an INT1 interrupt */
- .global avr32_int2irqno /* Returns the IRQ number of an INT2 interrupt */
- .global avr32_int3irqno /* Returns the IRQ number of an INT3 interrupt */
- .global up_doirq /* Dispatch an IRQ */
+ .global avr32_int0irqno /* Returns the IRQ number of an INT0 interrupt */
+ .global avr32_int1irqno /* Returns the IRQ number of an INT1 interrupt */
+ .global avr32_int2irqno /* Returns the IRQ number of an INT2 interrupt */
+ .global avr32_int3irqno /* Returns the IRQ number of an INT3 interrupt */
+ .global up_doirq /* Dispatch an IRQ */
+ .global up_fullcontextrestore /* Restore new task contex */
/****************************************************************************
* Macros
@@ -219,6 +220,16 @@ avr32_excptcommon:
/* and call the IRQ dispatching logic. */
avr32_common:
+ /* Disable interrupts in the current SR. This is necessary because the */
+ /* AVR32 permits nested interrupts (if they are of higher priority). */
+ /* We can support nested interrupts without some effort because: */
+ /* - The global variable current_regs permits only one interrupt, */
+ /* - If CONFIG_ARCH_INTERRUPTSTACK is defined, then there is a single */
+ /* interrupt stack, and */
+ /* - Probably other things. */
+
+ ssrf AVR32_SR_GM_SHIFT
+
/* Save the SP (as it was before the interrupt) in the conext save */
/* structure. */
/* xx xx xx xx xx xx xx xx SP SR PC LR 12 11 10 09 08 */
@@ -245,8 +256,7 @@ avr32_common:
#if CONFIG_ARCH_INTERRUPTSTACK > 3
mov r7, sp
- mov sp, up_intstackbase
- movh sp, (up_intstackbase >> 0)
+ lddpc sp, .Lup_instackbase
#endif
/* Call up_doirq with r12=IRQ number and r11=register save area */
@@ -282,12 +292,16 @@ avr32_common:
sub sp, -4
rete
- /* Context switch... we need to do a little more work. */
+ /* Context switch... jump to up_fullcontestrestor with r12=address of */
+ /* the task context to restore. */
+
1:
-#warning "Missing Logic"
+ lddpc pc, .Lup_fullcontextrestore
.Lup_doirq:
.word up_doirq
+.Lup_fullcontextrestore:
+ .word up_fullcontextrestore
/************************************************************************************
* Name: up_interruptstack
@@ -302,6 +316,9 @@ up_interruptstack:
.skip (CONFIG_ARCH_INTERRUPTSTACK & ~3)
up_intstackbase:
.size up_interruptstack, .-up_interruptstack
+.Lup_instackbase
+ .word up_intstackbase
+ .size .Lup_instackbase, .-.Lup_instackbase
#endif
.end
diff --git a/nuttx/arch/avr/src/avr32/up_fullcontextrestore.S b/nuttx/arch/avr/src/avr32/up_fullcontextrestore.S
index 6969b0bed..02c33adfd 100755
--- a/nuttx/arch/avr/src/avr32/up_fullcontextrestore.S
+++ b/nuttx/arch/avr/src/avr32/up_fullcontextrestore.S
@@ -44,6 +44,8 @@
* External Symbols
****************************************************************************/
+ .file "up_fullcontextrestore.S"
+
/****************************************************************************
* Macros
****************************************************************************/
@@ -54,6 +56,9 @@
* C Prototype:
* void up_fullcontextrestore(uint32_t *regs);
*
+ * Assumptions:
+ * Interrupts are disabled.
+ *
****************************************************************************/
.text
@@ -96,7 +101,7 @@ up_fullcontextrestore:
ldm r12++, r8-r11
/* r12 now points +4 beyond the end of the register save area. Restore */
- /* SR. */
+ /* SR. NOTE: This may enable interrupts! */
/* 07 06 05 04 03 02 01 00 SP SR PC LR 12 11 10 09 08 */
/* ^r12-4*8 ^r12 */
diff --git a/nuttx/arch/avr/src/avr32/up_nommuhead.S b/nuttx/arch/avr/src/avr32/up_nommuhead.S
index c80c98c29..7a4f2ae49 100644
--- a/nuttx/arch/avr/src/avr32/up_nommuhead.S
+++ b/nuttx/arch/avr/src/avr32/up_nommuhead.S
@@ -47,6 +47,7 @@
* External Symbols
****************************************************************************/
+ .file "up_nommuhead.S"
.global _sbss /* Start of .bss. Defined by ld.script */
.global _ebss /* End of .bss. Defined by ld.script */
#ifdef CONFIG_BOOT_RUNFROMFLASH