Now that the Adafruit NeoPixel example has been completed (see my eight previous blog posts, below), we’ll be moving on for a look at operating systems. But first, a short interlude. During the past week I received an interesting question about Part 24 of this blog that discussed communication across the Zynq SoC’s PS/PL (processor system/programmable logic) interface. The particular question related to raising an interrupt to an ARM Cortex-A9 MPCore CPU in the Zynq PS from the PL.
The diagram above shows that each CPU has a number of shared interrupts from the PL to the PS (16 interrupts) and five private interrupts for each CPU core from the PL. These interrupt sources drive a fast interrupt and a regular interrupt for each CPU core. In this example, I show how to use the private interrupt. However the general concept is the same regardless of interrupt used. For this example, I will be using an EMIO GPIO pin connected via the PL, looped back and connected to the processor’s interrupt pin. A simple software program can then demonstrate how an interrupt from the PL works. Note: The interrupt at the PL/PS interface is active high, not active low.
The first stage of this example is to enable the interrupts between the PL and PS and to enable the specific interrupt you wish to use.
The second step is to enable a single-bit GPIO using the EMIO option.
Both the interrupt and the GPIO pin will now appear on the Zynq PS block within the block diagram. These signals can be then be interconnected, so that we can drive the interrupt from the EMIO within the Zynq PL under software control.
Having gotten to this stage, the next step is to regenerate all of the output products for the design and implement the design so that we can export it to the SDK. In turn, this allows us to write the code to test the application.
Our test application will trigger an FPGA interrupt when we press the push-button switch on the MicroZed board.
Within the SDK, we need to perform the following steps:
Declare the following header files: Platform.h, xparameters.h, Xscugic.h, Xil_Exceptions.h and xgpio.h. These header files will provide functions and macros that enable us to generate the example.
Define the generic interrupt controller and GPIO device ID and interrupt numbers along with the FPGA interrupt and pin numbers for the EMIO and push-button switch.
Declare and write a number of required functions:
Interrupt controller set up function
PGA Interrupt handler, which prints a message
GPIO Interrupt handler, which drives the EMIO GPIO to trigger a FPGA interrupt upon a push-button interrupt.
The attached code (see attachment below, at the end of this blog post) shows in detail exactly how how I implemented this simple example. However, I think I should explain the way I set up the interrupt for the FPGA in a little more detail.
When setting up an interrupt in the Zynq we need to do the following things:
Initialize the Interrupt controller.
Connect the exception ID to the associated handler so that when an event occurs it can be run correctly.
Connect the FPGA interrupt to the generic interrupt controller. This requires the pre-defined interrupt ID, the call-back handler (which is defined to identify the source of the interrupt), and the interrupt service routine to be run when the interrupt occurs.
Enable the interrupt on the interrupt controller.
Enable interrupts on the processor.
The above flow is required for one interrupt or for many interrupts, with points 3 and 4 repeated for each interrupt required.
When I ran this code on my MicroZed and pushed the button, I saw the following response:
Please see the previous entries in this MicroZed series by Adam Taylor: