Using External I/O

Hardware accelerators generated in theSDSoC™environment can communicate with system inputs and outputs either directly through hardware connections, or though memory buffers (for example, a frame buffer). Examples of system I/O include analog-to-digital and digital-to-analog converters, image, radar, LiDAR, and ultrasonic sensors, andHDMI™multimedia streams.

A platform exports stream connections in hardware that can be accessed in software by calling platform library functions as described inAccessing External I/O Using Memory BuffersandAccessing External I/O Using Direct Hardware Connections. Direct hardware connections are implemented overAXI4-Streamchannels and connections to memory buffers are realized through function calls implemented by the standard data movers supported in theSDSoCenvironment.

For information and examples that show how to createSDSoCplatforms, see theSDSoC Environment Platform Development Guide.

Accessing External I/O Using Memory Buffers

This section uses the motion-detectZC702 + HDMI IO FMCor theZC706 + HDMI IO FMCplatform found under the "Boards, Kits, & Modules" page of theSDSoC Development Environment. The preconfiguredSDSoCplatform is responsible for theHDMIdata transfer to external memory. The application must call the platform interfaces to process the data from the frame buffer in DDR memory. The following figure shows an example of how the design is configured.

Figure:Motion Detect Design Configuration



TheSDSoCenvironment accesses the external frame buffer through an accelerator interface to the platform. Thezc702_hdmiplatform provides a software interface to access the video frame buffer through theVideo4Linux2(V4L2) API. The V4L2 framework provides an API accessing a collection of device drivers supporting real-time video capture in Linux. This API is the application development platform I/O entry point.

Themotion_demo_processingfunction in the following code snippet fromm2m_sw_pipeline.cdemonstrates the function call interface.

extern void motion_demo_processing(unsigned short int *prev_buffer, unsigned short int *in_buffer, unsigned short int *out_buffer, int fps_enable, int height, int width, int stride); . . . unsigned short *out_ptr = v_pipe->drm.d_buff[buf_next->index].drm_buff; unsigned short *in_ptr1 = buf_prev->v412_buff; unsigned short *in_ptr2 = buf_next->v412_buff; v_pipe->events[PROCESS_IN].counter_val++; motion_demo_processing(in_ptr1, in_ptr2, out_ptr, v_pipe->fps_enable, (int)m2m_sw_stream_handle.video_in.format.height, (int)m2m_sw_stream_handle.video_in.format.width, (int)m2m_sw_stream_handle.video_in.format.bytesperline/2);

The application accesses this API inmotion_detect.c, wheremotion_demo_procesingis defined and called by theimg_processfunction.

void motion_demo_processing(unsigned short int *prev_buffer, unsigned short int *in_buffer, unsigned short int *out_buffer, int fps_enable, int height, int width, int stride) { int param0=0, param1=1, param2=2; img_process(prev_buffer, in_buffer, out_buffer, height, width, stride); }

Finally,img_processcalls the various filters and transforms to process the data.

void img_process(unsigned short int *frame_prev, unsigned short int *frame_curr, unsigned short int *frame_out, int param0, int param1, int param2) { ... }

By using a platform API to access the frame buffers, the application developer does not program at the driver-level to process the video frames.

You can find the platform used for the code snippets on theSDSoC Downloads Pagewith the nameZC702 + HDMI IO FMCorZC706 + HDMI IO FMC.

Accessing the SDSoC Environment

The following steps outline how to access the project in the SDSoCenvironment.
  1. Download and extract the platform to your system.
  2. OpenSDx™and create a new application project.
  3. From the Platform dialog box, selectAdd Custom Platform.
  4. From theSpecify Custom Platform Locationdialog box, select the location of the downloaded platform, and clickOK.
  5. From the Platform dialog box, select the custom platform folder namedzc702_trdorzc706_trd, and clickNext.
  6. From the System Configuration dialog box, leave the default settings and clickNext.
  7. From the Templates dialog box, select theDense Optical Flow (1PPC)template, and clickFinish.

Accessing External I/O Using Direct Hardware Connections

Whereas the example inAccessing External I/O Using Memory Buffersdemonstrated how applications can access system I/O through memory buffers, a platform can also provide direct hardware connectivity to hardware accelerators within an application generated in theSDSoCenvironment. The following figure shows how a functions2mm_data_copycommunicates to the platform using anAXI4-Streamchannel and writes to DDR memory using thezero_copydata mover (implemented as anAXI4master interface). This design template is calledaximmdesign example in thesamples/platforms/zc702_axis_ioplatform.

Figure:AXI4Data Mover Design



In this example, thezc702_axis_ioplatform proxies actual I/O by providing a free-running binary counter (labeled Platform IP in the diagram) running at 50 MHz, connected to anAXI4-StreamData FIFO IP block that exports anAXI4-Streammaster interface to the platform clocked at the data motion clock (which might differ from the 50 MHz input clock).

The direct I/O interface is specified using thesys_portpragma for a stream port. In the following code snippet, the direct connection is specified forstream_fifo_M_AXIS.

#pragma SDS data sys_port (fifo:stream_fifo_M_AXIS) #pragma SDS data zero_copy(buf) int s2mm_data_copy(unsigned *fifo, unsigned buf[BUF_SIZE]) { #pragma HLS interface axis port=fifo for(int i=0; i

In the followingmainapplication code, therbuf0variable maps the FIFO input stream to thes2mm_data_copyfunction, so thesds++compiler creates a direct hardware connection over anAXI4-Streamchannel. Because thes2mm_data_copyfunction transfersbufusing thezero_copydata mover, the buffer must be allocated in physically contiguous memory usingsds_alloc, and released usingsds_free, as shown below.

int main() { unsigned *bufs[NUM_BUFFERS]; bool error = false; unsigned* rbuf0; for(int i=0; i

Information on creating a platform usingAXI4-Streamto write to memory directly can be found in the "SDSoCPlatform Examples" appendix ofSDSoC Environment Platform Development Guide.