contiki-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
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
00103
00104 int8u *stm32w_eui64 = ST_RadioGetEui64();
00105 {
00106 int8u c;
00107 for(c = 0; c < 8; c++) {
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
00139
00140 halInit();
00141 clock_init();
00142
00143 uart1_init(115200);
00144
00145
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
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);
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
00192 watchdog_periodic();
00193 r = process_run();
00194 } while(r > 0);
00195
00196
00197
00198 ENERGEST_OFF(ENERGEST_TYPE_CPU);
00199
00200 ENERGEST_ON(ENERGEST_TYPE_LPM);
00201
00202 halSleepWithOptions(SLEEPMODE_IDLE,0);
00203
00204
00205 ENERGEST_OFF(ENERGEST_TYPE_LPM);
00206 ENERGEST_ON(ENERGEST_TYPE_CPU);
00207
00208 }
00209
00210 }
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 void Default_Handler()
00262 {
00263
00264 leds_on(LEDS_RED);
00265 halReboot();
00266 }