1<?xml version="1.0" encoding="utf-8"?>
2
3<!--****************************************************************************
4* \file emusb.cypersonality
5* \version 1.0
6*
7* \brief
8* emusb personality description file.
9*
10********************************************************************************
11* \copyright
12* Copyright 2022 Cypress Semiconductor Corporation
13* SPDX-License-Identifier: Apache-2.0
14*
15* Licensed under the Apache License, Version 2.0 (the "License");
16* you may not use this file except in compliance with the License.
17* You may obtain a copy of the License at
18*
19*     http://www.apache.org/licenses/LICENSE-2.0
20*
21* Unless required by applicable law or agreed to in writing, software
22* distributed under the License is distributed on an "AS IS" BASIS,
23* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24* See the License for the specific language governing permissions and
25* limitations under the License.
26*****************************************************************************-->
27
28<Personality id="mxs40emusb" name="emUSB-Host/Device" version="1.0" xmlns="http://cypress.com/xsd/cyhwpersonality_v7">
29  <Dependencies>
30    <IpBlock name="mxusbfs" />
31    <Resource name="usb" />
32  </Dependencies>
33  <ExposedMembers />
34  <Parameters>
35
36    <!-- Debug mode selection -->
37    <ParamBool id="debug" name="debug" group="Internal" default="false" visible="false" editable="false" desc="Enable/Disable debug mode" />
38
39    <!-- Mode selection -->
40    <ParamChoice id="mode" name="USB mode" group="General" default="Host" visible="true" editable="true" desc="Select USB Mode">
41      <Entry name="Host" value="Host" visible="true" />
42      <Entry name="Device" value="Device" visible="true" />
43    </ParamChoice>
44    <ParamBool id="modeIsDevice" name="modeIsDevice" group="Internal" default="`${mode eq Device}`" visible="false" editable="false" desc="USB mode is Device" />
45    <ParamBool id="modeIsHost" name="modeIsHost" group="Internal" default="`${mode eq Host}`" visible="false" editable="false" desc="USB Mode is Host" />
46
47    <!-- Documentation -->
48    <ParamDoc id="emUsbDoc" name="Configuration Help" group="Overview" default="`${modeIsHost ? &quot;https://infineon.github.io/emusb-host/html/index.html&quot; : &quot;https://infineon.github.io/emusb-device/html/index.html&quot;}`" linkText="`${modeIsHost ? &quot;Open emUSB-Host Documentation&quot; : &quot;Open emUSB-Device Documentation&quot;}`" visible="true" desc="Open the USB Documentation" />
49
50    <!-- USB Hf clock configuration -->
51    <ParamSignal port="clk_usb_host[0]" name="Clock" group="Connections" visible="`${modeIsHost}`" desc="The clock to operate this block" canBeEmpty="true" />
52    <ParamBool id="clkUsbHostIsConnected" name="clkUsbHostIsConnected" group="Internal" default="`${hasConnection(&quot;clk_usb_host&quot;, 0)}`" visible="`${debug}`" editable="false" desc="Check if clk_usb_host[0] is connected" />
53    <ParamSignal port="clk_usb_dev[0]" name="Clock" group="Connections" visible="`${modeIsDevice}`" desc="The clock to operate this block" canBeEmpty="true" />
54    <ParamBool id="clkUsbDeviceIsConnected" name="clkUsbDeviceIsConnected" group="Internal" default="`${hasConnection(&quot;clk_usb_dev&quot;, 0)}`" visible="`${debug}`" editable="false" desc="Check if clk_usb_dev[0] is connected" />
55
56    <ParamString id="usbHfSource" name="usbHfSource" group="Internal" default="`${modeIsHost ? getBlockFromSignal(&quot;clk_usb_host[0]&quot;) : getBlockFromSignal(&quot;clk_usb_dev[0]&quot;)}`" visible="false" editable="false" desc="Select Hf clock source" />
57    <ParamRange  id="usbHfHz" name="usbHfHz" group="Internal" default="`${getExposedMember(usbHfSource, &quot;frequency&quot;)}`" min="0" max="200000000" resolution="1" visible="false" editable="false" desc="USB HF clock frequency in Hz." />
58
59    <ParamRange  id="usbHfRealAccuracyPercent" name="usbHfRealAccuracy" group="Internal" default="`${getExposedMember(usbHfSource, &quot;accuracy&quot;)}`" min="0" max="100" resolution="0.0001" visible="false" editable="false" desc="USB HF clock accuracy." />
60    <ParamRange  id="usbHfRealAccuracy" name="usbHfRealAccuracy" group="Internal" default="`${usbHfRealAccuracyPercent / 100}`" min="0" max="100" resolution="0.0001" visible="false" editable="false" desc="USB HF clock accuracy." />
61    <ParamRange  id="usbHfRealAccuracyUp" name="usbHfRealAccuracyUp" group="Internal" default="`${usbHfHz + (usbHfHz * usbHfRealAccuracy)}`" min="0" max="200000000" resolution="0.0001" visible="false" editable="false" desc="USB HF clock accuracy." />
62    <ParamRange  id="usbHfRealAccuracyLower" name="usbHfRealAccuracyLower" group="Internal" default="`${usbHfHz - (usbHfHz * usbHfRealAccuracy)}`" min="0" max="200000000" resolution="0.0001" visible="false" editable="false" desc="USB HF clock accuracy." />
63
64    <ParamRange id="usbHfAccuracy" name="usbHfClockAccuracy" group="Internal" default="`${modeIsHost ? 0.0005 : 0.0025}`" min="0" max="100" resolution="0.0001" visible="false" editable="false" desc="Hf Clock accuracy, the accuracy is in percent" />
65    <ParamRange id="usbHfAccuracyUp" name="usbHfClockAccuracyUp" group="Internal" default="`${48000000 + (48000000 * usbHfAccuracy)}`" min="0" max="200000000" resolution="1" visible="false" editable="false" desc="Hf Clock accuracy, the accuracy is in percent" />
66    <ParamRange id="usbHfAccuracyLower" name="usbHfClockAccuracyLower" group="Internal" default="`${48000000 - (48000000 * usbHfAccuracy)}`" min="0" max="200000000" resolution="1" visible="false" editable="false" desc="Hf Clock accuracy, the accuracy is in percent" />
67
68    <ParamString id="usbHfClockFreq" name="Clock real frequency" group="Connections" default="`${usbHfHz . &quot;Hz +/-&quot; . usbHfRealAccuracy * 100 . &quot;%&quot;}`" visible="`${debug}`" editable="false" desc="Real frequency of the connected clock" />
69
70    <!-- USB Reset clock configuration, only for Device -->
71    <ParamBool id="checkPeri" name="Check periclk" group="Internal" default="`${hasExposedMember(&quot;srss[0].clock[0].periclk[0]&quot;, &quot;frequency&quot;)}`" visible="false" editable="false" desc="Check if peri clk could be used." />
72    <ParamRange  id="clkPeriHz" name="clkPeriHz" group="Internal" default="`${checkPeri ? getExposedMember(&quot;srss[0].clock[0].periclk[0]&quot;, &quot;frequency&quot;) : 0}`" min="0" max="400000000" resolution="1" visible="false" editable="false" desc="Clk_Peri frequency." />
73    <ParamRange  id="clkPeriAccuracyPercent" name="clkPeriAccuracyPercent" group="Internal" default="`${checkPeri ? getExposedMember(&quot;srss[0].clock[0].periclk[0]&quot;, &quot;accuracy&quot;) : 0}`" min="0" max="100" resolution="0.0001" visible="false" editable="false" desc="Clk_Peri accuracy." />
74    <ParamRange  id="clkPeriAccuracy" name="clkPeriAccuracy" group="Internal" default="`${checkPeri ? clkPeriAccuracyPercent / 100 : 0}`" min="0" max="100" resolution="0.0001" visible="false" editable="false" desc="Clk_Peri accuracy." />
75
76    <ParamString id="emusb_solver" name="emusb_solver" group="Internal" default="`${runTcl(&quot;emusb_solver-1.0.tcl&quot;, clkPeriHz, clkPeriAccuracy)}`" visible="`${debug}`" editable="false" desc="Calculate the range of divider value" />
77    <ParamRange id="divCalcResult" name="divCalcResult" group="Internal" default="`${modeIsDevice ? getTclVar(&quot;result&quot;, emusb_solver) : 0}`" min="0" max="2" resolution="1" visible="`${debug}`" editable="false" desc="Returned result" />
78    <ParamRange id="divUpperLimit" name="divUpperLimit" group="Internal" default="`${modeIsDevice ? getTclVar(&quot;upperDiv&quot;, emusb_solver) : 1}`" min="0" max="16777215" resolution="1" visible="`${debug}`" editable="false" desc="This parameter defines the maximum allowable divider value" />
79    <ParamRange id="divLowerLimit" name="divLowerLimit" group="Internal" default="`${modeIsDevice ? getTclVar(&quot;lowerDiv&quot;, emusb_solver) : 1}`" min="0" max="16777215" resolution="1" visible="`${debug}`" editable="false" desc="This parameter defines the minimum allowable divider value" />
80    <ParamRange id="divBestVal" name="divBestVal" group="Internal" default="`${modeIsDevice ? getTclVar(&quot;bestDiv&quot;, emusb_solver) : 1}`" min="0" max="16777215" resolution="1" visible="`${debug}`" editable="false" desc="This parameter defines the minimum allowable divider value" />
81
82    <ParamBool id="usbRstDiv8" name="usbRstDiv8" group="Internal" default="`${modeIsDevice ? (divLowerLimit &lt;= pow(2, 8)) : 0}`" visible="false" editable="false" desc="Checks whether 8-bit divider can be used for USBFS bus reset detection." />
83
84    <ParamSignal port="clock_dev_brs[0]" name="Clock (Bus Reset)" group="Connections" visible="`${modeIsDevice}`" desc="The clock used to detect the USB Reset condition." canBeEmpty="`${modeIsHost}`" >
85
86      <Constraint type="ACCEPT" targetLocation="peri\[\d+\]\.div_8.*" valid="`${usbRstDiv8}`" >
87        <Parameter id="intDivider" severity="ERROR" reason="Clock frequency does not match desired 100 kHz.">
88          <Range min="`${divLowerLimit}`" max="`${divUpperLimit}`" preferred="`${divBestVal}`" />
89        </Parameter>
90      </Constraint>
91
92      <Constraint type="ACCEPT" targetLocation="peri\[\d+\]\.div_(16|16.5|24.5).*" valid="true" >
93        <Parameter id="intDivider" severity="ERROR" reason="Clock frequency does not match desired 100 kHz.">
94          <Range min="`${divLowerLimit}`" max="`${divUpperLimit}`" preferred="`${divBestVal}`" />
95        </Parameter>
96      </Constraint>
97
98      <Constraint type="ACCEPT" targetLocation="peri\[\d+\]\.div_(16.5|24.5).*" valid="true" >
99        <Parameter id="fracDivider" severity="ERROR" reason="Fractional divider must be 0.">
100          <Fixed value= "0" />
101        </Parameter>
102      </Constraint>
103    </ParamSignal>
104
105    <ParamString id="usbDivSource" name="usbDivSource" group="Internal" default="`${modeIsDevice ? getBlockFromSignal(&quot;clock_dev_brs[0]&quot;) : 0}`" visible="false" editable="false" desc="Source divider of Clock (Bus Reset)" />
106    <ParamBool id="usbDivOk" name="usbDivOk" group="Internal" default="`${hasConnection(&quot;clock_dev_brs&quot;, 0) &amp;&amp; isBlockUsed(usbDivSource)}`" visible="false" editable="false" desc="Checks whether there is a divider connected and enabled." />
107    <ParamString id="usbDivDst" name="usbDivDst" group="Internal" default="PCLK_USB_CLOCK_DEV_BRS" visible="false" editable="false" desc="Generates divider connection define." />
108    <ParamRange id="checkDivFreq" name="Check periclk" group="Internal" default="`${modeIsDevice ? getExposedMember(usbDivSource, &quot;frequency&quot;) : 0}`" min="0" max="400000000" resolution="1" visible="false" editable="false" desc="Divider value for Clock (Bus Reset)" />
109    <ParamRange id="checkDivAccur" name="Check periclk" group="Internal" default="`${modeIsDevice ? getExposedMember(usbDivSource, &quot;accuracy&quot;) : 0}`" min="0" max="100" resolution="0.01" visible="false" editable="false" desc="Divider accuracy of Clock (Bus Reset)" />
110
111    <ParamString id="usbRstClkFreq" name="Clock (Bus Reset) real frequency" group="Connections" default="`${checkDivFreq . &quot;Hz +/-&quot; . checkDivAccur . &quot;%&quot;}`" visible="`${debug &amp;&amp; modeIsDevice}`" editable="false" desc="Real frequency of the connected clock" />
112
113    <!-- Pins configuration -->
114    <ParamSignal port="usb_dp_pad[0]" name="D+" group="Connections" visible="true" desc="USB Data plus signal (USBDP)."  canBeEmpty="true" />
115    <ParamBool id="usbDpIsConnected" name="usbDpIsConnected" group="Internal" default="`${hasConnection(&quot;usb_dp_pad&quot;, 0)}`" visible="`${debug}`" editable="false" desc="Check if D+ is connected" />
116    <ParamSignal port="usb_dm_pad[0]" name="D-" group="Connections" visible="true" desc="USB Data minus signal (USBDM)." canBeEmpty="true" />
117    <ParamBool id="usbDmIsConnected" name="usbDmIsConnected" group="Internal" default="`${hasConnection(&quot;usb_dm_pad&quot;, 0)}`" visible="`${debug}`" editable="false" desc="Check if D- is connected" />
118
119    <!-- DMA configuration -->
120    <ParamBool id="enableDma" name="Enable DMA mode" group="DMA" default="false" visible="true" editable="true" desc="Enable DMA mode" />
121
122    <ParamBool id="enableDmaHost" name="Enable DMA for Host" group="DMA" default="`${modeIsHost &amp;&amp; enableDma}`" visible="false" editable="false" desc="Enable DMA mode for Host" />
123    <ParamBool id="enableDmaDevice" name="Enable DMA for Device" group="DMA" default="`${modeIsDevice &amp;&amp; enableDma}`" visible="false" editable="false" desc="Enable DMA mode for Device" />
124
125    <!-- For Host mode only the EP1 is used -->
126    <Repeat count="8">
127      <ParamBool id="dmaEnable$idx" name="Enable DMA channel for EP$idx" group="DMA Channel `${$idx}`" default="false" visible="`${enableDmaDevice}`" editable="`${enableDmaDevice}`" desc="Enable DMA channel for USB EP$idx" />
128      <ParamSignal port="dma_req[$idx]" name="DMA EP$idx" group="DMA Channel `${$idx}`" visible="`${dmaEnable$idx || (enableDmaHost &amp;&amp; ($idx eq 1))}`" desc="Connect DMA channel to EP$idx" canBeEmpty="`${!(dmaEnable$idx || (enableDmaHost &amp;&amp; ($idx eq 1)))}`" >
129        <Constraint type="REQUIRE" targetLocation="cpuss(\[\d+\])?\.(dw|dmac).*" valid="`${dmaEnable$idx || (enableDmaHost &amp;&amp; ($idx eq 1))}`" />
130      </ParamSignal>
131      <ParamRange id="dmaPriority$idx" name="DMA Channel $idx Priority" group="DMA Channel `${$idx}`" default="3" min="0" max="3" resolution="1" visible="`${dmaEnable$idx || (enableDmaHost &amp;&amp; ($idx eq 1))}`" editable="true" desc="Priority of the channel in the DMA block. Lower number takes precedence." />
132      <ParamString id="dmaChannel$idx" name="DMA channel" group="Internal" default="`${dmaEnable$idx || (enableDmaHost &amp;&amp; ($idx eq 1)) ? getBlockFromSignal(&quot;dma_req[$idx]&quot;) : 0}`" visible="false" editable="false" desc="DMA channel" />
133      <ParamString id="dmaHwBase$idx" name="DMA base address" group="Internal" default="`${dmaEnable$idx || (enableDmaHost &amp;&amp; ($idx eq 1)) ? getExposedMember(dmaChannel$idx, &quot;HWbase&quot;) : 0}`" visible="false" editable="false" desc="Expose DMA address" />
134      <ParamString id="dmaChannelNum$idx" name="DMA channel num" group="Internal" default="`${dmaEnable$idx || (enableDmaHost &amp;&amp; ($idx eq 1)) ? getExposedMember(dmaChannel$idx, &quot;channel&quot;) : 0}`" visible="false" editable="false" desc="Expose DMA channel" />
135
136      <ParamSignal port="dma_burstend[$idx]"  name="DMA Burst EP$idx" group="DMA Channel `${$idx}`" visible="`${dmaEnable$idx}`" desc="Connects DMA channel completion output to USB Burst End input of endpoint $idx." canBeEmpty="`${!dmaEnable$idx}`" />
137    </Repeat>
138
139  </Parameters>
140
141  <DRCs>
142    <DRC type="WARNING" text="`${&quot;CLK_HF3 does not meet the requirements. The frequency must be in the range 48 MHz +/- &quot; . usbHfAccuracy * 100 . &quot; % or the maximum deviation in the range &quot; . usbHfAccuracyLower . &quot;-&quot; . usbHfAccuracyUp . &quot;] Hz&quot;}`" condition="`${(usbHfRealAccuracyUp &gt; usbHfAccuracyUp) || (usbHfRealAccuracyLower &lt; usbHfAccuracyLower)}`" location="`${usbHfSource}`" paramId="frequencyInfo">
143    </DRC>
144    <DRC type="ERROR" text="Clock (Bus Reset) does not meet the requirements. The clock accuracy must be +/- 0.25 %." condition="`${divCalcResult eq 2}`" paramId="frequencyInfo">
145    </DRC>
146    <DRC type="ERROR" text="Clock (Bus Reset) does not meet the requirements. This frequency cannot be generated in the required range [99750-100250] Hz" condition="`${divCalcResult eq 1}`" paramId="frequencyInfo">
147    </DRC>
148    <DRC type="ERROR" text="USB Data plus signal (USBDP) must be always connected" condition="`${!usbDpIsConnected}`" paramId="usb_dp_pad[0]">
149    </DRC>
150    <DRC type="ERROR" text="USB Data minus signal (USBDM) must be always connected" condition="`${!usbDmIsConnected}`" paramId="usb_dm_pad[0]">
151    </DRC>
152    <DRC type="ERROR" text="Clock for USB must be always connected" condition="`${modeIsDevice ? !clkUsbDeviceIsConnected : false}`" paramId="clk_usb_dev[0]">
153    </DRC>
154    <DRC type="ERROR" text="Clock for USB must be always connected" condition="`${modeIsDevice ? false : !clkUsbHostIsConnected}`" paramId="clk_usb_host[0]">
155    </DRC>
156  </DRCs>
157
158  <ConfigFirmware>
159    <ConfigInclude value="cy_sysclk.h" include="`${usbDivOk}`" />
160    <ConfigInclude value="cyhal_hwmgr.h" include="true" guard="defined (CY_USING_HAL)" />
161
162    <ConfigDefine name="USBH_DMA_INST_ADDRESS" value="`${dmaHwBase1}`" public="true" include="`${enableDmaHost}`" />
163    <ConfigDefine name="USBH_DMA_CHANNEL_NUM" value="`${dmaChannelNum1}`U" public="true" include="`${enableDmaHost}`" />
164    <ConfigDefine name="USBH_DMA_CHANNEL_PRIORITY" value="`${dmaPriority1}`U" public="true" include="`${enableDmaHost}`" />
165
166    <ConfigDefine name="USBD_DMA_CHANNEL_PRIORITY_EP`${$idx}`" value="`${dmaPriority$idx}`U" public="true" include="`${dmaEnable$idx}`" repeatCount="8"/>
167    <ConfigDefine name="USBD_DMA_CHANNEL_ADDRESS_EP`${$idx}`" value="`${dmaHwBase$idx}`_CH_STRUCT`${dmaChannelNum$idx}`" public="true" include="`${dmaEnable$idx}`" repeatCount="8"/>
168    <ConfigDefine name="USBD_DMA_OUT_TRIG_MUX_EP`${$idx}`" value="`${INST_NAME . &quot;_dma_burstend_$idx_TRIGGER_OUT&quot;}`" public="true" include="`${dmaEnable$idx}`" repeatCount="8"/>
169
170    <ConfigStruct name="`${INST_NAME}`_obj" type="cyhal_resource_inst_t" const="true" public="true" include="true" guard="defined (CY_USING_HAL)">
171      <Member name="type" value="CYHAL_RSC_USB" />
172      <Member name="block_num" value="`${getInstNumber(&quot;usb&quot;)}`U" />
173      <Member name="channel_num" value="0U" />
174    </ConfigStruct>
175    <ConfigInstruction value="cyhal_hwmgr_reserve(&amp;`${INST_NAME}`_obj);" include="true" guard="defined (CY_USING_HAL)" />
176
177    <ConfigInstruction value="Cy_SysClk_PeriphAssignDivider(`${usbDivDst}`, `${getExposedMember(usbDivSource, &quot;clockSel&quot;)}`);" include="`${usbDivOk}`"  />
178
179  </ConfigFirmware>
180
181</Personality>
182