<?xml version="1.0" encoding="utf-8"?>


<!--****************************************************************************
* \file quaddec.cypersonality
* \version 1.0
*
* \brief
* Quadrature Decoder personality description file.
*
********************************************************************************
* \copyright
* Copyright 2018-2019 Cypress Semiconductor Corporation
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************-->

<Personality id="mxs40quaddac" name="Quadrature Decoder" version="1.0" path="Digital/Functions" xmlns="http://cypress.com/xsd/cyhwpersonality_v1">
  <Dependencies>
    <IpBlock name="mxtcpwm" />
    <Resource name="tcpwm\.cnt" used="true" />
  </Dependencies>
  <ExposedMembers />
  <Parameters>
    <!-- PDL documentation -->
    <ParamDoc id="pdlDoc" name="Configuration Help" group="Peripheral Documentation" default="file:///`${cy_libs_path()}`/docs/pdl_api_reference_manual/html/group__group__tcpwm__quaddec.html" linkText="Open Quadrature Decoder (TCPWM) Documentation" visible="true" desc="Opens the Peripheral Driver Library Documentation" />
  
    <!--General-->
    <ParamChoice id="CounterSize" name="Quadrature Decoder Resolution" group="General" default="`${(CNT.CNT_WIDTH eq 16) ? &quot;16&quot; : &quot;32&quot;}`" visible="true" editable="false" desc="Sets the resolution of the counter">
      <Entry name="16-bits" value="16" visible="true" />
      <Entry name="32-bits" value="32" visible="true" />
    </ParamChoice>
    <ParamChoice id="InterruptSource" name="Interrupt Source" group="General" default="CY_TCPWM_INT_NONE" visible="true" editable="true" desc="Selects which events can trigger an interrupt">
      <Entry name="None" value="CY_TCPWM_INT_NONE" visible="true" />
      <Entry name="Index" value="CY_TCPWM_INT_ON_TC" visible="true" />
      <Entry name="TC" value="CY_TCPWM_INT_ON_CC" visible="true" />
      <Entry name="Index or TC" value="CY_TCPWM_INT_ON_CC_OR_TC" visible="true" />
    </ParamChoice>
    <ParamChoice id="Resolution" name="Quadrature Mode" group="General" default="CY_TCPWM_QUADDEC_X1" visible="true" editable="true" desc="Selects the quadrature encoding mode">
      <Entry name="x1" value="CY_TCPWM_QUADDEC_X1" visible="true" />
      <Entry name="x2" value="CY_TCPWM_QUADDEC_X2" visible="true" />
      <Entry name="x4" value="CY_TCPWM_QUADDEC_X4" visible="true" />
    </ParamChoice>

    <!--Inputs-->
    <ParamSignal port="clock[0]" name="Clock Signal" group="Inputs" visible="true" desc="The clock input defines the operating frequency." canBeEmpty="false" />
    <ParamChoice id="IndexInput" name="Index Input" group="Inputs" default="CY_TCPWM_INPUT_DISABLED" visible="true" editable="true" desc="Determines if an index is needed and what edge causes an index to occur">
      <Entry name="Rising Edge" value="CY_TCPWM_INPUT_RISINGEDGE" visible="true" />
      <Entry name="Falling Edge" value="CY_TCPWM_INPUT_FALLINGEDGE" visible="true" />
      <Entry name="Either Edge" value="CY_TCPWM_INPUT_EITHEREDGE" visible="true" />
      <Entry name="Disabled" value="CY_TCPWM_INPUT_DISABLED" visible="true" />
    </ParamChoice>
    <ParamSignal port="reload[0]" name="Index Signal" group="Inputs" visible="`${IndexInput ne CY_TCPWM_INPUT_DISABLED}`" desc="This input causes an index (reload) event to occur (indicates a completed rotation to determine absolute position). This input is only visible if the IndexInput parameter is set to anything other than disabled." canBeEmpty="`${IndexInput eq CY_TCPWM_INPUT_DISABLED}`" >
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="DEFAULT" reason="">
          <Fixed value="CY_GPIO_DM_HIGHZ" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="INFO" reason="The pin Drive Mode parameter does not match expected.">
          <Fixed value="CY_GPIO_DM_HIGHZ" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation=".*" valid="true" />
    </ParamSignal>
    
    <ParamSignal port="count[0]" name="PhiA Signal" group="Inputs" visible="true" desc="This is the phase A input it is always required." canBeEmpty="false" >
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="DEFAULT" reason="">
          <Fixed value="CY_GPIO_DM_HIGHZ" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="INFO" reason="The pin Drive Mode parameter does not match expected.">
          <Fixed value="CY_GPIO_DM_HIGHZ" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation=".*" valid="true" />
    </ParamSignal>    
    <ParamSignal port="start[0]" name="PhiB Signal" group="Inputs" visible="true" desc="This is the phase B input it is always required." canBeEmpty="false" >
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="DEFAULT" reason="">
          <Fixed value="CY_GPIO_DM_HIGHZ" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="INFO" reason="The pin Drive Mode parameter does not match expected.">
          <Fixed value="CY_GPIO_DM_HIGHZ" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation=".*" valid="true" />
    </ParamSignal>    
    
    <ParamChoice id="StopInput" name="Stop Input" group="Inputs" default="CY_TCPWM_INPUT_DISABLED" visible="true" editable="true" desc="Determines if a stop input is needed and what edges causes a stop to occur">
      <Entry name="Rising Edge" value="CY_TCPWM_INPUT_RISINGEDGE" visible="true" />
      <Entry name="Falling Edge" value="CY_TCPWM_INPUT_FALLINGEDGE" visible="true" />
      <Entry name="Either Edge" value="CY_TCPWM_INPUT_EITHEREDGE" visible="true" />
      <Entry name="Disabled" value="CY_TCPWM_INPUT_DISABLED" visible="true" />
    </ParamChoice>
    <ParamSignal port="stop[0]" name="Stop Signal" group="Inputs" visible="`${StopInput ne CY_TCPWM_INPUT_DISABLED}`" desc="This input causes the Quad Dec to stop Counting. This input is only visible if the StopInput parameter is set to anything other than disabled." canBeEmpty="`${StopInput eq CY_TCPWM_INPUT_DISABLED}`" > 
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="DEFAULT" reason="">
          <Fixed value="CY_GPIO_DM_HIGHZ" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="INFO" reason="The pin Drive Mode parameter does not match expected.">
          <Fixed value="CY_GPIO_DM_HIGHZ" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation=".*" valid="true" />
    </ParamSignal>

    <!--Outputs-->
    <ParamSignal port="tr_compare_match[0]" name="TC (cc_match)" group="Outputs" visible="true" desc="This output goes high on an index event, or when the count equals 0x0000 or `${(CNT.CNT_WIDTH eq 16) ? &quot;0xffff&quot; : &quot;0xffffffff&quot;}`." canBeEmpty="true" >
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="DEFAULT" reason="">
          <Fixed value="CY_GPIO_DM_STRONG_IN_OFF" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation="ioss\[\d+\]\.port\[\d+\]\.pin.*" valid="true" >
        <Parameter id="DriveModes" severity="INFO" reason="The pin Drive Mode parameter does not match expected.">
          <Fixed value="CY_GPIO_DM_STRONG_IN_OFF" />
        </Parameter>
      </Constraint>
      <Constraint type="ACCEPT" targetLocation=".*" valid="true" />
    </ParamSignal>
    
    <!--Config-->
    <ParamBool id="inFlash" name="Store Config in Flash" group="Advanced" default="true" visible="true" editable="true" desc="Controls whether the configuration structure is stored in flash (const, true) or SRAM (not const, false)." />

    <!-- Peripheral clock divider connection -->
    <ParamRange id="tcpwmInst" name="TCPWM Number" group="Internal" default="`${getInstNumber(&quot;tcpwm&quot;)}`" min="0" max="127" resolution="1" visible="false" editable="false" desc="" />
    <ParamRange id="cntInst" name="CNT Number" group="Internal" default="`${getInstNumber(&quot;cnt&quot;)}`" min="0" max="31" resolution="1" visible="false" editable="false" desc="" />
    <ParamString id="definePrefix" name="Define prefix" group="Internal" default="`${&quot;TCPWM&quot; . tcpwmInst . &quot;_CNT&quot; . cntInst}`" visible="false" editable="false" desc="" />
    <ParamString id="defineInputDisabled" name="Define input disabled" group="Internal" default="`${INST_NAME . &quot;_INPUT_DISABLED &amp; 0x3U&quot;}`" visible="false" editable="false" desc="" />
    <ParamString id="pclk" name="PCLK" group="Internal" default="`${getBlockFromSignal(&quot;clock[0]&quot;)}`" visible="false" editable="false" desc="Connected peripheral clock divider (PCLK)" />
    <ParamBool id="pclkOk" name="PCLK Valid" group="Internal" default="`${hasConnection(&quot;clock&quot;, 0) &amp;&amp; isBlockUsed(pclk)}`" visible="false" editable="false" desc="Checks whether there is a PCLK connected and enabled" />
    <ParamString id="pclkDst" name="PCLK Destination" group="Internal" default="PCLK_TCPWM`${tcpwmInst}`_CLOCKS`${cntInst}`" visible="false" editable="false" desc="" />
  </Parameters>

  <DRCs>
  </DRCs>
  
  <ConfigFirmware>
    <ConfigInclude value="cy_tcpwm_quaddec.h" include="true" />
    <ConfigInclude value="cy_sysclk.h" include="`${pclkOk}`" />
    <ConfigInclude value="cycfg_routing.h" include="true" />
    <ConfigInclude value="cyhal_hwmgr.h" include="true" guard="defined (CY_USING_HAL)" />
    
    <ConfigDefine name="`${INST_NAME}`_HW" value="TCPWM`${tcpwmInst}`" public="true" include="true" />
    <ConfigDefine name="`${INST_NAME}`_NUM" value="`${cntInst}`UL" public="true" include="true" />
    <ConfigDefine name="`${INST_NAME}`_MASK" value="(1UL &lt;&lt; `${cntInst}`)" public="true" include="true" />
    <ConfigDefine name="`${INST_NAME}`_IRQ" value="tcpwm_`${tcpwmInst}`_interrupts_`${cntInst}`_IRQn" public="true" include="`${InterruptSource ne CY_TCPWM_INT_NONE}`" />
    <ConfigDefine name="`${INST_NAME}`_INPUT_DISABLED" value="0x7U" public="false" include="true" />
    <ConfigStruct name="`${INST_NAME . &quot;_config&quot;}`" type="cy_stc_tcpwm_quaddec_config_t" const="`${inFlash}`" public="true" include="true">
      <Member name="resolution" value="`${Resolution}`" />
      <Member name="interruptSources" value="`${InterruptSource}`" />
      <Member name="indexInputMode" value="`${IndexInput eq CY_TCPWM_INPUT_DISABLED ? defineInputDisabled : IndexInput}`" />
      <Member name="indexInput" value="`${IndexInput eq CY_TCPWM_INPUT_DISABLED ? &quot;CY_TCPWM_INPUT_0&quot; : (definePrefix . &quot;_RELOAD_VALUE&quot;)}`" />
      <Member name="stopInputMode" value="`${StopInput eq CY_TCPWM_INPUT_DISABLED ? defineInputDisabled : StopInput}`" />
      <Member name="stopInput" value="`${StopInput eq CY_TCPWM_INPUT_DISABLED ? &quot;CY_TCPWM_INPUT_0&quot; : (definePrefix . &quot;_STOP_VALUE&quot;)}`" />
      <Member name="phiAInput" value="`${(definePrefix . &quot;_COUNT_VALUE&quot;)}`" />
      <Member name="phiBInput" value="`${(definePrefix . &quot;_START_VALUE&quot;)}`" />
    </ConfigStruct>
    
    <ConfigStruct name="`${INST_NAME}`_obj" type="cyhal_resource_inst_t" const="true" public="true" include="true" guard="defined (CY_USING_HAL)">
      <Member name="type" value="CYHAL_RSC_TCPWM" />
      <Member name="block_num" value="`${getInstNumber(&quot;tcpwm&quot;)}`U" />
      <Member name="channel_num" value="`${getInstNumber(&quot;cnt&quot;)}`U" />
    </ConfigStruct>
    
    <ConfigInstruction value="Cy_SysClk_PeriphAssignDivider(`${pclkDst}`, `${getExposedMember(pclk, &quot;clockSel&quot;)}`);" include="`${pclkOk}`" />
    <ConfigInstruction value="cyhal_hwmgr_reserve(&amp;`${INST_NAME}`_obj);" include="true" guard="defined (CY_USING_HAL)" />
  </ConfigFirmware>
</Personality>
