最近移植coffee fs, 为了了解coffee细节,方便调试,因此在pc上编译coffee。
考虑到开虚拟机麻烦,费资源。因此安装Cygwin,在Cygwin下面编译。
1. Create cfs-coffee folder Create folder example-coffee/ in path contiki-2.5/examples/
Copy example-shell/ file to example-coffee/ Rename example-shell.c to example-coffee.c in the example-coffee/2. Modfiy Makefile Modify example-coffee/Makefile
1 CONTIKI_PROJECT = example - coffee 2 all : $(CONTIKI_PROJECT) 3 4 APPS = serial - shell 5 CONTIKI = . . / . . 6 7 include $(CONTIKI) / Makefile . include 8
Modfiy contiki-2.5/platform/native/Makefile.native
1 CONTIKI_TARGET_SOURCEFILES = contiki - main . c clock . c leds . c leds - arch . c \ 2 button - sensor . c pir - sensor . c vib - sensor . c xmem . c \ 3 sensors . c irq . c cfs - coffee . c 4 // 使用cfs-coffee.c取代原来的cfs-posix.c cfs-posix-dir.c 5
Tips:x86 PC的cpu和platfrom的类型都是native,platform中使用的dev是xmem,因此cfs-coffee-arch.c将一片内存作为device操作,这样可以dump内存内容来观察coffee的工作情况。
3. Modify code sync to spi_flash config to veriy porting state
1 2 #ifndef CFS_COFFEE_ARCH_H 3 #define CFS_COFFEE_ARCH_H 4 5 #include " contiki-conf.h " 6 #include " dev/xmem.h " 7 8 #define COFFEE_SECTOR_SIZE ( 4 * 1024UL) // 65536UL 9 #define COFFEE_PAGE_SIZE 512UL // 256UL 10 #define COFFEE_START 0 11 #define COFFEE_SIZE (( 2 * 1024 * 1024 ) - COFFEE_SECTOR_SIZE) // ((1024UL * 1024UL) - COFFEE_START) 12 #define COFFEE_NAME_LENGTH 16 13 #define COFFEE_DYN_SIZE (COFFEE_PAGE_SIZE * 1 ) 14 #define COFFEE_MAX_OPEN_FILES 6 15 #define COFFEE_FD_SET_SIZE 8 16 #define COFFEE_LOG_DIVISOR 4 17 #define COFFEE_LOG_SIZE 8192 18 #define COFFEE_LOG_TABLE_LIMIT 256 19 #define COFFEE_MICRO_LOGS 0 20 // #define COFFEE_IO_SEMANTICS 1 21 22 #define COFFEE_WRITE(buf, size, offset) \ 23 xmem_pwrite(( char * )(buf), (size), COFFEE_START + (offset)) 24 25 #define COFFEE_READ(buf, size, offset) \ 26 xmem_pread(( char * )(buf), (size), COFFEE_START + (offset)) 27 28 #define COFFEE_ERASE(sector) \ 29 xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE) 30 31 #define READ_HEADER(hdr, page) \ 32 COFFEE_READ((hdr), sizeof ( * hdr), (page) * COFFEE_PAGE_SIZE) 33 34 #define WRITE_HEADER(hdr, page) \ 35 COFFEE_WRITE((hdr), sizeof ( * hdr), (page) * COFFEE_PAGE_SIZE) 36 37 /* Coffee types. */ 38 typedef int16_t coffee_page_t; 39 40 #endif /* !COFFEE_ARCH_H */ 41
Add test code to example-coffee.c
4. Build and Debug
Cygwin不包含insight packet,因此使用DDD+gdb完成debug
Tips1: ddd使用需要安装Cygwin/X(x11 packet),参见
Tips2: ddd的启动需要先启动Cygwin/X,在XWin中启动ddd,启动XWind的方法见我使用startxwin命令启动XWin
在XWin中启动ddd:
启动后的UI,可在DDD中进行调试: