2010년 4월 29일 목요일

Install TinyOS and the 8051wg platforms

In order to use this port you need the following prerequisites. The tool chain assumes that the compiler and tools are installed in particular locations and that you setup your environment variables as described below.
  1. A TinyOS 2 installation, in Windows using Cygwin or natively in Linux or similar. Inline is only supported for x86 platforms.
  2. A 8051 compiler
    1. Keil PK51 (any version)
    2. IAR Workbench version 7 or later
    3. SDCC version 2.9.0 or later
  3. A copy of the port from TinyOS-contrib
  4. Hardware programming tools for you particular chip (eg. cc2430)

1. TinyOS 2 install

TinyOS 2 must be installed separate from this port, either in Windows through Cygwin or natively in Linux (or similar). TinyOS version 2.1. and NescC version 1.3.0 are supported presently.
1.1 Windows trough Cygwin
For Cygwin or Linux users follow the instructions from docs.tinyos.net. For Cygwin users remember to install the packages rpm and gcc-mingw. As a bare minimum you need to install the nescc, tinyos-tools, tinyos-deputy and tinyos packages.

$ rpm -i nesc-1.3.0-1.cygwin.i386.rmp
$ rpm -i tinyos-tools-1.3.0-1.cygwin.i386.rpm
$ rpm -i tinyos-deputy-1.1-1.cygwin.i386.rpm
$ rpm -i tinyos-2.1.0-1.cygwin.noarch.rpm


1.2 Windows trough virtual machine
Alternatively Windows users may want to run the Linux through a virtual machine such as Virtual PC or VMWare Server. XubunTOS provides an install image with TinyOS pre-installed. XubunTOS can also be downloaded ad a ready-to-run virtual machine here.
1.3 Linux native install
Linux (and similar) are supported natively, follow the appropriate instructions on docs.tinyos.net your distribution. For example, the installation of TinyOS 2.1 on Ubuntu, is described here.


2. 8051 compiler

To compile programs using this port an 8051 C-compiler is required. We recommend Keil PK51 - this port is written and tested using the Keil compiler. In addition IAR or SDCC may be used, but these are not tested. There are numerous other companies providing compilers that might or might not work, but additional compilers are not supported through the tool chain. Which compiler to used is selected using the environment variable MCS51_COMPILER (see Section 3).
Keil and IAR are Windows only compilers, to use them in Linux they are run through Wine. Each compiler is installed in a separate Wine directory (eg. .wine.keil for Keil) to avoid interference. First install wine and create the appropriate wine directory (using Ubunto or Xubuntos):

apt-get install wine
env WINEPREFIX=~/.wine.keil wineprefixcreate


2.1 Installing Keil PK51
Keil PK51 is a commercial 8051 compiler that can be purchased from http://www.keil.com/. A trial version is available with a 2 KiB code size limit on the compiled binaries. For either Cygwin or Wine install Keil in the default location (C:Keil).
2.1.1 Linux
The tool chain assumes Keil is install using the Wine environment in the directory named ~/.wine.keil. Run the Keil installer using Wine (either from the provided CD-rom or downloaded binary):

WINEPREFIX=$(HOME)/.wine.keil wine C51V809A.EXE


To enter your license code start the uVision development environment and enter it the same way you would in Linux:

WINEPREFIX=~/.wine.keil wine "C:\Keil\UV3\Uv3.exe"

2.1.2 Windows
Simply install the compiler using the appropriate installer.

2.2 Installing SDCC
SDCC is a free, open souce C compiler with native Linux and Windows support. SDCC versions 2.6 and greater provide native inline support. We have not been able to successfully compile a TinyOS application using this inliner. We recommend using the stand alone inline tool provided with this TinyOS port.

2.2.1 Linux
To install sdcc using Debian, Ubuntu or XUbunTOS run the following command:

apt-get install sdcc sdcc-libraries

2.2.2 Windows
Download and install the compiler from http://sdcc.sourceforge.net/. Answer yes to the question "Add to path".


2.3 Installing IAR
Iar is a commercial compiler for Windows. It has a 30 day evaluation is available here. In either Windows or Linux set the path of the compiler in the environment variable MCS51_IAR_PATH, for example the default is:

export MCS51_IAR_PATH=Program\ Files/IAR\ Systems/Embedded\ Workbench\ 4.0\ Evaluation\ version/common/bin/



2.3.1 Linux
Install the compiler using Wine:

env WINEPREFIX=~/.wine.iar wine EW8051-EV-730B.exe


2.3.1 Windows
Simply install the compiler using the native installer.


3. 8051 port from TinyOS-contrib

The code is located in the TinyOS-2.x-contrib section and is downloaded separately from TinyOS. See download for more.


3.1 8051 port directory
The the archive above contains the code in a directoryh namednamed tinyos-2.x-contrib/diku. This directory must be places in par particular location (or speficfied in the variable below).
By placing the directory in the following locations the build system will automatically be able to locate the port


  • For cygwin c:\cygwin\opt
  • Linux /opt
