Taylor’s Engineering Fair 2011

I was invited to be a guest judge for the Engineering Fair 2011 at Taylor’s University today. The fair is a showcase for the first year and third year projects of the various engineering students at Taylor’s. After finishing with the judging work, I went around to have a look at the projects personally.

It was a smart thing for them to coincide the Engineering Fair with the Open Day this weekend. As a result, parents and students who are shopping around for a university would get the opportunity to look at some of the student projects on display.

Some of the projects were quite interesting and the students’ enthusiasm for their project was quite evident. Some of the students caught me and I spent some time giving them advice on how to best exploit their time in engineering school. Too bad that they were a bunch of chemical engineering students.

Generally, I get the impression that the students who go to the university seem to be pretty decent. Some of them are actually downright impressive in terms of their personality and character. I would peg them squarely as achievers based on my limited dealing with them.

Unfortunately, I’d learned that the number of electronics engineering students that they have is a rather small one as it is the smallest engineering programme that they have. Thankfully, I have also heard that their numbers are on the increase and this is good news for me as I hope to be able to increase the pool of electronics engineers in Malaysia as a whole.

I do hope to establish more links between AESTE and various local engineering schools. I have close research and student links with two GLC universities and I’m hoping to diversify my pool of universities to include private and public universities next year.

This whole fair actually reminded me of the days when I was the EDX (Engineering Design Exhibition) director at my old alma-mater. It used to be a massive affair for us as we would invite high school students from across the state to come and visit the university.

Those were the carefree days of fun.

LwIP on AVR32

Since the basic function for HAL is able to run without serious problem. I have to put HAL on hold and start to do net layer for AVR32. However, I will come back to HAL when bugs ‘fly’ out or when the time I want to increase the performance of HAL.

The net layer for the AVR32 is based on LwIP (Light Weight Internet Protocol). The LwIP is a open-source networking library and API. It can support the basic networking protocol such as IP, ICMP, DHCP, DNS, UDP and TCP. It is widely used in embedded system since the resource usage is much lesser than normal TCP/IP protocol that used by PC. Besides that, it is able to run in multithread (RTOS) or single thread system.

The Atmel Software Framework provides several examples that using LwIP for network application. In these example, The LwIP has been ported into FreeRTOS. The ASF has done the low level jobs so programmers can go to design the application layer directly.

The LwIP provides three different types of API for programmers to write the web application, the APIs are:

  • Raw / native API – LwIP only API. This API uses a callback mechanism, which will increase the complexity of readability when the program become bigger.
  • Netconn API – LwIP only API. This API simplify the API with ‘sequential’ style.
  • Socket API – ‘Sequential’ API, targeted at compatibility to posix- / BSD-sockets

My job is to pack all the netconn API into three types of function and hides all LwIP function. The three types of function are follow the basic TCP/IP connection, which are:

  • Connection establishment – Create a task to handle the user defined application (eg. web server).
  • Data transfer – Capture input and send data, hide the LwIP detail from web application.
  • Connection termination – Close the connection and suspend the task.

The goal of the net layer is to simplify the design of web application. The programmer provides the basic information (port numbers and IP address) and lets the net layer handles all the trivial jobs for him. It will save their time and let them focus on the manipulation of information.

Physical Programming #3

Yesterday, I went to Universiti Kebangsaan Malaysia (UKM) in Bangi, to deliver a talk on physical programming. This is the third such talk that I have been delivering in various local universities, with the previous two at Universiti Teknologi PETRONAS and Multimedia University.

However, UKM is of note because of the reception that I received there. It was the biggest crowd of students that I had ever addressed, with about 50 students attending and filling up half the lecture room. Also, I was treated to a simple working lunch there with some of the staff.

The students themselves seemed interested in the talk as they were quite attentively listening, and also asking relevant questions and providing suitable answers. I actually took it as an opportunity to survey most of the students to see if there are any potential ones for hiring.

I have two reasons for delivering this talk – one is to pitch ourselves as a career destination of choice; and to expound the concept of physical programming, which is not new but is an enlightening thing. I do hope that the students heed my advice and to always think before they code.

As an engineering startup, it is vital for us to build strong links with local universities. This is critical to ensure that we will always have a supply of fresh graduates and also to ensure that we can collaborate on cutting edge research work.

I’d happily go back to UKM regularly.

AVR32: Displaying image on graphic LCD

Last weekend, I was dealing with the graphic LCD on EVK1105. I am happy to deal with output device. It is because they can interact with users and programmers. They can use for debugging, showing error and feedback. Another reason is the output devices are easier to debug when you have done something wrong.

The software driver of graphic LCD is provided by the Atmel Software Framework. It is also comes with a example that displays an AVR32 logo on the graphic LCD. The code is easy to understand, but the problem is to generate a 16-bits pixmap array that is compatible with the function provided by ASF.

After some research, I have found that GIMP (GNU Image Manipulation Program) is able to convert image file into a C-language array. The array can hold the RGB (or RGBA) value of each pixel. The pixel value are all represented by ASCII character, 8-bits for each color and 24-bits (or 32-bits) for each pixel. So, the only thing I need to do is translate the pixel format to 5R6G5B and send it to the Graphic LCD.

