2012年8月17日星期五

Write Your Own Module in GNU Radio ZZ


Burn Firmware and FPGA


To connect USRP2 to an external clock, you need to change the firmware and FPGA code on the SD Card
    1. Insert the SD card into the card reader
    2. Use "dmesg" command to check which interface is in use. The following is an example output in my machine, where the SC card is installed in /dev/sdc
    3. $ dmesg
      sd 4:0:0:1: [sdc] 3878912 512-byte logical blocks: (1.98 GB/1.84 GiB)
      sd 4:0:0:1: [sdc] Assuming drive cache: write through
      sd 4:0:0:1: [sdc] Assuming drive cache: write through
      sdc: unknown partition table
    4. Run$ cd gnuratio/usrp2/firmware/
      $ sudo ./u2_flash_tool --dev=/dev/XXXX -t s/w txrx.bin -w
      $ sudo ./u2_flash_tool --dev=/dev/XXXX -t fpga u2_rev3-20100603.bin -w 
      Be careful: /dev/XXXX has to be replaced with the device for the SD card reader.
    5. Insert the SD card to USRP2 and reboot USRP2. If your SD card is upgraded successfully, you should see all 6 LEDs flash, and LED 'D' and 'F' will remain on. If not, the card is not upgraded properly.

NOTE: Note that these firmware and FPGA codes work only when the external clock is in use. Otherwise, the USRPs behavior is unpredictable.



http://nms.citi.sinica.edu.tw/n+/software.html




Write Your Own Module


To create your own python module, you will need to write the python script (.py files), C library (.cc files), and the swig file (.i file). The simplest way to create a new module is to copy the existing module and modify it to what you want. We suggest modifying the 'mimo_ofdm_siso' module because it provides the most basic functionality so that you can build your own functions on top of it. In the following, we use modifying 'mimo_ofdm_siso' as the example to demonstrate how to create a new module, called 'mimo_ofdm_new'.
    1. Create python files$ cd gr-mimo/python/
      $ cp mimo_usrp2_ofdm_receiver_siso.py mimo_usrp2_ofdm_receiver_new.py
      $ ln -sf mimo_usrp2_ofdm_receiver_new.py mimo_usrp2_ofdm_receiver.py 
      Edit 'mimo_usrp2_ofdm_receiver_new.py' and replace all strings "_siso" with "_new". You might need to make other modifications if you want to create a module with a different number of input ports and output ports.
    2. Create C library$ cd ../lib/
      $ cp mimo_ofdm_siso.cc mimo_ofdm_new.cc
      $ cp mimo_ofdm_siso.h mimo_ofdm_new.h
      Edit 'mimo_ofdm_new.cc' and 'mimo_ofdm_new.h', and replace all strings "_siso" and "_SISO" to "_new" and "_NEW", respectively. Modify the makefile 'Makefile.am'. Add "mimo_ofdm_new.h" under the tag "modinclude_HEADERS =", and add "mimo_ofdm_new.cc" under the tag "libgnuradio_mimo_la_SOURCES =".
    3. Create .i file$ cd ../swig/
      $ cp mimo_ofdm_siso.i mimo_ofdm_new.i
      Edit 'mimo_ofdm_new.i', and replace all strings "_siso" with "_new".

      Add the following two lines in 'mimo.i'.#include "mimo_ofdm_new.h"
      %include "mimo_ofdm_new.i"
      Modify the makefile 'Makefile.am'. Add "mimo_ofdm_new.i" under the tag "mimo_swiginclude_headers =".
    4. Re-build$ cd ../
      $ make; sudo make install
    5. Create the new transmitter code$ cd gnuradio/usrp2/host/apps/
      $ cp mimo_siso_tx1.cc mimo_new.cc
      Add "mimo_new.cc" in 'Makefile.am', and reinstall$ make; sudo make install
    6. Run the example
      In the receiver,$ cd gr-mimo/python
      $ sudo ./mimo_usrp2_rx.py -f 2.45G -d 64 -e eth0 --rx_ant_num 1 -v
      In the transmitter,$ cd source/
      $ sudo mimo_new -f 2.45G -i 64 -e eth1 -v