Contiki OS on the web platform

From DP

Jump to: navigation , search

Shuckc ported Contiki OS 2.5 to run on the WebPlatform board. The port consists of a new cpu "dspic" using the pic30 Microchip/gcc toolchain and a new platform "dp-webplatform" with DP-specific board support. You can browse the code on GitHub at shuckc's github contiki-dspic or read on to use it!

Network notes: These examples assume the Web Platform is wired with CAT5 cable to your home Broadband/DSL Router's Ethernet port, and you are working from a computer either on the same wireless or wired network. Direct connection (laptop to Web Platform) will not work so easily as there is no device to give out DHCP addresses.

Contents

Here's what the base port does:

  • Assigns a new, random MAC address from the Microchip range and stores it in the eeprom, so you can network multiple web platforms together
  • Brings up the Ethernet interface and broadcasts to get an IP using DHCP
  • If assigned a DNS server by DHCP, resolve "pool.ntp.org" and set the hardware RTC using simple NTP
  • Sends a periodic UDP broadcast to port 4321 which can be picked up a by a simple python listener

This is the listener app with a couple of boards connected:

WebPlatform-ContikiOS-AnnounceListener.png

You can also build some of the Contiki "apps" to run, there is a basic webserver, telnet server etc included with Contiki that can be built - this first example your usual "hello world" example.

Hello World Example

It's fairly easy to fetch the code and build a working hex file. On windows you need Cygwin and a GIT client installed, plus the microchip compilers:

  • Install mplab C30 (3.30c) installer from [1]
    • I recommend using "versioned" mode to allow side-by-side installs
    • Lite mode is fine, we don't need the optimisations
  • Install cygwin from [2]
    • choose to install "Devel" -> "make", "automake", "cmake"
    • allow installer to select all of the dependant packages.
  • Install GIT for windows [3]
  • Notepad++ is a great editor for c code [4]

To grab the code and build it, fire up a cygwin terminal:

Code: Select all

Chris@cscs-839ffbb825 ~
$ mkdir dpweb; cd dpweb
 
Chris@cscs-839ffbb825 ~/dpweb
$ git clone git://github.com/shuckc/contiki-dspic.git
Cloning into contiki-dspic...
remote: Counting objects: 57089, done.
remote: Compressing objects: 100% (11558/11558), done.
remote: Total 57089 (delta 40912), reused 56774 (delta 40719)
Receiving objects: 100% (57089/57089), 46.90 MiB | 98 KiB/s, done.
Resolving deltas: 100% (40912/40912), done.
 
Chris@cscs-839ffbb825 ~/dpweb
$ cd contiki-dspic/examples/hello-world/
 
Chris@cscs-839ffbb825 ~/dpweb/contiki-dspic/examples/hello-world
$ make savetarget TARGET=dp-webplatform
pic30-gcc version is '4.0.3' recommend 4.0.3
saving Makefile.target
 
Chris@cscs-839ffbb825 ~/dpweb/contiki-dspic/examples/hello-world
$ make
using saved target 'dp-webplatform'
pic30-gcc version is '4.0.3' recommend 4.0.3
pic30-gcc -omf=elf -DCONTIKI=1 -DCONTIKI_TARGET_DP_WEBPLATFORM=1 -mcpu=33FJ128GP204 -c -Wall
-I"E:/Program Files/Microchip/mplabc30/v3.30c/s
upport/dsPIC33F/h" -I../../platform/dp-webplatform  -I../../core -I../../cpu/dspic -ffunction-sections
-D__dsPIC33FJ128GP204__=1  -I. -I../.
./platform/dp-webplatform/. -I../../platform/dp-webplatform/apps -I../../platform/dp-webplatform/net
-I../../cpu/dspic/. -I../../cpu/dspic/d
ev -I../../core/dev -I../../core/lib -I../../core/net -I../../core/net/mac -I../../core/net/rime
-I../../core/net/rpl -I../../core/sys -I../
../core/cfs -I../../core/ctk -I../../core/lib/ctk -I../../core/loader -I../../core/.
-DCONTIKI_VERSION_STRING="Contiki-2.5-1512-gc9f80e1"
-DAUTOSTART_ENABLE -c hello-world.c -o hello-world.co
.....
Total program memory used (bytes):        0x14391  (82833) 63%
...
Total data memory used (bytes):         0x15de  (5598) 68%
Dynamic Memory Usage
 
region     address                      maximum length  (dec)
------    -------                      ---------------------
heap      0x1780                       0x80  (128)
stack     0x1800                      0xa22  (2594)
 
Maximum dynamic memory (bytes):          0xaa2  (2722)
...
 
Chris@cscs-839ffbb825 ~/dpweb/contiki-dspic/examples/hello-world
$ ls -la hello-world.dp-webplatform.*
   hello-world.dp-webplatform.hex
   hello-world.dp-webplatform.out


WebPlatform-ContikiOS-DS30loader.png

Serial debugging port

Open up Device Manager to find the USB COM port the FTDI driver have allocated for the board.

Device-manager-COMport.png

You can then use PuTTY or another terminal program to see the console. The Board rate is 112,500 bps, 8bits, 1stop, no handshaking.

Putty-UART-config.png

Here's the serial console output from booting - if you want to replay it, hit the reset button on the board.