To get the C-source output from GIMP, go to File -> save as -> change the filename extension to “.c” -> save -> uncheck “Use GLib types” -> save. The output of the GIMP C-source array is shown at below.

/* GIMP RGBA C-Source image dump (aestelogo_150x50.c) */

static const struct {
  unsigned int 	 width;
  unsigned int 	 height;
  unsigned int 	 bytes_per_pixel; /* 3:RGB, 4:RGBA */
  unsigned char	 pixel_data[150 * 50 * 4 + 1];
} gimp_image = {
  150, 50, 4,
 "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
 "\377\343L1\377\3371\22\377\335%\3\377\334\36\377\334\37\377\334\37"
  "\377\334\37\377\334\37\377\334\37\377\334\37\377\334\36\377\334"
  "!\377\336+\13\377\3407\30\377\350jT\377\371\331\324\377\377\377\377\377"
  "\377\377\377\377\376\376\376\377\377\377\377\377\377\377\377\377\377\377"

  ......
  ...

  "",
  };

Below is the loop that used for converting the pixel value to 16-bits format and output to graphic LCD. It is slow since it accesses the pixel directly rather than the buffer. I can see the image ‘flash’ everytime I refreshes the screen.

for( i = 0; i < height; i++ ){
    for( j = 0; j < width; j++ ){

        /* Get Red Channel. */
        R = bitmap[count];
        count++;

        /* Get Green Channel. */
        G = bitmap[count];
        count++;

        /* Get Blue Channel. */
        B = bitmap[count];
        count++;

        /* Get Alpha Channel. */
        if(colorChannel == 4){
            /* Alpha Channel. */
            count++;
        }

        /* Change the 8R8G8B format to 5R6G5B. */
        pixel = et024006_Color( R, G, B );

        /* Convert the endianness. */
        pixel = ( pixel >> 8 ) | ( pixel << 8 );

        /* Draw the pixel on GLCD screen.
         * x, y is the offset.
         */
        et024006_DrawPixel( x+j, y+i, pixel );

    }
}

The code doesn’t support the alpha channel right now, but I left a branch there for future enhancement. Before adding the alpha channel, I need to improve the frame-rate until it is more ‘comfortable’ to human eyes.

AVR32 Development

These two weeks, my task is writing a Hardware Abstraction Layer (HAL) for AVR32. So I need to work on AVR32 along with AVR32 studio and development board.

The AVR32 is 32-bit micro-controller family developed by Atmel. Atmel provides most of the drivers for the on-chip peripherals and on-board components for AVR32. It also provides some third party services like FreeRTOS, light weight IP (LWIP), memory error-correcting code (ECC) as well as JPEG library. All the drivers and services are grouped together to form the ASL (Atmel Software Library). These services are ported to AVR32 architecture already. The users can save their time from porting the services to AVR32 architecture again.

For me, the most exciting part on the development board is the ethernet controller. I wished to play with ethernet port for a long time, but most of the ethernet-ready board or IC are quite expensive. Now, I can play with it without buying it. It is a good chance for me to learn the ethernet and networking stuff.

Besides that, a graphic LCD is also available, but it is quite a pity that it only supports the touch buttons rather than touch screen. This makes me a bit bored when dealing with the Graphic LCD. The most important part is the board come with USB bootloader. Finding a programmer is always a problem when learning a new micro-controller. The board does a great job in this, it simplifies the process to program the AVR32.

With all the features come with the board. It makes the FreeRTOS beginner like me, have a very nice platform to learn the FreeRTOS. The AVR32 really makes the learning process of FreeRTOS become very easy.

FreeRTOS: Inter-Task Communication

FreeRTOS is a type of real-time operating system. It is similar to all RTOS, having a serious problem with inter-task communication and resource sharing.

In RTOS, inter-task communication is not like passing variables between normal functions. Normal functions can pass the data to a global variable or pass it to another function by returning the value.

If the global variable is being used by RTOS, the data might be written by higher priority task before the lower priority task read it. This will corrupt the data.

The hardware resources have the same problem. For example, consider a task sending a string to a PC through the UART port. However, it has been interrupted by another higher priority task that also sends data through the same UART port. At the end, the data will appear between the string. Therefore, inter-task communication is important for the coordination of tasks.

There are few solution dealing with inter-task communication.

  • Queue – It is a temporary storage for the data that need to transfer between tasks. The length of the queue is depend on the rate of push and pull of the queue.
  • Semaphore – It can be divided into two types. Binary semaphore and counting semaphore.
    • Binary semaphore – It is similar to a queue that contains only a binary data. It functions like a signal that indicates that the data is ready. It is useful to synchronize data between tasks or interrupts.
    • Counting semaphore – It is similar to binary semaphore, but the length of queue is more than one. It is useful in counting events. For example, it can be used for counting the available resources (eg. memory) or the data that need to be processed by another task.
  • Mutex (Mutual Exclusion) – It is similar to a binary semaphore. However, mutex supports priority inheritance mechanism. Therefore, mutex is able to keep a low priority task from using the resource while another high priority task attempts to access the same resource. The mutex is very useful in resource sharing.

The solutions above is used to solve the data transfer problem between RTOS tasks. They might create other problem like priority inversion. Therefore, special care must be taken to use these solution in RTOS.