Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2006, Technical University of Munich 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 * @(#)$$ 00032 */ 00033 00034 /** 00035 * \file 00036 * Sample Contiki kernel for STK 501 development board 00037 * 00038 * \author 00039 * Simon Barner <barner@in.tum.de 00040 */ 00041 00042 /* Patched to allow hello-world ipv4 and ipv6 build */ 00043 00044 #include <avr/pgmspace.h> 00045 #include <stdio.h> 00046 #include "net/uip_arp.h" 00047 00048 #include "contiki-stk501.h" 00049 //#include "../core/cfs/cfs-eeprom.h" 00050 #include "cfs/cfs.h" 00051 #include "dev/eeprom.h" 00052 #include "lib/mmem.h" 00053 #include "loader/symbols-def.h" 00054 #include "loader/symtab.h" 00055 #include "../apps/codeprop/codeprop.h" 00056 #include "sys/mt.h" 00057 00058 /* Uncomment to enable demonstration of multi-threading libary */ 00059 /* #define MT_DEMO */ 00060 00061 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args) 00062 00063 //TODO: What happened to cfs_eeprom_process? 00064 //PROCINIT(&etimer_process, &tcpip_process, &uip_fw_process, &cfs_eeprom_process); 00065 #if UIP_CONF_IPV6 00066 PROCINIT(&etimer_process, &tcpip_process); 00067 #else 00068 PROCINIT(&etimer_process, &tcpip_process, &uip_fw_process); 00069 #endif 00070 00071 #ifdef MT_DEMO 00072 static struct mt_thread threads[3]; 00073 00074 static 00075 void thread_handler1 (void* data) { 00076 while (1) { 00077 PRINTF ("Thread 1. Data: 0x%x, %d\n", data, *(uint8_t*)data ); 00078 mt_yield (); 00079 } 00080 } 00081 00082 static 00083 void thread_handler2 (void* data) { 00084 while (1) { 00085 PRINTF ("Thread 2. Data: 0x%x, %d\n", data, *(uint8_t*)data ); 00086 mt_yield (); 00087 } 00088 } 00089 #endif 00090 00091 PROCESS(contiki_stk501_main_init_process, "Contiki STK501 init process"); 00092 PROCESS_THREAD(contiki_stk501_main_init_process, ev, data) 00093 { 00094 PROCESS_BEGIN(); 00095 00096 /* Network support (uIP) */ 00097 init_net(); 00098 00099 /* Initalize heap allocator */ 00100 mmem_init (); 00101 00102 /* Code propagator */ 00103 /* TODO: The core elfloader-avr.c has 16/32 bit pointer problems so this won't build */ 00104 //process_start(&codeprop_process, NULL); 00105 00106 /* Multi-threading support */ 00107 #ifdef MT_DEMO 00108 mt_init (); 00109 #endif 00110 00111 PROCESS_END(); 00112 } 00113 00114 #ifdef MT_DEMO 00115 static uint8_t d1=1, d2=2, d3=3; 00116 #endif 00117 00118 int 00119 main(void) 00120 { 00121 /* 00122 * GCC depends on register r1 set to 0. 00123 */ 00124 asm volatile ("clr r1"); 00125 00126 /* Initialize hardware */ 00127 init_lowlevel(); 00128 00129 /* Clock */ 00130 clock_init(); 00131 00132 /* Process subsystem */ 00133 process_init(); 00134 00135 /* Register initial processes */ 00136 procinit_init(); 00137 00138 /* Perform rest of initializations */ 00139 process_start(&contiki_stk501_main_init_process, NULL); 00140 00141 PRINTF("Initialized.\n"); 00142 00143 #ifdef MT_DEMO 00144 mt_start (&threads[0], thread_handler1, &d1); 00145 mt_start (&threads[1], thread_handler2, &d2); 00146 mt_start (&threads[2], thread_handler2, &d3); 00147 00148 uint8_t i; 00149 #endif 00150 00151 /* Main scheduler loop */ 00152 while(1) { 00153 00154 process_run(); 00155 00156 #ifdef MT_DEMO 00157 for (i=0; i<3; ++i) { 00158 mt_exec (&threads[i]); 00159 } 00160 #endif 00161 } 00162 00163 return 0; 00164 }