3.2 Environment variables
The ports need a few environment variables in addition to the default TinyOS variables. These variables enable the TinyOS make system to locate the Make rules and the source files.


  • TOSDIR (location of T2 tree)
  • MAKERULES (location of T2 Makerules)
  • TOSMAKE_PATH list of directories to search for .target files (separated by spac"
  • CONTRIBROOT (root of the contrib directory)
In addition a few optional variables control and select which compiler to use:


  • MCS51_COMPILER select compiler one of (keil, sdcc or iar)
  • MCS51_WINE_IAR_PATH wine directory for Keil (default ~/.wine.keil)
  • MCS51_WINE_KEIL_PATH wine directory for IAR (default ~/.wine.iar)
  • MCS51_IAR_PATH Path to IAR compiler
An example script is provided as diku/env which sets up these variables, to include them run the following command (for bash and zsh):

cd tinyos-2.x-contrib
source diku/env

4. Hardware programming tools.

In order to transfer the compiled binary to the chip you need the chip or platform maintainer's tool for this purpose.

Texas Instrumenst (ChipCon) Development Kit
ChipCon Flash Programmer. The programmer is only available for Windows. Other users will have to dual boot or run in an emulator. http://focus.ti.com/docs/toolsw/folders/print/cc2430dk.html#supportsoftware
SiLabs 8051
SiLabs provides a Windows GUI programmer. For Linux (and similar) the ec2drv project provides a command line programmer
nRF24e1
Nordic VSLI provides a programmer for Windows
Sensinode Nano
http://www.sensinode.com/top/information.php?info_id=10

5. Test the setup

With the above prerequisites your setup should be ready to go. To test the setup compile one of the example applications:

cd mcs51/apps/BlinkNoTimer
make cc2430em


If all goes well you should see the following message:

...
GENERATING INTEL HEX FILE: app.hex
compiled BlinkNoTimerTaskAppC to a cc2430em binary
Code size of app.o
MODULE INFORMATION:   STATIC OVERLAYABLE
CODE SIZE        =    635    ----
CONSTANT SIZE    =   ----    ----
XDATA SIZE       =      4       9
PDATA SIZE       =   ----    ----
DATA SIZE        =   ----    ----
IDATA SIZE       =   ----    ----
BIT SIZE         =   ----    ----
Total sizes
Program Size: data=9.0 xdata=10 const=0 code=694

6. Trouble shooting

In case of problems start your setup using the mcs51_env_check.sh script

./diku/mcs51/support/make/mcs51/mcs51_env_check.sh -v

2010년 4월 21일 수요일

MSP430Fxx series SPI Communication.

MSP430Fx에서 SPI 통신을 하기 위해서는 어떻게 해야 할까...

먼저 하드웨어를 살펴보자.
MSP430은 USART0과 USART1 이 존재한다.
USART0은 uart, i2c, spi 가 가능하며, USART1은 uart, spi가 가능하다.
여기서 USART0은 CC2420과 연결되어 무선 통신에 쓰이므로 무선 통신을 사용하기 위해서 패스하고, USART1을 이용하여 spi를 사용하도록 한다.
여기서 MSP430의 결점(?)이 드러나기 시작한다. MSP430 family는 SPI를 직접 컨트롤 할 수 있는 레지스터가 없다.
앞서 언급한 듯이 USART1은 uart와 spi 통신이 가능한데, 두 가지 통신을 한꺼번에 하지 못한다.
즉, 공유자원으로 사용한다는 것이다. uart 통신을 하고자 한다면 uart 모드로 변경해야 하고, spi 통신을 하고자 한다면 spi 모드로 변경해서 사용해야한다.
둘 다 사용하고자 한다면 소프트웨어적으로 스케줄링해서 사용할 수 있다.
tinyos에서는 이를 어떻게 해야 하는지는 뒤에서 언급하도록 한다.

USART1을 SPI 모드로 사용할 경우 p.5.1 ~ p5.3이 쓰인다.
p.5.1은 마스터 모드인 경우 데이터 출력, 슬레이브인 경우 데이터 입력이 가능하다. (SIMO1)
p.5.2는 반대로 마스터 모드인 경우 데이터 입력,  슬레이브인 경우 데이터 출력이 가능하다. (SOMI1)
p.5.3의 경우 마스터인 경우 시리얼 클럭의 출력, 슬레이브인 경우 시리얼 클럭의 입력이 가능하다.
만약 MSP430을 마스터로 사용한다면 어떤 핀을 제어해야 하는지 감이 올 것이다.

다시 돌아와서 tinyos의 경우 USART1의 uart와 spi를 위해 HPL단의 컴포넌트에 레지스터 셋팅이 되어 있다.
(/opt/tinyos-1.x/tos/platform/msp430/HPLUSART1M.nc)
이를 사용하기 위해서는 top-level app단에서 인터페이스를 연결하여 call 하면 된다.
(/opt/tinyos-1.x/tos/platform/msp430/HPLUSARTControl.nc)

참고로 슬레이브 모듈에 따라 레지스터를 변경 적용해야 하는 경우도 있으니 MSP430Fx의 데이터시트를 꼭 참고해야 한다.

TIP.
TinyOS에서 StdControl interface를 이용하여 초기화할 때, SPI 모드도 초기화 하게 되면 동작이 되지 않는다. 그러므로 스케줄러에 의해 모트의 동작이 시작할 때 초기화하고 SPI로 동작하도록 해야 한다.