contiki-msb430-main.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <io.h>
00041 #include <signal.h>
00042
00043 #include <stdio.h>
00044 #include <string.h>
00045
00046 #include "contiki.h"
00047 #include "contiki-msb430.h"
00048 #include "dev/adc.h"
00049 #include "dev/sd.h"
00050 #include "dev/serial-line.h"
00051 #include "dev/sht11.h"
00052 #include "dev/watchdog.h"
00053
00054 extern volatile bool uart_edge;
00055
00056 extern void init_net(void);
00057
00058 SENSORS(NULL);
00059
00060 static void
00061 msb_ports_init(void)
00062 {
00063 P1SEL = 0x00; P1OUT = 0x00; P1DIR = 0x00;
00064 P2SEL = 0x00; P2OUT = 0x18; P2DIR = 0x1A;
00065 P3SEL = 0x00; P3OUT = 0x09; P3DIR = 0x21;
00066 P4SEL = 0x00; P4OUT = 0x00; P4DIR = 0x00;
00067 P5SEL = 0x0E; P5OUT = 0xF9; P5DIR = 0xFD;
00068 P6SEL = 0x07; P6OUT = 0x00; P6DIR = 0xC8;
00069 }
00070
00071 int
00072 main(void)
00073 {
00074 #if WITH_SD
00075 int r;
00076 #endif
00077
00078 msp430_cpu_init();
00079 watchdog_stop();
00080
00081
00082 msb_ports_init();
00083 adc_init();
00084
00085 clock_init();
00086 rtimer_init();
00087
00088 sht11_init();
00089 leds_init();
00090 leds_on(LEDS_ALL);
00091
00092 process_init();
00093
00094
00095 rs232_set_input(serial_line_input_byte);
00096 rs232_init();
00097 serial_line_init();
00098
00099 uart_lock(UART_MODE_RS232);
00100 uart_unlock(UART_MODE_RS232);
00101 #if WITH_UIP
00102 slip_arch_init(BAUD2UBR(115200));
00103 #endif
00104
00105
00106 #if WITH_SD
00107 r = sd_initialize();
00108 if(r < 0) {
00109 printf("Failed to initialize the SD driver: %s\n", sd_error_string(r));
00110 } else {
00111 sd_offset_t capacity;
00112 printf("The SD driver was successfully initialized\n");
00113 capacity = sd_get_capacity();
00114 if(capacity < 0) {
00115 printf("Failed to get the SD card capacity: %s\n", sd_error_string(r));
00116 } else {
00117 printf("SD card capacity: %u MB\n",
00118 (unsigned)(capacity / (1024UL * 1024)));
00119 }
00120 }
00121 #endif
00122
00123 node_id_restore();
00124
00125
00126 process_start(&etimer_process, NULL);
00127 ctimer_init();
00128
00129
00130 NETSTACK_RADIO.init();
00131 NETSTACK_RDC.init();
00132 NETSTACK_MAC.init();
00133 NETSTACK_NETWORK.init();
00134 {
00135 rimeaddr_t rimeaddr;
00136
00137 rimeaddr.u8[0] = node_id & 0xff;
00138 rimeaddr.u8[1] = node_id >> 8;
00139 rimeaddr_set_node_addr(&rimeaddr);
00140 }
00141
00142 energest_init();
00143
00144 #if PROFILE_CONF_ON
00145 profile_init();
00146 #endif
00147
00148 leds_off(LEDS_ALL);
00149
00150 printf("Node %d.%d: %s %s, channel check rate %u Hz\n",
00151 rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
00152 NETSTACK_MAC.name, NETSTACK_RDC.name,
00153 CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ?
00154 1 : (unsigned)NETSTACK_RDC.channel_check_interval()));
00155
00156 autostart_start(autostart_processes);
00157
00158
00159
00160
00161 ENERGEST_ON(ENERGEST_TYPE_CPU);
00162
00163 while (1) {
00164 int r;
00165 #if PROFILE_CONF_ON
00166 profile_episode_start();
00167 #endif
00168 do {
00169
00170 watchdog_periodic();
00171 r = process_run();
00172 } while(r > 0);
00173
00174 #if PROFILE_CONF_ON
00175 profile_episode_end();
00176 #endif
00177
00178
00179
00180
00181 int s = splhigh();
00182 if (process_nevents() != 0) {
00183 splx(s);
00184 } else {
00185 static unsigned long irq_energest = 0;
00186
00187 ENERGEST_OFF(ENERGEST_TYPE_CPU);
00188 ENERGEST_ON(ENERGEST_TYPE_LPM);
00189
00190
00191
00192
00193
00194 energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
00195
00196 if (uart_edge) {
00197 _BIC_SR(LPM1_bits + GIE);
00198 } else {
00199 _BIS_SR(LPM1_bits + GIE);
00200 }
00201
00202
00203
00204
00205
00206 dint();
00207 irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
00208 eint();
00209 ENERGEST_OFF(ENERGEST_TYPE_LPM);
00210 ENERGEST_ON(ENERGEST_TYPE_CPU);
00211 #if PROFILE_CONF_ON
00212 profile_clear_timestamps();
00213 #endif
00214 }
00215 }
00216
00217 return 0;
00218 }