diff --git a/arch/cpu/arm/common/sys/mtarch.c b/arch/cpu/arm/common/sys/mtarch.c deleted file mode 100644 index 6bf011411..000000000 --- a/arch/cpu/arm/common/sys/mtarch.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (c) 2016, Benoît Thébaudeau - * 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. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. - */ -/** - * \addtogroup arm-cm-mtarch - * @{ - * - * \file - * Implmentation of the ARM Cortex-M support for Contiki multi-threading. - */ -#include CMSIS_DEV_HDR -#include "sys/mt.h" - -#include - -#define EXC_RETURN_PROCESS_THREAD_BASIC_FRAME 0xfffffffd - -/* Check whether EXC_RETURN[3:0] in LR indicates a preempted process thread. */ -#if __ARM_ARCH == 7 -#define PREEMPTED_PROCESS_THREAD() \ - "and r0, lr, #0xf\n\t" \ - "cmp r0, #0xd\n\t" -#elif __ARM_ARCH == 6 -#define PREEMPTED_PROCESS_THREAD() \ - "mov r0, lr\n\t" \ - "movs r1, #0xf\n\t" \ - "and r0, r1\n\t" \ - "cmp r0, #0xd\n\t" -#else -#error Unsupported ARM architecture -#endif -/*----------------------------------------------------------------------------*/ -/** - * \brief SVCall system handler - * - * This exception handler executes the action requested by the corresponding - * \c svc instruction, which is a task switch from the main Contiki thread to an - * mt thread or the other way around. - */ -__attribute__ ((__naked__)) -void -svcall_handler(void) -{ - /* - * Decide whether to switch to the main thread or to a process thread, - * depending on the type of the thread preempted by SVCall. - */ - __asm__ (PREEMPTED_PROCESS_THREAD() -#if __ARM_ARCH == 7 - "it eq\n\t" -#endif - "beq switch_to_main_thread\n\t" - - /* - * - Retrieve from the main stack the PSP passed to SVCall through R0. Note - * that it cannot be retrieved directly from R0 on exception entry because - * this register may have been overwritten by other exceptions on SVCall - * entry. - * - Save the main thread context to the main stack. - * - Restore the process thread context from the process stack. - * - Return to Thread mode, resuming the process thread. - */ -#if __ARM_ARCH == 7 - "ldr r0, [sp]\n\t" - "push {r4-r11, lr}\n\t" - "add r1, r0, #9 * 4\n\t" - "msr psp, r1\n\t" - "ldmia r0, {r4-r11, pc}"); -#elif __ARM_ARCH == 6 - "mov r0, r8\n\t" - "mov r1, r9\n\t" - "mov r2, r10\n\t" - "mov r3, r11\n\t" - "push {r0-r7, lr}\n\t" - "ldr r0, [sp, #9 * 4]\n\t" - "ldmia r0!, {r4-r7}\n\t" - "mov r8, r4\n\t" - "mov r9, r5\n\t" - "mov r10, r6\n\t" - "mov r11, r7\n\t" - "ldmia r0!, {r3-r7}\n\t" - "msr psp, r0\n\t" - "bx r3"); -#endif -} -/*----------------------------------------------------------------------------*/ -/** - * \brief PendSV system handler - * - * This exception handler executes following a call to mtarch_pstart() from - * another exception handler. It performs a task switch to the main Contiki - * thread if it is not already running. - */ -__attribute__ ((__naked__)) -void -pendsv_handler(void) -{ - /* - * Return without doing anything if PendSV has not preempted a process thread. - * This can occur either because PendSV has preempted the main thread, in - * which case there is nothing to do, or because mtarch_pstart() has been - * called from an exception handler without having called mt_init() first, in - * which case PendSV may have preempted an exception handler and nothing must - * be done because mt is not active. - */ - __asm__ ( PREEMPTED_PROCESS_THREAD() -#if __ARM_ARCH == 7 - "it ne\n\t" - "bxne lr\n" -#elif __ARM_ARCH == 6 - "beq switch_to_main_thread\n\t" - "bx lr\n" -#endif - - /* - * - Save the process thread context to the process stack. - * - Place into the main stack the updated PSP that SVCall must return through - * R0. - * - Restore the main thread context from the main stack. - * - Return to Thread mode, resuming the main thread. - */ - "switch_to_main_thread:\n\t" - "mrs r0, psp\n\t" -#if __ARM_ARCH == 7 - "stmdb r0!, {r4-r11, lr}\n\t" - "str r0, [sp, #9 * 4]\n\t" - "pop {r4-r11, pc}"); -#elif __ARM_ARCH == 6 - "mov r3, lr\n\t" - "sub r0, #5 * 4\n\t" - "stmia r0!, {r3-r7}\n\t" - "mov r4, r8\n\t" - "mov r5, r9\n\t" - "sub r0, #9 * 4\n\t" - "mov r6, r10\n\t" - "mov r7, r11\n\t" - "stmia r0!, {r4-r7}\n\t" - "pop {r4-r7}\n\t" - "sub r0, #4 * 4\n\t" - "mov r8, r4\n\t" - "mov r9, r5\n\t" - "str r0, [sp, #5 * 4]\n\t" - "mov r10, r6\n\t" - "mov r11, r7\n\t" - "pop {r4-r7, pc}"); -#endif -} -/*----------------------------------------------------------------------------*/ -void -mtarch_init(void) -{ - SCB->CCR = (SCB->CCR -#ifdef SCB_CCR_NONBASETHRDENA_Msk - /* - * Make sure that any attempt to enter Thread mode with exceptions - * active faults. - * - * Only SVCall and PendSV are allowed to forcibly enter Thread - * mode, and they are configured with the same, lowest exception - * priority, so no other exceptions may be active. - */ - & ~SCB_CCR_NONBASETHRDENA_Msk -#endif - /* - * Force 8-byte stack pointer alignment on exception entry in order - * to be able to use AAPCS-conforming functions as exception - * handlers. - */ - ) | SCB_CCR_STKALIGN_Msk; - - /* - * Configure SVCall and PendSV with the same, lowest exception priority. - * - * This makes sure that they cannot preempt each other, and that the processor - * executes them after having handled all other exceptions. If both are - * pending at the same time, then SVCall takes precedence because of its lower - * exception number. In addition, the associated exception handlers do not - * have to check whether they are returning to Thread mode, because they - * cannot preempt any other exception. - */ - NVIC_SetPriority(SVCall_IRQn, (1 << __NVIC_PRIO_BITS) - 1); - NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); - - /* - * Force the preceding configurations to take effect before further - * operations. - */ - __DSB(); - __ISB(); -} -/*----------------------------------------------------------------------------*/ -void -mtarch_start(struct mtarch_thread *thread, - void (*function)(void *data), void *data) -{ - struct mtarch_thread_context *context = &thread->start_stack.context; - - /* - * Initialize the thread context with the appropriate values to call - * function() with data and to make function() return to mt_exit() without - * having to call it explicitly. - */ - context->exc_return = EXC_RETURN_PROCESS_THREAD_BASIC_FRAME; - context->r0 = (uint32_t)data; - context->lr = (uint32_t)mt_exit; - context->pc = (uint32_t)function; - context->xpsr = xPSR_T_Msk; - thread->psp = (uint32_t)context; -} -/*----------------------------------------------------------------------------*/ -void -mtarch_exec(struct mtarch_thread *thread) -{ - /* Pass the PSP to SVCall, and get the updated PSP as its return value. */ - register uint32_t psp __asm__ ("r0") = thread->psp; - __asm__ volatile ("svc #0" - : "+r" (psp) - :: "memory"); - thread->psp = psp; -} -/*----------------------------------------------------------------------------*/ -__attribute__ ((__naked__)) -void -mtarch_yield(void) -{ - /* Invoke SVCall. */ - __asm__ ("svc #0\n\t" - "bx lr"); -} -/*----------------------------------------------------------------------------*/ -void -mtarch_stop(struct mtarch_thread *thread) -{ -} -/*----------------------------------------------------------------------------*/ -void -mtarch_pstart(void) -{ - /* Trigger PendSV. */ - SCB->ICSR = SCB_ICSR_PENDSVSET_Msk; -} -/*----------------------------------------------------------------------------*/ -void -mtarch_pstop(void) -{ -} -/*----------------------------------------------------------------------------*/ -void -mtarch_remove(void) -{ -} -/*----------------------------------------------------------------------------*/ - -/** @} */ diff --git a/arch/cpu/arm/common/sys/mtarch.h b/arch/cpu/arm/common/sys/mtarch.h deleted file mode 100644 index d483e6e3f..000000000 --- a/arch/cpu/arm/common/sys/mtarch.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2016, Benoît Thébaudeau - * 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. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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. - */ -/** - * \addtogroup arm - * @{ - * - * \defgroup arm-cm-mtarch ARM Cortex-M support for Contiki multi-threading - * - * All the Cortex-M devices supported by CMSIS-CORE are supported. - * - * An exception handler can decide to make the main Contiki thread preempt any - * running mt thread by calling mtarch_pstart() (e.g. to perform urgent - * operations that have been triggered by some event or that had been - * scheduled). If the running thread is already the main Contiki thread, then - * nothing happens. The corresponding task switch takes place when leaving - * Handler mode. The main Contiki thread then resumes after the call to - * mt_exec() that yielded to the preempted mt thread. - * @{ - * - * \file - * Header file for the ARM Cortex-M support for Contiki multi-threading. - */ -#ifndef MTARCH_H_ -#define MTARCH_H_ - -#include "contiki.h" -#include "sys/cc.h" - -#include - -#ifndef MTARCH_CONF_STACKSIZE -/** Thread stack size configuration, expressed as a number of 32-bit words. */ -#define MTARCH_CONF_STACKSIZE 256 -#endif -/** Actual stack size, with minimum size and alignment requirements enforced. */ -#define MTARCH_STACKSIZE ((MAX(MTARCH_CONF_STACKSIZE, \ - sizeof(struct mtarch_thread_context) / \ - sizeof(uint32_t)) + 1) & ~1) - -/** - * Structure of a saved thread context. - * - * xpsr..r0 are managed by the processor (except in mtarch_start()), - * while the other register values are handled by the software. - */ -struct mtarch_thread_context { -#if __ARM_ARCH == 7 - uint32_t r4; - uint32_t r5; - uint32_t r6; - uint32_t r7; -#endif - uint32_t r8; - uint32_t r9; - uint32_t r10; - uint32_t r11; - uint32_t exc_return; -#if __ARM_ARCH == 6 - uint32_t r4; - uint32_t r5; - uint32_t r6; - uint32_t r7; -#endif - uint32_t r0; - uint32_t r1; - uint32_t r2; - uint32_t r3; - uint32_t r12; - uint32_t lr; - uint32_t pc; - uint32_t xpsr; -}; - -struct mtarch_thread { - uint32_t psp; - union { - struct { - uint32_t free[MTARCH_STACKSIZE - - sizeof(struct mtarch_thread_context) / sizeof(uint32_t)]; - struct mtarch_thread_context context; - } start_stack; - uint32_t stack[MTARCH_STACKSIZE]; - } CC_ALIGN(8); -}; - -#endif /* MTARCH_H_ */ - -/** - * @} - * @} - */ diff --git a/arch/cpu/cc2538/startup-gcc.c b/arch/cpu/cc2538/startup-gcc.c index 547764ec3..bde8d1488 100644 --- a/arch/cpu/cc2538/startup-gcc.c +++ b/arch/cpu/cc2538/startup-gcc.c @@ -52,8 +52,6 @@ void nmi_handler(void); void default_handler(void); /* System Handler and ISR prototypes implemented elsewhere */ -void svcall_handler(void); /* See mtarch.c */ -void pendsv_handler(void); /* See mtarch.c */ void clock_isr(void); /* SysTick Handler */ void gpio_port_a_isr(void); void gpio_port_b_isr(void); @@ -121,10 +119,10 @@ void(*const vectors[])(void) = 0, /* 8 Reserved */ 0, /* 9 Reserved */ 0, /* 10 Reserved */ - svcall_handler, /* 11 SVCall handler */ + default_handler, /* 11 SVCall handler */ default_handler, /* 12 Debug monitor handler */ 0, /* 13 Reserved */ - pendsv_handler, /* 14 The PendSV handler */ + default_handler, /* 14 The PendSV handler */ clock_isr, /* 15 The SysTick handler */ gpio_port_a_isr, /* 16 GPIO Port A */ gpio_port_b_isr, /* 17 GPIO Port B */ diff --git a/arch/cpu/cc26xx-cc13xx/mtarch.h b/arch/cpu/cc26xx-cc13xx/mtarch.h deleted file mode 100644 index 4f696669d..000000000 --- a/arch/cpu/cc26xx-cc13xx/mtarch.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - Computer Science - * 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. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - */ -/* - * \file - * Stub header file for multi-threading. It doesn't do anything, it - * just exists so that mt.c can compile cleanly. - * - * This is based on the original mtarch.h for z80 by Takahide Matsutsuka - * - * \author - * George Oikonomou - - */ -#ifndef __MTARCH_H__ -#define __MTARCH_H__ - -struct mtarch_thread { - unsigned char *sp; -}; - -#endif /* __MTARCH_H__ */ diff --git a/arch/cpu/msp430/Makefile.msp430 b/arch/cpu/msp430/Makefile.msp430 index 6f9e1e29c..97ea7f3f2 100644 --- a/arch/cpu/msp430/Makefile.msp430 +++ b/arch/cpu/msp430/Makefile.msp430 @@ -40,13 +40,6 @@ MSP430 = msp430.c flash.c clock.c leds.c leds-arch.c \ watchdog.c lpm.c rtimer-arch.c UIPDRIVERS = slip.c crc16.c -ifndef CPU_HAS_MSP430X -# include mtarch.c only in the non-large memory model case, because -# the current implementation assumes 16-bit addresses (function pointers -# stored as "unsigned short"). -MSP430 += mtarch.c -endif - CONTIKI_TARGET_SOURCEFILES += $(MSP430) \ $(SYSAPPS) \ $(UIPDRIVERS) diff --git a/arch/cpu/msp430/mtarch.c b/arch/cpu/msp430/mtarch.c deleted file mode 100644 index 0ecd5d9c0..000000000 --- a/arch/cpu/msp430/mtarch.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2005, Swedish Institute of Computer Science - * 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. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - */ - -#include -#include "sys/mt.h" - -#ifdef __IAR_SYSTEMS_ICC__ -#define __asm__ asm -#endif - -static unsigned short *sptmp; -static struct mtarch_thread *running; - -/*--------------------------------------------------------------------------*/ -void -mtarch_init(void) -{ - -} -/*--------------------------------------------------------------------------*/ -static void -mtarch_wrapper(void) -{ - /* Call thread function with argument */ - ((void (*)(void *))running->function)((void*)running->data); -} -/*--------------------------------------------------------------------------*/ -void -mtarch_start(struct mtarch_thread *t, - void (*function)(void *), void *data) -{ - int i; - - for(i = 0; i < MTARCH_STACKSIZE; ++i) { - t->stack[i] = i; - } - - t->sp = &t->stack[MTARCH_STACKSIZE - 1]; - - *t->sp = (unsigned short)mt_exit; - --t->sp; - - *t->sp = (unsigned short)mtarch_wrapper; - --t->sp; - - /* Space for registers. */ - t->sp -= 11; - - /* Store function and argument (used in mtarch_wrapper) */ - t->data = data; - t->function = function; -} -/*--------------------------------------------------------------------------*/ - -static void -sw(void) -{ - - sptmp = running->sp; - - __asm__("push r4"); - __asm__("push r5"); - __asm__("push r6"); - __asm__("push r7"); - __asm__("push r8"); - __asm__("push r9"); - __asm__("push r10"); - __asm__("push r11"); - __asm__("push r12"); - __asm__("push r13"); - __asm__("push r14"); - __asm__("push r15"); - -#ifdef __IAR_SYSTEMS_ICC__ -/* use IAR intrinsic functions */ - running->sp = (unsigned short *) __get_SP_register(); - __set_SP_register((unsigned short) sptmp); -#else - __asm__("mov.w r1,%0" : "=r" (running->sp)); - __asm__("mov.w %0,r1" : : "m" (sptmp)); -#endif - - __asm__("pop r15"); - __asm__("pop r14"); - __asm__("pop r13"); - __asm__("pop r12"); - __asm__("pop r11"); - __asm__("pop r10"); - __asm__("pop r9"); - __asm__("pop r8"); - __asm__("pop r7"); - __asm__("pop r6"); - __asm__("pop r5"); - __asm__("pop r4"); -} -/*--------------------------------------------------------------------------*/ -void -mtarch_exec(struct mtarch_thread *t) -{ - running = t; - sw(); - running = NULL; -} -/*--------------------------------------------------------------------------*/ -void -mtarch_remove(void) -{ - -} -/*--------------------------------------------------------------------------*/ -void -mtarch_yield(void) -{ - sw(); -} -/*--------------------------------------------------------------------------*/ -void -mtarch_pstop(void) -{ - -} -/*--------------------------------------------------------------------------*/ -void -mtarch_pstart(void) -{ - -} -/*--------------------------------------------------------------------------*/ -void -mtarch_stop(struct mtarch_thread *thread) -{ - -} -/*--------------------------------------------------------------------------*/ -int -mtarch_stack_usage(struct mt_thread *t) -{ - int i; - - for(i = 0; i < MTARCH_STACKSIZE; ++i) { - if(t->thread.stack[i] != (unsigned short)i) { - return MTARCH_STACKSIZE - i; - } - } - - return MTARCH_STACKSIZE; -} -/*--------------------------------------------------------------------------*/ diff --git a/arch/cpu/msp430/mtarch.h b/arch/cpu/msp430/mtarch.h deleted file mode 100644 index f321bd176..000000000 --- a/arch/cpu/msp430/mtarch.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2005, Swedish Institute of Computer Science - * 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. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - */ -#ifndef MTARCH_H_ -#define MTARCH_H_ - -#include "contiki.h" - -#ifndef MTARCH_STACKSIZE -#define MTARCH_STACKSIZE 128 -#endif /* MTARCH_STACKSIZE */ - -struct mtarch_thread { - unsigned short stack[MTARCH_STACKSIZE]; - unsigned short *sp; - void *data; - void (* function)(void *); -}; - -struct mt_thread; - -int mtarch_stack_usage(struct mt_thread *t); - -#endif /* MTARCH_H_ */ diff --git a/arch/cpu/native/Makefile.native b/arch/cpu/native/Makefile.native index ba473a3d3..90a784e34 100644 --- a/arch/cpu/native/Makefile.native +++ b/arch/cpu/native/Makefile.native @@ -1,6 +1,6 @@ CONTIKI_CPU_DIRS = . net dev -CONTIKI_SOURCEFILES += mtarch.c rtimer-arch.c watchdog.c eeprom.c +CONTIKI_SOURCEFILES += rtimer-arch.c watchdog.c eeprom.c ### Compiler definitions CC ?= gcc diff --git a/arch/cpu/native/mtarch.c b/arch/cpu/native/mtarch.c deleted file mode 100644 index 397891efb..000000000 --- a/arch/cpu/native/mtarch.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2007, Swedish Institute of Computer Science. - * 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. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - * Author: Oliver Schmidt - * - * - */ - -#include "sys/mt.h" - -#ifndef MTARCH_STACKSIZE -#define MTARCH_STACKSIZE 4096 -#endif /* MTARCH_STACKSIZE */ - -#if defined(_WIN32) || defined(__CYGWIN__) - -#define WIN32_LEAN_AND_MEAN -#include - -static void *main_fiber; - -#elif defined(__linux) - -#include -#include -#include - -struct mtarch_t { - char stack[MTARCH_STACKSIZE]; - ucontext_t context; -}; - -static ucontext_t main_context; -static ucontext_t *running_context; -#elif defined(__APPLE) -/* No support for OS-X at the moment as swapcontext, etc are deprecated */ - -#endif /* _WIN32 || __CYGWIN__ || __linux */ - -/*--------------------------------------------------------------------------*/ -void -mtarch_init(void) -{ -#if defined(_WIN32) || defined(__CYGWIN__) - - main_fiber = ConvertThreadToFiber(NULL); - -#endif /* _WIN32 || __CYGWIN__ */ -} -/*--------------------------------------------------------------------------*/ -void -mtarch_remove(void) -{ -#if defined(_WIN32) || defined(__CYGWIN__) - - ConvertFiberToThread(); - -#endif /* _WIN32 || __CYGWIN__ */ -} -/*--------------------------------------------------------------------------*/ -void -mtarch_start(struct mtarch_thread *thread, - void (* function)(void *data), - void *data) -{ -#if defined(_WIN32) || defined(__CYGWIN__) - - thread->mt_thread = CreateFiber(0, (LPFIBER_START_ROUTINE)function, data); - -#elif defined(__linux) - - thread->mt_thread = malloc(sizeof(struct mtarch_t)); - - getcontext(&((struct mtarch_t *)thread->mt_thread)->context); - - ((struct mtarch_t *)thread->mt_thread)->context.uc_link = NULL; - ((struct mtarch_t *)thread->mt_thread)->context.uc_stack.ss_sp = - ((struct mtarch_t *)thread->mt_thread)->stack; - ((struct mtarch_t *)thread->mt_thread)->context.uc_stack.ss_size = - sizeof(((struct mtarch_t *)thread->mt_thread)->stack); - - /* Some notes: - - If a CPU needs stronger alignment for the stack than malloc() - guarantees (like i.e. IA64) then makecontext() is supposed to - add that alignment internally. - - According to POSIX the arguments to function() are of type int - and there are in fact 64-bit implementations which support only - 32 bits per argument meaning that a pointer argument has to be - splitted into two arguments. - - Most implementations interpret context.uc_stack.ss_sp on entry - as the lowest stack address even if the CPU stack actually grows - downwards. Although this means that ss_sp does NOT represent the - CPU stack pointer this behaviour makes perfectly sense as it is - the only way to stay independent from the CPU architecture. But - Solaris prior to release 10 interprets ss_sp as highest stack - address thus requiring special handling. */ - makecontext(&((struct mtarch_t *)thread->mt_thread)->context, - (void (*)(void))function, 1, data); - -#endif /* _WIN32 || __CYGWIN__ || __linux */ -} -/*--------------------------------------------------------------------------*/ -void -mtarch_yield(void) -{ -#if defined(_WIN32) || defined(__CYGWIN__) - - SwitchToFiber(main_fiber); - -#elif defined(__linux) - - swapcontext(running_context, &main_context); - -#endif /* _WIN32 || __CYGWIN__ || __linux */ -} -/*--------------------------------------------------------------------------*/ -void -mtarch_exec(struct mtarch_thread *thread) -{ -#if defined(_WIN32) || defined(__CYGWIN__) - - SwitchToFiber(thread->mt_thread); - -#elif defined(__linux) - running_context = &((struct mtarch_t *)thread->mt_thread)->context; - swapcontext(&main_context, running_context); - running_context = NULL; - -#endif /* _WIN32 || __CYGWIN__ || __linux */ -} -/*--------------------------------------------------------------------------*/ -void -mtarch_stop(struct mtarch_thread *thread) -{ -#if defined(_WIN32) || defined(__CYGWIN__) - - DeleteFiber(thread->mt_thread); - -#elif defined(linux) || defined(__linux) - free(thread->mt_thread); - -#endif /* _WIN32 || __CYGWIN__ || __linux */ -} -/*--------------------------------------------------------------------------*/ -void -mtarch_pstart(void) -{ -} -/*--------------------------------------------------------------------------*/ -void -mtarch_pstop(void) -{ -} -/*--------------------------------------------------------------------------*/ diff --git a/arch/cpu/native/mtarch.h b/arch/cpu/native/mtarch.h deleted file mode 100644 index d006c1360..000000000 --- a/arch/cpu/native/mtarch.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2007, Swedish Institute of Computer Science. - * 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. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - * Author: Oliver Schmidt - * - */ - -#ifndef MTARCH_H_ -#define MTARCH_H_ - -struct mtarch_thread { - void *mt_thread; -}; - -#endif /* MTARCH_H_ */ diff --git a/arch/cpu/nrf52832/mtarch.h b/arch/cpu/nrf52832/mtarch.h deleted file mode 100644 index 4f696669d..000000000 --- a/arch/cpu/nrf52832/mtarch.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - Computer Science - * 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. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - */ -/* - * \file - * Stub header file for multi-threading. It doesn't do anything, it - * just exists so that mt.c can compile cleanly. - * - * This is based on the original mtarch.h for z80 by Takahide Matsutsuka - * - * \author - * George Oikonomou - - */ -#ifndef __MTARCH_H__ -#define __MTARCH_H__ - -struct mtarch_thread { - unsigned char *sp; -}; - -#endif /* __MTARCH_H__ */ diff --git a/arch/platform/jn516x/Makefile.jn516x b/arch/platform/jn516x/Makefile.jn516x index bf1560e31..8664f9f0a 100644 --- a/arch/platform/jn516x/Makefile.jn516x +++ b/arch/platform/jn516x/Makefile.jn516x @@ -82,7 +82,7 @@ OBJDUMP:=$(CROSS_COMPILE)-objdump ARCH = jn516x-ccm-star.c exceptions.c rtimer-arch.c rtimer-arch-slow.c \ slip_uart0.c clock.c micromac-radio.c \ - mtarch.c node-id.c watchdog.c slip.c sprintf.c + node-id.c watchdog.c slip.c sprintf.c # Default uart0 for printf and slip TARGET_WITH_UART0 ?= 1 TARGET_WITH_UART1 ?= 0 diff --git a/arch/platform/jn516x/dev/mtarch.c b/arch/platform/jn516x/dev/mtarch.c deleted file mode 100644 index c3c81457e..000000000 --- a/arch/platform/jn516x/dev/mtarch.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2008 - * Telecooperation Office (TecO), Universitaet Karlsruhe (TH), Germany. - * 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. Neither the name of the Universitaet Karlsruhe (TH) nor the names - * of its contributors may be used to endorse or promote products - * derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT - * OWNER 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. - * - * Author(s): Philipp Scholl - */ - -/* Copied from Philipp Scholl's (BSD) Contiki port to Jennic */ - -#include "mtarch.h" - -void -mtarch_init(void) -{ -} -void -mtarch_remove(void) -{ -} -void -mtarch_start(struct mtarch_thread *thread, - void (*function)(void *data), - void *data) -{ -} -void -mtarch_yield(void) -{ -} -void -mtarch_exec(struct mtarch_thread *thread) -{ -} -void -mtarch_stop(struct mtarch_thread *thread) -{ -} -void -mtarch_pstart(void) -{ -} -void -mtarch_pstop(void) -{ -} diff --git a/arch/platform/jn516x/dev/mtarch.h b/arch/platform/jn516x/dev/mtarch.h deleted file mode 100644 index 3c6292f1d..000000000 --- a/arch/platform/jn516x/dev/mtarch.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2008 - * Telecooperation Office (TecO), Universitaet Karlsruhe (TH), Germany. - * 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. Neither the name of the Universitaet Karlsruhe (TH) nor the names - * of its contributors may be used to endorse or promote products - * derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT - * OWNER 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. - * - * Author(s): Philipp Scholl - */ - -/* Copied from Philipp Scholl's (BSD) Contiki port to Jennic */ - -#ifndef __MTARCH_H__ -#define __MTARCH_H__ - -struct mtarch_thread { - void *mt_thread; -}; - -#endif /* __MTARCH_H__ */ diff --git a/os/sys/mt.c b/os/sys/mt.c deleted file mode 100644 index d5bc10398..000000000 --- a/os/sys/mt.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * 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. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - * Author: Adam Dunkels - * - */ - -/** - * \file - * Implementation of the archtecture agnostic parts of the preemptive - * multithreading library for Contiki. - * - * \author - * Adam Dunkels - * - */ - -#include "contiki.h" -#include "sys/mt.h" -#include "sys/cc.h" - -static struct mt_thread *current; - -/*--------------------------------------------------------------------------*/ -void -mt_init(void) -{ - mtarch_init(); -} -/*--------------------------------------------------------------------------*/ -void -mt_remove(void) -{ - mtarch_remove(); -} -/*--------------------------------------------------------------------------*/ -void -mt_start(struct mt_thread *thread, void (* function)(void *), void *data) -{ - /* Call the architecture dependant function to set up the processor - stack with the correct parameters. */ - mtarch_start(&thread->thread, function, data); - - thread->state = MT_STATE_STARTED; -} -/*--------------------------------------------------------------------------*/ -void -mt_exec(struct mt_thread *thread) -{ - if(thread->state == MT_STATE_STARTED) { - current = thread; - /* Switch context to the thread. The function call will not return - until the the thread has yielded, or is preempted. */ - mtarch_exec(&thread->thread); - } -} -/*--------------------------------------------------------------------------*/ -void -mt_yield(void) -{ - mtarch_pstop(); - /* This function is called from the running thread, and we call the - switch function in order to switch the thread to the main Contiki - program instead. For us, the switch function will not return - until the next time we are scheduled to run. */ - mtarch_yield(); -} -/*--------------------------------------------------------------------------*/ -void -mt_exit(void) -{ - mtarch_pstop(); - current->state = MT_STATE_EXITED; - mtarch_yield(); -} -/*--------------------------------------------------------------------------*/ -void -mt_stop(struct mt_thread *thread) -{ - mtarch_stop(&thread->thread); -} -/*--------------------------------------------------------------------------*/ diff --git a/os/sys/mt.h b/os/sys/mt.h deleted file mode 100644 index abe04d12e..000000000 --- a/os/sys/mt.h +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2004, Swedish Institute of Computer Science. - * 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. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE 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. - * - * This file is part of the Contiki operating system. - * - * Author: Adam Dunkels - * - */ - -/** \addtogroup threads - * @{ - */ - -/** - * \defgroup mt Multi-threading library - * - * The event driven Contiki kernel does not provide multi-threading - * by itself - instead, preemptive multi-threading is implemented - * as a library that optionally can be linked with applications. This - * library consists of two parts: a platform independent part, which is - * the same for all platforms on which Contiki runs, and a platform - * specific part, which must be implemented specifically for the - * platform that the multi-threading library should run. - * @{ - * - * The Contiki multi-threading library requires some architecture - * specific support for setting up and switching stacks. This support - * requires four stack manipulation functions to be implemented: - * mtarch_start(), which sets up the stack frame for a new thread, - * mtarch_exec(), which switches in the stack of a thread, - * mtarch_yield(), which restores the kernel stack from a thread's - * stack and mtarch_stop(), which cleans up the stack of a thread. - * Additionally, two functions for controlling the preemption - * (if any) must be implemented: mtarch_pstart() and mtarch_pstop(). - * If no preemption is used, these functions can be implemented as - * empty functions. Finally, the function mtarch_init() is called by - * mt_init(), and can be used for initialization of timer interrupts, - * or any other mechanisms required for correct operation of the - * architecture specific support functions while mtarch_remove() is - * called by mt_remove() to clean up those resources. - * - */ - -/** - * \file - * Header file for the preemptive multitasking library for Contiki. - * \author - * Adam Dunkels - * - */ -#ifndef MT_H_ -#define MT_H_ - -#include "contiki.h" - -#define MT_STATE_STARTED 1 -#define MT_STATE_EXITED 2 - -/** - * An opaque structure that is used for holding the state of a thread. - * - * The structure should be defined in the "mtarch.h" file. This - * structure typically holds the entire stack for the thread. - */ -struct mtarch_thread; - -/** - * Initialize the architecture specific support functions for the - * multi-thread library. - * - * This function is implemented by the architecture specific functions - * for the multi-thread library and is called by the mt_init() - * function as part of the initialization of the library. The - * mtarch_init() function can be used for, e.g., starting preemption - * timers or other architecture specific mechanisms required for the - * operation of the library. - */ -void mtarch_init(void); - -/** - * Uninstall library and clean up. - * - */ -void mtarch_remove(void); - -/** - * Setup the stack frame for a thread that is being started. - * - * This function is called by the mt_start() function in order to set - * up the architecture specific stack of the thread to be started. - * - * \param thread A pointer to a struct mtarch_thread for the thread to - * be started. - * - * \param function A pointer to the function that the thread will - * start executing the first time it is scheduled to run. - * - * \param data A pointer to the argument that the function should be - * passed. - */ -void mtarch_start(struct mtarch_thread *thread, - void (* function)(void *data), - void *data); - -/** - * Start executing a thread. - * - * This function is called from mt_exec() and the purpose of the - * function is to start execution of the thread. The function should - * switch in the stack of the thread, and does not return until the - * thread has explicitly yielded (using mt_yield()) or until it is - * preempted. - * - * \param thread A pointer to a struct mtarch_thread for the thread to - * be executed. - * - */ -void mtarch_exec(struct mtarch_thread *thread); - -/** - * Yield the processor. - * - * This function is called by the mt_yield() function, which is called - * from the running thread in order to give up the processor. - * - */ -void mtarch_yield(void); - -/** - * Clean up the stack of a thread. - * - * This function is called by the mt_stop() function in order to clean - * up the architecture specific stack of the thread to be stopped. - * - * \note If the stack is wholly contained in struct mtarch_thread this - * function may very well be empty. - * - * \param thread A pointer to a struct mtarch_thread for the thread to - * be stopped. - * - */ -void mtarch_stop(struct mtarch_thread *thread); - -void mtarch_pstart(void); -void mtarch_pstop(void); - -/** @} */ - - -#include "mtarch.h" - -struct mt_thread { - int state; - struct mtarch_thread thread; -}; - -/** - * Initializes the multithreading library. - * - */ -void mt_init(void); - -/** - * Uninstalls library and cleans up. - * - */ -void mt_remove(void); - - -/** - * Starts a multithreading thread. - * - * \param thread Pointer to an mt_thread struct that must have been - * previously allocated by the caller. - * - * \param function A pointer to the entry function of the thread that is - * to be set up. - * - * \param data A pointer that will be passed to the entry function. - * - */ -void mt_start(struct mt_thread *thread, void (* function)(void *), void *data); - -/** - * Execute parts of a thread. - * - * This function is called by a Contiki process and runs a - * thread. The function does not return until the thread has yielded, - * or is preempted. - * - * \note The thread library must first be initialized with the mt_init() - * function. - * - * \param thread A pointer to a struct mt_thread block that must be - * allocated by the caller. - * - */ -void mt_exec(struct mt_thread *thread); - -/** - * Voluntarily give up the processor. - * - * This function is called by a running thread in order to give up - * control of the CPU. - * - */ -void mt_yield(void); - -/** - * Exit a thread. - * - * This function is called from within an executing thread in order to - * exit the thread. The function never returns. - * - */ -void mt_exit(void); - -/** - * Stop a thread. - * - * This function is called by a Contiki process in order to clean up a - * thread. The struct mt_thread block may then be discarded by the caller. - * - * \param thread A pointer to a struct mt_thread block that must be - * allocated by the caller. - * - */ -void mt_stop(struct mt_thread *thread); - -/** @} */ -#endif /* MT_H_ */ diff --git a/tools/sky/check-size b/tools/sky/check-size index fc0bb9429..99a8c6257 100755 --- a/tools/sky/check-size +++ b/tools/sky/check-size @@ -9,7 +9,6 @@ @sky = ( "battery-sensor", "button-sensor", "cfs-xmem", "clock", "contiki-sky-main", "ds2411", "flash", "msp430", - "mtarch", "i2c", "leds-arch", "light", "radio-sensor", "sht11", "simple-cc2420-arch", "simple-cc2420", "spi", "slip", "uart1", "watchdog", "xmem", "rtimer-arch" );