Thursday, April 17, 2008

Lock free communication channel

By taking advantage of existing Windows XP API such as InterlockedPushEntrySList and InterlockedPopEntrySList is possible to decouple data exchange in communication channel. That is very important in places where processing speed is crucial point. “An interlocked singly linked list eases the task of insertion and deletion from a linked list. Singly Linked Lists are implemented using a non-blocking algorithm to provide atomic synchronization, increase system performance, and avoid problems such as priority inversion and lock convoys.” Access to the Singly Linked Lists is synchronized on a multiprocessor system, and with no need of locking mechanism.

Writer’s thread will save data into Singly Linked Lists and assign unique ID to the package. Then reader’s thread will pick packages one by one, order them by ID, and store packages in a cache list.

The cache itself could be ignored when processing is interested only in latest package – real time data. Since InterlockedPopEntrySList could read packages in random order, is considered necessary after extracting all packages from a cache to find latest one.

Singly Linked Lists are straightforward to implement and use in 32-bit code.

Monday, April 7, 2008

SQL Express failed to install


During SQL Server Express installation on Microsoft Windows XP Home Edition next unexpected error occurs:

Product: Microsoft SQL Server Native Client -- Error 1706. An installation package for the product Microsoft SQL Server Native Client cannot be found. Try the installation again using a valid copy of the installation package 'sqlncli.msi'.

Workaround:
Extract 'sqlncli.msi' file from a package and install separately, then run SQLEXPR32 again.

Wednesday, April 2, 2008

Backing up and restoring MySQL db via the command line


In Windows click Start, select Run and type cmd, then hit OK button.

Backing up via the command line

    mysqldump -a -u USERNAME -p DATABASENAME > FILENAME.sql

Restoring via the command line

Drop the database (optional):

    mysqladmin -u USERNAME -p drop DATABASENAME

Create the database:

    mysqladmin -u USERNAME -p create DATABASENAME

Import the backup data:

    mysql -u USERNAME -p DATABASENAME < FILENAME.sql

Thursday, March 27, 2008

Configure system for Android development

Development for embedded devices is always fun. With release of Google Android contest level of fun could even higher. Next steps will demonstrate a way how to configure development environment:

0. Start a Virtual PC with Windows XP. It is my favorite way to create new development environment. But it is optional.
1. Download JDK6 from http://java.sun.com/javase/downloads. It will require 300 MB on you hard drive
2. Download Eclipse IDE for Java Developers - Windows (79 MB) from lipse Europa Winter Maintenance Packages (www.eclipse.org/downloads). Nice part that Eclipse does not have an installation process. Once files have been unzipped you are done.
3. Download Android SDK from code.google.com/android/download.html. Unzip into C:\android-sdk_m5-rc15_windows and add C:\android-sdk_m5-rc15_windows\tools to My Computer->Environment Variables->System Variables->Path.
4. Start Eclipse and configure development forlder for example C:\Projects
5. Follow instraction and install Installing the Eclipse Plugin (ADT) from code.google.com/android/intro/installing
6. After restart, update your Eclipse preferences to point to the SDK directory. This could be done from Window -> Preferences -> Android -> SDK Location

Done, now system is ready for development.

Thursday, February 7, 2008

BF537 performance measurements

Customized kernel image created in previous post provides a way to measure execution / performance time. It could be done with help of oscilloscope connected to the boards ground and LED connections. Application pflags-test is executed in user space of uClinux and is using GPIO driver to enable button and LEDs processing. Code below shows in comments measured with oscilloscope execution time.


    write(fd0,"0",sizeof("0"));    // 16 microseconds
    usleep(1000);                      //   4 milliseconds
    write(fd0,"1",sizeof("1"));    // 16 microseconds
    usleep(1000);                      //   4 milliseconds

Arithmetic operations could be tested with help of cycle. This will allow having sufficient amount of time to measure as shown in the code:

    long a, c, i = 0;
    for( i = 0; i < 100000; i++)
    {
         c = i + a;
    }
    printtime();

