A simple design with Wishbone bus
This article is intended to explain how to design Wishbone compatible components with simple example. The VHDL source code can be found in firmware/wishbone_example from our gitlab repository.
Description of the Wishbone structure for Armadeus APF boards can be found here (in french).
- 1 General structure
- 2 Wishbone slave application components
- 3 Components drivers
- 4 Using the design
The main functionality of this component is to allow to switch-on a LED when a button is pressed.
When button is pressed, the component button send interrupt signal to irq_mngr. irq_mngr will toggle a flag and send interruption to i.MX processor. A Linux driver on i.MX will read irq_mngr and acknowledge irq by writing '1' on the corresponding register. And finally, Linux driver will toggle LED value by writing in led register.
imx_wrapper, syscon and irq_mngr are standards ARMadeus-Wishbone IPs that just been instantiated in our design.
button and led are simple slave component we want to integrate in the FPGA.
All these components are connected together with the 'glue logic' component intercon.
The wrapper is used to convert i.MX interface signals into Wishbone signals.
The intercon is a component used to manage signals between Wishbone master and slave components. This component decode Wishbone-master addresses and dispatch them to Wishbone-slave components.
Wishbone slave application components
In this example there are 3 Wishbone-slave components :
Some components (here, only button) generate interrupts, irq manager is used to mux these interrupts for i.MX. The irq_mngr can manage up to 16 internal interrupts.
IRQ manager component has tree registers, one to enable interrupts, one for flags/acknowledge interrupts and one identification register :
|mask||write '1' to allow irq|
|ack/pend||read for pending irq, write to acknowledge irq|
This component is a simple 16-bit Wishbone slave output port, from wishbone specification example (p110).
It is a simple register, that can be read and write. The LED is controlled with register pin 0.
The two registers are :
|register name||(relative) address||function|
|LED||0x00||Write '1' in LSB to shutdown LED|
|id||0x02||read identification number|
Wb_button component, is like led but in read only and with an edge detector to rise irq.
The two registers are:
|id||0x00||read identification number|
|Button||0x02||read LSB to know button state|
Each component is driven by a Linux driver described above. All driver code is in armadeus directory in target/linux/module/fpga/wishbone_example/.
Each component has an identification register with unique number. This number is used by driver when modprobed to unsure that device is present.
LED driver is seen in Linux like a character driver. Writing in a /dev file will enable or disable the LED.
The driver is composed of two modules :
- led_ocore : this module implement generic LED driver mechanisms.
- wb_example_led : This module describe specific datas for each LED-component available in design. These datas are described in structure plat_led_port and plat_led_device. The module will register each LED with platform_device_register() function. When a plat_led_port device is registered, led_ocore driver will detect it and will probe it with led_probe function.
Button driver is seen in Linux like a character driver. When a process want to read value in button register, the driver will block reading until an interrupt occur.
Structure of button driver is similar to LED driver (two modules) :
- button_ocore : This module implements generic button driver mechanisms.
- wb_example_button : Like LED module, this module describes specific data for each button-component available in design.
Using the design
Make the FPGA bitstream
ISE Webpack is mandatory to generate the bitstream, so its installation is required. Once bitstream has been generated, it can be downloaded in FPGA with U-Boot or Linux. For apf51, bitstream is under the directory firmware/wishbone_example/wishbone_example51/binaries/top_wishbone_example51_lx9.bin. For apf27 and apf9328 bitstream can be found in firmware/wishbone_example/wishbone_example9328_27/bin/.
Compile Linux drivers
To compile the drivers for this design select them in Linux menuconfig:
$ make linux-menuconfig
Device Drivers ---> Armadeus specific drivers ---> FPGA Drivers ---> [*] Board designs [*] board drivers for wishbone example <M> board Button <M> board Led <M> board irq
and compile them:
$ make linux && make
Modules must be loaded in right order with modprobe command :
- IRQ manager :
# modprobe irq_ocore # modprobe wb_example_irq_mngr
- Button generic module must be loaded before board module:
# modprobe button_ocore # modprobe wb_example_buttons button button.0: BUTTON0: MAJOR: 249 MINOR: 0 BUTTON0 loaded
- LED generic module must be loaded before board module:
# modprobe led_ocore # modprobe wb_example_led LED0: MAJOR: 248 MINOR: 0 LED module LED0 insered
Devices access are done with special caracters file. These file must be created with major and minor number given when modules are loaded (see Load modules above) :
- Make LED access :
# mknod /dev/led0 c LED_MAJOR_NUMBER 0
- Make button access :
# mknod /dev/button0 c BUTTON_MAJOR_NUMBER 0
Replace LED_MAJOR_NUMBER and BUTTON_MAJOR_NUMBER with correct major number given when modprobe is done.
A test program is available in module directory:
simply compile it with arm-linux-gcc compiler :
$ make test
Download testled binary on your APF, then test it :
# ./testled /dev/led0 Testing led driver Read 1 Write 0 Read 0 Write 1 Read 1 Write 0 Read 0
LED is blinking slowly.
A test program is available in directory:
simply compile it in the directory with command:
$ make test
copy the testbutton binary in your target then launch it:
# ./testbutton /dev/button0 Testing button driver Read 1 Read 0 Read 1 Read 0 Read 1 Read 0 Read 0 Read 1 Read 0 Read 1
Each time button is pushed or released, button state is printed out.
A simple program is available in wishbone example directory:
to switch on the LED when button is pressed.
To compile :
$ make test
To use it, simply type (after downloaded it under your target):
# ./push-led /dev/button0 /dev/led0 Blink a led pushing button
Push the button to switch on/off the LED.