Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2004, Adam Dunkels. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the Contiki operating system. 00030 * 00031 * Author: Adam Dunkels <adam@sics.se> 00032 * 00033 * $Id: mtarch.c,v 1.1 2007/12/15 00:14:19 oliverschmidt Exp $ 00034 */ 00035 00036 #include <string.h> 00037 00038 #include "sys/mtarch.h" 00039 00040 unsigned char mtarch_asm_threadspreg; 00041 unsigned char *mtarch_asm_threadzp; 00042 unsigned char *mtarch_asm_threadstack; 00043 00044 void mtarch_asm_start(void); 00045 void mtarch_asm_yield(void); 00046 void mtarch_asm_exec(void); 00047 00048 /*--------------------------------------------------------------------------*/ 00049 void 00050 mtarch_init(void) 00051 { 00052 } 00053 /*--------------------------------------------------------------------------*/ 00054 void 00055 mtarch_remove(void) 00056 { 00057 } 00058 /*--------------------------------------------------------------------------*/ 00059 void 00060 mtarch_start(struct mtarch_thread *thread, 00061 void (* function)(void *data), 00062 void *data) 00063 { 00064 memset(thread->cpustack, 0, sizeof(thread->cpustack)); 00065 memset(thread->cstack, 0, sizeof(thread->cstack)); 00066 00067 /* Copy current zero page content as template. */ 00068 mtarch_asm_threadzp = thread->zp; 00069 mtarch_asm_start(); 00070 00071 /* Create a CPU stack frame with the appropriate values. */ 00072 thread->cpustack[MTARCH_CPUSTACKSIZE - 2] = ((unsigned short)function) / 0x100; /* high byte of return address */ 00073 thread->cpustack[MTARCH_CPUSTACKSIZE - 3] = ((unsigned short)function) % 0x100; /* low byte of return address */ 00074 thread->cpustack[MTARCH_CPUSTACKSIZE - 4] = 0x21; /* processor flags */ 00075 thread->cpustack[MTARCH_CPUSTACKSIZE - 5] = /* a register */ 00076 thread->cpustack[MTARCH_CPUSTACKSIZE - 6] = /* x register */ 00077 thread->cpustack[MTARCH_CPUSTACKSIZE - 7] = 0x00; /* y register */ 00078 thread->spreg = MTARCH_CPUSTACKSIZE - 8; 00079 00080 /* Setup the C stack with the data pointer. */ 00081 thread->cstack[MTARCH_CSTACKSIZE - 2] = ((unsigned short)data) / 0x100; /* high byte of data pointer */ 00082 thread->cstack[MTARCH_CSTACKSIZE - 3] = ((unsigned short)data) % 0x100; /* low byte of data pointer */ 00083 00084 /* Setup the C stack pointer. */ 00085 thread->zp[1] = ((size_t)&thread->cstack[MTARCH_CSTACKSIZE - 3]) / 0x100; /* high byte of C stack pointer */ 00086 thread->zp[0] = ((size_t)&thread->cstack[MTARCH_CSTACKSIZE - 3]) % 0x100; /* low byte of C stack pointer */ 00087 } 00088 /*--------------------------------------------------------------------------*/ 00089 void 00090 mtarch_yield(void) 00091 { 00092 mtarch_asm_yield(); 00093 } 00094 /*--------------------------------------------------------------------------*/ 00095 void 00096 mtarch_exec(struct mtarch_thread *thread) 00097 { 00098 /* Switch processor stack. The call to mtarch_asm_switch() will not 00099 return until the process that we switch to calls yield(). */ 00100 mtarch_asm_threadspreg = thread->spreg; 00101 00102 mtarch_asm_threadstack = thread->cpustack; 00103 mtarch_asm_threadzp = thread->zp; 00104 00105 mtarch_asm_exec(); 00106 00107 thread->spreg = mtarch_asm_threadspreg; 00108 } 00109 /*--------------------------------------------------------------------------*/ 00110 void 00111 mtarch_stop(struct mtarch_thread *thread) 00112 { 00113 } 00114 /*--------------------------------------------------------------------------*/ 00115 void 00116 mtarch_pstart(void) 00117 { 00118 } 00119 /*--------------------------------------------------------------------------*/ 00120 void 00121 mtarch_pstop(void) 00122 { 00123 } 00124 /*--------------------------------------------------------------------------*/