Using PicoBlaze
From RCSWiki
- Author: Siddharth Taduri
- 02/10/2009
PicoBlaze is a 8-bit soft processor core from Xilinx which can be embedded onto FPGA's and CPLD's. Being a smaller processor, it can be used for a variety of applications. This tutorial summarizes the following two documents for a quicker start working on the PicoBlaze.
Important Documents:
Downloads:
- PicoBlaze package can be downloaded here. This package contains the Source code, the netlist files, the ROM template files etc.
- picoasm is a command line assembler. More information can be found at [1]
- kpicosim is an assembler and a simulator with a GUI. More information can be found at [2]
Contents |
Features
- 64-byte scratchpad-RAM
- 256 multiplexed 8-bit input/output ports
- Single Interrupt, fast response
- 1k Program Memory
- 16 8-bit general purpose registers
- 96 Slices
- 200Mhz performance on Virtex-II Pro
- Auto 31-location Return/Call stack
- Assembler/Simulator Support
Interfacing PicoBlaze in UserLogic
To use PicoBlaze in a FPGA design, it has to be instantiated within a user core. It can be interfaced to slave registers and other buses for access. Refer to the Creating Custom Hardware Core Tutorial if you want to know more about creating a custom core.
Declaring the component in user logic:
- component KCPSM3
- port (
- address : out std_logic_vector( 9 downto 0);
- instruction : in std_logic_vector(17 downto 0);
- port_id : out std_logic_vector( 7 downto 0);
- write_strobe : out std_logic;
- out_port : out std_logic_vector( 7 downto 0);
- read_strobe : out std_logic;
- in_port : in std_logic_vector( 7 downto 0);
- interrupt : in std_logic;
- interrupt_ack : out std_logic;
- reset : in std_logic;
- clk : in std_logic
- );
- end component;
Declaring the PROM in user logic:
- component prog_rom
- port (
- address : in std_logic_vector( 9 downto 0);
- instruction : out std_logic_vector(17 downto 0);
- clk : in std_logic
- );
- end component;
Port mapping the Processor:
- processor: kcpsm3
- port map(
- address => address_signal,
- instruction => instruction_signal,
- port_id => port_id_signal,
- write_strobe => write_strobe_signal,
- out_port => out_port_signal,
- read_strobe => read_strobe_signal,
- in_port => in_port_signal,
- interrupt => interrupt_signal,
- interrupt_ack => interrupt_ack_signal,
- reset => reset_signal,
- clk => clk_signal
- );
Port Mapping the PROM:
- program: prog_rom
- port map( address => address_signal,
- instruction => instruction_signal,
- clk => clk_signal
- );
- Note: Do not forget to include 'OPTION STYLE = MIX' in the .pao file in the data/ directory and copy the netlist files (*.ngc) to the netlist/ directory under pcores/your_core
Some basic Syntax
- Declaring Constants
- CONSTANT abc, <value>
- CONSTANT abc, A5
- Naming Registers for convineince (s0-s15)
- NAMEREG s0, my_reg_1
- NAMEREG s1, my_reg_2
- Locating code or declaring the starting address of a section of code
- ADDRESS 000
- START: ....
- ....
- SUB-ROUTINE-1: ...
- ...
- Enabling Interrupts
- ENABLE INTERRUPT
- START: ...
- ...
- ISR: ... ;There has to be an ISR every time Interrupts are enabled
- ...
- ADDRESS 3FF ;Interrupt Vector is stored in this location
- JUMP ISR ;; Will jump to the ISR
- Arithmetic Instructions
- ADD sX, A5
- SUBsX, sY
- ADDCY sX, 12
- SUBCY sX, sY
- Logical Instructions
- AND sX, AC
- OR sX, sY
- XOR sY, BE
- COMPARE sX, OPERAND ; Sets the zero and carry flags
- Shifts and Rotates
- {SR0,SLO} sX ;fills with 0's
- {SR1,SL1} sY ;fills with 1's
- {SRX, SLX} sX ;bit zero stays intact
- {SRA,SLA} sX ;shift includes carry
- {RR,RL} sY
- Register
- LOAD sX, sY
- LOAD sX, 34
- Input/Output
- INPUT sX, 45
- OUTPUT sY, (sX) ;Indirect referencing
- Program Control
- {RETURN,JUMP,CALL} aa
- {RETURN,JUMP,CALL} {Z,NZ,C,NC}, aa ;where aa is the location to jump to
- ;Z,NZ,C,NC are the flag conditions
- Memory Operations
- STORE sX, A1
- FETCH sX, (sY)
Using picoasm
In the terminal window, type the following command to assemble your code:
- ./picoasm -i <input_file.psm> -t < ROM_template_file> -o <output_file.vhd> -d <output_directory>
- If you want to log the assmebler output you could add > log.txt to the above command.
- If output file isn't mentioned, default name will be input_file.vhd
- Use a text editor such as emacs or vi to edit your code.
Sample Code
/* To Do */
