Tuesday, November 30, 2010

Based on the nios and μ C l I n u x embedded system design (1)

Embedded system typically consists of an embedded microprocessor and a peripheral hardware devices, embedded operating system, and user applications of four parts, its development primarily in chip technology, as well as in chip technology constraints of algorithm and software development.

As chip manufacturing technology, embedded system structure has undergone major changes, from embedded systems based on microprocessor-based microcontrollers, embedded systems, and shall then be programmable logic pld (programmable logic device) technology into the embedded system design, turn to the soc (system on chip), eventually in conjunction with the pld and embedded processors and become sopc (programmable system on chip) that makes the sopc become embedded system design of a trend.

This article uses the sopc embedded 32-bit soft core processor nios, implements a uart serial ports and Ethernet interface converter (hereinafter referred to as converter), and the company based on the nios processor microtronix transplantation of μ I n c l u x developed application, his system structure as shown in Figure l.

  

  

1 embedded hardware based sopc platform

Different from the controller on the processor or embedded systems and SOC, sopc-based embedded system with configurable features, not including any specialized peripherals, but may need flexibility in constructing peripheral interface in the fpga.

Embedded systems based on SOPC mainly consists of 1 tablet core chip sopc and tablets, devices, as well as some related interface devices.

This article is to be achieved by using altera Corporation converter cyclone chip and the external circuit, where the external circuit includes 2 pieces of 512 kb sram, l 8 MB flash movie, uart electronic converters and 1 slice Ethernet controller lan91c111. System circuit diagram shown in Figure 2.

  

  

Sopc chip embedded soft core processor nios.

In addition to the sopc chip, cpu, can be equipped with on-chip rom, internal timers, uart serial interface, sram, flash interface, and other system components. These parts are in the form of programmable logic part, chip components chart as shown in Figure 3. Cpu and all parts through avalon bus connected.

  

  

  

Sopc chip system modules and avalon bus modules are automatically generated by sopcbuilder tool, use qualtus ii integrated development environment for logic design of the chip and PIN definitions.

After compiling the generated suffix .sof hardware image file download via byteblasterii cable to the target Board cyclone chip, or .sof files to download to a file, .flash target Board of flash. This completes the hardware design of the converter.

2 μ l I c based n u x sopc application development

Application development can be carried out directly on the hardware platform, but need to know the details of all hardware components, and to prepare the appropriate drivers, software designing subroutine more difficult and heavy workload, and portability.

Based on embedded system applications, all their hardware details are on the user's screen. On the hardware for direct control of the underlying drivers are encapsulated in the operating system, device driver interface, users just need to high through the operating system provides programming system calls. Μ I n c l u x is designed for control of embedded Linux operating system, such as nios processor and so does not have a memory management unit (mmu) microprocessor/microcontroller. Development based on the operating system, the operating system is loaded into the hardware platform, μ c l I n u x can take part in the form of integrated into sopc system.

2.1 load c μ l I n u x system steps

Will I n c μ l u x is loaded into a target plate sopc need to provide a cross-compilation environment, hardware requirements with a serial PC workstation, based on the nios processor sopc target Board and byteblastermv cable, etc.

Software demand windowsntv4.0, windows2000 or windowsxp, altera nios Development Kit ndk 3.0 the nios gnupro tools, ahera nios Development Kit provided by cygwin installation, as well as the quartus ii programmable logic development tools v2.2.

2.1.1 create and load the kernel image

Create and mount μ l I n u c x image file in linux developerbash environment, you first need to follow these steps to configure and build the kernel.

[linux developer]…

μclinux/:cd linux

[linux developer]…linux/:make xconfig

[linux developer]…linux/:make clean

[linux developer]…1inux/:make dep

[linux developer]…l

inux/:make

[linux developer]…

μclinux/:make linux.flash

Generated linux.flash file is μ I n c l u x kernel image.

When sopc target Board is powered on, on-chip rom monitor program running in the germs, [linux developer] ... Μ I n c l u x/:, type nios-runlinux.flash, download the file to the target Board linux.flash, complete loading of kernel image.

2.1.2 create and mount the root file system

In addition to loading the kernel, you need to mount the root file system.

Μ I n c l u x adopts romfs filesystem, the file system relative to the ext2 file system generally requires less space.

On the host and the target directory for linux that μ l I n u c x under the root (root) directory.

The current script and tool will convert the image file to the target directory (romdisk.flash), created in the following steps:

[linux developer]…

μclinux/:make clean_target

[linux developer]…

μclinux/:make romfs

And then type the following command:

[linux developer]…

μclinux/:nios-run romdisk.flash

Upcoming romdisk.flash file is downloaded to the target Board, complete μ I n c l u x root file system is loaded.

2.1.3 loading applications

The user application available through the target directory is loaded into the root file system, you can rebuild romdisk image.

Application in userland directory, run after the file is compiled to target the directory tree, and according to the target directory content creation romdisk.flash file. A new application, you first open a form in userland linuxdeveloperbash, create a directory in the directory app, application source files stored in this directory, and then in userland/app/a makefile file in the build.

Makefile content as shown below, where the application name appfile.

stackslze=8192

include..

/.. /rules.mak

all:appfile.relocbflt

sources=appfile.c

install:

$(romfsinst)appfile.reloebfh

$(romfsdir)/bin/appfile$(execsuffix)

clean:

rm-f *. [

iods]core appfile appfile.*elf appfile.*bflt

Run make to compile the application and modify the userland/.eonfig and/userland/makefile file.

In userland/.config file, add the line config_my_app = y, userland/makefile file, add the dir_ $ (config_my_app) + = app, enter a subdirectory, run make userland, you can install your application to userland/bin, and userland/.config file in the corresponding variable indicates that the application binaries are copied to the target directory.

Finally, type the following command to rebuild romdisk image file (romdisk.flash), and downloaded to the target Board.

[linux developer]…uclinux/:make clean_target

[linux developer]…uclinux/:make romfs

[linux developer]…uclinux/:nios-run romdisk.flash

2.1.4 run μ I n c l u x

Complete μ l I n u c x kernel and mount the file system, you can run μ c l I n u x.

Type g800000 (800000 as startup code address, set the sopc builder), μ c l I n u x automatically complete the initialization process, user-entered login username, password, nios μ c l I n u x, μ l I n u c x's prompt #, that has entered the μ c l I n u x running environment.

2.2 converter application implementation

Converter application system is mainly through the network interface and serial interface data transfer between the transmission of the data stream, as shown in Figure 4.

Μ I n c l u x operating system provides the network drivers and the serial port driver, and provides support for multiple threads.

  

>

Converter application system serial port transceiver data and network port transceiver data is asynchronous, respectively, may be treated as a single task, the task is complicated, so you can use multithreaded programming techniques to achieve multiple tasks concurrently executing the system main program flowchart as shown in Figure 5.

  

  

In this application system has four tasks, create four threads: network receive thread, net send thread, serial receive thread and serial port to send thread.

These four threads can execute concurrently. serial port for network speed and the speed differences, there is a need to set up the appropriate buffer to send and receive data buffer. In this application system set two ring buffer, as shown in Figure 4, which used to receive network data nctrv_uartsd_buf for storage from the network port to receive data, and then remove the serial data from the buffer. Another buffer to receive the serial data uartrv_netsd_bur, and then remove the network port of the data in this buffer.

Need to achieve mutually between threads and synchronizing communications, shared buffer to perform and to synchronize the mutex, its operation following the model of producers and consumers.

The operation of mutual exclusion between threads using a mutex (mu-tex [1] [2]

No comments:

Post a Comment