Friday, April 21, 2006

Tcl Script to Automate Quartus II Compilation

Below is a sample Tcl script that I use to automate the compilation of my Quartus II projects overnight or over the weekend. You can easily find more information about the usage by just typing "tcl" on the Altera search column in www.altera.com and you can easily get some examples over there. The most relevant reading material for Quartus II tool specific scripts would be the Tcl Scripting chapter of the Quartus II Handbook.


############################################
## auto_compile.tcl
## date created : April 9, 2006
## author : http://fpgaforum.blogspot.com
############################################


###Assume that the objective of this script is to compile
###a similar project twice, one with a minimum current strength
###and the other with a maximum current strength.
###(Sometimes you need to do some characterization of the current
###strength on your hardware!)
###The final product is two sof files, one for the minimum
###current strength and the other one for the maximum
###current strength. This means that this script will also rename
###the sof file for after every compilation to avoid being overwritten
###on the next compilation cycle

###go to project folder in command prompt
### Then type quartus_sh -s
### Verify the Quartus II Version number is as targeted, if you have multiple
### versions of Quartus II on your PC
### After verified, type the following command:
### source (This filename.tcl)
### OR
### Open the Quartus II project, then open up the Quartus II Tcl Console by
### go to View->Utility Windows->Tcl Console
### In the Quartus II Tcl Console, type the following command if the tcl script
### is placed in the project folder:
### source (This filename.tcl)

########## TCL script starts #################

####### Auto Compilation TCL Script ############
#change the following line according to your Quartus II project folder##
##assume the 1st project that I want to compile is in the following folder
cd D:/data/project1

##This is to set the minimum current strength
set project_name project1
set revision_name project1
project_open -revision $revision_name $project_name;
set_global_assignment -name Family StratixII
set_global_assignment -name DEVICE EP2S60F1020C3ES

#some assignments to the pins. Of course, I am not going to list all
set_instance_assignment -name CURRENT_STRENGTH_NEW "MINIMUM CURRENT" -to data_bus[0]
set_instance_assignment -name CURRENT_STRENGTH_NEW "MINIMUM CURRENT" -to data_bus[1]

load_package flow
execute_flow -compile
project_close

set sof [pwd]/project1.sof
if [file exists $sof] {
file rename $sof project1_MIN.sof
} else {
puts "ERROR! RENAME $sof to project1_MIN.sof"
}

###======================================

##This is to set the maximum current strength
set project_name project1
set revision_name project1
project_open -revision $revision_name $project_name;
set_global_assignment -name Family StratixII
set_global_assignment -name DEVICE EP2S60F1020C3ES

#some assignments to the pins. Of course, I am not going to list all
set_instance_assignment -name CURRENT_STRENGTH_NEW "MAXIMUM CURRENT" -to data_bus[0]
set_instance_assignment -name CURRENT_STRENGTH_NEW "MAXIMUM CURRENT" -to data_bus[1]

load_package flow
execute_flow -compile
project_close

set sof [pwd]/project1.sof
if [file exists $sof] {
file rename $sof project1_MAX.sof
} else {
puts "ERROR! RENAME $sof to project1_MAX.sof"
}

###======================================
########## TCL script ends #################

Wednesday, April 19, 2006

The Secret of NIOS II Success


Altera NIOS II soft processor has been known as the world’s most versatile embedded processors. What is the reason behind since in my opinion the CPU architecture is more or less the same compared with other processors? In my opinion, the unsung hero that contributes to the success of the NIOS II processor is the Avalon Switch Fabric. I find it a bit weird that Altera or distributors does not put very much effort in directly marketing the Avalon Interface Specification introduced by Altera years ago. I strongly believe that the user-friendly Avalon Interface is one of the main reasons engineers choosing NIOS II processor over their main rival’s Xilinx MicroBlaze processor. It doesn’t matter whether you are designing a master or slave peripheral, as long as your own-designed peripheral supports Avalon Interface, your peripheral can communicate with others peripheral, including NIOS II processor flawlessly as the Avalon Switch Fabric will handle the communication for you.

The Avalon Switch Fabric is generated by Altera SOPC Builder that comes together with Quartus II software tool. That means after installing Quartus II, you do not need to worry about installing the SOPC Builder as it is part of Quartus II software. I like this because I don’t like to open a few application softwares at the same time doing one job. Another good point to mention about the SOPC Builder is the evaluation is free and valid for unlimited period. You just have to re-apply a new Quartus II web edition license about every three months through internet and the license will be sent to your email in split seconds. Too bad that the newly-announced NIOS II C-to-Hardware Acceleration (C2H) Compiler is not available for evaluation to the public without going through the Altera distributors. I am very curious with the improvement achieved using the C2H compiler.

Although many free peripherals that support Avalon interface are available, such as SDRAM controller, DDR SDRAM controller, interval timer, DMA module, UART, etc, it is still very critical to be able to connect your custom IP to the Avalon Switch Fabric. You will find yourself in a situation at times where you need to complete a lot of intensive calculation work within a very short period of time in FPGA. Some good examples are carrying out blemish test for a camera module and CRC checking for a large amount of data. Most of the time, the intensive calculation part takes too much time in C and therefore you can design your own IP in HDL to achieve the performance needed. The purpose of the new C2H compiler is to help the software designers who are not familiar with HDL to accelerate the software functions in their systems. I don’t know how good they are yet without evaluation but I truly believe that if you know HDL, you are still the best person to do the parallel processing in hardware for yourself.

