Skip to main content
Topic: Webplatform Contiki 2.5 port (Read 49677 times) previous topic - next topic

Webplatform Contiki 2.5 port

As I hinted last week (and at least one sleuth tracked down on GitHub) I've ported Contiki OS 2.5 to run on the Microchip PIC WebPlatform board. The port consists of a new cpu "dspic" using the pic30 Microchip/gcc toolchain and a new platform "dp-webplatform" for Ians board. You can find the work on GitHub at https://github.com/shuckc/contiki-mirror

Here's what the base port does:
  • Assigns a new, random MAC address from the Microchip range and stores it in the eeprom
  • Brings up the Microchip 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 with a couple of boards connected:
[attachment=1]
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 is just "hello world" though. 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. Fire up a cygwin terminal:

Code: [Select]
Chris@cscs-839ffbb825 ~
$ mkdir dpweb; cd dpweb

Chris@cscs-839ffbb825 ~/dpweb
$ git clone git://github.com/shuckc/contiki-mirror.git
Cloning into contiki-mirror...
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-mirror/examples/hello-world/

Chris@cscs-839ffbb825 ~/dpweb/contiki-mirror/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-mirror/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-mirror/examples/hello-world
$ ls -la hello-world.dp-webplatform.*
-rwxr-xr-x+ 1 Chris None 332966 Jan 22 13:53 hello-world.dp-webplatform.hex
-rwxr-xr-x+ 1 Chris None 314510 Jan 22 13:53 hello-world.dp-webplatform.out

It takes around 5 minutes for the GIT clone to complete and about 2 minutes to build on my machine. You can program the .hex file using the normal ds30 Loader application:

[attachment=0]
Here's the serial console output from booting - you'll find this on the USB com port

Code: [Select]
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
The output is a bit verbose, and needs a bit of cleaning up.

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.

Thanks also to the previous work on FreeRTOS by Eric & Matt and uIP Stack that helped make it possible.

Chris

Re: Webplatform Contiki 2.5 port

Reply #1
To build the webserver example, checkout the repository as in the first post then build from the 'webserver' examples directory:

Code: [Select]
$ cd ~/dpweb/contiki-mirror/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 and you should the example pages:

[attachment=0]

Re: Webplatform Contiki 2.5 port

Reply #2
One last example for this weekend. I have a slightly more "dangerous" webserver that I 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 image like this:

Code: [Select]
Chris@cscs-839ffbb825 ~/c2/contiki-mirror/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-mirror/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

Chris@cscs-839ffbb825 ~/c2/contiki-mirror/apps/dpwebserver
$
And then build the example like this
Code: [Select]
Chris@cscs-839ffbb825 ~/c2/contiki-mirror/apps/dpwebserver
$ cd ../../examples/dpwebserver/

Chris@cscs-839ffbb825 ~/c2/contiki-mirror/examples/dpwebserver
$ rm *.out *.hex

Chris@cscs-839ffbb825 ~/c2/contiki-mirror/examples/dpwebserver
$ make clean && make
using saved target 'dp-webplatform'
....
These web pages are bit more pleasing on the eye!  (ps. still working on ${ } macro expansion in the HTML).

[attachment=0]
The forum does not allow attaching the .hex files so I have posted this example in .hex form for anyone who wants to try it without setting up the build environment at GitHub Downloads:
http://https://github.com/shuckc/contiki-mirror/downloads

Chris

Re: Webplatform Contiki 2.5 port

Reply #3
This is amazing Chris, thank you. I'll post it up. May I also please copy your posts and images to the web platform wiki (BY-SA license)?
Got a question? Please ask in the forum for the fastest answers.

Re: Webplatform Contiki 2.5 port

Reply #4
Yeah sure Ian, all docs released for BY-SA.

I forgot to mention how to find the python announce GUI - it is on the git repository at http://https://github.com/shuckc/contiki-mirror/raw/master/platform/dp-webplatform/tools/locate.py
On windows you should be able to just double-click it if python installed, doesn't use anything outside of the usual core modules.


