contiki-avr-zigbit-main.c
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 #include <avr/pgmspace.h>
00035 #include <avr/fuse.h>
00036 #include <avr/eeprom.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039
00040 #include "lib/mmem.h"
00041 #include "loader/symbols-def.h"
00042 #include "loader/symtab.h"
00043
00044 #define ANNOUNCE_BOOT 0 //adds about 600 bytes to program size
00045 #define DEBUG 0
00046 #if DEBUG
00047 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
00048 #define PRINTSHORT(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
00049 #else
00050 #define PRINTF(...)
00051 #define PRINTSHORT(...)
00052 #endif
00053
00054 #if RF230BB //radio driver using contiki core mac
00055 #include "radio/rf230bb/rf230bb.h"
00056 #include "net/mac/frame802154.h"
00057 #include "net/mac/framer-802154.h"
00058 #include "net/sicslowpan.h"
00059 #else //radio driver using Atmel/Cisco 802.15.4'ish MAC
00060 #include <stdbool.h>
00061 #include "mac.h"
00062 #include "sicslowmac.h"
00063 #include "sicslowpan.h"
00064 #include "ieee-15-4-manager.h"
00065 #endif
00066
00067 #include "contiki.h"
00068 #include "contiki-net.h"
00069 #include "contiki-lib.h"
00070
00071 #include "dev/rs232.h"
00072 #include "dev/serial-line.h"
00073 #include "dev/slip.h"
00074
00075 #include "sicslowmac.h"
00076
00077 FUSES =
00078 {
00079 .low = (FUSE_CKSEL0 & FUSE_CKSEL2 & FUSE_CKSEL3 & FUSE_SUT0),
00080 .high = (FUSE_BOOTSZ0 & FUSE_SPIEN & FUSE_JTAGEN),
00081 .extended = 0xff,
00082 };
00083
00084 #if RF230BB
00085
00086 #else
00087 PROCINIT(&etimer_process, &mac_process, &tcpip_process );
00088 #endif
00089
00090 uint8_t mac_address[8] EEMEM = {0x02, 0x11, 0x22, 0xff, 0xfe, 0x33, 0x44, 0x55};
00091
00092
00093 void
00094 init_lowlevel(void)
00095 {
00096
00097
00098 rs232_init(RS232_PORT_1, USART_BAUD_115200,
00099 USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
00100
00101
00102 rs232_redirect_stdout(RS232_PORT_1);
00103
00104
00105 clock_init();
00106
00107
00108 rtimer_init();
00109
00110
00111 process_init();
00112
00113 process_start(&etimer_process, NULL);
00114
00115 #if RF230BB
00116
00117 ctimer_init();
00118
00119 NETSTACK_RADIO.init();
00120
00121
00122
00123 rimeaddr_t addr;
00124 memset(&addr, 0, sizeof(rimeaddr_t));
00125 eeprom_read_block ((void *)&addr.u8, &mac_address, 8);
00126
00127 #if UIP_CONF_IPV6
00128 memcpy(&uip_lladdr.addr, &addr.u8, 8);
00129 #endif
00130 rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *)&addr.u8);
00131 #ifdef CHANNEL_802_15_4
00132 rf230_set_channel(CHANNEL_802_15_4);
00133 #else
00134 rf230_set_channel(26);
00135 #endif
00136
00137 rimeaddr_set_node_addr(&addr);
00138
00139 PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
00140
00141
00142 queuebuf_init();
00143 NETSTACK_RDC.init();
00144 NETSTACK_MAC.init();
00145 NETSTACK_NETWORK.init();
00146
00147 #if ANNOUNCE_BOOT
00148 printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
00149 if (NETSTACK_RDC.channel_check_interval) {
00150 unsigned short tmp;
00151 tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
00152 NETSTACK_RDC.channel_check_interval());
00153 if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp);
00154 }
00155 printf_P(PSTR("\n"));
00156 #endif
00157
00158 #if UIP_CONF_ROUTER
00159 #if ANNOUNCE_BOOT
00160 printf_P(PSTR("Routing Enabled\n"));
00161 #endif
00162 rime_init(rime_udp_init(NULL));
00163 uip_router_register(&rimeroute);
00164 #endif
00165
00166 process_start(&tcpip_process, NULL);
00167
00168 #else
00169
00170 process_start(&mac_process, NULL);
00171 process_start(&tcpip_process, NULL);
00172 #endif
00173
00174 }
00175
00176
00177 int
00178 main(void)
00179 {
00180
00181
00182
00183 init_lowlevel();
00184
00185
00186
00187
00188
00189 autostart_start(autostart_processes);
00190
00191 printf_P(PSTR("\n********BOOTING CONTIKI*********\n"));
00192
00193 printf_P(PSTR("System online.\n"));
00194
00195
00196 while(1) {
00197 process_run();
00198 }
00199
00200 return 0;
00201 }