Using Circuit Code Files
This exercise will demonstrate how and when to use circuit code files. It starts with a project installed as a zip file: CompletedTutorial4.zip. The project is based on the one created in the main part of this tutorial.
- Extract the zip file CompletedTutorial4.zip to a new, empty directory of your choice.
- Navigate into the Board Test directory.
- Open the XJDemo Board.xjd project using XJDeveloper.
Circuit code files contain two types of functions:
- Functions which are specific to the circuit, such as programming flash memory. The same programming method is used every time a particular type of flash needs to be programmed (and can therefore be put in a test device file). However, the parameters (e.g. which data file is to be programmed into which flash device) are specific to the circuit.
- Functions that use more than one non-JTAG device, e.g. one device is used to transmit some data and another device is used to receive the data.
The XJEase library file that has been used to categorise the ADC contains the code used to interact with the ADC. This device file code is generic and can be used to read any NCD9830 ADC in any circuit in which it is used. In this exercise you will create a circuit code file that uses code from this library file to make circuit-specific measurements that are only relevant to the XJDemo board.
- Click the
Circuit Code Files screen button under the Setup header.
- At the top of the Circuit Code Files screen, click the
button and select New... from the dropdown.
- Name the file CircuitTest.xje and click Save.
- Replace the default content of the file by pasting the following function into your new file in its place:
GLOBAL PowerSupplyTest()(INT result) CONST INT EXPECTED_VOLTAGE := 1800; CONST INT PERCENTAGE_MARGIN := 10; INT margin := EXPECTED_VOLTAGE * PERCENTAGE_MARGIN / 100; INT mV; PRINT("\nChecking the voltage on ADC ("); PRINT_DEVICE_LINK("U11"); PRINT(") channel 1.\n"); CALL("U11", "ReadADC")(1, 1, 2500)(mV, result); IF result = RESULT_FAIL THEN RETURN; END; // Plus or minus 10% IF mV > EXPECTED_VOLTAGE + margin ||? mV < EXPECTED_VOLTAGE - margin THEN PRINT("FAILED: Voltage (", mV, "mV) out of tolerance.\n"); result := RESULT_FAIL; ELSE PRINT("PASSED: Voltage (", mV, "mV) within tolerance.\n"); result := RESULT_PASS; END; END;
- Click the
Save button within the Circuit Code Files screen.
The test uses the internal voltage reference of the ADC to measure the 1.8 V power supply to the CPLD. It then checks that the measured voltage is within 10% of the expected value.
The measurement is made using the CALL keyword, which allows functions defined in test device files to be executed from circuit code files.
The CALL keyword has three sets of arguments, each of which are contained within brackets:
- The device reference and the test function to be executed from the associated device file.
- Input parameters to the function being called.
- Output parameters from the function being called.
N.B. You can get full help on any XJEase keyword by highlighting it in the XJEase code editor and pressing F1 to open the relevant help page.
With the code added to CircuitTest.xje, the final step before running the test is to add the PowerSupplyTest function to the Test List.
- Click the
XJRunner Setup screen button under the Run and Deploy header.
- Click
Add Group... at the bottom of the XJRunner Tests panel.
- Set the Name of the Test Group to Power Supply Test.
- Click the
Add Global Function button.
- From the Available Global Functions dialog select PowerSupplyTest then click OK.
- Click the OK button in the New Test Group dialog to confirm the creation of the test.
- Click the
Save button on the main XJDeveloper toolbar.
The test is now ready to run.
- Click the
Run Tests screen button under the Run and Deploy header.
- Enable just the Power Supply Test in the Test List.
- Finally, click the
Run button.
The test coverage tutorial exercise will demonstrate how to update the test coverage report with functional test coverage to reflect the increased testing.
See Also
XJTAG v4.1.100