diff --git a/platforms/qemu_integratorcp/Makefile b/platforms/qemu_integratorcp/Makefile new file mode 100644 index 0000000..551529f --- /dev/null +++ b/platforms/qemu_integratorcp/Makefile @@ -0,0 +1,91 @@ +ifeq ($(TARGET_NAME),) +TARGET_NAME=boot +endif +ifeq ($(ATOMTHREADS),) +ATOMTHREADS = $(shell pwd)/../../ +endif +ifeq ($(TEST_NAME),) +TEST_NAME = kern1 +endif + + + +CC = arm-none-eabi-gcc +LN = arm-none-eabi-gcc +AS = arm-none-eabi-gcc + +CFLAGS := $(CFLAGS) -Wall -g -c -mcpu=arm926ej-s -ffreestanding +AFLAGS := $(CFLAGS) -Wall -g -c -mcpu=arm926ej-s -ffreestanding +LFLAGS := $(LFLAGS) -Wall -mcpu=arm926ej-s -Wl,-Map=system.map,--verbose -Tsystem.ld + +CDEFS := $(CDEFS) -DATOMTHREADS_TEST='"$(TEST_NAME)"' +ADEFS := $(ADEFS) + +LLIBS := $(LLIBS) + + +SRCS := $(SRCS) \ + modules.c \ + main.c \ + $(ATOMTHREADS)/tests/$(TEST_NAME).c + +ASMS := $(ASMS) \ + startup.S \ + +INCLUDES := $(INCLUDES) \ + -I$(ATOMTHREADS) + +include $(ATOMTHREADS)/ports/arm/Makefile + +OBJS = $(SRCS:.c=.o) $(ASMS:.S=.o) + +include ../rules.mk + + +run_test: clean all + echo "START TEST $(TEST_NAME)" + qemu-system-arm -M integratorcp -kernel boot.elf -semihosting | tee atomthreads_test.out + +all_tests: + echo "Starting atomthreads test suite" > atomthreads_test.out + make run_test "TEST_NAME=mutex1" + make run_test "TEST_NAME=mutex2" + make run_test "TEST_NAME=mutex3" + make run_test "TEST_NAME=mutex4" + make run_test "TEST_NAME=mutex5" + make run_test "TEST_NAME=mutex6" + make run_test "TEST_NAME=mutex7" + make run_test "TEST_NAME=mutex8" + make run_test "TEST_NAME=mutex9" + make run_test "TEST_NAME=kern1" + make run_test "TEST_NAME=kern2" + make run_test "TEST_NAME=kern3" + make run_test "TEST_NAME=kern4" + make run_test "TEST_NAME=timer1" + make run_test "TEST_NAME=timer2" + make run_test "TEST_NAME=timer3" + make run_test "TEST_NAME=timer5" + make run_test "TEST_NAME=timer6" + make run_test "TEST_NAME=timer7" + make run_test "TEST_NAME=queue1" + make run_test "TEST_NAME=queue2" + make run_test "TEST_NAME=queue3" + make run_test "TEST_NAME=queue4" + make run_test "TEST_NAME=queue5" + make run_test "TEST_NAME=queue6" + make run_test "TEST_NAME=queue7" + make run_test "TEST_NAME=queue8" + make run_test "TEST_NAME=queue9" + make run_test "TEST_NAME=sem1" + make run_test "TEST_NAME=sem2" + make run_test "TEST_NAME=sem3" + make run_test "TEST_NAME=sem4" + make run_test "TEST_NAME=sem5" + make run_test "TEST_NAME=sem6" + make run_test "TEST_NAME=sem7" + make run_test "TEST_NAME=sem8" + make run_test "TEST_NAME=sem9" + +run_last: + qemu-system-arm -M integratorcp -kernel boot.elf -monitor stdio -semihosting + diff --git a/platforms/qemu_integratorcp/atomthreads_test.out b/platforms/qemu_integratorcp/atomthreads_test.out new file mode 100644 index 0000000..1c4897d --- /dev/null +++ b/platforms/qemu_integratorcp/atomthreads_test.out @@ -0,0 +1,75 @@ +Starting atomthreads test suite +VNC server running on `127.0.0.1:5900' +atomthreads starting mutex1... mutex1 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting mutex2... mutex2 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting mutex3... mutex3 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting mutex4... mutex4 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting mutex5... mutex5 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting mutex6... mutex6 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting mutex7... mutex7 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting mutex8... mutex8 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting mutex9... mutex9 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting kern1... kern1 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting kern2... kern2 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting kern3... kern3 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting kern4... kern4 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting timer1... timer1 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting timer2... timer2 FAIL +VNC server running on `127.0.0.1:5900' +atomthreads starting timer3... timer3 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting timer5... timer5 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting timer6... timer6 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting timer7... timer7 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting queue1... queue1 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting queue2... queue2 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting queue3... queue3 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting queue4... queue4 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting queue5... queue5 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting queue6... queue6 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting queue7... queue7 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting queue8... queue8 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting queue9... queue9 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting sem1... sem1 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting sem2... sem2 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting sem3... sem3 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting sem4... sem4 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting sem5... sem5 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting sem6... sem6 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting sem7... sem7 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting sem8... sem8 PASS +VNC server running on `127.0.0.1:5900' +atomthreads starting sem9... sem9 PASS diff --git a/platforms/qemu_integratorcp/boot.elf b/platforms/qemu_integratorcp/boot.elf new file mode 100644 index 0000000..c0f6468 Binary files /dev/null and b/platforms/qemu_integratorcp/boot.elf differ diff --git a/platforms/qemu_integratorcp/main.c b/platforms/qemu_integratorcp/main.c new file mode 100644 index 0000000..3222170 --- /dev/null +++ b/platforms/qemu_integratorcp/main.c @@ -0,0 +1,85 @@ +/* + * 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 +#include "modules.h" +#include "atom.h" +#include "tests/atomtests.h" + +#ifndef ATOMTHREADS_TEST +#define ATOMTHREADS_TEST "kern1" +#endif + +#define TEST_STACK_BYTE_SIZE 1024 +#define IDLE_STACK_BYTE_SIZE 512 + +static unsigned char test_stack[TEST_STACK_BYTE_SIZE] ; +static unsigned char idle_stack[IDLE_STACK_BYTE_SIZE] ; +ATOM_TCB test_tcb ; + + +/** + * \b test_thread + * + * Function calling the test function of the Atomthreads test suite. + * + */ +void +test_thread (uint32_t param) +{ + uint32_t failures ; + CRITICAL_STORE ; + + failures = test_start () ; + + atomTimerDelay (10) ; + CRITICAL_START() ; + printf ("%s %s\r\n", ATOMTHREADS_TEST, failures ? "FAIL" : "PASS") ; + exit (failures) ; + CRITICAL_END() ; +} + +/** + * \b main + * + * Initialize atomthreads and start a test_thread to run the Atomthreads test suite. + * + */ +int +main (void) +{ + uint32_t failures ; + + printf ("atomthreads starting %s... ", ATOMTHREADS_TEST) ; + + atomOSInit(&idle_stack[IDLE_STACK_BYTE_SIZE - sizeof(unsigned int)], IDLE_STACK_BYTE_SIZE - sizeof(unsigned int)) ; + atomThreadCreate ((ATOM_TCB *)&test_tcb, TEST_THREAD_PRIO, test_thread, 0, &test_stack[(TEST_STACK_BYTE_SIZE) - sizeof(unsigned int)], TEST_STACK_BYTE_SIZE - sizeof(unsigned int)); + atomOSStart() ; + + return 0 ; +} diff --git a/platforms/qemu_integratorcp/modules.c b/platforms/qemu_integratorcp/modules.c new file mode 100644 index 0000000..c611d68 --- /dev/null +++ b/platforms/qemu_integratorcp/modules.c @@ -0,0 +1,115 @@ +/* + * 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 "modules.h" +#include +#include +#include "atomport_private.h" +#include "atom.h" +#include "atomport.h" +#include "types.h" + +ICP_TIMER_T* const board_timer_0 = (ICP_TIMER_T*) BOARD_BASE_ADDRESS_TIMER_0 ; +ICP_PIC_T * const board_pic = (ICP_PIC_T*) BOARD_BASE_ADDRESS_PIC ; + +/** + * \b dbg_format_msg + * + * Same as printf. + * + */ +void +dbg_format_msg (char *format, ...) +{ + va_list args; + static char msg[256] ; + CRITICAL_STORE ; + + va_start (args, format) ; + CRITICAL_START() ; + vsnprintf ((char*)msg, 256, (char*)format, args) ; + CRITICAL_END() ; + + printf (msg) ; +} + +/** + * \b low_level_init + * + * Initializes the PIC and start the system timer tick intrerupt. + * + */ +int +low_level_init (void) +{ + + board_pic->IRQ_ENABLECLR = ICP_PIC_IRQ_TIMERINT0 ; + board_timer_0->INTCLR = 1 ; + board_pic->IRQ_ENABLESET |= ICP_PIC_IRQ_TIMERINT0 ; + + board_timer_0->LOAD = 0x2000 ; + board_timer_0->BGLOAD = 0x2000 ; + board_timer_0->CONTROL = ICP_TIMER_CONTROL_ENABLE | + ICP_TIMER_CONTROL_MODE | + ICP_TIMER_CONTROL_IE | + /*ICP_TIMER_CONTROL_PRESCALE_256 |*/ + ICP_TIMER_CONTROL_TIMER_SIZE ; + + return 0 ; +} + + +/** + * \b __context_preempt_handler + * + * System timer tic interupt handler. + * + */ +void +__context_preempt_handler (void) +{ + unsigned int status = board_pic->IRQ_STATUS ; + + if (status | ICP_PIC_IRQ_TIMERINT0) { + + atomIntEnter(); + + /* Call the OS system tick handler */ + atomTimerTick(); + + /* ack the interrupt */ + board_timer_0->INTCLR = 0x1 ; + + /* Call the interrupt exit routine */ + atomIntExit(TRUE); + + } + + +} + diff --git a/platforms/qemu_integratorcp/modules.h b/platforms/qemu_integratorcp/modules.h new file mode 100644 index 0000000..38aa37f --- /dev/null +++ b/platforms/qemu_integratorcp/modules.h @@ -0,0 +1,124 @@ +/* + * 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 __MODULES_H__ +#define __MODULES_H__ + +#include "atomport.h" + +extern void dbg_format_msg (char *format, ...) ; + +#define DBG_MESSAGE(fmt_str) { dbg_format_msg fmt_str ; } + + +typedef volatile unsigned int REG_DWORD ;// Hardware register definition +typedef volatile unsigned short REG_WORD ; +typedef volatile unsigned char REG_BYTE ; + + +// ***************************************************************************** +// INTEGRATORCP TIMER +// ***************************************************************************** +typedef struct ICP_TIMER_S { + // offset read/write word size reset Description + REG_DWORD LOAD ; // 0x0000 Read/write 32 0x00000000 Load value for Timer + REG_DWORD VALUE ; // 0x0004 Read 32 0xFFFFFFFF The current value for Timer + REG_BYTE CONTROL ; // 0x0008 Read/write 8 0x20 Timer control register + REG_DWORD INTCLR ; // 0x000C Write - - Timer interrupt clear + REG_DWORD RIS ; // 0x0010 Read 1 0x0 Timer raw interrupt status + REG_DWORD MIS ; // 0x0014 Read 1 0x0 Timer masked interrupt status + REG_DWORD BGLOAD ; // 0x0018 Read/write 32 0x00000000 Background load value for Timer + +} ICP_TIMER_T, *PICP_TIMER_T ; + +// -------- ICP_TIMER_LOAD : (LOAD Offset: 0x00) Load value for Timer -------- +// -------- ICP_TIMER_VALUE : (LOAD Offset: 0x04) The current value for Timer -------- +// -------- ICP_TIMER_CONTROL : (CONTROL Offset: 0x04) Timer control register -------- +#define ICP_TIMER_CONTROL_MASK ((unsigned int)0x0F << 0) // Timer control mask + #define ICP_TIMER_CONTROL_ENABLE ((unsigned int)0x01 << 7) // Timer enable: 0 = disabled 1 = enabled. + #define ICP_TIMER_CONTROL_MODE ((unsigned int)0x01 << 6) // Timer mode: 0 = free running, counts once and then wraps to 0xFFFF 1 = periodic, reloads from load register at the end of each count.. + #define ICP_TIMER_CONTROL_IE ((unsigned int)0x01 << 5) // Interrupt enable. + #define ICP_TIMER_CONTROL_R ((unsigned int)0x01 << 4) // Unused, always write as 0s. + #define ICP_TIMER_CONTROL_PRESCALE_MASK ((unsigned int)0x03 << 2) // Prescale divisor + #define ICP_TIMER_CONTROL_PRESCALE_NONE ((unsigned int)0x00 << 2) // + #define ICP_TIMER_CONTROL_PRESCALE_16 ((unsigned int)0x01 << 2) // + #define ICP_TIMER_CONTROL_PRESCALE_256 ((unsigned int)0x02 << 2) // +#define ICP_TIMER_CONTROL_TIMER_SIZE ((unsigned int)0x01 << 1) // Selects 16/32 bit counter operation: 0 = 16-bit counter (default) 1 = 32-bit counter For 16-bit mode, write the high 16 bits of the 32-bit value as 0. +#define ICP_TIMER_CONTROL_ONE_SHOT ((unsigned int)0x01 << 0) // Selects one-shot or wrapping counter mode: 0 = wrapping mode (default) 1 = one-shot mode +// -------- ICP_TIMER_INTCLR : (INTCLR Offset: 0x0C) Timer interrupt clear -------- +// -------- ICP_TIMER_RIS : (RIS Offset: 0x10) Timer raw interrupt status -------- +// -------- ICP_TIMER_MIS : (MIS Offset: 0x14) Timer masked interrupt status -------- +#define ICP_TIMER_INT ((unsigned int)0x01 << 0) // Interrupt +// -------- ICP_TIMER_BGLOAD : (BGLOAD Offset: 0x18) Timer masked interrupt status -------- + + +// ***************************************************************************** +// INTEGRATORCP PIC +// ***************************************************************************** +typedef struct ICP_PIC_S { + // offset read/write word size reset Description + REG_DWORD IRQ_STATUS ; // 0x0000 Read 22 IRQ gated interrupt status + REG_DWORD IRQ_RAWSTAT ; // 0x0004 Read 22 IRQ raw interrupt status + REG_DWORD IRQ_ENABLESET ; // 0x0008 Read/write 22 IRQ enable set + REG_DWORD IRQ_ENABLECLR ; // 0x000C Write 22 IRQ enable clear + REG_DWORD INT_SOFTSET ; // 0x0010 Read/write 16 Software interrupt set + REG_DWORD INT_SOFTCLR ; // 0x0014 Write 16 Software interrupt clear + REG_DWORD RESERVED[2] ; // 0x0018 + REG_DWORD FIQ_STATUS ; // 0x0020 Read 22 FIQ gated interrupt status + REG_DWORD FIQ_RAWSTAT ; // 0x0024 Read 22 FIQ raw interrupt status + REG_DWORD FIQ_ENABLESET ; // 0x0028 Read/write 22 FIQ enable set + REG_DWORD FIQ_ENABLECLR ; // 0x002C Write-only 22 FIQ enable clear + +} ICP_PIC_T, *PICP_PIC_T ; + +// -------- ICP_PIC_IRQ_STATUS : (IRQ_STATUS Offset: 0x00) IRQ gated interrupt status -------- +// -------- ICP_PIC_IRQ_RAWSTAT : (IRQ_RAWSTAT Offset: 0x04) IRQ raw interrupt status -------- +// -------- ICP_PIC_IRQ_ENABLESET : (IRQ_ENABLESET Offset: 0x08) IRQ enable set -------- +// -------- ICP_PIC_IRQ_ENABLECLR : (IRQ_ENABLECLR Offset: 0x0C) IRQ enable clear -------- +#define ICP_PIC_IRQ_MASK ((unsigned int)0x3FFFFF << 0) // IRQ mask + #define ICP_PIC_IRQ_TIMERINT2 ((unsigned int)0x01 << 7) // TIMERINT2 Counter-timer 2 interrupt + #define ICP_PIC_IRQ_TIMERINT1 ((unsigned int)0x01 << 6) // TIMERINT1 Counter-timer 1 interrupt + #define ICP_PIC_IRQ_TIMERINT0 ((unsigned int)0x01 << 5) // TIMERINT0 Counter-timer 0 interrupt + #define ICP_PIC_IRQ_SOFTINT ((unsigned int)0x01 << 0) // OFTINT Software interrupt +// -------- ICP_PIC_INT_SOFTSET : (INT_SOFTSET Offset: 0x10) Software interrupt set -------- +// -------- ICP_PIC_INT_SOFTCLR : (INT_SOFTCLR Offset: 0x14) Software interrupt clear -------- + + + + +#define BOARD_BASE_ADDRESS_TIMER_0 0x13000000 +#define BOARD_BASE_ADDRESS_PIC 0x14000000 + +extern ICP_TIMER_T* const board_timer_0 ; +extern ICP_PIC_T* const board_pic ; + + + +extern int low_level_init (void) ; + +#endif /* __MODULES_H__ */ diff --git a/platforms/qemu_integratorcp/startup.s b/platforms/qemu_integratorcp/startup.s new file mode 100644 index 0000000..dc4a167 --- /dev/null +++ b/platforms/qemu_integratorcp/startup.s @@ -0,0 +1,55 @@ +.section .vectors, "x" + +.global __interrupt_vector_table +.global __irq_stack_top__ +.global __fiq_stack_top__ +.global __svc_stack_top__ + +.global bsp_ints_enable +.global bsp_ints_disable +.global bsp_ints_restore + + +.equ USR_MODE, 0x10 +.equ FIQ_MODE, 0x11 +.equ IRQ_MODE, 0x12 +.equ SVC_MODE, 0x13 +.equ ABT_MODE, 0x17 +.equ UND_MODE, 0x1B +.equ SYS_MODE, 0x1F + +.equ I_BIT, 0x80 /* when I bit is set, IRQ is disabled */ +.equ F_BIT, 0x40 /* when F bit is set, FIQ is disabled */ + +__interrupt_vector_table: + + B Reset_Handler /* Reset */ + B . /* Undefined */ + B . /* SWI */ + B . /* Prefetch Abort */ + B . /* Data Abort */ + B . /* reserved */ + B IRQ_Handler /* IRQ */ + B . /* FIQ */ + + + +Reset_Handler: + + + MSR CPSR_c,#(IRQ_MODE | I_BIT | F_BIT) + LDR sp,=__irq_stack_top__ /* set the IRQ stack pointer */ + MSR CPSR_c,#(FIQ_MODE | I_BIT | F_BIT) + LDR sp,=__fiq_stack_top__ /* set the FIQ stack pointer */ + MSR CPSR_c,#(SVC_MODE | I_BIT | F_BIT) + LDR sp,=__svc_stack_top__ /* set the SVC stack pointer */ + + BL low_level_init + BL _mainCRTStartup + + + B . + +IRQ_Handler: + B archIRQHandler + diff --git a/platforms/qemu_integratorcp/system.ld b/platforms/qemu_integratorcp/system.ld new file mode 100644 index 0000000..4d4fc2c --- /dev/null +++ b/platforms/qemu_integratorcp/system.ld @@ -0,0 +1,94 @@ + +ENTRY(__interrupt_vector_table) + + +MEMORY +{ + flash (rx) : ORIGIN = 0x00000000, LENGTH = 0x00020000 + sram (rwx) : ORIGIN = 0x00020000, LENGTH = 0x00020000 +} + + +EXTERN(__interrupt_vector_table); + + +C_STACK_SIZE = 512; +IRQ_STACK_SIZE = 256; +FIQ_STACK_SIZE = 256; +SVC_STACK_SIZE = 512; +ABT_STACK_SIZE = 256; +UND_STACK_SIZE = 256; + +SECTIONS +{ + + + .text : + { + *(.vectors) + /* Startup assembly */ + *(.startup) + *(.init) + + /* Rest of the code (C) */ + *(.text) + *(.rodata) + *(.rodata*) + + _end_text = .; + } >flash + + .data : + { + _start_data = .; + *(.data) + _end_data = .; + } >sram + + .bss : + { + _start_bss = .; + __bss_start__ = . ; + *(.bss) + *(.eh_*) + } >sram + + . = ALIGN(4); + _end_bss = .; + __bss_end__ = . ; + + . = ALIGN(256); + + + .stack : { + __stack_start__ = . ; + . += IRQ_STACK_SIZE; + . = ALIGN (4); + __irq_stack_top__ = . ; + . += FIQ_STACK_SIZE; + . = ALIGN (4); + __fiq_stack_top__ = . ; + . += SVC_STACK_SIZE; + . = ALIGN (4); + __svc_stack_top__ = . ; + . += ABT_STACK_SIZE; + . = ALIGN (4); + __abt_stack_top__ = . ; + . += UND_STACK_SIZE; + . = ALIGN (4); + __und_stack_top__ = . ; + . += C_STACK_SIZE; + . = ALIGN (4); + __c_stack_top__ = . ; + __stack_end__ = .; + } >sram + + + /*DISCARD : + { + *(.eh_*) + }*/ +} + +_end = .; +PROVIDE(end = .); \ No newline at end of file diff --git a/platforms/rules.mk b/platforms/rules.mk new file mode 100644 index 0000000..7f0f767 --- /dev/null +++ b/platforms/rules.mk @@ -0,0 +1,60 @@ +# +# The following part of the makefile is generic; it can be used to +# build any executable just by changing the definitions above and by +# deleting dependencies appended to the file from 'make depend' +# +.SUFFIXES: .asm .elf .hex .lst .o .S .s .c .cpp +.PHONY: depend clean + +dump: + @echo "Target: " + @echo $(TARGET_NAME) + @echo "Source files: " + @echo $(SRCS) + @echo $(ASMS) + @echo "Object files: " + @echo $(OBJS) + +all: target + +target: $(OBJS) + $(LN) $(LFLAGS) $(LIBFLAGS) $(OBJS) $(LLIBS) -o $(TARGET_NAME).elf + @echo $(TARGET_NAME).elf was compiled + +clean: + rm -f $(OBJS) + + +# this is a suffix replacement rule for building .o's from .c's +# it uses automatic variables $<: the name of the prerequisite of +# the rule(a .c file) and $@: the name of the target of the rule (a .o file) +# (see the gnu make manual section about automatic variables) + +.c.o: + $(CC) $(CDEFS) $(CFLAGS) $(INCLUDES) -c $< -o $@ + +.cpp.o: + $(CC) $(CDEFS) $(CFLAGS) $(INCLUDES) -c $< -o $@ + +.S.o: + $(AS) $(ADEFS) $(AFLAGS) $(INCLUDES) -c $< -o $@ + +.s.o: + $(AS) $(ADEFS) $(AFLAGS) $(INCLUDES) -c $< -o $@ + +DEPFILE=.depends +DEPTOKEN='\# MAKEDEPENDS' +DEPFLAGS=-Y -f $(DEPFILE) -s $(DEPTOKEN) -p $(OUTDIR)/ + + +depend: + rm -f $(DEPFILE) + make $(DEPFILE) + +$(DEPFILE): + @echo $(DEPTOKEN) > $(DEPFILE) + makedepend $(DEPFLAGS) -- $(CFLAGS) -- $(SRCS) >&/dev/null + +# put this file in the last line of your Makefile +sinclude $(DEPFILE) + \ No newline at end of file diff --git a/ports/armv7/Makefile b/ports/arm/Makefile similarity index 68% rename from ports/armv7/Makefile rename to ports/arm/Makefile index 3a15998..9c33741 100644 --- a/ports/armv7/Makefile +++ b/ports/arm/Makefile @@ -1,5 +1,5 @@ -ATOMTHREADS_PORT = .../libraries/atomthreads/ports/armv7 -ATOMTHREADS_KERNEL = .../libraries/atomthreads/kernel +ATOMTHREADS_PORT = $(ATOMTHREADS)/ports/arm +ATOMTHREADS_KERNEL = $(ATOMTHREADS)/kernel INCLUDES := $(INCLUDES) \ -I$(ATOMTHREADS_KERNEL) \ @@ -14,6 +14,6 @@ SRCS := $(SRCS) \ $(ATOMTHREADS_PORT)/atomport.c ASMS := $(ASMS) \ - $(ATOMTHREADS_PORT)/atomport_arm.asm - - + $(ATOMTHREADS_PORT)/atomport_s.S + + diff --git a/ports/armv7/README b/ports/arm/README similarity index 100% rename from ports/armv7/README rename to ports/arm/README diff --git a/ports/arm/atomport-tests.h b/ports/arm/atomport-tests.h new file mode 100644 index 0000000..cfb909a --- /dev/null +++ b/ports/arm/atomport-tests.h @@ -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__ */ diff --git a/ports/armv7/atomport.c b/ports/arm/atomport.c similarity index 94% rename from ports/armv7/atomport.c rename to ports/arm/atomport.c index 8fa0b2a..da96930 100644 --- a/ports/armv7/atomport.c +++ b/ports/arm/atomport.c @@ -33,14 +33,14 @@ /* * * - * Functions defined in atomport_arm.asm + * Functions defined in atomport_s.asm * */ +typedef void * SYSCONTEXT ; + extern void contextInit (void) ; extern void contextSwitch (SYSCONTEXT* save_context, SYSCONTEXT* new_context) ; extern void contextStart (SYSCONTEXT* context) ; -extern uint32_t contextEnterCritical (void) ; -extern void contextExitCritical (uint32_t posture) ; extern void contextEnableInterrupts (void) ; /** @@ -83,7 +83,6 @@ thread_shell (void) void archThreadContextInit (ATOM_TCB *tcb_ptr, void *stack_top, void (*entry_point)(uint32_t), uint32_t entry_param) { - static uint32_t context_thread_id = 0 ; uint32_t * stack_ptr ; tcb_ptr->sp_save_ptr = stack_top; @@ -111,10 +110,10 @@ archThreadContextInit (ATOM_TCB *tcb_ptr, void *stack_top, void (*entry_point)(u stack_ptr--; *stack_ptr = ( uint32_t ) 0x00000404; /* R4 */ -// #ifdef CONTEXT_THREAD_ID +#ifdef CONTEXT_THREAD_ID stack_ptr--; *stack_ptr = context_thread_id++ ; /* thread_id */ -// #endif +#endif tcb_ptr->sp_save_ptr = stack_ptr ; } diff --git a/ports/armv7/atomport.h b/ports/arm/atomport.h similarity index 90% rename from ports/armv7/atomport.h rename to ports/arm/atomport.h index 2a6cf50..39bd0c0 100644 --- a/ports/armv7/atomport.h +++ b/ports/arm/atomport.h @@ -30,10 +30,9 @@ #ifndef __ATOM_PORT_H__ #define __ATOM_PORT_H__ -#include "arch/context.h" #include "types.h" -#define SYSTEM_TICKS_PER_SEC 1000 +#define SYSTEM_TICKS_PER_SEC 100 /** @@ -43,12 +42,18 @@ */ #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__ */ diff --git a/ports/arm/atomport.o b/ports/arm/atomport.o new file mode 100644 index 0000000..3170872 Binary files /dev/null and b/ports/arm/atomport.o differ diff --git a/ports/arm/atomport_asm.o b/ports/arm/atomport_asm.o new file mode 100644 index 0000000..06ae214 Binary files /dev/null and b/ports/arm/atomport_asm.o differ diff --git a/ports/armv7/atomport_private.h b/ports/arm/atomport_private.h similarity index 100% rename from ports/armv7/atomport_private.h rename to ports/arm/atomport_private.h diff --git a/ports/arm/atomport_s.S b/ports/arm/atomport_s.S new file mode 100644 index 0000000..1227c52 --- /dev/null +++ b/ports/arm/atomport_s.S @@ -0,0 +1,227 @@ +/* + 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 archIRQHandler + +.global contextEnterCritical +.global contextExitCritical +.global contextEnableInterrupts +.global contextId +.global contextStart +.global contextSwitch +.global contextInit + + +.global __context_preempt_handler + +/**/ +.equ USR_MODE, 0x10 +.equ FIQ_MODE, 0x11 +.equ IRQ_MODE, 0x12 +.equ SVC_MODE, 0x13 +.equ ABT_MODE, 0x17 +.equ UND_MODE, 0x1B +.equ SYS_MODE, 0x1F + +.equ I_BIT, 0x80 /* when I bit is set, IRQ is disabled */ +.equ F_BIT, 0x40 /* when F bit is set, FIQ is disabled */ + + +.text +.code 32 + +/** + * \b contextInit + * + * Architecture-specific one time initialization. + * + * @return None + */ +contextInit: + + 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: + STMFD sp!, {r4 - r11, lr} /* Save registers */ + +#ifdef CONTEXT_THREAD_ID + MRC p15, 0, r3, c13, c0, 2 + STMFD sp!, {r3} +#endif + + STR sp, [r0] /* Save old stack pointer */ + LDR r1, [r1] /* Load new stack pointer */ + MOV sp, r1 + +#ifdef CONTEXT_THREAD_ID + LDMFD sp!, {r3} + MCR p15, 0, r3, c13, c0, 2 +#endif + + LDMFD sp!, {r4 - r11, pc} /* Load new registers */ + +/** + * \b contextStart + * + * Architecture-specific context start routine. + * + * @param[in] [r0] -> Address where stack pointer is stored + * + * @return Does not return + */ +contextStart: + LDR r0, [r0] + MOV sp, r0 /* Load new stack pointer */ + +#ifdef CONTEXT_THREAD_ID + LDMFD sp!, {r3} + MCR p15, 0, r3, c13, c0, 2 +#endif + + LDMFD sp!, {r4 - r11, pc} /* Load new registers */ + +/** + * \b contextId + * + * Returns a unique ID for the context + * + * @return ID + */ +contextId: +#ifdef CONTEXT_THREAD_ID + MRC p15, 0, r0, c13, c0, 2 +#else + MOV r0, #0 +#endif + BX lr + +/** + * \b contextEnableInterrupts + * + * Enables interrupts on the processor + * + * @return None + */ +contextEnableInterrupts: + MRS r0, CPSR + MOV r1, #I_BIT + BIC r0, r0, r1 + MSR CPSR_c, r0 + BX lr + +/** + * \b contextExitCritical + * + * Exit critical section (restores interrupt posture) + * + * @param[in] r0 Interrupt Posture + * + * @return None + */ +contextExitCritical: + MSR CPSR_cxsf, r0 + BX lr + +/** + * \b contextEnterCritical + * + * Enter critical section (disables interrupts) + * + * @return Current interrupt posture + */ +contextEnterCritical: + MRS r0, CPSR + ORR r1, r0, #I_BIT + MSR CPSR_cxsf, r1 + BX lr + + + +/** + * \b archIRQHandler + * + * IRQ entry point. + * + * Save the process/thread context onto its own stackm before calling __context_preempt_handler (). + * __context_preempt_handler() might switch stacks. On return the same context is poped from the + * stack and control is returned to the process. + * + * @return None + */ +archIRQHandler: + + MSR cpsr_c, #(SVC_MODE | I_BIT) /* Save current process context in process stack */ + STMFD sp!, {r0 - r3, ip, lr} + + MSR cpsr_c, #(IRQ_MODE | I_BIT) /* Save lr_irq and spsr_irq in process stack */ + SUB lr, lr, #4 + MOV r1, lr + MRS r2, spsr + MSR cpsr_c, #(SVC_MODE | I_BIT) + STMFD sp!, {r1, r2} + + BL __context_preempt_handler /* Dispatch the interrupt to archTickHandler for + the timer tick interrupt or a simular function + for other interrupts which might call atomthread + functions. */ + + LDMFD sp!, {r1, r2} /* Restore lr_irq and spsr_irq from process stack */ + MSR cpsr_c, #(IRQ_MODE | I_BIT) + STMFD sp!, {r1} + MSR spsr_cxsf, r2 + + MSR cpsr_c, #(SVC_MODE | I_BIT) /* Restore process regs */ + LDMFD sp!, {r0 - r3, ip, lr} + + MSR cpsr_c, #(IRQ_MODE | I_BIT) /* Exit from IRQ */ + LDMFD sp!, {pc}^ + + + diff --git a/ports/armv7/types.h b/ports/arm/types.h similarity index 96% rename from ports/armv7/types.h rename to ports/arm/types.h index 0fd6feb..d383d84 100644 --- a/ports/armv7/types.h +++ b/ports/arm/types.h @@ -40,7 +40,7 @@ typedef int int32_t ; typedef short int16_t ; typedef char int8_t ; -typedef volatile unsigned int REG_DWORD ;// Hardware register definition +// typedef volatile unsigned int REG_DWORD ;// Hardware register definition #define UWORD64 unsigned long long #define UWORD32 unsigned int diff --git a/ports/armv7/atomport_arm.asm b/ports/armv7/atomport_arm.asm deleted file mode 100644 index 496e779..0000000 --- a/ports/armv7/atomport_arm.asm +++ /dev/null @@ -1,211 +0,0 @@ -; -; 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. -; - - - PRESERVE8 {TRUE} - AREA UTILS, CODE, READONLY -;-- - EXPORT contextInit - EXPORT contextSwitch - EXPORT contextStart - EXPORT contextEnableInterrupts - EXPORT contextEnterCritical - EXPORT contextExitCritical - EXPORT archIRQHandler - - EXTERN __context_preempt_handler [WEAK] - -;-- -ARM_SVC_MODE EQU 0xd3 -ARM_IRQ_MODE EQU 0xD2 -ARM_FIQ_MODE EQU 0xD1 -ARM_MODE_MASK EQU 0x1F -ARM_FIQ_MODE_BITS EQU 0x11 -ARM_IRQ_MODE_BITS EQU 0x12 - - - ARM - -;-- -; \b contextInit -; -; Architecture-specific one time initialization. -; -; @return None -; -contextInit - - 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 - STMFD sp!, {r4 - r11, lr} ;- Save registers - - ;- IF :DEF:CONTEXT_THREAD_ID - MRC p15, 0, r3, c13, c0, 2 - STMFD sp!, {r3} - ;- ENDIF - - STR sp, [r0] ;- Save old stack pointer - LDR r1, [r1] ;- Load new stack pointer - MOV sp, r1 - - ISB - - ;- IF :DEF:CONTEXT_THREAD_ID - LDMFD sp!, {r3} - MCR p15, 0, r3, c13, c0, 2 - ;- ENDIF - - LDMFD sp!, {r4 - r11, pc} ;- Load new registers - -;-- -; \b contextStart -; -; Architecture-specific context start routine. -; -; @param[in] [r0] -> Address where stack pointer is stored -; -; @return Does not return -; -contextStart - LDR r0, [r0] - MOV sp, r0 ;- Load new stack pointer - - ;- IF :DEF:CONTEXT_THREAD_ID - LDMFD sp!, {r3} - MCR p15, 0, r3, c13, c0, 2 - ;- ENDIF - - LDMFD sp!, {r4 - r11, pc} ;- Load new registers - -;-- -; \b contextId -; -; Returns a unique ID for the context -; -; @return ID -; -contextId - MRC p15, 0, r0, c13, c0, 2 - BX lr - -;-- -; \b contextEnableInterrupts -; -; Enables interrupts on the processor -; -; @return None -; -contextEnableInterrupts - MRS r0, CPSR - MOV r1, #0x80 - BIC r0, r0, r1 - MSR CPSR_c, r0 - BX lr - -;-- -; \b contextExitCritical -; -; Exit critical section (restores interrupt posture) -; -; @param[in] r0 Interrupt Posture -; -; @return None -; -contextExitCritical - MSR CPSR_cxsf, r0 - BX lr - -;-- -; \b contextEnterCritical -; -; Enter critical section (disables interrupts) -; -; @return Current interrupt posture -; -contextEnterCritical - MRS r0, CPSR - ORR r1, r0, #0x80 - MSR CPSR_cxsf, r1 - BX lr - -;-- -; \b archIRQHandler -; -; IRQ entry point. -; -; Save the process/thread context onto its own stackm before calling __context_preempt_handler (). -; __context_preempt_handler() might switch stacks. On return the same context is poped from the -; stack and control is returned to the process. -; -; @return None -; -archIRQHandler - - MSR cpsr_c, #ARM_SVC_MODE ;- Save current process context in process stack - STMFD sp!, {r0 - r3, ip, lr} - - MSR cpsr_c, #ARM_IRQ_MODE ;- Save lr_irq and spsr_irq in process stack - SUB lr, lr, #4 - MOV r1, lr - MRS r2, spsr - MSR cpsr_c, #ARM_SVC_MODE - STMFD sp!, {r1, r2} - - BL __context_preempt_handler ;- Dispatch the interrupt to archTickHandler for the timer tick interrupt or a simular function for other interrupts which might call atomthread functions. - - LDMFD sp!, {r1, r2} ;- Restore lr_irq and spsr_irq from process stack - MSR cpsr_c, #ARM_IRQ_MODE - STMFD sp!, {r1} - MSR spsr_cxsf, r2 - - MSR cpsr_c, #ARM_SVC_MODE ;- Restore process regs - LDMFD sp!, {r0 - r3, ip, lr} - - MSR cpsr_c, #ARM_IRQ_MODE ;- Exit from IRQ - LDMFD sp!, {pc}^ - - -;-- - END diff --git a/tests/atomtests.h b/tests/atomtests.h index 9e0d0f2..2018a28 100644 --- a/tests/atomtests.h +++ b/tests/atomtests.h @@ -44,4 +44,4 @@ extern uint32_t test_start (void); -#endif /* __ATOM_TESTS_H */ +#endif /* __ATOM_TESTS_H */ \ No newline at end of file diff --git a/tests/kern1.c b/tests/kern1.c index 1695039..d0cce0c 100644 --- a/tests/kern1.c +++ b/tests/kern1.c @@ -64,7 +64,7 @@ uint32_t test_start (void) /* atomThreadCreate: Pass a bad TCB pointer */ if (atomThreadCreate (NULL, TEST_THREAD_PRIO, test_thread_func, 0, - &test_thread_stack[TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_ERR_PARAM) { ATOMLOG (_STR("Bad TCB check\n")); @@ -73,7 +73,7 @@ uint32_t test_start (void) /* atomThreadCreate: Pass a bad entry point */ if (atomThreadCreate (&tcb1, TEST_THREAD_PRIO, NULL, 0, - &test_thread_stack[TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_ERR_PARAM) { ATOMLOG (_STR("Bad entry check\n")); @@ -90,7 +90,7 @@ uint32_t test_start (void) /* atomThreadCreate: Pass a bad stack size */ if (atomThreadCreate (&tcb1, TEST_THREAD_PRIO, test_thread_func, 0, - &test_thread_stack[TEST_THREAD_STACK_SIZE - 1], 0) != ATOM_ERR_PARAM) + &test_thread_stack[TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], 0) != ATOM_ERR_PARAM) { ATOMLOG (_STR("Bad stack size check\n")); failures++; diff --git a/tests/kern3.c b/tests/kern3.c index 20304f8..47fc6bb 100644 --- a/tests/kern3.c +++ b/tests/kern3.c @@ -95,7 +95,7 @@ uint32_t test_start (void) /* Create low priority thread */ if (atomThreadCreate (&tcb[0], 253, test_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { ATOMLOG (_STR("Bad thread create\n")); @@ -104,7 +104,7 @@ uint32_t test_start (void) /* Create high priority thread */ else if (atomThreadCreate (&tcb[1], 252, test_thread_func, 1, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { ATOMLOG (_STR("Bad thread create\n")); diff --git a/tests/kern4.c b/tests/kern4.c index 909232e..b38be51 100644 --- a/tests/kern4.c +++ b/tests/kern4.c @@ -97,28 +97,28 @@ uint32_t test_start (void) * a spell in which this thread was run. */ if (atomThreadCreate (&tcb[0], TEST_THREAD_PRIO + 1, test_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { ATOMLOG (_STR("Bad thread create\n")); failures++; } else if (atomThreadCreate (&tcb[1], TEST_THREAD_PRIO + 1, test_thread_func, 1, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { ATOMLOG (_STR("Bad thread create\n")); failures++; } else if (atomThreadCreate (&tcb[2], TEST_THREAD_PRIO + 1, test_thread_func, 2, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { ATOMLOG (_STR("Bad thread create\n")); failures++; } else if (atomThreadCreate (&tcb[3], TEST_THREAD_PRIO + 1, test_thread_func, 3, - &test_thread_stack[3][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[3][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { ATOMLOG (_STR("Bad thread create\n")); diff --git a/tests/mutex1.c b/tests/mutex1.c index e3bc16a..af1e157 100644 --- a/tests/mutex1.c +++ b/tests/mutex1.c @@ -138,7 +138,7 @@ uint32_t test_start (void) } else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test1_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -201,7 +201,7 @@ uint32_t test_start (void) } else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test2_thread_func, 0, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/mutex2.c b/tests/mutex2.c index 9725f44..033d8b6 100644 --- a/tests/mutex2.c +++ b/tests/mutex2.c @@ -144,7 +144,7 @@ uint32_t test_start (void) /* Create a test thread, the sole purpose of which is to own mutex2 */ g_owned = 0; if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/mutex3.c b/tests/mutex3.c index f604430..1f2becc 100644 --- a/tests/mutex3.c +++ b/tests/mutex3.c @@ -108,7 +108,7 @@ uint32_t test_start (void) { /* Create Thread 1 (lower priority thread A) */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO+1, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -121,7 +121,7 @@ uint32_t test_start (void) /* Create Thread 2 (lower priority thread B) */ if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO+1, test_thread_func, 2, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -134,7 +134,7 @@ uint32_t test_start (void) /* Create Thread 3 (higher priority thread A) */ if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 3, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -147,7 +147,7 @@ uint32_t test_start (void) /* Create Thread 4 (higher priority thread B) */ if (atomThreadCreate(&tcb[3], TEST_THREAD_PRIO, test_thread_func, 4, - &test_thread_stack[3][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[3][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/mutex4.c b/tests/mutex4.c index b478517..7d9eeda 100644 --- a/tests/mutex4.c +++ b/tests/mutex4.c @@ -101,7 +101,7 @@ uint32_t test_start (void) /* Create Thread 1 */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -113,7 +113,7 @@ uint32_t test_start (void) /* Create Thread 2 */ if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 2, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -125,7 +125,7 @@ uint32_t test_start (void) /* Create Thread 3 */ if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 3, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -137,7 +137,7 @@ uint32_t test_start (void) /* Create Thread 4 */ if (atomThreadCreate(&tcb[3], TEST_THREAD_PRIO, test_thread_func, 4, - &test_thread_stack[3][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[3][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/mutex5.c b/tests/mutex5.c index 9aa18f2..7e91197 100644 --- a/tests/mutex5.c +++ b/tests/mutex5.c @@ -95,7 +95,7 @@ uint32_t test_start (void) /* Create second thread */ else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/mutex6.c b/tests/mutex6.c index ca2c2d6..de4754f 100644 --- a/tests/mutex6.c +++ b/tests/mutex6.c @@ -100,7 +100,7 @@ uint32_t test_start (void) /* Create second thread */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/mutex7.c b/tests/mutex7.c index 9189dee..5a9f312 100644 --- a/tests/mutex7.c +++ b/tests/mutex7.c @@ -94,7 +94,7 @@ uint32_t test_start (void) /* Create second thread */ else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/mutex8.c b/tests/mutex8.c index 14febb9..3c1776d 100644 --- a/tests/mutex8.c +++ b/tests/mutex8.c @@ -94,7 +94,7 @@ uint32_t test_start (void) /* Create test thread 1 */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -104,7 +104,7 @@ uint32_t test_start (void) /* Create test thread 2 */ else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -114,7 +114,7 @@ uint32_t test_start (void) /* Create test thread 3 */ else if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 2, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/mutex9.c b/tests/mutex9.c index e509762..23d2782 100644 --- a/tests/mutex9.c +++ b/tests/mutex9.c @@ -88,7 +88,7 @@ uint32_t test_start (void) /* Create second thread */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/queue2.c b/tests/queue2.c index 8528ade..24bcd60 100644 --- a/tests/queue2.c +++ b/tests/queue2.c @@ -90,7 +90,7 @@ uint32_t test_start (void) /* Create a test thread that will block because the queue is empty */ else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test1_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -147,7 +147,7 @@ uint32_t test_start (void) /* Create a test thread that will block because the queue is empty */ else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test2_thread_func, 0, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/queue3.c b/tests/queue3.c index 277a4e3..fed9ca8 100644 --- a/tests/queue3.c +++ b/tests/queue3.c @@ -107,7 +107,7 @@ uint32_t test_start (void) /* Create a test thread that will block because the queue is full */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test1_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -178,7 +178,7 @@ uint32_t test_start (void) /* Create a test thread that will block because the queue is full */ if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test2_thread_func, 0, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/queue5.c b/tests/queue5.c index bf07960..bf7303b 100644 --- a/tests/queue5.c +++ b/tests/queue5.c @@ -115,7 +115,7 @@ uint32_t test_start (void) /* Create Thread 1 (lower priority thread A) */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO+1, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -128,7 +128,7 @@ uint32_t test_start (void) /* Create Thread 2 (lower priority thread B) */ if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO+1, test_thread_func, 2, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -141,7 +141,7 @@ uint32_t test_start (void) /* Create Thread 3 (higher priority thread A) */ if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 3, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -154,7 +154,7 @@ uint32_t test_start (void) /* Create Thread 4 (higher priority thread B) */ if (atomThreadCreate(&tcb[3], TEST_THREAD_PRIO, test_thread_func, 4, - &test_thread_stack[3][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[3][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/queue6.c b/tests/queue6.c index 4de62f0..eb77e04 100644 --- a/tests/queue6.c +++ b/tests/queue6.c @@ -107,7 +107,7 @@ uint32_t test_start (void) /* Create a test thread that will block because the queue is empty */ else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO + 1, test1_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/queue7.c b/tests/queue7.c index 5b249d8..fda8132 100644 --- a/tests/queue7.c +++ b/tests/queue7.c @@ -94,7 +94,7 @@ uint32_t test_start (void) /* Create test thread 1 */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -104,7 +104,7 @@ uint32_t test_start (void) /* Create test thread 2 */ else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -114,7 +114,7 @@ uint32_t test_start (void) /* Create test thread 3 */ else if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 2, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/queue9.c b/tests/queue9.c index 1bc1034..7251dd6 100644 --- a/tests/queue9.c +++ b/tests/queue9.c @@ -103,7 +103,7 @@ uint32_t test_start (void) { /* Create Thread 1 */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -115,7 +115,7 @@ uint32_t test_start (void) /* Create Thread 2 */ if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 2, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -127,7 +127,7 @@ uint32_t test_start (void) /* Create Thread 3 */ if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 3, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -139,7 +139,7 @@ uint32_t test_start (void) /* Create Thread 4 */ if (atomThreadCreate(&tcb[3], TEST_THREAD_PRIO, test_thread_func, 4, - &test_thread_stack[3][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[3][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/sem1.c b/tests/sem1.c index b7b6335..69be29b 100644 --- a/tests/sem1.c +++ b/tests/sem1.c @@ -134,7 +134,7 @@ uint32_t test_start (void) } else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test1_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -201,7 +201,7 @@ uint32_t test_start (void) failures++; } else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test2_thread_func, 0, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/sem3.c b/tests/sem3.c index 6648b39..7bdb489 100644 --- a/tests/sem3.c +++ b/tests/sem3.c @@ -103,7 +103,7 @@ uint32_t test_start (void) { /* Create Thread 1 (lower priority thread A) */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO+1, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -116,7 +116,7 @@ uint32_t test_start (void) /* Create Thread 2 (lower priority thread B) */ if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO+1, test_thread_func, 2, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -129,7 +129,7 @@ uint32_t test_start (void) /* Create Thread 3 (higher priority thread A) */ if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 3, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -142,7 +142,7 @@ uint32_t test_start (void) /* Create Thread 4 (higher priority thread B) */ if (atomThreadCreate(&tcb[3], TEST_THREAD_PRIO, test_thread_func, 4, - &test_thread_stack[3][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[3][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/sem4.c b/tests/sem4.c index 419195c..092b0f9 100644 --- a/tests/sem4.c +++ b/tests/sem4.c @@ -97,7 +97,7 @@ uint32_t test_start (void) { /* Create Thread 1 */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -109,7 +109,7 @@ uint32_t test_start (void) /* Create Thread 2 */ if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 2, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -121,7 +121,7 @@ uint32_t test_start (void) /* Create Thread 3 */ if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 3, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -133,7 +133,7 @@ uint32_t test_start (void) /* Create Thread 4 */ if (atomThreadCreate(&tcb[3], TEST_THREAD_PRIO, test_thread_func, 4, - &test_thread_stack[3][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[3][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/sem5.c b/tests/sem5.c index dc87f9f..ae0c0a5 100644 --- a/tests/sem5.c +++ b/tests/sem5.c @@ -84,7 +84,7 @@ uint32_t test_start (void) { /* Create second thread */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/sem6.c b/tests/sem6.c index 851f9b8..309de97 100644 --- a/tests/sem6.c +++ b/tests/sem6.c @@ -94,7 +94,7 @@ uint32_t test_start (void) /* Create second thread */ else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/sem7.c b/tests/sem7.c index 62fa16f..5507c70 100644 --- a/tests/sem7.c +++ b/tests/sem7.c @@ -100,7 +100,7 @@ uint32_t test_start (void) /* Create second thread */ else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/sem8.c b/tests/sem8.c index 432cf32..67e2ea3 100644 --- a/tests/sem8.c +++ b/tests/sem8.c @@ -110,7 +110,7 @@ uint32_t test_start (void) /* Create thread 1: Higher priority than main thread so should sleep */ else if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO - 1, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -120,7 +120,7 @@ uint32_t test_start (void) /* Create thread 2: Same priority as main thread so should not sleep */ else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 0, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -130,7 +130,7 @@ uint32_t test_start (void) /* Create thread 3: Same priority as main thread so should not sleep */ else if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO + 1, test_thread_func, 0, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/sem9.c b/tests/sem9.c index d7a86d6..ab4653d 100644 --- a/tests/sem9.c +++ b/tests/sem9.c @@ -87,7 +87,7 @@ uint32_t test_start (void) { /* Create test thread 1 */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 0, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -97,7 +97,7 @@ uint32_t test_start (void) /* Create test thread 2 */ else if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -107,7 +107,7 @@ uint32_t test_start (void) /* Create test thread 3 */ else if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 2, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ diff --git a/tests/timer2.c b/tests/timer2.c index a606830..95c1dc6 100644 --- a/tests/timer2.c +++ b/tests/timer2.c @@ -73,7 +73,7 @@ uint32_t test_start (void) /* Create Thread 1 */ if (atomThreadCreate(&tcb[0], TEST_THREAD_PRIO, test_thread_func, 1, - &test_thread_stack[0][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[0][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -83,7 +83,7 @@ uint32_t test_start (void) /* Create Thread 2 */ if (atomThreadCreate(&tcb[1], TEST_THREAD_PRIO, test_thread_func, 2, - &test_thread_stack[1][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[1][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */ @@ -93,7 +93,7 @@ uint32_t test_start (void) /* Create Thread 3 */ if (atomThreadCreate(&tcb[2], TEST_THREAD_PRIO, test_thread_func, 3, - &test_thread_stack[2][TEST_THREAD_STACK_SIZE - 1], + &test_thread_stack[2][TEST_THREAD_STACK_SIZE - sizeof(uint32_t)], TEST_THREAD_STACK_SIZE) != ATOM_OK) { /* Fail */