This time measurements were done with help of system time functions and results are presented in table below.

OperationCycle NumberVariable TypeTime
+100000long4 ms
+1000000long45 ms
*100000long6 ms
*1000000long48 ms
+100000float107 ms
+1000000float1061 ms
*100000float89 ms
*1000000float887 ms

Trigonometric functions measurements could be done with adding in C file #include <math.h>, and option "-lm" to the linker command. Review previous post on details of how to configure blackfin toolkit for uClinux program compilation.


bfin-uclinux-gcc -Wl,-elf2flt perftest.c -o perftest -lm

OperationCycle NumberVariable TypeTime
cos100000long6268 ms
cos1000000long62681 ms

Thursday, January 31, 2008

Compiling the Kernel for BF537

BF537 STAMP board has buttons and LEDs provided to be accessed by software for testing purpose. In order to do that is required to have customized kernel image. Default image for BF537 has no driver for such operations.

Source code for uClinux kernel could be downloaded from blackfin site. There are an easy way to uncompress it by just right click on a file in SUSE File Browser and selecting Extract Here. Lets open this folder and configure blackfin toolkit used for kernel compilation. Details on how to do that is provided in previous post.

Next command in terminal window will invoke kernel configuration utility.

make menuconfig

Choosing BF537-STAMP in Vendor/Product Selection will produce kernel for BF537. It is important to do that, otherwise kernel image will halt on boot up execution.



Ability to add required driver is provided with selection of Customize Kernel Settings (NEW):

Kernel/Library/Defaults Selection.
Device Drivers --->
Character devices --->
[*] Blackfin BF53x Programmable Flags Driver


Exit and saving configuration will bring back the terminal console. Executing next commands will reset cached objects and make a new kernel image:

make clean
make

The compilation process will take time and could last for about 30 minutes. BF537 U-Boot loader has a nice feature of loading kernel from a network over tftp. SUSE YaST in a few steps allows to configure TFTP server and then copy kernel image into server folder with File Browser.

Now let’s jump to Windows XP host environment and start HyperTerminal application.


For tftp command to work is necessary to configure BF537 U-Boot environment with ipaddress for tftp server and BF537. Saving environment settings into flash memory is an optional step. After that is loading kernel image to memory and booting uClinux.

BF537> setenv ipaddr x.y.z.n
BF537> setenv serverip x.y.z.m
BF537> saveenv
BF537> tftp 0x1000000 linux
BF537> bootelf 0x1000000

Now everything is ready to run test application on a custom kernel image. Source code for button test application could be found in user\blkfin-test\pflags-test subfolder where kernel was compiled. Check my previous post on how to compile and download application into BF537.

Wednesday, January 23, 2008

Hello World under uClinux

Let's test Hello World application compiled in previous post under uClinux. There are many ways how to copy application file into BF537 board and one of them with help of wget command by downloading file over HTTP protocol.

This command will communicate with web server installed on development platform. Ethernet connection between board and computer is necessary.

YaST allow an easy way to verify that HTTP server is enabled and take a look on my previous post on how to configure Linux SUSE to be development platform for BF537.

Then application file has to be placed into web server working folder. That could be done from command line as well by using Cut and Paste file operation.

cp ./hello /srv/www/htdocs/hello

The natural way of running BF537 under Windows XP is with use of HyperTerminal application and serial cable. Connection setting could be found on support site. After powering up board next text will be shown in terminal window:

With DHCP server available board's network settings could be configured by:

root> dhcpcd &

Next commands will do switch to tmp folder as preferable place for this application, download file from web site, permission modification that allows program to be executed and finally now is possible to execute Hello World application

root:~> cd /tmp
root:/tmp> wget http://yourwebserver/hello
root:/tmp> chmod 777 hello
root:/tmp> ./hello