mirror of
https://github.com/kelvinlawson/atomthreads.git
synced 2026-09-17 19:07:07 +02:00
Merge https://github.com/navaro/atomthreads into navaro branch. Remove tests/ folder changes as they were based on an old Atomthreads API. Remove some binaries and other unnecessary files.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
ATOMTHREADS_PORT = $(ATOMTHREADS)/ports/cortex_m
|
||||
ATOMTHREADS_KERNEL = $(ATOMTHREADS)/kernel
|
||||
|
||||
INCLUDES := $(INCLUDES) \
|
||||
-I$(ATOMTHREADS_KERNEL) \
|
||||
-I$(ATOMTHREADS_PORT)
|
||||
|
||||
SRCS := $(SRCS) \
|
||||
$(ATOMTHREADS_KERNEL)/atomkernel.c \
|
||||
$(ATOMTHREADS_KERNEL)/atommutex.c \
|
||||
$(ATOMTHREADS_KERNEL)/atomqueue.c \
|
||||
$(ATOMTHREADS_KERNEL)/atomsem.c \
|
||||
$(ATOMTHREADS_KERNEL)/atomtimer.c \
|
||||
$(ATOMTHREADS_PORT)/atomport.c
|
||||
|
||||
ASMS := $(ASMS) \
|
||||
$(ATOMTHREADS_PORT)/atomport_s.S
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Library: Atomthreads CortexM3 Port
|
||||
Author: Natie van Rooyen <natie@navaro.nl>
|
||||
License: BSD Revised
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
ARM CortexM3 PORT
|
||||
|
||||
This folder contains a port of the Atomthreads real time kernel for the
|
||||
ARM CortexM3 processor architecture.
|
||||
|
||||
To Use:
|
||||
|
||||
1. Install the "pendSV_Handler" and "tick_Handler" implemented in the file
|
||||
"atomport_arm.asm" in your platforms interrupt vectors.
|
||||
|
||||
2. Complete the function "archTickInit()" implemented in "atomport.c" to
|
||||
initialize your platforms timer tick interrupt. If you use the build in
|
||||
SysTick of the CortexM3 you also have to add code here to start it.
|
||||
|
||||
3. If required, add code to acknowledge your timer hardware's interrupt in
|
||||
the function "archTickHandler()" also implemented in "atomport.c".
|
||||
|
||||
4. During your platform initialization call the function "archTickInit()"
|
||||
exported from "atomport_private.h" to initialize the CortexM3
|
||||
"PendSV_Handler".
|
||||
|
||||
5. After your platforms c-runtime initialization has completed, start
|
||||
Atomthreads from your runtime's "main()" function.
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2012, Natie van Rooyen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. No personal names or organizations' names associated with the
|
||||
* Atomthreads project may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __ATOMPORT_TEST_H__
|
||||
#define __ATOMPORT_TEST_H__
|
||||
|
||||
/* Include Atomthreads kernel API */
|
||||
#include "atom.h"
|
||||
|
||||
extern void dbg_format_msg (char *format, ...) ;
|
||||
|
||||
|
||||
#define TEST_THREAD_STACK_SIZE 1024
|
||||
#define ATOMLOG dbg_format_msg
|
||||
#define _STR(x) x
|
||||
|
||||
|
||||
|
||||
|
||||
/* API for starting each test */
|
||||
extern uint32_t test_start (void);
|
||||
|
||||
|
||||
#endif /* __ATOMPORT_TEST_H__ */
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2012, Natie van Rooyen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. No personal names or organizations' names associated with the
|
||||
* Atomthreads project may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "atom.h"
|
||||
#include "atomport.h"
|
||||
#include "types.h"
|
||||
|
||||
|
||||
/* *
|
||||
*
|
||||
* Functions defined in atomport_s.S
|
||||
*
|
||||
*/
|
||||
typedef void * SYSCONTEXT ;
|
||||
|
||||
extern void contextInit (void) ;
|
||||
extern void contextSwitch (SYSCONTEXT* save_context, SYSCONTEXT* new_context) ;
|
||||
extern void contextStart (SYSCONTEXT* context) ;
|
||||
extern void contextEnableInterrupts (void) ;
|
||||
|
||||
/**
|
||||
* \b thread_shell
|
||||
*
|
||||
* Documented in atomThreads.
|
||||
*
|
||||
*/
|
||||
void
|
||||
thread_shell (void)
|
||||
{
|
||||
ATOM_TCB *curr_tcb;
|
||||
|
||||
/* Get the TCB of the thread being started */
|
||||
curr_tcb = atomCurrentContext();
|
||||
|
||||
/**
|
||||
* Enable interrupts - these will not be enabled when a thread
|
||||
* is first restored.
|
||||
*/
|
||||
// sei();
|
||||
contextEnableInterrupts () ;
|
||||
|
||||
/* Call the thread entry point */
|
||||
if (curr_tcb && curr_tcb->entry_point)
|
||||
{
|
||||
curr_tcb->entry_point(curr_tcb->entry_param);
|
||||
}
|
||||
|
||||
/* Not reached - threads should never return from the entry point */
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \b archThreadContextInit
|
||||
*
|
||||
* Documented in atomThreads.
|
||||
*
|
||||
*/
|
||||
void
|
||||
archThreadContextInit (ATOM_TCB *tcb_ptr, void *stack_top, void (*entry_point)(uint32_t), uint32_t entry_param)
|
||||
{
|
||||
uint32_t * stack_ptr ;
|
||||
|
||||
tcb_ptr->sp_save_ptr = stack_top;
|
||||
tcb_ptr->entry_param = entry_param ;
|
||||
tcb_ptr->entry_point = entry_point ;
|
||||
|
||||
stack_ptr = (uint32_t *)stack_top; //-- Load stack pointer
|
||||
|
||||
*stack_ptr = 0x01000000L; //-- xPSR
|
||||
stack_ptr--;
|
||||
*stack_ptr = ((uint32_t)thread_shell) | 1; //-- Entry Point (1 for THUMB mode)
|
||||
stack_ptr--;
|
||||
*stack_ptr = ((uint32_t)/*exit*/0) | 1; //-- R14 (LR) (1 for THUMB mode)
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00121212L; //-- R12
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00030303L; //-- R3
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00020202L; //-- R2
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00010101L; //-- R1
|
||||
stack_ptr--;
|
||||
*stack_ptr = entry_param ; //-- R0 - task's function argument
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00111111L; //-- R11
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00101010L; //-- R10
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00090909L; //-- R9
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00080808L; //-- R8
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00070707L; //-- R7
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00060606L; //-- R6
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00050505L; //-- R5
|
||||
stack_ptr--;
|
||||
*stack_ptr = 0x00040404L; //-- R4
|
||||
|
||||
tcb_ptr->sp_save_ptr = stack_ptr ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \b archFirstThreadRestore
|
||||
*
|
||||
* Documented in atomThreads.
|
||||
*
|
||||
*/
|
||||
void
|
||||
archFirstThreadRestore(ATOM_TCB * p_sp_new)
|
||||
{
|
||||
contextStart (&p_sp_new->sp_save_ptr) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \b archContextSwitch
|
||||
*
|
||||
* Documented in atomThreads.
|
||||
*
|
||||
*/
|
||||
void
|
||||
archContextSwitch (ATOM_TCB * p_sp_old, ATOM_TCB * p_sp_new)
|
||||
{
|
||||
contextSwitch (&p_sp_old->sp_save_ptr, &p_sp_new->sp_save_ptr) ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \b archTimerTickIrqHandler
|
||||
*
|
||||
* System timer tick interrupt handler.
|
||||
*
|
||||
*/
|
||||
void
|
||||
archTickHandler (void)
|
||||
{
|
||||
atomIntEnter();
|
||||
|
||||
/* Call the OS system tick handler */
|
||||
atomTimerTick();
|
||||
|
||||
/* ack the interrupt if needed */
|
||||
/* ... */
|
||||
|
||||
/* Call the interrupt exit routine */
|
||||
atomIntExit(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* \b archTickInit
|
||||
*
|
||||
* System timer initialization.
|
||||
*
|
||||
*/
|
||||
void
|
||||
archTickInit (void)
|
||||
{
|
||||
/* Initialize NVIC PendSV */
|
||||
contextInit () ;
|
||||
|
||||
/* Initializa Timer Hardware */
|
||||
/* ... */
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2012, Natie van Rooyen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. No personal names or organizations' names associated with the
|
||||
* Atomthreads project may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __ATOM_PORT_H__
|
||||
#define __ATOM_PORT_H__
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define SYSTEM_TICKS_PER_SEC 100
|
||||
|
||||
|
||||
/**
|
||||
* Architecture-specific types.
|
||||
* Most of these are available from types.h on this platform, which is
|
||||
* included above.
|
||||
*/
|
||||
#define POINTER void *
|
||||
|
||||
/* *
|
||||
*
|
||||
* Functions defined in atomport_arm.asm
|
||||
*
|
||||
*/
|
||||
extern uint32_t contextEnterCritical (void) ;
|
||||
extern void contextExitCritical (uint32_t posture) ;
|
||||
|
||||
|
||||
/* Critical region protection */
|
||||
#define CRITICAL_STORE uint32_t __atom_critical
|
||||
#define CRITICAL_START() __atom_critical = contextEnterCritical()
|
||||
#define CRITICAL_END() contextExitCritical(__atom_critical)
|
||||
|
||||
#endif /* __ATOM_PORT_H__ */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2012, Natie van Rooyen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. No personal names or organizations' names associated with the
|
||||
* Atomthreads project may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __ATOM_PORT_PRIVATE_H__
|
||||
#define __ATOM_PORT_PRIVATE_H__
|
||||
|
||||
|
||||
/* Function prototypes */
|
||||
extern void archTickHandler (void) ;
|
||||
extern void archTickInit (void) ;
|
||||
|
||||
#endif /* __ATOM_PORT_PRIVATE_H__ */
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
Copyright (c) 2012, Natie van Rooyen. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. No personal names or organizations' names associated with the
|
||||
Atomthreads project may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
.global contextInit
|
||||
.global contextSwitch
|
||||
.global contextStart
|
||||
.global contextEnableInterrupts
|
||||
.global contextEnterCritical
|
||||
.global contextExitCritical
|
||||
.global pendSV_Handler
|
||||
.global tick_Handler
|
||||
|
||||
.global archTickHandler
|
||||
|
||||
|
||||
|
||||
/**/
|
||||
.equ NVIC_INT_CTRL, 0xE000ED04 // Interrupt control state register
|
||||
.equ NVIC_PENDSVSET, 0x10000000 // Value to trigger PendSV exception
|
||||
.equ NVIC_PR_12_15_ADDR, 0xE000ED20 // System Handlers 12-15 Priority Register Address
|
||||
.equ NVIC_PENDS_VPRIORITY, 0x00FF0000 // PendSV priority is minimal (0xFF)
|
||||
|
||||
.syntax unified
|
||||
.text
|
||||
.thumb
|
||||
|
||||
/**
|
||||
* \b contextInit
|
||||
*
|
||||
* Architecture-specific one time initialization.
|
||||
*
|
||||
* Configures PendSV priority to lowest.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
contextInit:
|
||||
LDR r1, =NVIC_PR_12_15_ADDR // Load the System 12-15 Priority Register
|
||||
LDR r0, [r1]
|
||||
ORR r0, r0, #NVIC_PENDS_VPRIORITY // set PRI_14 (PendSV) to 0xFF - minimal
|
||||
STR r0, [r1]
|
||||
|
||||
BX lr
|
||||
|
||||
/**
|
||||
* \b contextSwitch
|
||||
*
|
||||
* Architecture-specific context switch routine.
|
||||
*
|
||||
* Note that interrupts are always locked out when this routine is
|
||||
* called. For cooperative switches, the scheduler will have entered
|
||||
* a critical region. For preemptions (called from an ISR), the
|
||||
* interrupts will have disabled in the tick_Handler.
|
||||
*
|
||||
* @param[in] [r0] -> Address to save old stack pointer
|
||||
* @param[in] [r1] -> Address where new stack pointer is stored
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
contextSwitch:
|
||||
LDR r2, =context_new_stack_ptr
|
||||
STR r1, [r2]
|
||||
|
||||
LDR r2, =context_save_stack_ptr
|
||||
LDR r1, [r2]
|
||||
CMP r1, #0 // if contextSwitch is going to be called again before pend_sv
|
||||
IT EQ
|
||||
STREQ r0, [r2]
|
||||
|
||||
LDR R0, =NVIC_INT_CTRL // Trigger the PendSV exception (causes context switch)
|
||||
LDR R1, =NVIC_PENDSVSET
|
||||
STR R1, [R0]
|
||||
|
||||
BX lr
|
||||
|
||||
/**
|
||||
* \b contextStart
|
||||
*
|
||||
* Architecture-specific context start routine.
|
||||
*
|
||||
* @param[in] [r0] -> Address where stack pointer is stored
|
||||
*
|
||||
* @return Does not return
|
||||
*/
|
||||
contextStart:
|
||||
LDR r1, =context_new_stack_ptr
|
||||
STR r0, [r1]
|
||||
LDR r1, =context_save_stack_ptr
|
||||
MOV r0, #0
|
||||
STR r0, [r1]
|
||||
LDR r0, =NVIC_INT_CTRL // Trigger the PendSV exception (causes context switch)
|
||||
LDR r1, =NVIC_PENDSVSET
|
||||
STR r1, [r0]
|
||||
|
||||
BX lr
|
||||
|
||||
/**
|
||||
* \b contextEnableInterrupts
|
||||
*
|
||||
* Enables interrupts on the processor
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
contextEnableInterrupts:
|
||||
CPSIE i
|
||||
BX lr
|
||||
|
||||
|
||||
/**
|
||||
* \b contextExitCritical
|
||||
*
|
||||
* Exit critical section (restores interrupt posture)
|
||||
*
|
||||
* @param[in] r0 Interrupt Posture
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
contextExitCritical:
|
||||
MSR PRIMASK, r0
|
||||
BX lr
|
||||
|
||||
|
||||
/**
|
||||
* \b contextEnterCritical
|
||||
*
|
||||
* Enter critical section (disables interrupts)
|
||||
*
|
||||
* @return Current interrupt posture
|
||||
*/
|
||||
contextEnterCritical:
|
||||
MRS r0, PRIMASK
|
||||
CPSID i
|
||||
BX lr
|
||||
|
||||
/**
|
||||
* \b PendSV_Handler
|
||||
*
|
||||
* CortexM3 PendSV_Handler. Switch context to a new stack.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
pendSV_Handler:
|
||||
CPSID i // Disable core int
|
||||
|
||||
LDR r1, =context_save_stack_ptr
|
||||
LDR r0, [r1] // Load old (current) stack pointer address
|
||||
|
||||
LDR r2, =context_new_stack_ptr
|
||||
LDR r2, [r2] // Load new stack pointer address
|
||||
CMP r0, r2
|
||||
BEQ pendsv_handler_exit
|
||||
|
||||
CMP r0, #0
|
||||
BEQ pendsv_handler_new_stack
|
||||
// Save context
|
||||
MRS r3, PSP // Get PSP point
|
||||
STMDB r3!, {R4-R11} // Store r4-r11
|
||||
STR r3, [r0] // Save old stack pointer
|
||||
MOV r3, #0
|
||||
STR r3, [r1]
|
||||
|
||||
pendsv_handler_new_stack:
|
||||
// Restore context
|
||||
LDR r2, [r2] // Load new stack pointer
|
||||
LDMIA r2!, {r4-r11} // Restore context
|
||||
MSR PSP, r2 // Mov new stack point to PSP
|
||||
|
||||
pendsv_handler_exit:
|
||||
CPSIE i // Enable core int
|
||||
|
||||
ORR lr, lr, #0x04 // Ensure exception return uses process stack
|
||||
BX lr // Exit interrupt
|
||||
|
||||
|
||||
/**
|
||||
* \b Tick_Handler
|
||||
*
|
||||
* System timer tick interrupt handler.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
tick_Handler:
|
||||
PUSH {r4-r11, lr}
|
||||
cpsid I // Disable core int
|
||||
BL archTickHandler
|
||||
cpsie I // Enable core int
|
||||
POP {r4-r11, pc}
|
||||
|
||||
|
||||
/**/
|
||||
context_new_stack_ptr: .long 0x00000000
|
||||
context_save_stack_ptr: .long 0x00000000
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2012, Natie van Rooyen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. No personal names or organizations' names associated with the
|
||||
* Atomthreads project may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __TYPES_H__
|
||||
#define __TYPES_H__
|
||||
|
||||
typedef unsigned int uintptr_t ;
|
||||
typedef int intptr_t ;
|
||||
typedef unsigned long long uint64_t ;
|
||||
typedef unsigned int uint32_t ;
|
||||
typedef unsigned short uint16_t ;
|
||||
typedef unsigned char uint8_t ;
|
||||
typedef int int32_t ;
|
||||
typedef short int16_t ;
|
||||
typedef char int8_t ;
|
||||
|
||||
#endif /* __TYPES_H__ */
|
||||
|
||||
Reference in New Issue
Block a user