Driver

The JPEG Encoder IP requires a processor to set up the core. This can be any processor. A JPEG encoder driver (prt_jpeg_enc_drv) is provided for this task. It is plain C with no operating system or vendor library behind it, so it ports to whatever core sits next to the IP.

The driver is deliberately small. The encoder has no protocol to run and no link to bring up, so there is no firmware and no system controller behind it — the whole API is a handful of register accesses. One prt_jpeg_enc_ds_struct describes one IP-core; a design with several encoders keeps one of these per core and passes the right one to every call.

The one substantial thing the driver does is build the JPEG header. The hardware does not generate markers: it produces entropy coded data and replays whatever header the host gave it in front of every image. prt_jpeg_enc_cfg assembles that header — SOI, APP0, the two DQT tables, SOF0, the four DHT tables, a COM comment and SOS — and writes it into the core. The comment is padded with spaces so the header ends on an 8-byte boundary, which is what lets the codestream mux hand out whole 64-bit words.

Note

The quantization tables in the header must match the constants built into the hardware quantizer. They are the standard tables of ISO/IEC 10918-1 Annex K, and changing one without the other produces a codestream that decodes to the wrong picture rather than one that fails to decode.

An IP-core is brought up in this order.

prt_jpeg_enc_init (&jpeg, JPEG_ENC_BASE_ADDR);   // find the IP-core
prt_jpeg_enc_cfg  (&jpeg, 3840, 2160);           // build and load the JPEG header
prt_jpeg_enc_str  (&jpeg);                       // start encoding

From that point on every incoming frame is encoded and appears on the codestream interface. The image resolution is fixed by the header, so a change of video format means calling prt_jpeg_enc_stp, prt_jpeg_enc_cfg with the new size, and prt_jpeg_enc_str again.

API

This section provides information about the driver API. The functions are grouped the same way as in prt_jpeg_enc_drv.h: setup and control.

Setup

prt_jpeg_enc_init

  • description: Sets the JPEG encoder base address, clears the control register and checks that the core responds.
  • syntax: bool prt_jpeg_enc_init (prt_jpeg_enc_ds_struct *jpeg, uint32_t base);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
    • basebase address
  • returns: true when the identification register reads back correctly, else false.

prt_jpeg_enc_cfg

  • description: Builds the JPEG header for the given image size and writes it into the core. The header is replayed by the hardware in front of every image, so this only has to be called once per video format.
  • syntax: void prt_jpeg_enc_cfg (prt_jpeg_enc_ds_struct *jpeg, uint16_t width, uint16_t height);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
    • widthimage width in pixels
    • heightimage height in lines
  • returns: none

prt_jpeg_enc_ver_major

  • description: Returns the major version of the IP-core.
  • syntax: uint8_t prt_jpeg_enc_ver_major (prt_jpeg_enc_ds_struct *jpeg);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
  • returns: major version number.

prt_jpeg_enc_ver_minor

  • description: Returns the minor version of the IP-core.
  • syntax: uint8_t prt_jpeg_enc_ver_minor (prt_jpeg_enc_ds_struct *jpeg);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
  • returns: minor version number.

Control

prt_jpeg_enc_str

  • description: Starts the encoder by setting the run bit in the control register. From this point every incoming frame is encoded.
  • syntax: void prt_jpeg_enc_str (prt_jpeg_enc_ds_struct *jpeg);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
  • returns: none

prt_jpeg_enc_stp

  • description: Stops the encoder by clearing the run bit in the control register, which holds the datapath in reset.
  • syntax: void prt_jpeg_enc_stp (prt_jpeg_enc_ds_struct *jpeg);
  • parameters:
    • jpegpointer to JPEG encoder IP-core
  • returns: none