The Avalon Interface uses very easy-to-understand signal types, such as chipselect, read, write, address, clock, reset, readdata, writedata, etc and you can expect yourself to get comfortable with this standard within a day or two. The latest feature that was added to Altera Avalon Interface Specification is Burst Transfer, which is very useful when maximum throughput is required. Burst Transfer guarantees that arbitration between the Avalon Master-Slave pair locked throughout a burst until the burst completes.


Many engineers misunderstand that Avalon Switch Fabric is meant for FPGA devices. Guess what, the CPLD device such as MAX II also supports Avalon Interface. For an example, you can design your custom IP, say a SDRAM master that reads and writes to a SDRAM device that connects to your MAX II device. The setup in the SOPC Builder is as shown in the figure beside. Anyway, NIOS II processor is not supported in MAX or MAX II device as I believe the NIOS II architecture requires on-chip memory.

Recently, due to some reasons, I was required to migrate a NIOS II design to a MicroBlaze design. Unfortunately, there are so many different interface buses involved when I look at the MicroBlaze data sheet, such as On-Chip Peripheral (OPB) bus, Local Memory Bus (LMB) and Fast Simple Link (FSL) bus, just to name a few. I believe it is going to take me quite some times to go through all these new bus standards. No wonder Altera claims that the NIOS II soft processor is the world’s most versatile embedded processor. Well, I think they are right.

Saturday, April 08, 2006

Essential Guide to RF and Wireless


If you find yourself in of the following categories, then, BINGO, you can consider looking for this book.

1. You are an engineer but haven’t got in touch with the RF circuitries and terminologies since graduation. Yet, you want to, or perhaps you have to recall the basic knowledge about this subject, either for interest or job requirement.
2. You are a sales and marketing person for RF stuff but have no or little background in RF industry. You need to pick up the fastest learning curve in this area in order to speak about your product features.
3. You are a science enthusiast but you don’t bother about the mathematics such as Maxwell’s equation, Gauss’s Law, etc.
4. You are an engineering undergraduate and you are on the edge of giving up when you are studying the RF subject due to the complicated multi-dimensional RF equations
5. You just want to know about the wireless and RF stuff
6. You are curious to read the content of this book after reading this post.

I read this book quite sometime ago and I did achieve what I wanted from this book. If I remember correctly, you couldn’t find any mathematics equation in this book. So, don’t worry bringing along your scientific calculator and note pad to do calculation while reading. Many jokes are there to make you feel interested and keep on looking for the next one coming. Anyway, you can easily look out for some of the content inside this book such as preface from the internet before buying this book. Well, don’t just listen to me. Find out what others’ opinion about this book, too, for your own judgement!

Saturday, April 01, 2006

Accessing EPCS from NIOS II


If you are wondering how to access the EPCS from the NIOS II directly, you have come to the right place. I believe you might have tried to read the NIOS II handbook that covers almost 600 pages to find out the answer. Nevertheless, it seems like there is no straight answer to the question in the NIOS II handbook. You might have even tried to look into the Software Files mentioned in the chapter named EPCS Device Controller Core with Avalon Interface, which are altera_avalon_epcs_controller_flash.c, altera_avalon_epcs_controller_flash.h, epcs_commands.c and epcs_commands.h. However, still, none of these files give you much clue how to access the EPCS from the NIOS II processor.

In fact, the handler that gives you the access to the EPCS device is not alt_flash_epcs_dev (as you see in altera_avalon_epcs_controller_flash.h), but alt_flash_fd, which is the exact same handler that you use to access the common flash device like Spansion and Intel flash device. To my surprise, the NIOS II handbook does not mention about this. Perhaps this is a common sense to everybody else that the Spansion/Intel flash and the SPI Serial Flash should have a same handler, but NOT to a dummy user like me! After asking around, I believe I am not the only one who thinks like this! Therefore, I still see that there is some room for improvement in the next version of NIOS II handbook. Not every NIOS II user is a hardware designer. Not every NIOS II user is a software developer, either. Some NIOS II users like me have to do co-hardware/software design and development at the same time. Sometimes I just feel that the handbook couldn’t link me very well between the hardware and software. For an example, my earlier frustration could have been resolved if there is a small piece of C code like the following included in the Chapter 3 of the Quartus II Handbook Volume 5 (a.k.a. NIOS II Handbook Volume 3).

////////////////////////////////////////////
// hello_epcs.cpp
// date created: March 30, 2006
// author:
http://fpgaforum.blogspot.com
////////////////////////////////////////////
#include <iostream>
#include "system.h"
#include "sys/alt_flash.h"
#include "sys/alt_flash_dev.h"
using namespace std;

int main()
{
  alt_flash_fd* my_epcs;
  char my_data[256];

  //check your (EPCS_CONTROLLER_NAME) from system.h
  
my_epcs = alt_flash_open_dev(EPCS_CONTROLLER_NAME);

  if(my_epcs)
  {
    cout << "EPCS opened successfully!" << endl;

    //example application, read general data from epcs address 0x70000
    int ret_code =     alt_read_flash(my_epcs, 0x70000, my_data, 256);
    if(!ret_code)
    {
      cout << my_data << endl;
      return 0;
    }
    else
      return -1;
  }
  else
  {
    cout << "Error! EPCS not opened!" << endl;
    return -2;
  }
}
// The end
/////////////////////////////////////////////////////////

Anyway, I just found out that if you are lucky, you might still be able to find out the code very similar like above from the software example called memtest.c in the <NIOS II Path>\examples\software\memtest folder. By the way, you can only view the code after installing the NIOS II software tool.