contiki-main.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, STMicroelectronics.
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
00011  *    copyright notice, this list of conditions and the following
00012  *    disclaimer in the documentation and/or other materials provided
00013  *    with the distribution.
00014  * 3. The name of the author may not be used to endorse or promote
00015  *    products derived from this software without specific prior
00016  *    written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
00019  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00020  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00022  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00024  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  * This file is part of the Contiki OS
00031  *
00032  * $Id: contiki-main.c,v 1.2 2010/10/27 14:05:24 salvopitru Exp $
00033  */
00034 /*---------------------------------------------------------------------------*/
00035 /**
00036 * \file
00037 *                       Contiki main file.
00038 * \author
00039 *                       Salvatore Pitrulli <salvopitru@users.sourceforge.net>
00040 */
00041 /*---------------------------------------------------------------------------*/
00042 
00043 
00044 #include PLATFORM_HEADER
00045 #include "hal/error.h"
00046 #include "hal/hal.h"
00047 #include BOARD_HEADER
00048 #include "micro/adc.h"
00049 
00050 #include <stdio.h>
00051 
00052 
00053 #include "contiki.h"
00054 
00055 #include "dev/watchdog.h"
00056 #include "dev/leds.h"
00057 #include "dev/button-sensor.h"
00058 #include "dev/temperature-sensor.h"
00059 #include "dev/acc-sensor.h"
00060 #include "dev/uart1.h"
00061 #include "dev/serial-line.h"
00062 
00063 #include "dev/stm32w-radio.h"
00064 #include "net/netstack.h"
00065 #include "net/rime/rimeaddr.h"
00066 #include "net/rime.h"
00067 #include "net/rime/rime-udp.h"
00068 #include "net/uip.h"
00069 
00070 
00071 #define DEBUG 1
00072 #if DEBUG
00073 #include <stdio.h>
00074 #define PRINTF(...) printf(__VA_ARGS__)
00075 #define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
00076 #define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",lladdr.u8[0], lladdr.u8[1], lladdr.u8[2], lladdr.u8[3],lladdr.u8[4], lladdr.u8[5], lladdr.u8[6], lladdr.u8[7])
00077 #else
00078 #define PRINTF(...)
00079 #define PRINT6ADDR(addr)
00080 #define PRINTLLADDR(addr)
00081 #endif
00082 
00083 
00084 #if UIP_CONF_IPV6
00085 PROCINIT(&etimer_process, &tcpip_process, &sensors_process);
00086 #else
00087 PROCINIT(&etimer_process, &sensors_process);
00088 #warning "No TCP/IP process!"
00089 #endif
00090 
00091 SENSORS(&button_sensor,&temperature_sensor,&acc_sensor);
00092 
00093 /*---------------------------------------------------------------------------*/
00094 static void
00095 set_rime_addr(void)
00096 {
00097   int i;
00098   union {
00099     u8_t u8[8];
00100   }eui64;
00101   
00102   //rimeaddr_t lladdr;
00103   
00104   int8u *stm32w_eui64 = ST_RadioGetEui64();
00105   {
00106           int8u c;
00107           for(c = 0; c < 8; c++) {      // Copy the EUI-64 to lladdr converting from Little-Endian to Big-Endian.
00108                   eui64.u8[c] = stm32w_eui64[7 - c];
00109           }
00110   }
00111   PRINTF("\n\rRadio EUI-64:");
00112   PRINTLLADDR(eui64);
00113   PRINTF("\n\r");
00114   
00115 #if UIP_CONF_IPV6
00116   memcpy(&uip_lladdr.addr, &eui64, sizeof(uip_lladdr.addr));
00117 #endif
00118 
00119 #if UIP_CONF_IPV6
00120   rimeaddr_set_node_addr((rimeaddr_t *)&eui64);
00121 #else  
00122   rimeaddr_set_node_addr((rimeaddr_t *)&eui64.u8[8-RIMEADDR_SIZE]);
00123 #endif
00124 
00125   printf("Rime started with address ");
00126   for(i = 0; i < sizeof(rimeaddr_t) - 1; i++) {
00127     printf("%d.", rimeaddr_node_addr.u8[i]);
00128   }
00129   printf("%d\n", rimeaddr_node_addr.u8[i]);
00130   
00131 }
00132 /*---------------------------------------------------------------------------*/
00133 int
00134 main(void)
00135 {
00136   
00137   /*
00138    * Initalize hardware.
00139    */
00140   halInit();
00141   clock_init();
00142   
00143   uart1_init(115200);
00144   
00145   // Led initialization
00146   leds_init();
00147     
00148   INTERRUPTS_ON(); 
00149 
00150   PRINTF("\r\nStarting ");
00151   PRINTF(CONTIKI_VERSION_STRING);
00152   PRINTF(" on MB851\r\n"); 
00153 
00154   /*
00155    * Initialize Contiki and our processes.
00156    */
00157   
00158   process_init();
00159   
00160 #if WITH_SERIAL_LINE_INPUT
00161   uart1_set_input(serial_line_input_byte);
00162   serial_line_init();
00163 #endif
00164   
00165   netstack_init();
00166 #if !UIP_CONF_IPV6
00167   ST_RadioEnableAutoAck(FALSE); // Because frames are not 802.15.4 compatible. 
00168   ST_RadioEnableAddressFiltering(FALSE);
00169 #endif
00170 
00171   set_rime_addr();
00172   
00173   ctimer_init();
00174   rtimer_init();
00175   
00176   procinit_init();    
00177 
00178   energest_init();
00179   ENERGEST_ON(ENERGEST_TYPE_CPU);
00180   
00181   autostart_start(autostart_processes);
00182   
00183   
00184   watchdog_start();
00185   
00186   while(1){
00187     
00188     int r;    
00189     
00190     do {
00191       /* Reset watchdog. */
00192       watchdog_periodic();
00193       r = process_run();
00194     } while(r > 0);
00195     
00196     
00197     
00198     ENERGEST_OFF(ENERGEST_TYPE_CPU);
00199     //watchdog_stop();    
00200     ENERGEST_ON(ENERGEST_TYPE_LPM);
00201     /* Go to idle mode. */
00202     halSleepWithOptions(SLEEPMODE_IDLE,0);
00203     /* We are awake. */
00204     //watchdog_start();
00205     ENERGEST_OFF(ENERGEST_TYPE_LPM);
00206     ENERGEST_ON(ENERGEST_TYPE_CPU);  
00207     
00208   }
00209   
00210 }
00211 
00212 
00213 
00214 /*int8u errcode __attribute__(( section(".noinit") ));
00215 
00216 void halBaseBandIsr(){
00217   
00218   errcode = 1;
00219   leds_on(LEDS_RED);
00220 }
00221 
00222 void BusFault_Handler(){
00223   
00224   errcode = 2; 
00225   leds_on(LEDS_RED);
00226 }
00227 
00228 void halDebugIsr(){
00229   
00230   errcode = 3;
00231   leds_on(LEDS_RED);  
00232 }
00233 
00234 void DebugMon_Handler(){
00235   
00236   errcode = 4;
00237   //leds_on(LEDS_RED);  
00238 }
00239 
00240 void HardFault_Handler(){
00241   
00242   errcode = 5; 
00243   //leds_on(LEDS_RED);
00244   //halReboot();
00245 }
00246 
00247 void MemManage_Handler(){
00248   
00249   errcode = 6; 
00250   //leds_on(LEDS_RED);
00251   //halReboot();
00252 }
00253 
00254 void UsageFault_Handler(){
00255   
00256   errcode = 7; 
00257   //leds_on(LEDS_RED);
00258   //halReboot();
00259 }*/
00260 
00261 void Default_Handler() 
00262 { 
00263   //errcode = 8; 
00264   leds_on(LEDS_RED);
00265   halReboot();
00266 }

Generated on Mon Apr 11 14:23:41 2011 for Contiki 2.5 by  doxygen 1.6.1