tutorial
CoMET Version 5.9 Tutorial Document Version No: 1.
© Copyright 1997 – 2005 VaST Systems Technology Corp. All rights reserved The copyright owner of CoMET hereby disclaims all warranties relating to this software, whether express or implied, including without limitation any implied warranties of merchantability or fitness for a particular purpose. The copyright owner will not be liable for any special, incidental, consequential, indirect or similar damages due to loss of data or any other reasons, even if the possibility of such damages has been advised.
Contents Introduction ................................................................................................................... 7 Conventions used in the tutorials................................................................................. 7 References ................................................................................................................... 7 Standalone C - Hello World .........................................................................................
Contents Prerequisites...............................................................................................................24 Creating a New Workspace and VSP Project ............................................................25 Viewing the Workspace, Project and .fmx File .........................................................28 Creating a Virtual Platform Module Project ..............................................................29 Choosing an .fmx View in the Document window. ............
Contents Adding a Target Image .............................................................................................. 69 Simulating SimpleVSP1............................................................................................ 70 Unconnected Ports..................................................................................................... 71 Debugging a Simulation ............................................................................................
Contents Determining When a Match Occurs...................................................................94 The CIF Peripheral Model Template......................................................................95 Template Functions............................................................................................95 Additional Callback and Helper Functions........................................................96 Events and Responses in Behavioral Code............................................
Contents Metrix Output....................................................................................................... 128 CoMET Version 5.
Introduction This tutorial covers creating: • a standalone C project • a CIF Virtual System Prototype Conventions used in the tutorials The following conventions are used in the tutorials. Choosing an option from a menu is indicated by the notation: Choose Menu name/option/option . For example, choosing the New Workspace option from the File menu is indicated by: Choose File/New Workspace. Fields or objects within a dialog are preceded by the dialog name.
Standalone C - Hello World Overview This tutorial covers a simple CoMET project, to compile and run a standalone C Hello World program. The Hello World tutorial uses no Fabric or other modules and does not model a hardware system.
Standalone C - Hello World Creating a new workspace and project Choose File/New Workspace. Workspace dialog Workspace Name: Type desired name: Hello Location: This is set automatically according to Workspace name. Alter if desired. Workspace dialog: click Next When you create a workspace, CoMET automatically creates a new project. CoMET opens a dialog for specifying project properties. 10 CoMET Version 5.
Standalone C - Hello World Workspace: Hello dialog: Project panel: Select General Project Name: Type Hello1 Location: Accept default or type alternative C compiler: Select desired compiler, MS Visual C++ or Cygwin Gcc Select Application Workspace: Hello dialog: Click Finish CoMET Version 5.
Standalone C - Hello World Navigating the Workspace and Project CoMET creates the new workspace and project and displays them in the Workspace window. The Hello1 project is displayed with a yellow icon, indicating it is of type General. In the Workspace window, expand the Hello1 project to see the default folders. To expand a node, click the symbol beside it as shown above. To contract a node, click the symbol beside it.
Standalone C - Hello World Creating a Source File Choose File/New File, or press Ctrl-N, or click the button in the tool bar. New dialog: Choose Text Document Click OK A new text document opens in the Document window. CoMET supplies a default window title of Text1. Type in the following text: #include void main() { printf("Hello world\n"); } Now save the file. Choose File/Save File, or press Ctrl-S, or click the button in the tool bar.
Standalone C - Hello World The file now displays with the file name as the window title, and with C syntax coloring. CoMET determines they syntax coloring choice from the file extension. You can change this at any time by choosing Edit/Syntax Coloring and selecting a language from the list. The source file has now been created, but it has still to be added to the project. 14 CoMET Version 5.
Standalone C - Hello World Adding the File to the Project In the Workspace window, open the Hello1 project, Folders node and right click on the Source Files node to display the context menu. Source Files context menu: choose Add File Browse for source files dialog: Navigate to the directory in which you saved hello1.c, select hello1.c, and click Open CoMET Version 5.
Standalone C - Hello World hello1.c appears in the Workspace window, Hello1 project, Source Files folder. Adding a Build Configuration This project is to be built as a console application, so we add a new build configuration. Workspace window, Hello1 project: right click Configurations to display the context menu. Choose Add Configuration. 16 CoMET Version 5.
Standalone C - Hello World Project dialog: Configuration tab: Properties group: Type: Select VcConApp if using the Visual C++ compiler or GccConApp if using the gcc compiler Mode: Choices are Debug or Release. For the purposes of this tutorial either is appropriate Path: Select the current directory by typing. Alternatively browse to the directory of your choice Active: Select True. This sets this as the active configuration for building.
Standalone C - Hello World Select Project Properties from the context menu. In the Project dialog, Project panel, set Active to True. Ensure the active build configuration is the appropriate console configuration, VcConApp or GccConApp. The active configuration is displayed in bold text. This was set to active in the previous section. If the VcConApp or GccConApp is not the active build configuration: To set the active configuration Right click on the configuration entry in the Workspace window.
Standalone C - Hello World Executing the Compiled Project When the project is successfully built, you can execute it, or simulate it. The Simulate command runs the active project. See the previous section for details on activating a project.
CIF Module - SimpleVSP Overview This tutorial demonstrates how to build a Virtual System Prototype (VSP) and simulate it running target code, using the CoMET System Engineering Environment. A VSP (Virtual System Prototype) is a constructed from a collection of software projects made up of source code, compiled modules and xml files. The software runs on a simulation engine on a host PC, modeling the behavior of a hardware system.
CIF Module - SimpleVSP Constructing a VSP in CoMET CoMET manages a group of projects within a Workspace. To construct a VSP, you first create a workspace then create a CIF Virtual System Prototype project within it. You also create CIF Projects for the component Virtual Platforms and Peripheral Devices required by the system. You may also use pre-built VPMs and Peripheral Device models. You specify the hierarchical structure of the VSP and the Virtual Platforms by adding instances of component modules.
CIF Module - SimpleVSP SimpleVSP Project Block Diagram Virtual System Prototype - SimpleVSP1 VastGpReset1 Reset VastGpClock1 ResetNet Clock ClockNet PlatformReset Virtual Platform - VirtualPlatform1 PlatformClock StdLogic0Net VastGpStdLogic01 Arm926ejs1 Irq Fiq Reset Clock DataBus DataBusClock InstBus InstBusClock StdBus1 Bus BusClock BusClockIn StdBus1Net StdBus1ClockNet GenericMemory1 Bus BusClock Reset The SimpleVSP project This tutorial demonstrates: • Creating a new Workspace and V
CIF Module - SimpleVSP • Using the Modules Window • Adding ports and nets • Connecting ports and nets • Using table views of the .fmx file to verify connections and parameters • Building the VirtualPlatform project • Adding SimpleVSP1 module instances and connecting them • Adding a target image to the VSP • Building the SimpleVSP project • Running the simulation • Monitoring output and measuring performance Prerequisites This tutorial assumes: Comet 5 is installed and open.
CIF Module - SimpleVSP Creating a New Workspace and VSP Project Choose File/New Workspace. Workspace dialog Workspace Name: Type desired name: SimpleVSP Location: This is set automatically according to Workspace name. Alter if desired. Workspace dialog: click Next When you create a workspace, CoMET automatically creates a new project to go with it. CoMET opens a dialog for specifying project properties. CoMET Version 5.
CIF Module - SimpleVSP Workspace: SimpleVSP dialog: Project panel: Select Fabric Project Name: Type SimpleVSP1 Location: Accept default or type alternative C compiler: Select desired compiler, MS Visual C++ or Cygwin Gcc Library (DLL) is only option Workspace: SimpleVSP dialog: Click Next When you choose a Fabric project, CoMET creates a new module. CoMET opens a dialog to specify module properties. 26 CoMET Version 5.
CIF Module - SimpleVSP Project: SimpleVSP1 dialog: Fabric Module panel: Module Class: Select Virtual System Prototype Module Type: This is the name of the module type by which instances of this module are classified. Accept the suggested name. Version: Accept the suggested version. Project: SimpleVSP1 dialog: Click Finish. CoMET Version 5.
CIF Module - SimpleVSP Viewing the Workspace, Project and .fmx File CoMET creates the new workspace and project and displays them in the Workspace window. The VSP1 project is displayed with a blue icon, indicating it is of type Fabric. Expand the SimpleVSP1 project. On creating the Fabric project, CoMET creates a number of files from templates. The C source and header files contain skeleton code and definitions as a basis for developing the module. In this tutorial we do not edit these files.
CIF Module - SimpleVSP Creating a Virtual Platform Module Project Choose Workspace/Add New Project Workspace: SimpleVSP dialog: Project panel: Select Fabric Project Name: Type VirtualPlatform Location: Accept default or type alternative C compiler: Select desired compiler, MS Visual C++ or Cygwin Gcc Library (DLL) is only build option Workspace: SimpleVSP dialog: Click Next When you choose a Fabric project, CoMET creates a new module. CoMET opens a dialog to specify module properties.
CIF Module - SimpleVSP Project: VirtualPlatform dialog: Fabric Module panel: Module Class: Select Virtual Platform Accept default values for other fields. Project: VirtualPlatform dialog: click Finish CoMET displays the VirtualPlatform project in the Workspace tree. We have created the VirtualPlatform module. After we have added module instances to the Virtual Platform, we can build it and add an instance of the Virtual Platform to the VSP. The next step is to add module instances to the platform.
CIF Module - SimpleVSP Choosing an .fmx View in the Document window. Open the VirtualPlatform.fmx file in the Document window (see Viewing the Workspace, Project and .fmx File, above). The .fmx file XML Tree Display view shows the same basic structure as the SimpleVSP1 .fmx file. To ensure the VirtualPlatform.fmx file is displayed in XML tree view: Right click on a line in the VirtualPlatform.fmx Document window Choose XML Tree View from the context menu. We will demonstrate other .
CIF Module - SimpleVSP Adding Module Instances to the Virtual Platform Refer to the SimpleVSP Project Block Diagram, page 23, for the structure of the VSP. The modules to be added can be found in the VaST modules library. Open the modules window and expand the Gp and VPM nodes and sub nodes. The modules to add, identified by their location in the VaST Modules library, are: • VpmARM926EJS. In this tutorial we use the ARM926EJS. Other VPMs may be substituted if available.
CIF Module - SimpleVSP Adding a Module Instance by Drag and Drop Click on the ARM926EJS icon in the Modules window. Drag and drop onto the Module Instances node in the VirtualPlatform.fmx file Document window. The .fmx file tree display shows the module instance, with a default instance name. The default names are acceptable for this tutorial. To change an instance name, select it in the XML Tree View and press F2, or right click and choose Edit Module Instance from the context menu.
CIF Module - SimpleVSP It is possible to edit, search and process the XML directly, but the CoMET SEE tools are a more convenient way to modify the .fmx file, and help to ensure integrity. 34 CoMET Version 5.
CIF Module - SimpleVSP Adding a Module Instance by Copy and Paste, XML Tree View Choose XML Tree View in the VirtualPlatform.fmx Document window. Select the GenericMemory module in the Modules Window (click it). Press Ctrl-C to copy. Alternatively right click and choose Copy Fabric Module from the context menu. Select the Module Instances node in the VirtualPlatform.fmx XML Tree View (click it). Press Ctrl-V to paste. Alternatively right click and choose Paste Fabric Module from the context menu.
CIF Module - SimpleVSP Adding a Module Instance by Copy and Paste, XML Table View Choose Logic Connection View in the VirtualPlatform.fmx Document window. Select the StdBus module in the Modules Window (click it). Press Ctrl-C to copy. Select the VirtualPlatform.fmx Logic Connection View (click anywhere in the table). Press Ctrl-V to paste. The .fmx XML Tree View shows the module instance, with a default instance name. You can paste into any of the table views.
CIF Module - SimpleVSP Using the method of your choice, add a module instance of VastGpStdLogic0 to the VirtualPlatform.fmx file. The VirtualPlatform.fmx, XML Tree View now shows all the required module instances. The next step is to add ports and nets to connect the module instances. CoMET Version 5.
CIF Module - SimpleVSP Creating an Array of Module Instances For the ARM926EJS VPM three memory blocks are required, for reset vector, code and data. Other VPMs may have differing requirements. Here we create an array of GenericMemory instances to model the multiple memory blocks. We also create a parameter to specify the number of blocks. This allows us to alter the number of memory blocks at a higher level, without recompiling the VirtualPlatform module. First we add the parameter.
CIF Module - SimpleVSP Fabric Module dialog, Parameter tab, Properties panel Name: Type NumberOfMemoryBlocks Type: Select tWord32 Value: type 3 Fmx Access: Accept default Public Pcx Access: Accept default Public Description: Determines the size of the array of GenericMemory1 module instances Other fields: Accept defaults The description appears in the Fabric Module Definition Report for the module. Fabric Module dialog: Click OK CoMET Version 5.
CIF Module - SimpleVSP The VirtualPlatform.fmx XML Tree Display shows the new parameter. Now we alter the GenericMemory1 module instance properties to specify an array of instances determined by the NumberOfMemoryBlocks parameter. In the VirtualPlatform.fmx XML Tree View, Double click the GenericMemory1 element or Right click the GenericMemory1 element and select Module Instance Properties from the context menu. or Select the GenericMemory1 node and press Ctrl-P or Enter 40 CoMET Version 5.
CIF Module - SimpleVSP Fabric Module dialog, Module Instance tab, Properties panel: Number Of: Type NumberOfMemoryBlocks Description: This is an array of module instances, with the size of the array determined by the NumberOfMemoryBlocks parameter. Other fields: Accept existing values Fabric Module dialog: Click OK The number of instances of GenericMemory1 can now be determined by overriding the parameter at the higher SimpleVSP1 level. We show this later in the tutorial.
CIF Module - SimpleVSP Viewing the Fmx Report Save the fmx file (press Ctrl-S) and open the Fmx Report: To view the prototype report for the .fmx file Select Tools/Prototype Report or click the Prototype Report button . CoMET opens the report in the default XML browser. The Summary part of the report shows the Parameters and Module Instances so far created. You can view the Fmx Report at any time to see an alternative layout of module details.
CIF Module - SimpleVSP Adding Nets and Port Connections The ports of devices at the same level of the module hierarchy must be connected by nets. A device port can connect directly only to the port of the device's parent module or to the port of a child module of the device. Devices within the VirtualPlatform module must be connected by nets.
CIF Module - SimpleVSP Fabric Module dialog, Net tab, Properties panel: Name: Type StdBus1Net Type: Select StdBus Description: This connects the VPM and Memory to the StdBus Accept default for other fields Fabric Module dialog: click OK The VirtualPlatform.fmx XML Tree View shows the new net. 44 CoMET Version 5.
CIF Module - SimpleVSP Referring to the SimpleVSP Project Block Diagram, page 23, this net must be connected to the StdBus device, the VPM and the memory. Connecting a Net to an Instance Port, XML Tree View In the VirtualPlatform.fmx XML Tree, open the Module Instances/StdBus1/Instance Ports node Right click on Bus and choose Add Port Connection from the context menu Fabric Module dialog, Port Connection tab, Properties panel: Port or Net Name: Select StdBus1Net from the list box.
CIF Module - SimpleVSP Adding an Instance Port connection, Bus Connection View Open the VirtualPlatform.fmx Bus Connection View Click in the GenericMemory1 row, StdBus1Net column, then click again to display the list box showing GenericMemory1 ports. Select the Bus port Click again to display The Bus Connection View displays the new port connection. We now want to connect StdBus1Net to two ports on the VPM: the InstBus port and the DataBus port.
CIF Module - SimpleVSP VirtualPlatform.fmx XML Tree View: Repeat the process to add a StdBus1Net port connection to the Instances/ARM926EJS1/Instance Ports/DataBus port. The VirtualPlatform.fmx XML Tree View now shows the ports connected to StdBus1Net. We will now use the Clock Connection View to create and connect the StdBus1ClockNet. CoMET Version 5.
CIF Module - SimpleVSP Adding Clock Connections using the Clock Connection View Open the VirtualPlatform.fmx Clock Connection View Right click anywhere on the grid and select Add Net from the context menu. The Fabric Module dialog, Net tab is the same as that shown above in Adding a Net, XML Tree View, page 43.
CIF Module - SimpleVSP Right click InstBusClock and choose Add Port Connection Fabric Module dialog, Port Connection tab, Properties panel: Port or Net Name: Select StdBus1ClockNet from the list box. Other fields: Accept defaults Fabric Module dialog: Click OK The VirtualPlatform.fmx XML Tree View now shows the ports connected to StdBus1ClockNet. Save the fmx file (press Ctrl-S) and open the Fmx Report by selecting Tools/Prototype Report or clicking the Prototype Report button .
CIF Module - SimpleVSP Scroll down to the Nets entry in the Summary section. The Nets Summary shows a table with attributes of each Net. It also shows the number of Connections for each Net. Click the Name link to move to the detail entry for a Net. The Net Detail entry shows the attributes and the Instance Port Connections for the Net, with links to the associated Module Instances for the Port Connection. Click a link to move to the Module Instance detail entry.
CIF Module - SimpleVSP In XML Tree View add the Net StdLogic0Net. Right Click Nets and choose Add Net. Fabric Module, Net tab, Properties: Name: StdLogic0Net Type: StdLogic. Description: This ties the VPM Irq and Fiq ports down to logic 0. In XML Tree View connect StdLogic0Net to ports Irq and Fiq on the ARM926EJS1 VPM. In XML Tree View connect StdLogic0Net to port SignalOut on StdLogic01. The VirtualPlatform.fmx XML Tree View now shows the connections of StdLogic0Net. CoMET Version 5.
CIF Module - SimpleVSP Adding Ports Referring to the SimpleVSP Project Block Diagram, page 23, the VirtualPlatform needs a PlatformClock port to connect to the VSP clock and a PlatformReset port to connect to the VSP reset. These ports can be connected directly to the reset and clock ports on the VirtualPlatform's child modules. Adding a Port VirtualPlatform.fmx, XML Tree View: Right click Ports Choose Add Port from the context menu 52 CoMET Version 5.
CIF Module - SimpleVSP Fabric Module dialog, Port tab, Properties panel: Name: Type PlatformClock Type: Select StdClock Description: This connects all module instances within VirtualPlatform to the VSP clock. Other fields: Accept defaults Fabric Module dialog: Click OK Similarly, add the PlatformReset port. In VirtualPlatform.
CIF Module - SimpleVSP The VirtualPlatform.fmx XML Tree View shows the new ports. Now we connect the VirtualPlatform ports to the child devices. Open VirtualPlatform.fmx Clock Connection View Click in the StdBus1 row, PlatformClock.Port column. Click again to show the list box. Choose BusClockIn from the list box. Similarly, connect the ARM926EJS1 ClockIn instance port to the PlatformClock port. 54 CoMET Version 5.
CIF Module - SimpleVSP For the next procedure you can use either the VirtualPlatform.fmx Logic Connection View or the XML Tree View. Connect PlatformReset to GenericMemory1 Reset port and the ARM926EJS1 ResetPort. Here we show the Logic Connection View. CoMET Version 5.
CIF Module - SimpleVSP Checking Connections You can check connections against your block diagram using the VirtualPlatform.fmx XML Tree View. The various Connection views can be used, however because there is a single row for each device and a single column for each net or port, they do not cover situations where: • two ports from the same device connect to the same net or port • a port is connected to multiple nets or ports You can also check connections with the Fmx Report. The VirtualPlatform.
CIF Module - SimpleVSP Building the VirtualPlatform The VirtualPlatform must be built before it is added to the VSP. CoMET extracts information about module structure from the built .dll file, so the module .dll must exist before you add a module instance to another project. Ensure VirtualPlatform is the active project. The active project is displayed in bold. If VirtualPlatform is not the active project, activate it as follows.
CIF Module - SimpleVSP Building a Project Choose Workspace/Build, or click the tool bar Build button The Output Window, Build tab shows messages as the project is built. The messages indicate the cause of any problems that prevent a successful build. 58 CoMET Version 5.
CIF Module - SimpleVSP Adding a VirtualPlatform Module Instance to the VSP We now add and instance of the VirtualPlatform module to the SimpleVSP1 module. In the example below we add the module instance without using the Modules Window. An alternative is to first create a new module library containing the VirtualPlatform module (see CoMET User Guide, Getting Started, Modules Configuration Settings), and then use the methods already shown to add the VirtualPlatform from the Modules Window.
CIF Module - SimpleVSP Fabric Module dialog, Module Instance tab Instance Name: Type VirtualPlatform1. The name for your new instance of the VirtualPlatform module should begin with an alphabetic character, contain no spaces, and follow the standard C naming convention. This name is used to form the names of automatically generated functions in the source code CoMET creates for the module instance. Module Type: In the list box, select VirtualPlatform.
CIF Module - SimpleVSP The SimpleVSP1.fmx file now contains VirtualPlatform1, an instance of the VirtualPlatform module type. The VirtualPlatform1 module instance shows the ports we created earlier. We now add the clock and reset to the SimpleVSP and connect them to the VirtualPlatform instance ports. Adding Clock and Reset to SimpleVSP Referring to the SimpleVSP Project Block Diagram, page 23, we now need to add to SimpleVSP an instance of VastGpClock and an instance of VastGpReset.
CIF Module - SimpleVSP Connecting the SimpleVSP Module Instances We now connect the module instance ports. Because the modules are on the same level, we must create nets to connect the ports. For the steps below use the appropriate methods for adding nets and connecting ports described in Adding Nets and Port Connections, page 43. Add to SimpleVSP1 the net ClockNet, of type StdClock. Add the Description: This connects the VSP Clock to the VirtualPlatform PlatformClock port.
CIF Module - SimpleVSP stage we want to alter the number of memory blocks we can do it at this level. For this tutorial, using this VPM, the default number of memory blocks is correct. We can now build the SimpleVSP module, generate a Prototype Parameter Configuration file, and modify it to suit our specific VPM. Modifying Module Instance Parameters The Prototype Configuration (.pcx) file, or Platform Configuration file, contains override parameters for the module instances in the project.
CIF Module - SimpleVSP One message indicates that CoMET has built the platform config (Prototype Configuration) file. Editing the Prototype (Platform) Configuration file This file can now be edited to suit our specific VPM. To open the Prototype Configuration file, click the tool bar Open Config File button down arrow, and select SimpleVSP1.pcx The .pcx file is an XML file and can be viewed in XML Tree View, or in parameter views. The tree view shows that the .pcx file mirrors the structure of the .
CIF Module - SimpleVSP The VirtualPlatform GenericMemory1 array size is specified by the NumberOfMemoryBlocks parameter, so the .pcx file shows three GenericMemory1 elements. CoMET Version 5.
CIF Module - SimpleVSP We can now edit the start address and memory size of these blocks to suit our VPM. This is conveniently done in Memory Parameter view. Open SimpleVSP1.
CIF Module - SimpleVSP Creating and Compiling Target Code This tutorial does not cover compiling target code for a particular VPM. The following code writes a string to the memory, reads it back and displays it. The code works for the ARM926EJS processor. Some adjustments may be necessary for the VPM you use. /* **----------------------------------------------------------------------------** ** Copyright (c) 2004, VaST Systems Technology Corporation.
CIF Module - SimpleVSP /* define any additional handers required for your specific VPM */ /*****************************************************/ /* Empty IRQ & FIQ handlers called from crt0 */ /*****************************************************/ void irq_handler(void) { } void fiq_handler(void) { } /* bottom of file */ This code uses the TSPI (Target Software Programming Interface) to allow use of the standard C stdout facility from within target software.
CIF Module - SimpleVSP Adding a Target Image We now add the target image to the SimpleVsp1 project. In the Workspace Window, right click SimpleVSP1/Target Test and choose Add Target Image from the context menu. CoMET displays the Project dialog, Properties tab.
CIF Module - SimpleVSP Project dialog: Click OK. The target image node appears under the Target Test node. Simulating SimpleVSP1 We have built a VSP with target code. We can now simulate it. Ensure that SimpleVSP1 is the active project. See Activating the Project to be Built, page 57 Choose Workspace/Simulate or click the Simulate button CoMET builds the project if necessary. There may be dialogs requiring confirmation. After building the project, CoMET runs the simulation.
CIF Module - SimpleVSP Unconnected Ports When you run a project, CoMET checks the integrity of the model. It reports any errors it finds. For example unconnected StdBus Ports are not permitted. If CoMET finds an unconnected StdBus port it displays the error You can find unconnected ports using the XML Tree View, the Fmx Report or the Connection views. The Fmx Report lists unconnected Ports and Nets in the Errors and Warnings section.
CIF Module - SimpleVSP Debugging a Simulation CoMET allows you to debug both target code and hardware modules during a simulation. This tutorial does not cover coding modules or writing target code. However we can demonstrate placing a breakpoint in the SimpleVSP1 skeleton code. When you run the simulation in debug mode execution stops at the breakpoint, allowing you to step through execution. In the Workspace Window, double click SimpleVSP1/Folders/Source Files/SimpleVSP1.c to open SimpleVSP1.
CIF Module - SimpleVSP Debug Options dialog. H/W Model: Choose Debug ARM926EJS (or other VPM): Choose Simulate Click OK CoMET executes the simulation until it reaches the breakpoint in SimpleVSP1.c. It then pauses execution. The Debug Step buttons are now active. You can Step into the highlighted block, Step over it, or Step out of it. In this example there is little else to see, but useful debug information can be obtained by following execution in more complex module functions.
CIF Module - SimpleVSP Obtaining a Value Change Dump The standard VCD format output is a useful tool for analysis. To obtain a VCD: Choose Tools/VCD Configuration Check Enabled and specify the Location of the vcd file to be saved. Enabling Bus Monitoring CoMET by default dumps all port and net changes to the VCD file, however no bus information is dumped unless bus monitoring is enabled. The interesting events in our simulation happen on the bus, so we wish to enable bus monitoring.
CIF Module - SimpleVSP The SimpleVSP1.pcx displays the BusMonitor parameter with value Enabled. Bus signals will appear in the VCD. Run the simulation. CoMET generates the VCD and writes it to the location you specified. CoMET Version 5.
CIF Module - SimpleVSP Analyzing the VCD Events such as the reset and memory reads can be identified. Any VCD viewer or analysis tool can be used. The pictures below are obtained using SignalScan. Reset Read string back from memory 76 CoMET Version 5.
CIF Module - SimpleVSP Obtaining a Metrix Trace If you have the Metrix option, you can create a Metrix Configuration (.mcx) file to view VPM trace and StdBusProbes and StdLogicProbes. See the Metrix Configuration File User Guide. A suitable mcx setup is shown below. CoMET Version 5.
CIF Peripheral Model - SimpleTimer Overview This tutorial demonstrates to how construct a Peripheral Model and how to write the code that models the device behavior. The device is a 32 bit general purpose timer. The details are given in the specification below. This tutorial demonstrates: • Creating a CIF Peripheral Device project • Setting up the Fabric Module Definition (.
CIF Peripheral Model - SimpleTimer You are familiar with viewing and editing an .fmx file. This is covered in the Simple VSP tutorial above. You have completed the SimpleVSP tutorial and have the SimpleVSP workspace available to add the SimpleTimer project. You are familiar with writing and building target code for the microprocessor you will use in this tutorial. Alternatively it is assumed you have access to someone who can build the tutorial target code and provide a binary image.
CIF Peripheral Model - SimpleTimer Specification • The SimpleTimer is a 32 bit general purpose timer • The SimpleTimer has two general purpose match registers • Each match can be individually enable and disabled • Each match event can generate an interrupt • The interrupts for each match can be disabled and enabled • The current timer value can be written at any time from the bus • Each interrupt shall have its own flag • The match registers shall cause a match only when the counter value eq
CIF Peripheral Model - SimpleTimer Registers The SimpleTimer requires registers to enable and configure the timer, as well as provide a mechanism for the embedded target software to communicate with the device. The timer has the following registers: General Timer Register (GTR) The General Timer (GT) is the reference timer used by the Match Timers. It consists of a 32bit counter register called the General Timer Register (GTR).
CIF Peripheral Model - SimpleTimer MSB Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 Upper 16 bits of the match value LSB Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Lower 16 bits of the match value Timer Enable Register (TER) The Timer Enable Register (TER) is a 2-bit register, one bit per special timer: ‘1’ enables the timer, and ‘0’ disables the timer.
CIF Peripheral Model - SimpleTimer Timer Interrupt Enable Register (TIER) The Timer Interrupt Enable Register (TIER) is a 2-bit register, one bit per special timer: ‘1’ enables the timer interrupt, and ‘0’ disables the timer interrupt. Note that the address is word-aligned and can be read as a byte or a word, but only the two bits are used. Register is readable and writeable Value after reset = 0x00000000; 3.
CIF Peripheral Model - SimpleTimer MSB Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit Bit 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 Bit 16 Unused LSB Bit Bit Bit Bit Bit Bit Bit 15 14 13 12 11 10 9 Bit Bit 8 7 Bit 6 Bit Bit Bit 5 4 3 Bit Bit Bit 2 1 0 TIFR1 TIFR2 Unused Ports The SimpleTimer has the following ports: • Bus – connects to the bus on which the timer is instantiated • BusClock – connects to the clock input from the bus • Reset – connects to the system reset input • TimerClo
CIF Peripheral Model - SimpleTimer Event Responses for SimpleTimer From the specification we can prepare the following table of events and the corresponding responses.
CIF Peripheral Model - SimpleTimer Creating the SimpleTimer Project Open CoMET Choose File/Open Workspace In the Browse for Workspace files dialog, locate and select SimpleVSP Choose Workspace/Add New Project CoMET displays the Workspace:SimpleVSP dialog, in which you specify details of a project in the Workspace.
CIF Peripheral Model - SimpleTimer Project: SimpleTimer dialog: In the Module Class field, choose Peripheral Model. In the Module Type field, accept SimpleTimer. In the Version field, accept 1.0.0 Click Finish 88 CoMET Version 5.
CIF Peripheral Model - SimpleTimer Editing the SimpleTimer fmx file CoMET creates a CIF Peripheral Model project from templates. It displays the newly created .fmx file for the SimpleTimer in the Document window. To display the .fmx file at any time In the Workspace window, open the SimpleTimer project/Folders/Source Files folder. Double-click the SimpleTimer.fmx file. CoMET opens the fmx file in the Document window. Ensure that the fmx file is displayed in XML Tree view.
CIF Peripheral Model - SimpleTimer Adding Ports Ports provide the input to and output from the Peripheral Mode. The required Bus, BusClock and Reset ports are created by default. Add the following ports: Name Type Direction Description MatchInterrupt1 StdLogic Output Output interrupt line for match 1 MatchInterrupt2 StdLogic Output Output interrupt line for match 2 TimerClock StdClock Input Connects to a dedicated clock input for the timer To add a port: Right click the Ports node.
CIF Peripheral Model - SimpleTimer The fmx file shows the ports as follows. Adding Tasks Tasks handle the initialization, execution flow, and destruction of the module instance. Most peripheral models have a single task which initializes and then suspends indefinitely. After initialization, callbacks handle execution. CoMET automatically creates one task for a new CIF Peripheral Model project.
CIF Peripheral Model - SimpleTimer Add the following PortOrNetView elements to the fmx file. Name Type MatchInterrupt1 Master MatchInterrupt2 Master TimerClock Slave To add a PortOrNetView Right click on the Task/Port Or Net Views node in the fmx file. Select Add Port Or Net View from the context menu. CoMET displays the Fabric Module dialog, Port Or Net View tab. Fabric Module dialog, Port Or Net View tab, Properties panel.
CIF Peripheral Model - SimpleTimer Adding Behavioral Code We now implement the behavioral code associated with the Simple Timer device. In this section we discuss the recommended methodology and implementation details for the behavioral code. General Modeling Guidelines In designing VaST models we aim for speed and accuracy. The model should accurately model the hardware. It should execute as efficiently as possible, to save real time when simulating.
CIF Peripheral Model - SimpleTimer Consequently, the code modeling the GTR (General Timer Register) behavior calculates and updates the counter at the time of read or write. The tick count at the last time the counter was updated is tracked in an instance variable, LastCounterUpdateTime. The AmpiClockGetTicks function is used to determine the number of clock ticks since the clock started. The LastCounterUpdateTime holds timer clock tick count at the last update.
CIF Peripheral Model - SimpleTimer The CIF Peripheral Model Template The SimpleTimer project source files are created from the CIF (Communications and Infrastructure Fabric) Peripheral Model template. The template provides a general set of functions and structure. We add code within the supplied template functions and structures, and add additional functions for our specific callbacks and other requirements. Template Functions The table below shows functions supplied in the template.
CIF Peripheral Model - SimpleTimer initialization Instance Data structure and stores the module id and pathname in it. SimpleTimerInitTaskInstance Task initialization Modify to set up required instance data and callback data structures SimpleTimerTaskFunction Processing commences Unmodified. Simply suspends. Behavior is implemented with callbacks InitDll Unmodified empty function stub PreSymlinkInit Unmodified InitSymlink Unmodified. Sets value of pAmpiTaskId, used later by macros.
CIF Peripheral Model - SimpleTimer Events and Responses in Behavioral Code We can now review the Event and Response table derived from the specification, adding the information on how our behavioral code handles the response to events.
CIF Peripheral Model - SimpleTimer Declarations, Definitions and Instance Data Instance data stores the state of a particular instance of a model. Each instance of a Simple Timer device needs to maintain its own state, while all instances of a device share behavioral code. State is maintained in the instance data structure. This structure is defined in the header file SimpleTimer.h. This file can be found in the CoMET workspace: SimpleTimer/Folders/Header Files/SimpleTimer.
CIF Peripheral Model - SimpleTimer #define #define #define TIFR_SET_1 TIFR_SET_2 TIFR_SET_ALL 0x01 0x02 (TIFR_SET_1 | TIFR_SET_2) #define #define MATCH1_REGISTER 0 //array index MATCH2_REGISTER 1 //array index Defining the Callback Data Structure Define the following data structure immediately after the typedef for the instance struct, outside of the instance struct definition.
CIF Peripheral Model - SimpleTimer The default output section appears as follows: /* ** Output handles */ /* const tAmpiLogicHandleMaster */ *OutputName; Replace the commented-out line const tAmpiLogicHandleMaster *OutputName; with the following: CODE BEGINS const tAmpiLogicHandleMaster *MatchInterrupt[NUM_MATCH_REGISTERS]; CODE ENDS The default input handles section appears as follows: /* ** Input handles.
CIF Peripheral Model - SimpleTimer CODE ENDS Declaring Instance Data Callback Handles and Callback Data Structures Callback handles are used to register callback functions with the simulation engine. We will use callbacks for match events (i.e. timer matches a match registers value) and unmatch events (i.e. next callback after a match event, occurring on next clock tick).
CIF Peripheral Model - SimpleTimer Creating the Behavioral Functions We will add all behavioral code for the SimpleTimer device to the SimpleTimer.c file. This file can be found in the Workspace at SimpleTimer/Folders/Source Files/SimpleTimer.c. Double click on the SimpleTimer.c node to open the file for editing in the Document window.
CIF Peripheral Model - SimpleTimer ** Do nothing if in reset. */ if (IP->InReset) return; /* ** If match register index is -1, set up all match registers. ** Otherwise, set up the requested match register. */ if (MTR_ix == -1) { size_t j; for (j = 0; j < lengthof(IP->MatchInterrupt); j++) { SetupNextMatch(IP, j); } } else if ( MTR_ix >= 0 && (tWord32)MTR_ix < lengthof(IP->MatchInterrupt) ) { tWord32 Count; /* ** Cancel any existing "match" events for the match register.
CIF Peripheral Model - SimpleTimer if (IP->regMTR[MTR_ix] > Count) MatchTicks = IP->regMTR[MTR_ix] - Count; else MatchTicks = (tWord32)(ULL(0x100000000) + IP->regMTR[MTR_ix] - Count); /* ** Setup the timeout. */ AmpiTaskScheduleCallbackTicksAfterSync ( IP->MatchEvent[MTR_ix], MatchTicks, 0 ); } } } /** ** void ClearMatchInterrupts(const tInstanceData *IP, const tWord32 Mask) ** ** Clears match interrupts corresponding to the given bit mask. ** ** Parameters ** IP ** A pointer to the instance data.
CIF Peripheral Model - SimpleTimer ** Parameters ** p ** Pointer to a tTimerCallbackData structure. */ static void Match(void *p) { tTimerCallbackData *pCallbackData = (tTimerCallbackData *)p; tInstanceData *IP = pCallbackData->IP; tWord32 regMTRN = pCallbackData->regMTRN; /* ** Do nothing if in reset. */ if (IP->InReset) return; /* ** By definition of the match register, the count register ** must equal the match register.
CIF Peripheral Model - SimpleTimer return; /* ** Setup the next match. */ SetupNextMatch(pCallbackData->IP, pCallbackData->regMTRN); } CODE ENDS Modifying the Task Initialization Function The Task Initialization function runs once, after the Module Initialization function. In this function we obtain and store handles, set up data structures and perform other initialization functions. Search for the function SimpleTimerInitTaskInstance. To seach, choose Edit/Find or press Ctrl-F.
CIF Peripheral Model - SimpleTimer IP->BusClock = AmpiClockInitSlavePortView("BusClock", "All"); IP->Bus = AmpiStdBusInitSlavePortView("Bus", "All"); IP->Reset = AmpiLogicInitSlavePortView("Reset", "All"); Add the following after the IP->Reset line: CODE BEGINS IP->TimerClock = AmpiClockInitSlavePortView("TimerClock", "All"); CODE ENDS Setup callback data structures In the SimpleTimer.h instance structure we defined CallbackData, an array of tTimerCallbackData structures, one for each match register.
CIF Peripheral Model - SimpleTimer Modify module and version information function CoMET generates a call to print out model version information for the device. The default section within the SimpleTimerInitTaskInstance function looks similar to the following: /* ** Display the module banner with version number.
CIF Peripheral Model - SimpleTimer case StdLogicH: /* ** Deassert all outputs. */ IP->InReset = TRUE; AmpiLogicWrite(IP->MatchInterrupt[MATCH1_IX], StdLogicL); AmpiLogicWrite(IP->MatchInterrupt[MATCH2_IX], StdLogicL); // Cancel all "match" callbacks. AmpiTaskScheduleCallbackCancel(IP->MatchEvent[MATCH1_IX]); AmpiTaskScheduleCallbackCancel(IP->MatchEvent[MATCH2_IX]); // Cancel all "unmatch" callbacks.
CIF Peripheral Model - SimpleTimer ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** */ Description: Reads a device register. This function assumes that all registers are 4-bytes in length. It also assumes that all the registers are aligned on a 4-byte boundary. Parameters: IP A pointer to the instance data. Address The address of the register to be read. Untimed Flag is true if this function is called by the Untimed read. Returns: The 32-bit value read from the register.
CIF Peripheral Model - SimpleTimer Data = IP->regTIFR; #ifdef _DEBUG AmpiStreamPrintf(DEBUG_MSG, "%s: Read data %#06x from TIFR\n",IP->pModulePathName,Data); #endif break; case MTR1_OFFSET: Data = IP->regMTR[MATCH1_IX]; #ifdef _DEBUG AmpiStreamPrintf(DEBUG_MSG, "%s: Read data %#06x from MTR1\n",IP->pModulePathName,Data); #endif break; case MTR2_OFFSET: Data = IP->regMTR[MATCH2_IX]; #ifdef _DEBUG AmpiStreamPrintf(DEBUG_MSG, "%s: Read data %#06x from MTR2\n",IP->pModulePathName,Data); #endif break; default:
CIF Peripheral Model - SimpleTimer { This function is called by the BusWrite and BusUntimedWrite functions. The WriteRegister function is called each time there is a request to write data to a register from the bus. This function returns the value put on the bus. Often writing a register signifies the start of some event in the device. Callback functions are frequently scheduled from the WriteRegister function.
CIF Peripheral Model - SimpleTimer #ifdef _DEBUG AmpiStreamPrintf(DEBUG_MSG, "%s: Write data %#06x to TIER\n",IP->pModulePathName,Data); #endif if (IP->regTIER != (Data & TIER_ENABLE_ALL)) { IP->regTIER = Data & TIER_ENABLE_ALL; // Clear the match interrupts that are now disabled. ClearMatchInterrupts(IP, ~Data); // Reschedule the next match events.
CIF Peripheral Model - SimpleTimer CODE ENDS At this point it is appropriate to perform another build. See Building the Project, page 101. 1. Click on the build button to do a build of your device, if all of the code has been added correctly the device should build with no errors or warnings. NOTE: depending on where you placed your callback and helper functions you may need to create function prototypes for the callback and helper functions.
CIF Peripheral Model - SimpleTimer VSP and SimpleTimer Block Diagram Virtual System Prototype - SimpleVSP1 VastGpReset1 Reset ResetNet VastGpClock1 Clock ClockNet PlatformReset Virtual Platform - VirtualPlatform1 PlatformClock StdLogic0Net VastGpStdLogic01 Arm926ejs1 IrqNet Irq Fiq Clock Reset DataBus DataBusClock InstBus InstBusClock StdBus1 Bus SignalOut BusClockIn StdBus1Net StdBus1ClockNet GenericMemory1 Bus BusClock Reset SimpleTimer1 Bus BusClock MatchInterrupt1 MatchInterrupt2
CIF Peripheral Model - SimpleTimer Creating the SimpleTimer1 instance in the Virtual Platform In the CoMET Workspace, open the project Virtual Platform/Folders/Source Files and double click the VirtualPlatform.fmx file top open it in the Document window. In the VirtualPlatform.fmx file, right click the Module Instances node and choose Add Module Instance from the context menu.
CIF Peripheral Model - SimpleTimer Creating the IrqNet To add the IrqNet, right click the Virtual Platform Net nodes and choose Add Net. In the Fabric Module dialog, Net tab, Properties panel: Name: Type IrqNet Type: Select StdLogic Description: Type Net for connecting SimpleTimer1 MatchInterrupt Ports to VPM interrupt port. Click OK.
CIF Peripheral Model - SimpleTimer CoMET opens the Fabric Module dialog, Port Connect tab. Port Or Net Name: Select the required net or port from the list You can use any of the methods described in the SimpleVSP tutorial to add connections. See Adding Nets and Port Connections, page 43. Add the required Instance Port Connections to the SimpleTimer1 and the VPM module instances. 118 CoMET Version 5.
CIF Peripheral Model - SimpleTimer The final connections for the VirtualPlatform are as follows: Check the VPM Irq Instance Port Connection and all SimpleTimer1 Instance Port Connections. Other connections are retained from the SimpleVSP tutorial. CoMET Version 5.
CIF Peripheral Model - SimpleTimer Setting the SimpleTimer1 Base Address with a pcx Parameter Override Rebuild the system and open the SimpleVSP1 .pcx file. Change the value of the SimpleTimer1/Parameter Overrides/StartAddress to 0x90000000 Creating Target Code This tutorial does not cover creating target code for the full range of VPMs available. Here we present code for the ARM926EJS1. In the case of the ARM, the target code can be edited and compiled in a Target project from within the CoMET SEE.
CIF Peripheral Model - SimpleTimer #include "vastdef.h" #include "tspi.h" #include "printf_to_tspi.h" /* This section copied from SimpleTimer.h */ /* SimpleTimer register offsets. This section copied from SimpleTimer.
CIF Peripheral Model - SimpleTimer tWord32 interruptsReceived = 0; int main(void) { printf("Testing the SimpleTimer\n"); varm_enable_interrupts(); // enable the ARM interrupts enableMtr((tInt8) MTR_1); /* enable the Timer Match Timer 1 Register and Interrupt */ setSimpleTimerMtr((tWord32) MATCH_TEST_VALUE, (tInt8) MTR_1); /* set the value of the Match Timer */ while (interruptsReceived < MAX_INTERRUPTS){ int i; for (i = 0;i < MAX_LOOPS;i++){ } } TspiVpmStop(); } /* define any additional handlers required
CIF Peripheral Model - SimpleTimer case MTR_1: *mtr1Ptr break; case MTR_2: *mtr1Ptr break; case MTR_ALL: *mtr1Ptr *mtr2Ptr break; default: = time; = time; = time; = time; *mtr1Ptr = time; *mtr2Ptr = time; break; } } tWord32 getSimpleTimerMtr(tInt8 mtrId){ tWord32 *mtr1Ptr = (tWord32 *) MTR1_PTR; tWord32 *mtr2Ptr = (tWord32 *) MTR2_PTR; tWord32 value = 0; switch (mtrId) { case MTR_1: value = *mtr1Ptr; break; case MTR_2: value = *mtr1Ptr; break; default: value = -1; break; } return value; } void enableMt
CIF Peripheral Model - SimpleTimer break; } } void disableMtr(tInt8 mtrId){ tWord32 *terPtr = (tWord32 *) TER_PTR; tWord32 *tierPtr = (tWord32 *) TIER_PTR; switch (mtrId) { case MTR_1: *terPtr = *terPtr & ~ TER_ENABLE_1; *tierPtr = *tierPtr & ~ TIER_ENABLE_1; break; case MTR_2: *terPtr = *terPtr & ~ TER_ENABLE_2; *tierPtr = *tierPtr & ~ TIER_ENABLE_2; break; case MTR_ALL: *terPtr = TER_ENABLE_NONE; *tierPtr = TIER_ENABLE_NONE; break; default: *terPtr = TER_ENABLE_NONE; *tierPtr = TIER_ENABLE_NONE; break; }
CIF Peripheral Model - SimpleTimer Adding the Target Image After compiling the target code, you add the Target Image to the SimpleVSP1 Targets. See Adding a Target Image, page 69. The example above shows a target compiled for a SimpleVSP using the ARM926EJS1 VPM. Simulating SimpleVSP1 with SimpleTimer You can now simulate SimpleVSP1 with the SimpleTimer device and test target code. See Simulating SimpleVSP1, page 70.
CIF Peripheral Model - SimpleTimer /Top/VirtualPlatform1/VastGpStdLogic01 VaST GP Standard Logic 0 Module v3.0.0 /Top/VirtualPlatform1/GenericMemory1[0] VaST GP Memory Module v3.8.0: Start Address 0x0, Size 0x800000, Memory width 4 bytes /Top/VirtualPlatform1/GenericMemory1[1] VaST GP Memory Module v3.8.0: Start Address 0xa0000000, Size 0x4000000, Memory width 4 bytes /Top/VirtualPlatform1/GenericMemory1[2] VaST GP Memory Module v3.8.
CIF Peripheral Model - SimpleTimer • debug output from the SimpleTimer1 module instance lines beginning with Scheduler Debug: /Top/VirtualPlatform1/SimpleTimer1: • CoMET simulation statistics: lines beginning Total Instructions Executed SimpleTimer Release Configuration Software Window Output Sample output from the target code show, with the SimpleTimer model compiled in Debug configuration, and Metrix enabled, is as follows. Note that the SimpleTimer output is missing.
CIF Peripheral Model - SimpleTimer Metrix Output A Metrix trace shows the timing and details of instructions executed by the VPM. Probes show changes in Nets and Ports, such as the IrqNet and the StdBus1 Net. An extract from a sample Metrix output is shown below. This is around the point at which the SimpleTimer test target code writes MATCH_TEST_VALUE (0x0000FF00) to MTR1 (at address 0x90000028).