{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://ternara.local/schemas/fir-mask-v0.1.schema.json",
  "title": "Ternara FIR Spec v0.1",
  "description": "Declarative specification for polyphase decimating FIR filters (Ternara FIR Fit)",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "name",
    "sampling",
    "mask",
    "fixed_point",
    "target_fpga",
    "csd_options"
  ],
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "0.1"
    },
    "name": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9_-]+$"
    },
    "description": {
      "type": "string"
    },
    "sampling": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "fs_mhz",
        "decimation_m",
        "fclk_mhz",
        "folding"
      ],
      "properties": {
        "fs_mhz": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "decimation_m": {
          "type": "integer",
          "minimum": 2
        },
        "fclk_mhz": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "folding": {
          "type": "integer",
          "enum": [1, 2]
        }
      }
    },
    "mask": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "fpass_mhz",
        "fstop_mhz",
        "apass_db",
        "astop_db",
        "max_group_delay_us"
      ],
      "properties": {
        "fpass_mhz": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "fstop_mhz": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "apass_db": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "astop_db": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "max_group_delay_us": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      }
    },
    "fixed_point": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "input_bits",
        "output_bits",
        "rounding",
        "target_sfdr_db",
        "target_enob_bits"
      ],
      "properties": {
        "input_bits": {
          "type": "integer",
          "minimum": 8,
          "maximum": 24
        },
        "output_bits": {
          "type": "integer",
          "minimum": 8,
          "maximum": 32
        },
        "rounding": {
          "type": "string",
          "enum": ["convergent", "half_up"]
        },
        "target_sfdr_db": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "target_enob_bits": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      }
    },
    "target_fpga": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "family",
        "part",
        "channels_k_sweep"
      ],
      "properties": {
        "family": {
          "type": "string",
          "enum": ["xc7", "xcu", "xcup", "ecp5"]
        },
        "part": {
          "type": "string",
          "minLength": 1
        },
        "parts_for_kmax": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "channels_k_sweep": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "integer",
            "minimum": 1
          }
        }
      }
    },
    "csd_options": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "coeff_bits",
        "max_nzd",
        "enable_cse",
        "pipe_stride"
      ],
      "properties": {
        "coeff_bits": {
          "type": "integer",
          "minimum": 10,
          "maximum": 24
        },
        "max_nzd": {
          "type": "integer",
          "minimum": 1,
          "maximum": 8
        },
        "enable_cse": {
          "type": "boolean"
        },
        "pipe_stride": {
          "type": "integer",
          "minimum": 1,
          "maximum": 4
        }
      }
    }
  }
}