Re: Webplatform Contiki 2.5 port

Reply #6
Fantastic, can't wait to try this out! Sorry that development of the uIP port just, um...stopped.

Re: Webplatform Contiki 2.5 port

Reply #7
Hi,

I succesfully installed contiki on Webplatform !
Great Works !

I'd like to connect a DHT (DHT11/DHT22/AM2302) temperature and humidity sensor to web platform running ContikiOS.
Is there any port already done of the DHT library that are available for Arduino plaform ?

Regards
emkant

Re: Webplatform Contiki 2.5 port

Reply #8
There's a DHT driver for the PIC Micro here http://http://embedded-lab.com/blog/?p=4333&mid=576 (not mine!)

So long as you run the DHT sensor from the Web platform 3.3V supply you should be within the dsPIC IO pin spec. You will find +3.3v, ground and a data pin on the IO expansion header.

That driver is "blocking" so would halt web page reloads for the duration of the sample. It would do to get going with, but it really needs re-writing to be interrupt driven, rather than interrupt+blocking poll. I would keep a small 6-byte buffer for the sample, and write to it from timer interrupts so that the main event loop keeps running. When the conversion completes or times out you can schedule an event to be sent to the process using the contiki event stuff.

Once you have the data you can then put that on the webpage, serial port or upload it to patchube etc etc.

Might be worth splitting to a new topic.

Re: Webplatform Contiki 2.5 port

Reply #9
I was looking for an embedded tcp stack and it appears that uip and lwip were outdated and replaced by contiki. The OS and multitasking is a nice pro, but there is no (official) port to microchip uCs. Then I found this thread.. On the official wiki I can't find any tips/howtos to port it to an other architecture, How did you do it and was it hard?

I need (like to have) the tcp/ip stac for a PIC24E with a SPI ethernet chip (no enc624j600 or enc24j60)

Re: Webplatform Contiki 2.5 port

Reply #10
It's very easily to port as contiki is pure C, and since it's cooperative multitasking there's no timeslice/stack switching in assembly to worry about. The microchip C environment is totally compatible. A port consists of the "plaform" eg. ethernet driver, and the "cpu" part, which is an implementation of the clock/rtimer/watchdog functions.

You should be able to customise or use directly my PIC cpu contiki-mirror/cpu/dspic/ code. Ethernet driver might take more time though.


Re: Webplatform Contiki 2.5 port

Reply #12
That is amazing, i will be getting one of this soon!

Re: Webplatform Contiki 2.5 port

Reply #13
This does look really good. Well done!

I would like to time some signals coming into the board on a pin. Does anyone know a way to implement a timer compare with this contiki port? The signals are 50us wide and so I need some form of interrupt driven routine to capture them. I do not really know where to start with it in Contiki.

Any ideas would be great.

Thanks

Trev

Re: Webplatform Contiki 2.5 port

Reply #14
Probably best to fire this off as a new Topic.

There's 3 things to consider:
1) signal interface - make sure you protect the PIC pins - they are only 3.3V tolerant, easily toasted by ESD and there's no buffering on the board. Consider an external resister divider network and a clamp diodes. You can then wire into one of the GPIO headers on the web platform, I use the one near the LEDs as it has change notification enabled pins.

2) To capture short signals reliably: If you need only approximate times, use an interrupt on change feature. If you need precise measurements, use the Compare/Capture/PWM (CCP) Module to stash timestamps from a free-running Timer module in hardware, then an interrupt is fired to tell you it is complete. Fcy on the board is 40Mhz so pick a pre-scalar ratio to balance the accuracy you need vs. the overflow time of the register. Take a look at the Microchip CCP peripheral block manual, or AN594 http://http://ww1.microchip.com/downloads/en/AppNotes/00594B.PDF . You'll end up with some C-code to setup the registers, and print the results out to the serial UART.

3) Once you have (1) and (2), think about reporting. There's enough resources on the board to store the last hundred triggers, real-time clock timestamp and duration values in RAM and show them on a web page... but get the basics working first!

Chris