PROCESS_THREAD(example_coffee_process, ev, data) { PROCESS_BEGIN(); #define SDCARD #ifdef SDCARD uSDcard_init(); printf("sdcard initialised.\n"); #endif #if NEED_FORMATTING cfs_coffee_format(); #endif /* Ensure that we will be working with a new file. */ cfs_remove(FILENAME); if (file_test(FILENAME, "The first test") == 0) { printf("file test 1 failed\n"); } if (file_test(FILENAME, "The second test") == 0) { printf("file test 2 failed\n"); } if (dir_test() == 0) { printf("dir test failed\n"); } PROCESS_END(); }
PROCESS_THREAD(onboard_flash_test_process, ev, data) { PROCESS_BEGIN(); etimer_set(&et, CLOCK_SECOND * 5); PROCESS_YIELD_UNTIL(etimer_expired(&et)); while(RUNNING) { printf("Starting test...\n"); int ret = coffee_file_test(); printf("Test finished with %d\n", ret); printf("Result: "); if( ret == 0 ) { printf("SUCCESS\n"); RUNNING = 0; } else { printf("FAILURE\n"); printf("Formatting Flash..."); fflush(stdout); cfs_coffee_format(); printf("OK\n"); } etimer_set(&et, CLOCK_SECOND * 60); PROCESS_YIELD_UNTIL(etimer_expired(&et)); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(testcoffee_process, ev, data) { int start; int result; PROCESS_BEGIN(); start = clock_seconds(); printf("Coffee test started\n"); result = cfs_coffee_format(); print_result("Formatting", result); result = coffee_test_basic(); print_result("Basic operations", result); result = coffee_test_append(); print_result("File append", result); result = coffee_test_modify(); print_result("File modification", result); result = coffee_test_gc(); print_result("Garbage collection", result); printf("Coffee test finished. Duration: %d seconds\n", (int)(clock_seconds() - start)); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ static void copy_file_from_romfs_to_cfs(const char * from, const char * to) { static char buf[128]; cfs_offset_t filesize, read, pos; /* Format CFS */ cfs_coffee_format(); /* Open file for writing in CFS */ int cfs_fd = cfs_open(to, CFS_WRITE); /* Open file for reading in ROMFS */ int rom_fd = romfs_open(from, CFS_READ); /* Determine file size */ filesize = romfs_seek(rom_fd, 0, CFS_SEEK_END) - 1; /* Restore offset to start of file */ romfs_seek(rom_fd, 0, CFS_SEEK_SET); /* Copy file data from romfs to cfs in chunks of 128 bytes */ for (pos = 0; pos < filesize; pos += read) { read = romfs_read(rom_fd, buf, sizeof(buf)); cfs_write(cfs_fd, buf, read); } /* Close both files */ cfs_close(cfs_fd); romfs_close(rom_fd); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udpstream_process, ev, data) { static uint16_t streamno; static struct etimer et; static uip_ipaddr_t *ipaddr; PROCESS_BEGIN(); PROCESS_PAUSE(); printf("Formatting Coffee FS...\n"); cfs_coffee_format(); printf("done.\n"); /* We need re-initialize queuebuf after formatting */ queuebuf_init(); /* Start service registration */ servreg_hack_init(); ipaddr = set_global_address(); if(node_id == SINK_ID) { /* The sink creates a dag and waits for UDP datagrams */ create_rpl_dag(ipaddr); servreg_hack_register(SERVICE_ID, ipaddr); simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); while(1) { PROCESS_WAIT_EVENT(); } } else if(node_id == SENDER_ID) { /* The sender looks for the sink and sends UDP streams */ ipaddr = NULL; simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); etimer_set(&et, 10*CLOCK_SECOND); etimer_restart(&et); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); if(ipaddr != NULL) { streamno++; send_stream(ipaddr, streamno); } else { ipaddr = servreg_hack_lookup(SERVICE_ID); if(ipaddr != NULL) { etimer_set(&et, 2*CLOCK_SECOND); printf("Streaming to "); uip_debug_ipaddr_print(ipaddr); printf("\n"); } else { printf("Service %d not found\n", SERVICE_ID); } } etimer_restart(&et); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(flash_format_process, ev, data) { PROCESS_BEGIN(); cfs_coffee_format(); PROCESS_END(); }
int logging_format(void) { if(log_state == LOGGING_NOT_INIT || log_state == LOGGING_FATAL_ERROR){ return 1; /* Don't even try, we're not ready */ } /* If writing to flash, then wait till we're done */ while(log_state == LOGGING_BUSY){ ; } if(cfs_coffee_format() == 0) { printf("Logging-format complete\n"); return 0; } else { printf("FATAL: Logging-format failed\n"); return 1; /* no success in removal of file */ } }
int main() { init(); printf("\n\nFirmware info - git: " GIT_VERSION ", built: " __DATE__ " " __TIME__ "\n"); printf("--- COFFEE TEST ---\n"); char buf[80] = "Hello, world\n"; int ret = cfs_coffee_format(); if (ret < 0) while(1); int fd = cfs_open("test", CFS_READ | CFS_WRITE); if(fd >= 0) { ret = cfs_write(fd, buf, strlen(buf)); if (ret < 0) while(1); ret = cfs_write(fd, "JELLO\n", 7); if (ret < 0) while(1); ret = cfs_seek(fd, 0, CFS_SEEK_SET); if (ret < 0) while(1); ret = cfs_read(fd, buf, sizeof(buf)); if (ret < 0) while(1); printf("Read message: %s\n", buf); ret = cfs_seek(fd, 0, CFS_SEEK_SET); if (ret < 0) while(1); ret = cfs_write(fd, "JELLO", 5); if (ret < 0) while(1); ret = cfs_seek(fd, 0, CFS_SEEK_SET); if (ret < 0) while(1); ret = cfs_read(fd, buf, sizeof(buf)); if (ret < 0) while(1); printf("Read message: %s\n", buf); cfs_close(fd); if (ret < 0) while(1); } while (1); return 0; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(console_server, ev, data) { static uint8_t buf[257]; static uint8_t processingFile = 0; static uint32_t received = 0; static struct cfs_dirent dirent; static struct cfs_dir dir; static uint32_t fdFile; static char *filename; PROCESS_BEGIN(); elfloader_init(); printf("Console server started !\n"); while(1) { PROCESS_YIELD(); if (ev == serial_line_event_message) { if (!strcmp(data, "ls")) { if(cfs_opendir(&dir, ".") == 0) { while(cfs_readdir(&dir, &dirent) != -1) { printf("File: %s (%ld bytes)\n", dirent.name, (long)dirent.size); } cfs_closedir(&dir); } } else if (!strcmp(data, "format")) { /* format the flash */ printf("Formatting\n"); printf("It takes around 3 minutes\n"); printf("...\n"); fdFile = cfs_coffee_format(); printf("Formatted with result %ld\n", fdFile); } else if (strstr(data, "cat") == data) { int n, jj; char* tmp = strstr(data, " "); tmp++; fdFile = cfs_open(tmp, CFS_READ); if (fdFile < 0) printf("error opening the file %s\n", tmp); while ((n = cfs_read(fdFile, buf, 60)) > 0) { for (jj = 0 ; jj < n ; jj++) printf("%c", (char)buf[jj]); } printf("\n"); cfs_close(fdFile); if (n!=0) printf("Some error reading the file\n"); } else if (strstr(data, "loadelf") == data) { filename = strstr(data, " "); filename++; // Cleanup previous loads if (elfloader_autostart_processes != NULL) autostart_exit(elfloader_autostart_processes); elfloader_autostart_processes = NULL; // Load elf file fdFile = cfs_open(filename, CFS_READ | CFS_WRITE); received = elfloader_load(fdFile); cfs_close(fdFile); printf("Result of loading %lu\n", received); // As the file has been modified and can't be reloaded, remove it printf("Remove dirty firmware '%s'\n", filename); cfs_remove(filename); // execute the program if (ELFLOADER_OK == received) { if (elfloader_autostart_processes) { PRINT_PROCESSES(elfloader_autostart_processes); autostart_start(elfloader_autostart_processes); } } else if (ELFLOADER_SYMBOL_NOT_FOUND == received) { printf("Symbol not found: '%s'\n", elfloader_unknown); } } else if (strstr(data, "rm") == data) { int n, jj; char* tmp = strstr(data, " "); tmp++; cfs_remove(tmp); } else if (strstr(data, "upload") == data) { char* tmp = strstr(data, " "); tmp++; fdFile = cfs_open(tmp, CFS_READ | CFS_WRITE); printf("Uploading file %s\n", tmp); processingFile = 1; } else if (!strcmp(data, "endupload")) { cfs_close(fdFile); printf("File uploaded (%ld bytes)\n", received); received = 0; processingFile = 0; } else if (processingFile) { int n = strlen(data); int r = decode(data, n, buf); received += r; cfs_write(fdFile, buf, r); } else { printf("%s (%lu bytes received)\n", (char*)data, received); } } } PROCESS_END(); }
/*------Done in a subroutine to keep main routine stack usage small--------*/ void initialize(void) { //calibrate_rc_osc_32k(); //CO: Had to comment this out #ifdef RAVEN_LCD_INTERFACE /* First rs232 port for Raven 3290 port */ rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Set input handler for 3290 port */ rs232_set_input(0,raven_lcd_serial_input); #endif /* Second rs232 port for debugging */ rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_1); clock_init(); printf_P(PSTR("\n*******Booting %s*******\n"),CONTIKI_VERSION_STRING); /* Initialize process subsystem */ process_init(); #ifdef RF230BB { /* Start radio and radio receive process */ rf230_init(); sicslowpan_init(sicslowmac_init(&rf230_driver)); // ctimer_init(); // sicslowpan_init(lpp_init(&rf230_driver)); // rime_init(sicslowmac_driver.init(&rf230_driver)); // rime_init(lpp_init(&rf230_driver)); /* Set addresses BEFORE starting tcpip process */ rimeaddr_t addr; memset(&addr, 0, sizeof(rimeaddr_t)); AVR_ENTER_CRITICAL_REGION(); eeprom_read_block ((void *)&addr.u8, &mac_address, 8); AVR_LEAVE_CRITICAL_REGION(); memcpy(&uip_lladdr.addr, &addr.u8, 8); rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *)&addr.u8); rf230_set_channel(24); rimeaddr_set_node_addr(&addr); 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]); // uip_ip6addr(&ipprefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); // uip_netif_addr_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0, AUTOCONF); // uip_nd6_prefix_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0); // PRINTF("Prefix %x::/%u\n",ipprefix.u16[0],UIP_DEFAULT_PREFIX_LEN); #if UIP_CONF_ROUTER rime_init(rime_udp_init(NULL)); uip_router_register(&rimeroute); #endif PRINTF("Driver: %s, Channel: %u\n", sicslowmac_driver.name, rf230_get_channel()); } #endif /*RF230BB*/ /* Register initial processes */ procinit_init(); /* Autostart processes */ autostart_start(autostart_processes); //Give ourselves a prefix // init_net(); /*---If using coffee file system create initial web content if necessary---*/ #if COFFEE_FILES int fa = cfs_open( "/index.html", CFS_READ); if (fa<0) { //Make some default web content printf_P(PSTR("No index.html file found, creating upload.html!\n")); printf_P(PSTR("Formatting FLASH file system for coffee...")); cfs_coffee_format(); printf_P(PSTR("Done!\n")); fa = cfs_open( "/index.html", CFS_WRITE); int r = cfs_write(fa, &"It works!", 9); if (r<0) printf_P(PSTR("Can''t create /index.html!\n")); cfs_close(fa); // fa = cfs_open("upload.html"), CFW_WRITE); // <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html> } #endif /*--------------------------Announce the configuration---------------------*/ #if WEBSERVER char buf[80]; unsigned int size; eeprom_read_block (buf,server_name, sizeof(server_name)); buf[sizeof(server_name)]=0; printf_P(PSTR("%s"),buf); eeprom_read_block (buf,domain_name, sizeof(domain_name)); buf[sizeof(domain_name)]=0; size=httpd_fs_get_size(); #ifndef COFFEE_FILES printf_P(PSTR(".%s online with fixed %u byte web content\n"),buf,size); #elif COFFEE_FILES==1 printf_P(PSTR(".%s online with static %u byte EEPROM file system\n"),buf,size); #elif COFFEE_FILES==2 printf_P(PSTR(".%s online with dynamic %u KB EEPROM file system\n"),buf,size>>10); #elif COFFEE_FILES==3 printf_P(PSTR(".%s online with static %u byte program memory file system\n"),buf,size); #elif COFFEE_FILES==4 printf_P(PSTR(".%s online with dynamic %u KB program memory file system\n"),buf,size>>10); #endif #else printf_P(PSTR("Online\n")); #endif /* WEBSERVER */ }
PROCESS_THREAD(checkpoint_serial_process, ev, data) { static int set_fd = -1; static int set_count = -1; PROCESS_BEGIN(); /* Note: 'cp', 'rb', and 'mt' commands are intercepted */ PROCESS_PAUSE(); uart1_set_input(serial_input_byte_intercept); /* Format Coffee? */ PRINTF("Formatting Coffee\n"); cfs_coffee_format(); PRINTF("Formatting Coffee... done!\n"); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message && data != NULL); if(strcmp("set", data) == 0) { /* TODO Handle set command */ /* Open file */ cfs_remove("cp"); cfs_coffee_reserve("cp", checkpoint_arch_size()); set_fd = cfs_open("cp", CFS_WRITE); set_count = 0; if(set_fd < 0) { printf("SET:FSBUSY\n"); } else { printf("SET:LINE\n"); } } else if(set_fd >= 0 && strcmp("set:done", data) == 0) { cfs_close(set_fd); set_fd = -1; if(set_count == 9862) { printf("SET:DONE\n"); } else { printf("SET:WRONGSIZE\n"); } } else if(set_fd >= 0) { /* We are ready for another line */ printf("SET:LINE\n"); /* Set command: parse hex data */ int len = strlen((char*)data); if(len > 16 || (len%2)!=0) { printf("WARN: bad set data: %s\n", (char*)data); } else { int i; for (i=0; i < len; i+=2) { uint8_t b = (hex_decode_char(((char*)data)[i]) << 4) + (hex_decode_char(((char*)data)[i+1])); PRINTF("Parsing set command: writing to CFS: %02x\n", b); write_byte(set_fd, b); /* TODO Check return value */ set_count++; } } } else if(strcmp("", data) == 0 || strcmp("cp", data) == 0 || strcmp("rb", data) == 0 || strcmp("mt", data) == 0) { /* ignore commands: handled by interrupt */ } else if(strcmp("ping", data) == 0) { nr_pongs++; printf("pong %u\n", nr_pongs); } else if(strcmp("get", data) == 0) { handle_get_command(); } else { printf("WARN: Unknown command: '%s'\n", (char*)data); } } PROCESS_END(); }
/*------Done in a subroutine to keep main routine stack usage small--------*/ void initialize(void) { #ifdef BUZZER buzz_id(); #endif watchdog_init(); watchdog_start(); clock_init(); PRINTD("\n\nChecking MCUSR...\n"); if(MCUSR & (1<<PORF )) PRINTD("Power-on reset.\n"); if(MCUSR & (1<<EXTRF)) PRINTD("External reset!\n"); if(MCUSR & (1<<BORF )) PRINTD("Brownout reset!\n"); if(MCUSR & (1<<WDRF )) PRINTD("Watchdog reset!\n"); if(MCUSR & (1<<JTRF )) PRINTD("JTAG reset!\n"); MCUSR = 0; PRINTD("CLOCK_SECOND %d\n",CLOCK_SECOND); PRINTD("RTIMER_ARCH_SECOND %lu\n",RTIMER_ARCH_SECOND); PRINTD("F_CPU %lu\n",F_CPU); #if STACKMONITOR /* Simple stack pointer highwater monitor. Checks for magic numbers in the main * loop. In conjuction with PERIODICPRINTS, never-used stack will be printed * every STACKMONITOR seconds. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=10; } while (p<SP-10); //don't overwrite our own stack } #endif /* Calibrate internal mcu clock against external 32768Hz watch crystal */ #define CONF_CALIBRATE_OSCCAL 0 #if CONF_CALIBRATE_OSCCAL void calibrate_rc_osc_32k(); { extern uint8_t osccal_calibrated; uint8_t i; PRINTD("\nBefore calibration OSCCAL=%x\n",OSCCAL); for (i=0;i<10;i++) { calibrate_rc_osc_32k(); PRINTD("Calibrated=%x\n",osccal_calibrated); //#include <util/delay_basic.h> //#define delay_us( us ) ( _delay_loop_2(1+(us*F_CPU)/4000000UL) ) // delay_us(50000); } clock_init(); } #endif PRINTA("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); leds_init(); leds_on(LEDS_RED); /* Initialize USART */ #ifdef CAMERA_INTERFACE camera_init(); #else init_usart(); #endif /* rtimers needed for radio cycling */ rtimer_init(); /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); #if RF2XXBB ds2401_init(); node_id_restore(); /* Get a random seed for the 802.15.4 packet sequence number. * Some layers will ignore duplicates found in a history (e.g. Contikimac) * causing the initial packets to be ignored after a short-cycle restart. */ random_init(rng_get_uint8()); ctimer_init(); init_net(); #else /* !RF2XXBB */ /* Original RF230 combined mac/radio driver */ /* mac process must be started before tcpip process! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /* RF2XXBB */ /* Autostart other processes */ autostart_start(autostart_processes); /*---If using coffee file system create initial web content if necessary---*/ #if COFFEE_FILES int fa = cfs_open( "/index.html", CFS_READ); if (fa<0) { //Make some default web content PRINTA("No index.html file found, creating upload.html!\n"); PRINTA("Formatting FLASH file system for coffee..."); cfs_coffee_format(); PRINTA("Done!\n"); fa = cfs_open( "/index.html", CFS_WRITE); int r = cfs_write(fa, &"It works!", 9); if (r<0) PRINTA("Can''t create /index.html!\n"); cfs_close(fa); // fa = cfs_open("upload.html"), CFW_WRITE); // <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html> } #endif /* COFFEE_FILES */ /* Add addresses for testing */ #if 0 { uip_ip6addr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); // uip_ds6_prefix_add(&ipaddr,64,0); } #endif /*--------------------------Announce the configuration---------------------*/ #if ANNOUNCE_BOOT { #if AVR_WEBSERVER uint8_t i; char buf1[40],buf[40]; unsigned int size; for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf); PRINTA("IPv6 Address: %s\n",buf); } } cli(); eeprom_read_block (buf1,eemem_server_name, sizeof(eemem_server_name)); eeprom_read_block (buf,eemem_domain_name, sizeof(eemem_domain_name)); sei(); buf1[sizeof(eemem_server_name)]=0; PRINTA("%s",buf1); buf[sizeof(eemem_domain_name)]=0; size=httpd_fs_get_size(); #ifndef COFFEE_FILES PRINTA(".%s online with fixed %u byte web content\n",buf,size); #elif COFFEE_FILES==1 PRINTA(".%s online with static %u byte EEPROM file system\n",buf,size); #elif COFFEE_FILES==2 PRINTA(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10); #elif COFFEE_FILES==3 PRINTA(".%s online with static %u byte program memory file system\n",buf,size); #elif COFFEE_FILES==4 PRINTA(".%s online with dynamic %u KB program memory file system\n",buf,size>>10); #endif /* COFFEE_FILES */ #else PRINTA("Online\n"); #endif /* AVR_WEBSERVER */ #endif /* ANNOUNCE_BOOT */ } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(coffee_test_process, ev, data) { int fd_write, n, i; static int cnt = 0; uint8_t buffer[FILE_SIZE]; clock_time_t now; unsigned short now_fine; static uint32_t time_start, time_stop; printf("###########################################################\n"); PROCESS_BEGIN(); printf("process running\n"); // wait for 5 sec etimer_set(&et, CLOCK_SECOND * 5); PROCESS_YIELD_UNTIL(etimer_expired(&et)); #if (COFFEE_DEVICE == 6) int initialized = 0, i; SDCARD_POWER_ON(); //--- Detecting devices and partitions TEST_EQUALS(diskio_detect_devices(), DISKIO_SUCCESS); info = diskio_devices(); for (i = 0; i < DISKIO_MAX_DEVICES; i++) { if ((info + i)->type == (DISKIO_DEVICE_TYPE_SD_CARD | DISKIO_DEVICE_TYPE_PARTITION)) { info += i; initialized = 1; break; } } TEST_EQUALS(initialized, 1); diskio_set_default_device(info); #endif printf("fomartting...\n"); TEST_EQUALS(cfs_coffee_format(), 0); //printf("test starting\n"); do { now_fine = clock_time(); now = clock_seconds(); } while (now_fine != clock_time()); time_start = ((unsigned long)now)*CLOCK_SECOND + now_fine%CLOCK_SECOND; while(1) { // Shortest possible pause PROCESS_PAUSE(); // Determine the filename char b_file[8]; sprintf(b_file,"%u.b", cnt); // Set the file size printf("Reserving '%s'...\n", b_file); TEST_EQUALS(cfs_coffee_reserve(b_file, FILE_SIZE), 0); // And open it printf("Opening '%s'...\n", b_file); fd_write = cfs_open(b_file, CFS_WRITE); TEST_NEQ(fd_write, -1); // fill buffer for(i=0; i<FILE_SIZE; i++) { buffer[i] = cnt % 0xFF; } // Open was successful, write has to be successful too since the size has been reserved printf("Writing'%s'...\n", b_file); n = cfs_write(fd_write, buffer, FILE_SIZE); cfs_close(fd_write); TEST_EQUALS(n, FILE_SIZE); printf("%s written\n", b_file); if( cnt >= FILES_IN_STORAGE ) { int fd_read; // Figure out the filename char r_file[8]; sprintf(r_file,"%u.b", cnt - FILES_IN_STORAGE); // Open the bundle file printf("Reopening '%s'...\n", r_file); fd_read = cfs_open(r_file, CFS_READ); if(fd_read == -1) { // Could not open file printf("############# STORAGE: could not open file %s\n", r_file); fail(); } memset(buffer, 0, FILE_SIZE); // And now read the bundle back from flash printf("Reading '%s'...\n", b_file); if (cfs_read(fd_read, buffer, FILE_SIZE) == -1){ printf("############# STORAGE: cfs_read error\n"); cfs_close(fd_read); fail(); } cfs_close(fd_read); for(i=0; i<FILE_SIZE; i++) { if( buffer[i] != (cnt - FILES_IN_STORAGE) % 0xFF ) { printf("############# STORAGE: verify error\n"); fail(); } } if( cfs_remove(r_file) == -1 ) { printf("############# STORAGE: unable to remove %s\n", r_file); fail(); } printf("%s deleted\n", r_file); } cnt ++; if( cnt >= 10 ) { do { now_fine = clock_time(); now = clock_seconds(); } while (now_fine != clock_time()); time_stop = ((unsigned long)now)*CLOCK_SECOND + now_fine%CLOCK_SECOND; TEST_REPORT("data written", FILE_SIZE*cnt*CLOCK_SECOND, time_stop-time_start, "bytes/s"); TEST_PASS(); watchdog_stop(); while(1); } } PROCESS_END(); }
/*------Done in a subroutine to keep main routine stack usage small--------*/ void initialize(void) { watchdog_init(); watchdog_start(); #ifdef RAVEN_LCD_INTERFACE /* First rs232 port for Raven 3290 port */ rs232_init(RS232_PORT_0, USART_BAUD_38400,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Set input handler for 3290 port */ rs232_set_input(0,raven_lcd_serial_input); #endif /* Second rs232 port for debugging */ rs232_init(RS232_PORT_1, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_1); clock_init(); #if STACKMONITOR /* Simple stack pointer highwater monitor. Checks for magic numbers in the main * loop. In conjuction with TESTRTIMER, never-used stack will be printed * every STACKMONITOR seconds. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=10; } while (p<SP-10); //don't overwrite our own stack } #endif #define CONF_CALIBRATE_OSCCAL 0 #if CONF_CALIBRATE_OSCCAL { extern uint8_t osccal_calibrated; uint8_t i; PRINTF("\nBefore calibration OSCCAL=%x\n",OSCCAL); for (i=0;i<10;i++) { calibrate_rc_osc_32k(); PRINTF("Calibrated=%x\n",osccal_calibrated); //#include <util/delay_basic.h> //#define delay_us( us ) ( _delay_loop_2(1+(us*F_CPU)/4000000UL) ) // delay_us(50000); } clock_init(); } #endif #if ANNOUNCE_BOOT PRINTF("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif /* rtimers needed for radio cycling */ rtimer_init(); /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); #if RF230BB ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ rimeaddr_t addr; memset(&addr, 0, sizeof(rimeaddr_t)); get_mac_from_eeprom(addr.u8); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &addr.u8, 8); #endif rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&addr.u8 ); rf230_set_channel(get_channel_from_eeprom()); rimeaddr_set_node_addr(&addr); PRINTFD("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]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE_BOOT PRINTF("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp); } PRINTF("\n"); #if UIP_CONF_IPV6_RPL PRINTF("RPL Enabled\n"); #endif #if UIP_CONF_ROUTER PRINTF("Routing Enabled\n"); #endif #endif /* ANNOUNCE_BOOT */ // rime_init(rime_udp_init(NULL)); // uip_router_register(&rimeroute); process_start(&tcpip_process, NULL); #else /* Original RF230 combined mac/radio driver */ /* mac process must be started before tcpip process! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /*RF230BB*/ #ifdef RAVEN_LCD_INTERFACE process_start(&raven_lcd_process, NULL); #endif /* Autostart other processes */ autostart_start(autostart_processes); //Give ourselves a prefix // init_net(); /*---If using coffee file system create initial web content if necessary---*/ #if COFFEE_FILES int fa = cfs_open( "/index.html", CFS_READ); if (fa<0) { //Make some default web content PRINTF("No index.html file found, creating upload.html!\n"); PRINTF("Formatting FLASH file system for coffee..."); cfs_coffee_format(); PRINTF("Done!\n"); fa = cfs_open( "/index.html", CFS_WRITE); int r = cfs_write(fa, &"It works!", 9); if (r<0) PRINTF("Can''t create /index.html!\n"); cfs_close(fa); // fa = cfs_open("upload.html"), CFW_WRITE); // <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html> } #endif /* COFFEE_FILES */ /* Add addresses for testing */ #if 0 { uip_ip6addr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); // uip_ds6_prefix_add(&ipaddr,64,0); } #endif /*--------------------------Announce the configuration---------------------*/ #if ANNOUNCE_BOOT #if AVR_WEBSERVER uint8_t i; char buf[80]; unsigned int size; for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf); PRINTF("IPv6 Address: %s\n",buf); } } eeprom_read_block (buf,server_name, sizeof(server_name)); buf[sizeof(server_name)]=0; PRINTF("%s",buf); eeprom_read_block (buf,domain_name, sizeof(domain_name)); buf[sizeof(domain_name)]=0; size=httpd_fs_get_size(); #ifndef COFFEE_FILES PRINTF(".%s online with fixed %u byte web content\n",buf,size); #elif COFFEE_FILES==1 PRINTF(".%s online with static %u byte EEPROM file system\n",buf,size); #elif COFFEE_FILES==2 PRINTF(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10); #elif COFFEE_FILES==3 PRINTF(".%s online with static %u byte program memory file system\n",buf,size); #elif COFFEE_FILES==4 PRINTF(".%s online with dynamic %u KB program memory file system\n",buf,size>>10); #endif /* COFFEE_FILES */ #else PRINTF("Online\n"); #endif /* AVR_WEBSERVER */ #endif /* ANNOUNCE_BOOT */ }
/*------Done in a subroutine to keep main routine stack usage small--------*/ void initialize(void) { watchdog_init(); watchdog_start(); init_lowlevel(); clock_init(); forwarding_enabled = get_forwarding_from_eeprom(); #if ANNOUNCE_BOOT PRINTF("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif /* rtimers needed for radio cycling */ rtimer_init(); /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); #if RF230BB || RF212BB ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ rimeaddr_t addr; memset(&addr, 0, sizeof(rimeaddr_t)); get_mac_from_eeprom(addr.u8); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &addr.u8, 8); #endif #if RF230BB rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&addr.u8 ); rf230_set_channel(CHANNEL_802_15_4); #elif RF212BB rf212_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&addr.u8 ); #endif extern uint16_t mac_dst_pan_id; extern uint16_t mac_src_pan_id; //set pan_id for frame creation mac_dst_pan_id = get_panid_from_eeprom(); mac_src_pan_id = mac_dst_pan_id; rimeaddr_set_node_addr(&addr); PRINTFD("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]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE_BOOT #if RF230BB PRINTF("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel()); #elif RF212BB PRINTF("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name, rf212_get_channel()); #endif /* RF230BB */ if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp); } PRINTF("\n"); #if UIP_CONF_IPV6_RPL PRINTF("RPL Enabled\n"); #endif #if UIP_CONF_ROUTER PRINTF("Routing Enabled\n"); #endif #endif /* ANNOUNCE_BOOT */ // rime_init(rime_udp_init(NULL)); // uip_router_register(&rimeroute); process_start(&tcpip_process, NULL); #else /* Original RF230 combined mac/radio driver */ /* mac process must be started before tcpip process! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /*RF230BB || RF212BB*/ #if WEBSERVER process_start(&webserver_nogui_process, NULL); #endif /* Handler for HEXABUS UDP Packets */ process_start(&udp_handler_process, NULL); mdns_responder_init(); /* Button Process */ process_start(&button_pressed_process, NULL); /* Init Metering */ metering_init(); /*Init Relay */ relay_init(); /* Autostart other processes */ autostart_start(autostart_processes); /*---If using coffee file system create initial web content if necessary---*/ #if COFFEE_FILES int fa = cfs_open( "/index.html", CFS_READ); if (fa<0) { //Make some default web content PRINTF("No index.html file found, creating upload.html!\n"); PRINTF("Formatting FLASH file system for coffee..."); cfs_coffee_format(); PRINTF("Done!\n"); fa = cfs_open( "/index.html", CFS_WRITE); int r = cfs_write(fa, &"It works!", 9); if (r<0) PRINTF("Can''t create /index.html!\n"); cfs_close(fa); // fa = cfs_open("upload.html"), CFW_WRITE); // <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html> } #endif /* COFFEE_FILES */ /* Add addresses for testing */ #if 0 { uip_ip6addr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); // uip_ds6_prefix_add(&ipaddr,64,0); } #endif /*--------------------------Announce the configuration---------------------*/ #if ANNOUNCE_BOOT #if WEBSERVER uint8_t i; char buf[80]; unsigned int size; for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf); PRINTF("IPv6 Address: %s\n",buf); } } eeprom_read_block(buf, (const void*) EE_DOMAIN_NAME, EE_DOMAIN_NAME_SIZE); buf[EE_DOMAIN_NAME_SIZE] = 0; size=httpd_fs_get_size(); #ifndef COFFEE_FILES PRINTF(".%s online with fixed %u byte web content\n",buf,size); #elif COFFEE_FILES==1 PRINTF(".%s online with static %u byte EEPROM file system\n",buf,size); #elif COFFEE_FILES==2 PRINTF(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10); #elif COFFEE_FILES==3 PRINTF(".%s online with static %u byte program memory file system\n",buf,size); #elif COFFEE_FILES==4 PRINTF(".%s online with dynamic %u KB program memory file system\n",buf,size>>10); #endif /* COFFEE_FILES */ #else PRINTF("Online\n"); #endif /* WEBSERVER */ #endif /* ANNOUNCE_BOOT */ }