Home > User Support > CoverageMaster winAMS FAQ

CoverageMaster winAMS FAQ

Test Data Settings

301_01: How to test a function including a while() loop waiting for an external signal?

Question:

Within the function there is a while() loop that waits for a hardware signal with I/O control, and in order to break from the loop it is necessary to change the value of the I/O port during function execution. How can I get out of the while() loop waiting for a hardware signal?

Answer:

If there is a part of the function that monitors the I/O register signal, this part becomes a permanent loop during simulation and cannot be verified as is. If there is a loop due to I/O register signal monitoring, depending on the processing type, there are cases where you can exit the loop by the test data set in the CSV, and cases where you need to enter a macro in the startup command file.

(1) When simply waiting for the I/O register signal to turn ON.

#define PORT1 *(volatile unsigned chat *)0xffffff50 // port1
void sample()
{
        : process
    while ((PORT1 & 0x01) == 0); //End loop when bit0 is ON
        : process
}

In such a case, you can exit the while() loop by simply setting the value of the I/O port PORT1 to 0x01 as one of the test cases. Since the address of PORT1 is cast directly and there is no symbol information, in order to make this PORT1 an input item in the CSV file, from the "Unit Test CSV Settings" dialog click the "Add" button without a variable selected to add a variable to the Input.

From the "Add I/O" dialog, PORT1 can be handled as an input variable by specifying "Address" as the I/O type, "0xffffff50" for the address, and "unsigned char" for the variable type. "0xffffff50#U1#1" will be added to the Input list.

(2) When waiting for the signal to turn ON after clearing the I/O register in the function.

#define PORT1 *(volatile unsigned char *)0xffffff50 // port1
void sample()
{
        : process
    PORT1 = 0; // clear I/O register
    while ((PORT1 & 0x01)==0); //End loop when bit0 is ON
        : process
}

In this case, the I/O register is cleared immediately before monitoring the signal, so inputting data to the I/O register using method (1) above has no effect. In this case, the simulator function is used to rewrite the PORT1 value during function execution. This is done by defining a command (simulator script) in the startup command file that changes the value of PORT1 to 1 when the I/O register is referenced.

Add the following to the startup command file. This command executes a macro that sets the signal 0x01 to "PORT1" defined in dataset by using the PORT1 (address 0ffffff50h) reference (read) as a trigger.

; dataset macro definition
macro dataset
store/loc=1 0ffffff50h = 01h ; set signal 0x01 to PORT1
mend

; execute macro dataset when address 0xffffff50 is referenced
set do/read=0ffffff50h#1 dataset

[Reference Information]
The simulator commands used in the above macro can be referenced in the GAIO XAIL-Debugger User's Manual. This manual is located in C:\WinAMS\DOC\XAIL-Debugger.chm.

[Macro User Guide: Reference Information]
The following linked Macro User Guide PDF file explains how to use macros (simulator commands) set in the startup command file with numerous examples.


Related Technical Tips Search

Other technical tips in GAIO's web site can be searched for using the links below.

Search key word link: Loop Function | while Loop
Technical Tips Google Search


Information Links