Code: Select all

    DP Web Platform - CONTIKI_VERSION_STRING started.
    Last system reset caused by one or more of:
    Reset Button press
    a2d: Gathering entropy from analogue input AN0
    a2d: 4cd1 e9bf 1fd4 d0b4
    a2d: 1eac 1362 1890 220f
    a2d: 0f7f 211a 4f1d 580a
    a2d: 52e6 2c81 024c 1c8c
    a2d: 3b13 e6b0 59dc fbbf
    a2d: 359c ad29 0750 7e6f
    a2d: 7466 27d5 06f7 c405
    a2d: 039c 7283 7e91 84a8
    a2d: done
    main: leds init
    main: process init
    main: etimer init
    main: clock init
    main: loading from eeprom read sz=32 address=0000
    eeprom: read dev address 0000 to buffer 0000180c sz 32
    main: using stored configuration
    main: eth start
    eth init
    eth device init
    eth reset delay
    eth reset delay end
    enc28j60DMAInit
    main: tcpip start
    pdhcp: init
    main: autostart
    Hello, world
    main: all processes running
    pdhcp: PROCESS_EVENT_TIMER
    pdhcp: TCPIP_EVENT
    DHCPC: send discover
    pdhcp: TCPIP_EVENT
    DHCPC: send request
    tcpip packet_input output len 284
    pdhcp: TCPIP_EVENT
    Got IP address 192.168.1.5
    Got netmask 255.255.255.0
    Got DNS server 192.168.1.1
    Got default router 192.168.1.1
    Lease expires in 86400 seconds
    DHCP Configured
    pdhcp: PROCESS_EVENT_MSG
    resolv: pool.ntp.org to IP address 178.63.105.200
    pdhcp: resolve event callback: pool.ntp.org
    pdhcp: resolv callback for ntp IP 178.63.105.200
    NTP: configured for new server
    NTP: sending request to 178.63.105.200
    NTP: utctime: Sun 22. Jan 2012 14:00:15
    NTP: setting hw time
    2012-01-22T14:00:15Z


Note the line that says "main: autostart" - at this point the "platform" is handing over to the hello-world application, which prints the next message "Hello, world". You can see the sample application at examples/hello-world/hello-world.c while the platform boot code is at platform/dp-webplatform/contiki-dp-webplatform-main.c .

Contiki Webserver Example

To build the contiki webserver, re-use the cloned the repository from the hello-world example. Run 'make' from the the webserver examples directory:

Code: Select all

$ cd ~/dpweb/contiki-dspic/examples/webserver
$ make savetarget TARGET=dp-webplatform
$ make

That should create file webserver-example.dp-webplatform.hex which you can program in the usual way. Once you know the IP address from the announce tool, open up a web browser to the IP shown in the announce GUI and you should find the example pages:

WebPlatform-ContikiOS-processes.png

DP Webserver Example

There's a slightly more "dangerous" webserver that we hope will become a useful demo app. It's quite different from the stock webserver in that it supports long filenames without extensions, and uses a filesystem flags byte for each file to set the MIME type and determine if the file can be cached. You can rebuild the HTML web pages by modifying files in the /apps/dpwebserver/httpd-fs/ directory, then running makefsdata like so:

Code: Select all

Chris@cscs-839ffbb825 ~/c2/contiki-dspic/apps/dpwebserver
$ ./makefsdata -d httpd-fs -o httpd-fsdata.c
Processing directory httpd-fs as root of packed httpd-fs file system
Writing to /cygdrive/e/Documents and Settings/Chris/c2/contiki-dspic/apps/dpwebserver/httpd-fsdata.c
processing flags from flags
$VAR1 = {
          'style.css' => 'HTTPD_FS_FLAGS_CACHE | HTTPD_FS_CTYPE_TEXTCSS',
          'upload.html' => 'HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML',
          'files' => 'HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML',
          'status' => 'HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML',
          'processes' => 'HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML',
          'tcp' => 'HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML',
          'orange.png' => 'HTTPD_FS_FLAGS_CACHE | HTTPD_FS_CTYPE_IMGPNG',
          '404.html' => 'HTTPD_FS_FLAGS_CACHE | HTTPD_FS_CTYPE_TEXTHTML',
          'temp' => 'HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML',
          'log' => 'HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML',
          'io' => 'HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML',
          'index.html' => 'HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML'
        };
Adding /404.html  {HTTPD_FS_FLAGS_CACHE | HTTPD_FS_CTYPE_TEXTHTML}
Adding /files  {HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML}
Adding /footer.html  {0}
Adding /header  {0}
Adding /index.html  {HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML}
Adding /io  {HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML}
Adding /log  {HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML}
Adding /orange.png  {HTTPD_FS_FLAGS_CACHE | HTTPD_FS_CTYPE_IMGPNG}
Adding /processes  {HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML}
Adding /style.css  {HTTPD_FS_FLAGS_CACHE | HTTPD_FS_CTYPE_TEXTCSS}
Adding /tcp  {HTTPD_FS_FLAGS_DYNAMIC | HTTPD_FS_CTYPE_TEXTHTML}
All done, files occupy 4476 bytes

These files are incorporated into the flash 'program memory' so keep the total less than ~8kb. You then rebuild the firmware .hex file like this:

Code: Select all

Chris@cscs-839ffbb825 ~/c2/contiki-dspic/apps/dpwebserver
$ cd ../../examples/dpwebserver/
 
Chris@cscs-839ffbb825 ~/c2/contiki-dspic/examples/dpwebserver
$ rm *.out *.hex
$ make savetarget TARGET=dp-webplatform
 
Chris@cscs-839ffbb825 ~/c2/contiki-dspic/examples/dpwebserver
$ make clean && make
using saved target 'dp-webplatform'
....

These web pages are bit more pleasing on the eye!

WebPlatform-ContikiOS-webserver.png

The DP Webserver app is available pre-built in .hex format for anyone wanting to try without setting up the build environment on the GitHub Downloads page.

Contributing to the project

If you want to use this platform as a base for a project it would be great to see you "fork" the project on github and push back any changes. Here's a tutorial to fork a github repository.

Thanks also to the previous work on FreeRTOS by Eric & Matt and uIP Stack that helped make it possible, and the upstream Contiki developers!